]>
Commit | Line | Data |
---|---|---|
857510e8 | 1 | #include "extern.h" |
2 | #include "aClient.h" | |
3 | #include "flags.h" | |
4 | #include "options.h" | |
5 | #include "item.h" | |
6 | #include "pouch.h" | |
7 | ||
8 | void do_use(char *u) | |
9 | { | |
10 | aClient *user; | |
11 | pouch *p; | |
12 | ||
13 | char *item = strtok(NULL, " "); | |
14 | char *numuse = strtok(NULL, " "); | |
15 | int id, num; | |
16 | itemContainer *used; | |
17 | ||
18 | if (!item || int(item[0]) < 48 || int(item[0]) > 57 || (numuse && (int(numuse[0]) < 48 || int(numuse[0]) > 57))) | |
19 | { | |
20 | notice(s_GameServ, u, "SYNTAX: USE ####"); | |
21 | notice(s_GameServ, u, "Type /msg <S HELP USE for more information."); | |
22 | return; | |
23 | } | |
24 | else if (!(user = find(u))) | |
25 | { | |
26 | notice(s_GameServ, u, "Fatal Error in do_use. Contact a(n) <S Admin"); | |
27 | return; | |
28 | } | |
29 | else if (isIgnore(user)) | |
30 | { | |
31 | #ifdef DEBUGMODE | |
32 | log("Ignoring %s.", user->getNick()); | |
33 | #endif | |
34 | return; | |
35 | } | |
36 | else if (!is_playing(user)) | |
37 | { | |
38 | notice(s_GameServ, u, "You must be playing to use items!"); | |
39 | return; | |
40 | } | |
41 | id = stringtoint(item); | |
42 | ||
43 | if (!numuse) | |
44 | { | |
45 | num = 1; | |
46 | } | |
47 | else | |
48 | { | |
49 | num = stringtoint(numuse); | |
50 | } | |
51 | ||
52 | updateTS(user->stats); | |
53 | p = user->stats->inventory; | |
54 | ||
55 | ||
56 | if (!(used = p->Find(id))) | |
57 | { | |
58 | if (!p->isEmpty()) | |
59 | { | |
60 | notice(s_GameServ, u, "You aren't carrying that item!"); | |
61 | } | |
62 | showinventory(user->stats, user); | |
63 | } | |
64 | else if (used->getItem()->getType() != POTION) | |
65 | { | |
66 | notice(s_GameServ, u, "You can't use %s like that. Try /msg <S equip", used->getItem()->getName().c_str()); | |
67 | } | |
68 | else | |
69 | { | |
70 | // Use the item(s) | |
71 | if (num <= 1 || is_fighting(user)) | |
72 | { | |
73 | notice(s_GameServ, u, "You used %s.", used->getItem()->getName().c_str()); | |
74 | used->use(user->stats); | |
75 | if (used->getUses() <= 0) | |
76 | { | |
77 | p->deleteItem(used->getItem()); | |
78 | } | |
79 | end_turn(user); | |
80 | } | |
81 | else if (num > 1) | |
82 | { | |
83 | int count; | |
84 | const char *name = used->getItem()->getName().c_str(); | |
85 | for (count = 0; count < num; count++) | |
86 | { | |
87 | if (!(used = p->Find(id))) | |
88 | { | |
89 | break; | |
90 | } | |
91 | else | |
92 | { | |
93 | used->use(user->stats); | |
94 | if (used->getUses() == 0) | |
95 | { | |
96 | p->deleteItem(used->getItem()); | |
97 | } | |
98 | } | |
99 | } | |
100 | notice(s_GameServ, u, "You used %d %s's", count, name); | |
101 | } | |
102 | } | |
103 | } | |
104 |