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