]>
Commit | Line | Data |
---|---|---|
857510e8 | 1 | #include "extern.h" |
2 | #include "aClient.h" | |
3 | #include "flags.h" | |
4 | #include "options.h" | |
5 | #include "player.h" | |
6 | #include "item.h" | |
7 | #include "pouch.h" | |
8 | ||
9 | void do_store(char *u) | |
10 | { | |
11 | list<item*>::iterator item_iterator; | |
12 | item *tempItem; | |
13 | char *cmd = strtok(NULL, " "); | |
14 | char *num = strtok(NULL, " "); | |
857510e8 | 15 | int id; |
16 | aClient *user; | |
17 | Player *p; | |
18 | ||
19 | ||
20 | if (!cmd || !num) | |
21 | { | |
22 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
23 | notice(s_GameServ, u, " \ 2STORE SELL NUMBER\ 2"); | |
24 | notice(s_GameServ, u, " \ 2STORE BUY \1fNUMBER\1f\ 2"); | |
25 | return; | |
26 | } | |
27 | else if (!(user = find(u))) | |
28 | { | |
29 | log("Fatal Error: could not find %s in client list", u); | |
30 | return; | |
31 | } | |
32 | else if (isIgnore(user)) | |
33 | { | |
34 | #ifdef DEBUGMODE | |
35 | log("Ignoring %s.", user->getNick()); | |
36 | #endif | |
37 | return; | |
38 | } | |
39 | else if (!is_playing(user)) | |
40 | { | |
41 | notice(s_GameServ, u, "You must be playing to use the store!"); | |
42 | return; | |
43 | } | |
44 | else if (is_fighting(user)) | |
45 | { | |
46 | notice(s_GameServ, u, "You can't go to the store while fighting!"); | |
47 | return; | |
48 | } | |
49 | else if (!isAlive(user->stats)) | |
50 | { | |
51 | notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!"); | |
52 | return; | |
53 | } | |
54 | updateTS(user->stats); | |
55 | ||
56 | if (stricmp(cmd, "LIST") == 0) | |
57 | { | |
58 | if (stricmp(num, "WEAPONS") == 0) | |
59 | { | |
60 | notice(s_GameServ, u, "Welcome to Kain's Armory"); | |
61 | notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:"); | |
62 | for (item_iterator = store.begin(); item_iterator != store.end(); ++item_iterator) | |
63 | { | |
64 | if ((*item_iterator)->getType() == WEAPON) | |
65 | { | |
857510e8 | 66 | notice(s_GameServ, u, "%s%ld. %20s..........%ld", |
67 | ((*item_iterator)->getID() < 10 ? " " : ""), | |
68 | (*item_iterator)->getID(), (*item_iterator)->getName().c_str(), (*item_iterator)->price()); | |
69 | } | |
70 | } | |
71 | notice(s_GameServ, u, "To purchase a weapon, type /msg <S STORE BUY \ 2#\ 2."); | |
72 | notice(s_GameServ, u, "Where # is the weapon number from the menu above."); | |
73 | ||
74 | } | |
75 | else if (stricmp(num, "ARMOR") == 0) | |
76 | { | |
77 | notice(s_GameServ, u, "Welcome to Kain's Armory"); | |
78 | notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:"); | |
79 | for (item_iterator = store.begin(); item_iterator != store.end(); ++item_iterator) | |
80 | { | |
81 | if ((*item_iterator)->getType() == ARMOR) | |
82 | { | |
83 | notice(s_GameServ, u, "%s%ld. %20s..........%d", | |
84 | ((*item_iterator)->getID() < 10 ? " " : ""), | |
85 | (*item_iterator)->getID(), (*item_iterator)->getName().c_str(), | |
86 | (*item_iterator)->price()); | |
87 | } | |
88 | } | |
89 | ||
90 | notice(s_GameServ, u, "To purchase armor, type /msg <S store buy #"); | |
91 | notice(s_GameServ, u, "Where # is the armor number from the menu above."); | |
92 | } | |
93 | ||
94 | } | |
95 | else if (stricmp(cmd, "BUY") == 0) | |
96 | { | |
97 | p = user->stats; | |
98 | if (!num) | |
99 | { | |
100 | notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2"); | |
101 | return; | |
102 | } | |
103 | else | |
104 | { | |
105 | id = stringtoint(num); | |
106 | } | |
107 | ||
108 | if (!isstringnum(num)) | |
109 | { | |
110 | notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2"); | |
111 | return; | |
112 | } | |
113 | else if (!(tempItem = findStoreItemByID(id))) | |
114 | { | |
115 | notice(s_GameServ, u, "Sorry, we don't carry that item!"); | |
116 | return; | |
117 | } | |
118 | else if (p->getGold() < tempItem->price()) | |
119 | { | |
120 | notice(s_GameServ, u, "You can't afford to buy %s", tempItem->getName().c_str()); | |
121 | return; | |
122 | } | |
123 | else if (p->inventory->addItem(tempItem)) | |
124 | { | |
125 | notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", tempItem->getName().c_str()); | |
126 | p->subtractGold(tempItem->price()); | |
127 | notice(s_GameServ, u, "Don't forget to type /msg <S equip %ld", tempItem->getID()); | |
128 | } | |
129 | else | |
130 | { | |
131 | notice(s_GameServ, u, "You can't carry any more!"); | |
132 | } | |
133 | } | |
134 | else if (stricmp(cmd, "SELL" ) == 0) | |
135 | { | |
136 | itemContainer *tempContainer; | |
137 | p = user->stats; | |
138 | id = stringtoint(num); | |
139 | if (!isstringnum(num)) | |
140 | { | |
141 | notice(s_GameServ, u, "SYNTAX: /msg <S store sell #"); | |
142 | return; | |
143 | } | |
144 | else if (!(tempContainer = p->inventory->Find(id))) | |
145 | { | |
146 | notice(s_GameServ, u, "You're not carrying that!"); | |
147 | return; | |
148 | } | |
149 | else if (p->getGold() >= 2000000000) | |
150 | { | |
151 | notice(s_GameServ, u, "You have enough gold. Just hang on to it for now."); | |
152 | } | |
153 | else | |
154 | { | |
155 | tempItem = tempContainer->getItem(); | |
156 | ||
157 | notice(s_GameServ, u, "Thank you for your business! We gave you %ld gold for %s!", (tempItem->price() / 2), tempItem->getName().c_str()); | |
158 | p->addGold((tempItem->price() / 2)); | |
159 | p->inventory->deleteItem(tempItem); | |
160 | if (tempItem == p->getWeapon()) | |
161 | { | |
162 | notice(s_GameServ, u, "Since you equipped %s, you're going to have to reequip something", tempItem->getName().c_str()); | |
163 | tempItem->undo(p); | |
164 | p->clearWeapon(); | |
165 | } | |
166 | else if (tempItem == p->getArmor()) | |
167 | { | |
168 | tempItem->undo(p); | |
169 | notice(s_GameServ, u, "Since you equipped %s, you're going to have to reequip something", tempItem->getName().c_str()); | |
170 | p->clearArmor(); | |
171 | } | |
172 | } | |
173 | } | |
174 | else | |
175 | { | |
176 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
177 | notice(s_GameServ, u, " \ 2STORE SELL #\ 2"); | |
178 | notice(s_GameServ, u, " \ 2STORE BUY \1f#\1f\ 2"); | |
179 | return; | |
180 | } | |
181 | } |