]>
Commit | Line | Data |
---|---|---|
8f0f4c84 | 1 | #include "aClient.h" |
2 | #include "extern.h" | |
857510e8 | 3 | #include "options.h" |
8f0f4c84 | 4 | #include "flags.h" |
5 | #include "level.h" | |
6 | #include "player.h" | |
1781f48a | 7 | #include "item.h" |
8f0f4c84 | 8 | |
9 | ||
10 | void do_attack(char *u) | |
11 | { | |
1781f48a | 12 | int hit = 0, mhit = 0; |
8f0f4c84 | 13 | aClient *ni, *battle; // The player and perhaps the player they're fighting |
14 | Monster *fight; // The monster they may be fighting | |
fbb87959 | 15 | |
8f0f4c84 | 16 | if (!(ni = find(u))) |
17 | { | |
abb0a0b9 | 18 | notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) <S admin for help."); |
8f0f4c84 | 19 | return; |
20 | } | |
21 | else if (isIgnore(ni)) | |
22 | { | |
fbb87959 | 23 | #ifdef DEBUGMODE |
8f0f4c84 | 24 | log("Ignoring %s.", ni->getNick()); |
fbb87959 | 25 | #endif |
8f0f4c84 | 26 | return; |
27 | } | |
28 | else if (!is_playing(ni)) | |
29 | { | |
30 | notice(s_GameServ, u, "You're not playing!"); | |
31 | return; | |
32 | } | |
33 | else if (!is_fighting(ni)) | |
34 | { | |
35 | notice(s_GameServ, u, "You're not in battle!"); | |
36 | return; | |
37 | } | |
38 | else | |
39 | { | |
00e51ca8 | 40 | |
41 | fight = ni->stats->getMonster(); // Monster Could be NULL | |
fbb87959 | 42 | battle = ni->stats->getBattle(); // Player Could be NULL |
43 | ||
8f0f4c84 | 44 | // One has to be !NULL based on the previous else if |
45 | // We wouldn't be here if they were all NULL | |
46 | } | |
47 | updateTS(ni->stats); | |
fbb87959 | 48 | |
8f0f4c84 | 49 | if (!player_fight(ni)) |
50 | { | |
51 | // Player's Hit | |
fbb87959 | 52 | if ((ni->stats->getStrength() / 2) == 0) |
53 | { | |
54 | hit = 0; | |
55 | } | |
1781f48a | 56 | else |
fbb87959 | 57 | { |
58 | hit = (ni->stats->getStrength()/ 2) + (rand() % (ni->stats->getStrength() / 2)) - fight->defense; | |
59 | } | |
60 | ||
8f0f4c84 | 61 | // Opponent's Hit |
1781f48a | 62 | if ((fight->strength / 2) == 0) |
fbb87959 | 63 | { |
64 | mhit = 0; | |
65 | } | |
1781f48a | 66 | else |
fbb87959 | 67 | { |
68 | mhit = (fight->strength / 2) + | |
69 | (rand() % (fight->strength / 2) - (ni->stats->getDefense())); | |
70 | } | |
8f0f4c84 | 71 | } |
72 | else | |
73 | { | |
74 | // Opponent's Hit | |
fbb87959 | 75 | mhit = (((battle->stats->getStrength()) / 2) + |
76 | (rand() % ((battle->stats->getStrength())) / 2) - | |
77 | (ni->stats->getDefense())); | |
78 | ||
8f0f4c84 | 79 | // Player's Hit |
fbb87959 | 80 | hit = (((ni->stats->getStrength()) / 2) + |
81 | (rand() % ((ni->stats->getStrength())) / 2) - | |
82 | (battle->stats->getDefense())); | |
8f0f4c84 | 83 | } |
fbb87959 | 84 | |
8f0f4c84 | 85 | if (!player_fight(ni)) |
86 | { | |
87 | if (hit > 0) | |
1781f48a | 88 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 hp!", fight->name.c_str(), hit); |
8f0f4c84 | 89 | else |
90 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name.c_str()); | |
fbb87959 | 91 | |
8f0f4c84 | 92 | if (hit >= fight->hp) |
fbb87959 | 93 | { |
94 | if (master_fight(ni) && !dragon_fight(ni)) | |
95 | { | |
96 | notice(s_GameServ, u, "You have bested %s!", fight->name.c_str()); | |
97 | addNews(todaysnews, "%s has bested %s and moved "\ | |
98 | "to level %d", ni->stats->getName().c_str(), fight->name.c_str(), | |
99 | (ni->stats->getLevel() + 1)); | |
100 | } | |
101 | else | |
8f0f4c84 | 102 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name.c_str()); |
fbb87959 | 103 | |
104 | notice(s_GameServ, u, "%s", fight->death.c_str()); | |
105 | notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!", | |
8f0f4c84 | 106 | fight->exp, fight->gold); |
fbb87959 | 107 | |
108 | if (dragon_fight(ni)) | |
109 | { | |
110 | addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!"\ | |
111 | " %s is now watching over the Dragon's lair!", | |
112 | ni->stats->getName().c_str(), ni->stats->getName().c_str(), | |
113 | ni->stats->getMonster()->name.c_str(), ni->stats->getName().c_str()); | |
2ca6a3de | 114 | dragon.name = "Dragon " + ni->stats->getName(); |
fbb87959 | 115 | dragon.weapon = "Breath of Fire"; |
116 | dragon.strength = ni->stats->getStrength(); | |
117 | dragon.defense = ni->stats->getDefense(); | |
118 | dragon.hp = ni->stats->getMaxHP(); | |
119 | dragon.maxhp = ni->stats->getMaxHP(); | |
120 | save_dragon(); | |
121 | clearDragonFight(ni->stats); | |
122 | reset(ni->stats); | |
d7c069e2 | 123 | ni->stats->delMonster(); |
124 | return; | |
fbb87959 | 125 | } |
126 | ||
127 | ni->stats->addExp(fight->exp); | |
128 | ni->stats->addGold(fight->gold); | |
129 | ||
130 | if (master_fight(ni)) | |
131 | { | |
132 | notice(s_GameServ, u, "You are now level %d!", ni->stats->getLevel() + 1); | |
133 | notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!", | |
134 | strbonus[ni->stats->getLevel() - 1], defbonus[ni->stats->getLevel() - 1]); | |
135 | ||
136 | // Increase your level | |
137 | ||
138 | // Increase your maximum hit points | |
139 | ni->stats->addMaxHP(hpbonus[ni->stats->getLevel() - 1]); | |
140 | ||
141 | // Heal the player by setting hp to their max | |
142 | ni->stats->healall(); | |
143 | ||
144 | // Add to your strength | |
145 | ni->stats->addStrength(strbonus[ni->stats->getLevel() - 1]); | |
146 | ||
147 | // Add to your defensive power | |
148 | ni->stats->addDefense(defbonus[ni->stats->getLevel() - 1]); | |
149 | ||
150 | ni->stats->addLevel(1); | |
151 | ||
152 | } | |
153 | ||
154 | // They're dead so remove the pointer | |
155 | ni->stats->delMonster(); | |
156 | ||
157 | // Clear the pointer for your master | |
158 | ni->stats->delMaster(); | |
159 | ||
160 | return; | |
161 | } | |
8f0f4c84 | 162 | else |
fbb87959 | 163 | { |
164 | if (hit > 0) | |
8f0f4c84 | 165 | fight->hp -= hit; |
fbb87959 | 166 | if (mhit > 0) |
167 | { | |
168 | notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!", | |
8f0f4c84 | 169 | fight->name.c_str(), fight->weapon.c_str(), mhit); |
fbb87959 | 170 | } |
171 | else if (mhit <= 0) | |
8f0f4c84 | 172 | notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str()); |
fbb87959 | 173 | |
174 | if (mhit >= ni->stats->getHP()) | |
175 | { | |
176 | if (!master_fight(ni)) | |
177 | { | |
178 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name.c_str()); | |
179 | notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ | |
180 | "of your experience!"); | |
181 | addNews(todaysnews, "%s has been killed by %s!", | |
182 | ni->stats->getName().c_str(), fight->name.c_str()); | |
183 | ni->stats->setGold(0); | |
184 | ni->stats->subtractExp((long int)(ni->stats->getExp() * .10)); | |
185 | ni->stats->setHP(0); | |
186 | ni->stats->delMonster(); | |
187 | clearAlive(ni->stats); | |
188 | return; | |
189 | } | |
190 | else | |
191 | { | |
192 | notice(s_GameServ, u, "%s has bested you! You will have to wait "\ | |
193 | "until tomorrow to try again", ni->stats->getMaster()->name.c_str()); | |
194 | addNews(todaysnews, "%s tried to best %s and failed!", | |
195 | ni->stats->getName().c_str(), fight->name.c_str()); | |
196 | ni->stats->delMonster(); | |
197 | ni->stats->delMaster(); | |
198 | return; | |
199 | } | |
200 | } | |
201 | else | |
202 | { | |
203 | if (mhit > 0) | |
204 | ni->stats->subtractHP(mhit); | |
205 | display_monster(u); | |
206 | return; | |
207 | } | |
8f0f4c84 | 208 | } |
8f0f4c84 | 209 | } |
210 | else if (player_fight(ni)) | |
211 | { | |
212 | if (is_playing(battle)) | |
8f0f4c84 | 213 | { |
65326d0c | 214 | if (!isYourTurn(ni->stats) && isYourTurn(battle->stats)) |
fbb87959 | 215 | { |
216 | notice(s_GameServ, u, "Please wait until %s decides what to do!", | |
217 | battle->stats->getName().c_str()); | |
218 | return; | |
219 | } | |
65326d0c | 220 | else if (!isYourTurn(ni->stats) && !isYourTurn(battle->stats)) |
221 | { | |
222 | // If somehow the player vs. player fight hangs, give the turn to the first attacker | |
223 | setYourTurn(ni->stats); | |
224 | } | |
225 | if (hit > 0) | |
fbb87959 | 226 | { |
227 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->getName().c_str(), hit); | |
228 | ||
229 | notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\ | |
230 | "\ 2%d\ 2 damage!", ni->stats->getName().c_str(), | |
231 | (ni->stats->getWeapon() ? ni->stats->getWeapon()->getName().c_str() : "Fists"), hit); | |
232 | } | |
233 | else | |
234 | { | |
235 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->getName().c_str()); | |
236 | notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->getName().c_str()); | |
237 | } | |
238 | ||
239 | if (hit >= battle->stats->getHP()) | |
240 | { | |
241 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->stats->getName().c_str()); | |
242 | notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!", | |
243 | (long int)(battle->stats->getExp() * .10), battle->stats->getGold()); | |
8443f36d | 244 | addNews(todaysnews, "%s has defeated %s, leaving %s in a pool of blood", ni->stats->getName().c_str(), battle->stats->getName().c_str(), battle->stats->getName().c_str()); /* DrLnet - Modified by kain for news instead of just a message */ |
fbb87959 | 245 | notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", |
246 | ni->stats->getName().c_str()); | |
247 | battle->stats->setHP(0); | |
248 | clearAlive(battle->stats); | |
249 | ||
250 | ni->stats->addHP((long int)(battle->stats->getExp() * .10)); | |
251 | battle->stats->subtractExp((long int)(battle->stats->getExp() * .10)); | |
252 | ||
253 | notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\ | |
254 | "all gold on hand!"); | |
255 | ni->stats->addGold(battle->stats->getGold()); | |
256 | battle->stats->setGold(0); | |
257 | ||
258 | ||
259 | clearYourTurn(ni->stats); | |
260 | clearYourTurn(battle->stats); | |
261 | ||
262 | battle->stats->delBattle(); | |
263 | ni->stats->delBattle(); | |
264 | return; | |
265 | } | |
266 | else | |
267 | { | |
268 | if (hit > 0) | |
269 | battle->stats->subtractHP(hit); | |
e248e6be | 270 | |
fbb87959 | 271 | clearYourTurn(ni->stats); |
272 | setYourTurn(battle->stats); | |
273 | display_players(battle); | |
274 | notice(s_GameServ, u, "Please wait while %s decides what to do!", | |
275 | battle->stats->getName().c_str()); | |
276 | return; | |
277 | } | |
8f0f4c84 | 278 | } |
8f0f4c84 | 279 | } |
280 | } |