]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_attack.cpp
fixed some of the special characters being displayed as ^B or ^_
[irc/gameservirc.git] / gameserv / do_attack.cpp
1 #include "aClient.h"
2 #include "extern.h"
3 #include "flags.h"
4 #include "level.h"
5 #include "player.h"
6 #include "item.h"
7
8
9 void do_attack(char *u)
10 {
11 int hit = 0, mhit = 0;
12 aClient *ni, *battle; // The player and perhaps the player they're fighting
13 Monster *fight; // The monster they may be fighting
14
15 if (!(ni = find(u)))
16 {
17 notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) %S admin for help.");
18 return;
19 }
20 else if (isIgnore(ni))
21 {
22 #ifdef DEBUGMODE
23 log("Ignoring %s.", ni->getNick());
24 #endif
25 return;
26 }
27 else if (!is_playing(ni))
28 {
29 notice(s_GameServ, u, "You're not playing!");
30 return;
31 }
32 else if (!is_fighting(ni))
33 {
34 notice(s_GameServ, u, "You're not in battle!");
35 return;
36 }
37 else
38 {
39 if (!ni->stats->master) // This is not a master fight
40 fight = ni->stats->fight; // Monster Could be NULL
41 else // This IS a master fight
42 fight = ni->stats->master; // Master Could be NULL
43
44 battle = ni->stats->battle; // Player Could be NULL
45
46 // One has to be !NULL based on the previous else if
47 // We wouldn't be here if they were all NULL
48 }
49 updateTS(ni->stats);
50
51 if (!player_fight(ni))
52 {
53 // Player's Hit
54 if ((ni->stats->strength / 2) == 0)
55 {
56 hit = 0;
57 }
58 else
59 {
60 hit = (ni->stats->strength / 2) + (rand() % (ni->stats->strength / 2)) - fight->defense;
61 }
62
63 // Opponent's Hit
64 if ((fight->strength / 2) == 0)
65 {
66 mhit = 0;
67 }
68 else
69 {
70 mhit = (fight->strength / 2) +
71 (rand() % (fight->strength / 2) - (ni->stats->defense));
72 }
73 }
74 else
75 {
76 // Opponent's Hit
77 mhit = (((battle->stats->strength) / 2) +
78 (rand() % ((battle->stats->strength)) / 2) -
79 (ni->stats->defense));
80
81 // Player's Hit
82 hit = (((ni->stats->strength) / 2) +
83 (rand() % ((ni->stats->strength)) / 2) -
84 (battle->stats->defense));
85 }
86
87 if (!player_fight(ni))
88 {
89 if (hit > 0)
90 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 hp!", fight->name.c_str(), hit);
91 else
92 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name.c_str());
93
94 if (hit >= fight->hp)
95 {
96 if (master_fight(ni) && !dragon_fight(ni))
97 {
98 notice(s_GameServ, u, "You have bested %s!", fight->name.c_str());
99 addNews(todaysnews, "%s has bested %s and moved "\
100 "to level %d", ni->stats->name.c_str(), fight->name.c_str(),
101 (ni->stats->level + 1));
102 }
103 else
104 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name.c_str());
105
106 notice(s_GameServ, u, "%s", fight->death.c_str());
107 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
108 fight->exp, fight->gold);
109
110 if (dragon_fight(ni))
111 {
112 addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!"\
113 " %s is now watching over the Dragon's lair!",
114 ni->stats->name.c_str(), ni->stats->name.c_str(),
115 ni->stats->fight->name.c_str(), ni->stats->name.c_str());
116 dragon.name = "DRAGON-" + ni->stats->name;
117 dragon.weapon = "Breath of Fire";
118 dragon.strength = ni->stats->strength;
119 dragon.defense = ni->stats->defense;
120 dragon.hp = ni->stats->maxhp;
121 dragon.maxhp = ni->stats->maxhp;
122 save_dragon();
123 clearDragonFight(ni->stats);
124 reset(ni->stats);
125 }
126
127 // If your new experience (or gold) will be greater than 2 billion,
128 // then set your exp to 2bil. (2 billion max)... otherwise add them.
129 // This could be a problem with overflowing out of the sign bit.
130 // Unsigned long int maybe? Leave it for now.
131 ni->stats->exp += fight->exp;
132 if (ni->stats->exp < 0 || ni->stats->exp > 2000000000)
133 ni->stats->exp = 2000000000;
134
135 ni->stats->gold += fight->gold;
136 if (ni->stats->gold < 0 || ni->stats->gold > 2000000000)
137 ni->stats->gold = 2000000000;
138
139 if (master_fight(ni))
140 {
141 notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1);
142 notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!",
143 strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]);
144
145 // Increase your level
146
147 // Increase your maximum hit points
148 ni->stats->maxhp += hpbonus[ni->stats->level - 1];
149
150 // Heal the player by setting hp to their max
151 ni->stats->hp = ni->stats->maxhp;
152
153 // Add to your strength
154 ni->stats->strength += strbonus[ni->stats->level - 1];
155
156 // Add to your defensive power
157 ni->stats->defense += defbonus[ni->stats->level - 1];
158
159 ni->stats->level++;
160
161 // Clear the pointer for your master
162 ni->stats->master = NULL;
163 }
164
165 // They're dead so remove the pointer
166 delete ni->stats->fight;
167 ni->stats->fight = NULL;
168 ni->stats->master = NULL;
169
170 return;
171 }
172 else
173 {
174 if (hit > 0)
175 fight->hp -= hit;
176 if (mhit > 0)
177 {
178 notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
179 fight->name.c_str(), fight->weapon.c_str(), mhit);
180 }
181 else if (mhit <= 0)
182 notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str());
183
184 if (mhit >= ni->stats->hp)
185 {
186 if (!master_fight(ni))
187 {
188 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name.c_str());
189 notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
190 "of your experience!");
191 addNews(todaysnews, "%s has been killed by %s!",
192 ni->stats->name.c_str(), fight->name.c_str());
193 ni->stats->gold = 0;
194 ni->stats->exp -= (long int)(ni->stats->exp * .10);
195 ni->stats->hp = 0;
196 ni->stats->fight = NULL;
197 clearAlive(ni->stats);
198 return;
199 }
200 else
201 {
202 notice(s_GameServ, u, "%s has bested you! You will have to wait "\
203 "until tomorrow to try again", ni->stats->master->name.c_str());
204 addNews(todaysnews, "%s tried to best %s and failed!",
205 ni->stats->name.c_str(), fight->name.c_str());
206 ni->stats->fight = NULL;
207 ni->stats->master = NULL;
208 return;
209 }
210 }
211 else
212 {
213 if (mhit > 0)
214 ni->stats->hp -= mhit;
215 display_monster(u);
216 return;
217 }
218 }
219 }
220 else if (player_fight(ni))
221 {
222 if (is_playing(battle))
223 {
224 if (!isYourTurn(ni->stats))
225 {
226 notice(s_GameServ, u, "Please wait until %s decides what to do!",
227 battle->stats->name.c_str());
228 return;
229 }
230 if (hit > 0)
231 {
232 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->name.c_str(), hit);
233
234 notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
235 "\ 2%d\ 2 damage!", ni->stats->name.c_str(),
236 (ni->stats->getWeapon() ? ni->stats->getWeapon()->getName().c_str() : "Fists"), hit);
237 }
238 else
239 {
240 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->name.c_str());
241 notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name.c_str());
242 }
243
244 if (hit >= battle->stats->hp)
245 {
246 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->stats->name.c_str());
247 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
248 (long int)(battle->stats->exp * .10), battle->stats->gold);
249 notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!",
250 ni->stats->name.c_str());
251 battle->stats->hp = 0;
252 clearAlive(battle->stats);
253
254 ni->stats->exp += (long int)(battle->stats->exp * .10);
255 battle->stats->exp -= (long int)(battle->stats->exp * .10);
256
257 if (ni->stats->exp < 0 || ni->stats->exp > 2000000000)
258 ni->stats->exp = 2000000000;
259
260 if (2000000000 - ni->stats->gold > battle->stats->gold)
261 {
262 notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\
263 "all gold on hand!");
264 ni->stats->gold += battle->stats->gold;
265 battle->stats->gold = 0;
266 }
267 else
268 {
269 battle->stats->gold = 2000000000 - ni->stats->gold;
270 notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!");
271
272 notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\
273 "gold.", ni->stats->name.c_str());
274
275 notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
276 "left. All is not lost!", battle->stats->gold);
277
278 ni->stats->gold = 2000000000;
279 }
280 clearYourTurn(ni->stats);
281 clearYourTurn(battle->stats);
282 battle->stats->battle = NULL;
283 ni->stats->battle = NULL;
284 return;
285 }
286 else
287 {
288 if (hit > 0)
289 battle->stats->hp -= hit;
290 clearYourTurn(ni->stats);
291 setYourTurn(battle->stats);
292 display_players(battle);
293 notice(s_GameServ, u, "Please wait while %s decides what to do!",
294 battle->stats->name.c_str());
295 return;
296 }
297 }
298 }
299 }