]>
Commit | Line | Data |
---|---|---|
8ad9f659 | 1 | #include "item.h" |
37ed80a9 | 2 | #include "player.h" |
8ad9f659 | 3 | |
37ed80a9 | 4 | item::item() |
5 | { | |
6 | myname = "New Item"; | |
7 | myprice = 0; | |
8 | myuses = 0; | |
9 | for (int x = 0; x < 8; x++) | |
10 | mymodifiers[x] = 0; | |
11 | } | |
12 | ||
b6bf4226 | 13 | item::item(const char *name, long int p, int uses, long int identifier, int m1, int m2, int m3, int m4, int m5, int m6, int m7, int m8) |
8ad9f659 | 14 | { |
15 | myname = name; // string = char* | |
16 | myprice = p; | |
17 | myuses = uses; | |
18 | mymodifiers[0] = m1; | |
19 | mymodifiers[1] = m2; | |
20 | mymodifiers[2] = m3; | |
21 | mymodifiers[3] = m4; | |
22 | mymodifiers[4] = m5; | |
23 | mymodifiers[5] = m6; | |
24 | mymodifiers[6] = m7; | |
25 | mymodifiers[7] = m8; | |
b6bf4226 | 26 | id = identifier; |
8ad9f659 | 27 | } |
28 | ||
b6bf4226 | 29 | item::item(string name, long int p, int uses, long int identifier, int m1, int m2, int m3, int m4, int m5, int m6, int m7, int m8) |
8ad9f659 | 30 | { |
31 | myname = name; // string = char* | |
32 | myprice = p; | |
33 | myuses = uses; | |
34 | mymodifiers[0] = m1; | |
35 | mymodifiers[1] = m2; | |
36 | mymodifiers[2] = m3; | |
37 | mymodifiers[3] = m4; | |
38 | mymodifiers[4] = m5; | |
39 | mymodifiers[5] = m6; | |
40 | mymodifiers[6] = m7; | |
41 | mymodifiers[7] = m8; | |
b6bf4226 | 42 | id = identifier; |
8ad9f659 | 43 | } |
44 | ||
45 | item::~item() | |
46 | { | |
b6bf4226 | 47 | for (int x = 0; x < 8; x++) |
48 | { | |
49 | mymodifiers[x] = 0; | |
50 | } | |
51 | ||
52 | myuses = 0; | |
53 | myname = ""; | |
54 | myprice = 0; | |
55 | } | |
56 | ||
57 | void item::setType(type t) | |
58 | { | |
59 | mytype = t; | |
8ad9f659 | 60 | } |
61 | ||
26b17386 | 62 | bool item::operator<(const item &right) const |
63 | { | |
64 | return myname < right.myname; | |
65 | } | |
66 | ||
67 | bool item::operator>(const item &right) const | |
68 | { | |
69 | return myname > right.myname; | |
70 | } | |
71 | ||
72 | bool item::operator==(const item &right) const | |
73 | { | |
74 | return myname == right.myname; | |
75 | } | |
76 | ||
77 | bool item::operator!=(const item &right) const | |
78 | { | |
79 | return myname != right.myname; | |
80 | } | |
81 | ||
b6bf4226 | 82 | weapon::~weapon() |
83 | { | |
84 | } | |
85 | ||
8ad9f659 | 86 | bool weapon::use(Player *p) |
87 | { | |
88 | // weapon(char *name, int p=0, int uses = -1, int strength=0, int defense=0, int maxhp=0) | |
89 | if (myuses == 0) | |
90 | return false; | |
91 | else | |
92 | { | |
93 | p->strength += mymodifiers[0]; | |
94 | p->defense += mymodifiers[1]; | |
95 | p->maxhp += mymodifiers[2]; | |
96 | } | |
97 | ||
98 | if (myuses > 0) | |
99 | { | |
100 | myuses--; | |
101 | } | |
102 | return true; | |
103 | } | |
104 | ||
105 | void weapon::undo(Player *p) | |
106 | { | |
107 | p->strength -= mymodifiers[0]; | |
108 | p->defense -= mymodifiers[1]; | |
109 | p->maxhp -= mymodifiers[2]; | |
110 | } | |
111 | ||
b6bf4226 | 112 | bool weapon::setData(const char *dataStr) |
113 | { | |
114 | ||
115 | return true; | |
116 | } | |
117 | ||
118 | armor::~armor() | |
119 | { | |
120 | } | |
121 | ||
37ed80a9 | 122 | void armor::undo(Player *p) |
123 | { | |
124 | p->strength -= mymodifiers[0]; | |
125 | p->defense -= mymodifiers[1]; | |
126 | p->maxhp -= mymodifiers[2]; | |
127 | } | |
128 | ||
b6bf4226 | 129 | bool armor::setData(const char *dataStr) |
130 | { | |
131 | return true; | |
132 | } | |
133 | ||
37ed80a9 | 134 | bool armor::use(Player *p) |
135 | { | |
136 | // weapon(char *name, int p=0, int uses = -1, int strength=0, int defense=0, int maxhp=0) | |
137 | if (myuses == 0) | |
138 | return false; | |
139 | else | |
140 | { | |
141 | p->strength += mymodifiers[0]; | |
142 | p->defense += mymodifiers[1]; | |
143 | p->maxhp += mymodifiers[2]; | |
144 | } | |
145 | ||
146 | if (myuses > 0) | |
147 | { | |
148 | myuses--; | |
149 | } | |
150 | return true; | |
151 | } | |
152 | ||
8ad9f659 | 153 | bool potion::use(Player *p) |
154 | { | |
155 | // potion(char *name, int p=0, int uses = 1, int strength=0, int defense=0, int maxhp=0, int hp=0, int forest_fights=0, int player_fights=0, int gold=0, int bank=0) | |
156 | ||
157 | if (myuses == 0) | |
158 | return false; | |
159 | else | |
160 | { | |
161 | p->strength += mymodifiers[0]; | |
162 | p->defense += mymodifiers[1]; | |
163 | p->maxhp += mymodifiers[2]; | |
164 | p->hp += mymodifiers[3]; | |
165 | p->forest_fights += mymodifiers[4]; | |
166 | p->player_fights += mymodifiers[5]; | |
167 | p->gold += mymodifiers[6]; | |
168 | p->bank += mymodifiers[7]; | |
169 | } | |
170 | ||
171 | if (myuses > 0) | |
172 | { | |
173 | myuses--; | |
174 | } | |
175 | return true; | |
176 | } | |
37ed80a9 | 177 | |
178 | void potion::undo(Player *p) | |
179 | { | |
180 | return; | |
181 | } | |
b6bf4226 | 182 | |
183 | bool potion::setData(const char *dataStr) | |
184 | { | |
185 | ||
186 | return true; | |
187 | } | |
e696687e | 188 | |
189 | ||
190 | itemContainer::itemContainer() | |
191 | { | |
192 | myuses = 0; | |
193 | myitem = NULL; | |
194 | } | |
195 | ||
196 | itemContainer::itemContainer(item *i) | |
197 | { | |
198 | myuses = i->uses(); | |
199 | myitem = i; | |
200 | } | |
201 | itemContainer::itemContainer(const itemContainer &right) | |
202 | { | |
203 | myuses = right.myuses; | |
204 | myitem = right.myitem; | |
205 | } | |
206 | itemContainer::~itemContainer() | |
207 | { | |
208 | myuses = 0; | |
209 | myitem = NULL; | |
210 | } | |
211 | ||
212 | itemContainer &itemContainer::operator--() | |
213 | { | |
214 | --myuses; | |
215 | return *this; | |
216 | } | |
217 | ||
218 | itemContainer itemContainer::operator--(int) | |
219 | { | |
220 | itemContainer oldValue = *this; | |
221 | ||
222 | operator--(); | |
223 | ||
224 | return oldValue; | |
225 | } | |
226 | ||
227 | itemContainer &itemContainer::operator++() | |
228 | { | |
229 | ++myuses; | |
230 | ||
231 | return *this; | |
232 | } | |
233 | ||
234 | itemContainer itemContainer::operator++(int) | |
235 | { | |
236 | itemContainer oldValue = *this; | |
237 | ||
238 | operator++(); | |
239 | ||
240 | return oldValue; | |
241 | } | |
242 | ||
243 | void itemContainer::setItem(item *i) | |
244 | { | |
245 | myitem = i; | |
246 | } | |
247 | ||
248 | bool itemContainer::operator<(const itemContainer &right) const | |
249 | { | |
250 | return (*myitem < *right.myitem); | |
251 | } | |
252 | ||
253 | bool itemContainer::operator>(const itemContainer &right) const | |
254 | { | |
255 | return (*myitem > *right.myitem); | |
256 | } | |
257 | ||
258 | bool itemContainer::operator==(const itemContainer &right) const | |
259 | { | |
260 | return (*myitem == *right.myitem); | |
261 | } | |
262 | ||
263 | bool itemContainer::operator!=(const itemContainer &right) const | |
264 | { | |
265 | return (*myitem == *right.myitem); | |
266 | } |