]> jfr.im git - irc/gameservirc.git/blame - gameserv/do_attack.cpp
removed currentdragon.dat
[irc/gameservirc.git] / gameserv / do_attack.cpp
CommitLineData
8f0f4c84 1
2#include "aClient.h"
3#include "extern.h"
4#include "flags.h"
5#include "level.h"
6#include "player.h"
7
8
9void do_attack(char *u)
10{
11 int hit, mhit;
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 hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
55 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
56
57 // Opponent's Hit
58 mhit = (fight->strength / 2) +
59 (rand() % (fight->strength / 2) - (ni->stats->defense +
60 arbonus[ni->stats->armor]));
61 }
62 else
63 {
64 // Opponent's Hit
65 mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
66 (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
67 (ni->stats->defense + arbonus[ni->stats->armor]));
68
69 // Player's Hit
70 hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
71 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) -
72 (battle->stats->defense + arbonus[battle->stats->armor]));
73 }
74
75 if (!player_fight(ni))
76 {
77 if (hit > 0)
78 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name.c_str(), hit);
79 else
80 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name.c_str());
81
82 if (hit >= fight->hp)
83 {
84 if (master_fight(ni) && !dragon_fight(ni))
85 {
86 notice(s_GameServ, u, "You have bested %s!", fight->name.c_str());
87 addNews(todaysnews, "%s has bested %s and moved "\
88 "to level %d", ni->stats->name.c_str(), fight->name.c_str(),
89 (ni->stats->level + 1));
90 }
91 else
92 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name.c_str());
93
94 notice(s_GameServ, u, "%s", fight->death.c_str());
95 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
96 fight->exp, fight->gold);
97
98 if (dragon_fight(ni))
99 {
100 addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!",
101 ni->stats->name.c_str(), ni->stats->name.c_str(),
102 ni->stats->master->name.c_str());
103 ni->stats->master = NULL; // Don't progress in levels
104 }
105
106 // If your new experience (or gold) will be greater than 2 billion,
107 // then set your exp to 2bil. (2 billion max)... otherwise add them.
108 // This could be a problem with overflowing out of the sign bit.
109 // Unsigned long int maybe? Leave it for now.
110 ni->stats->exp += fight->exp;
111 if (ni->stats->exp < 0 || ni->stats->exp > 2000000000)
112 ni->stats->exp = 2000000000;
113
114 ni->stats->gold += fight->gold;
115 if (ni->stats->gold < 0 || ni->stats->gold > 2000000000)
116 ni->stats->gold = 2000000000;
117
118 if (master_fight(ni))
119 {
120 notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1);
121 notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!",
122 strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]);
123
124 // Increase your level
125
126 // Increase your maximum hit points
127 ni->stats->maxhp += hpbonus[ni->stats->level - 1];
128
129 // Heal the player by setting hp to their max
130 ni->stats->hp = ni->stats->maxhp;
131
132 // Add to your strength
133 ni->stats->strength += strbonus[ni->stats->level - 1];
134
135 // Add to your defensive power
136 ni->stats->defense += defbonus[ni->stats->level - 1];
137
138 ni->stats->level++;
139
140 // Clear the pointer for your master
141 ni->stats->master = NULL;
142 }
143
144 // They're dead so remove the pointer
145 delete ni->stats->fight;
146 ni->stats->fight = NULL;
147 ni->stats->master = NULL;
148
149 return;
150 }
151 else
152 {
153 if (hit > 0)
154 fight->hp -= hit;
155 if (mhit > 0)
156 {
157 notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
158 fight->name.c_str(), fight->weapon.c_str(), mhit);
159 }
160 else if (mhit <= 0)
161 notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str());
162
163 if (mhit >= ni->stats->hp)
164 {
165 if (!master_fight(ni))
166 {
167 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name.c_str());
168 notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
169 "of your experience!");
170 addNews(todaysnews, "%s has been killed by %s!",
171 ni->stats->name.c_str(), fight->name.c_str());
172 ni->stats->gold = 0;
173 ni->stats->exp -= (long int)(ni->stats->exp * .10);
174 ni->stats->hp = 0;
175 ni->stats->fight = NULL;
176 clearAlive(ni->stats);
177 return;
178 }
179 else
180 {
181 notice(s_GameServ, u, "%s has bested you! You will have to wait "\
182 "until tomorrow to try again", ni->stats->master->name.c_str());
183 addNews(todaysnews, "%s tried to best %s and failed!",
184 ni->stats->name.c_str(), fight->name.c_str());
185 ni->stats->fight = NULL;
186 ni->stats->master = NULL;
187 return;
188 }
189 }
190 else
191 {
192 if (mhit > 0)
193 ni->stats->hp -= mhit;
194 display_monster(u);
195 return;
196 }
197 }
198 }
199 else if (player_fight(ni))
200 {
201 if (is_playing(battle))
202 {
203 if (!isYourTurn(ni->stats))
204 {
205 notice(s_GameServ, u, "Please wait until %s decides what to do!",
206 battle->stats->name.c_str());
207 return;
208 }
209 if (hit > 0)
210 {
211 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->name.c_str(), hit);
212
213 notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
214 "^B%d^B damage!", ni->stats->name.c_str(),
215 weapons[ni->stats->weapon], hit);
216 }
217 else
218 {
219 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->name.c_str());
220 notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name.c_str());
221 }
222
223 if (hit >= battle->stats->hp)
224 {
225 notice(s_GameServ, u, "You have killed ^\ 2%s\ 2!", battle->stats->name.c_str());
226 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
227 (long int)(battle->stats->exp * .10), battle->stats->gold);
228 notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!",
229 ni->stats->name.c_str());
230 battle->stats->hp = 0;
231 clearAlive(battle->stats);
232
233 ni->stats->exp += (long int)(battle->stats->exp * .10);
234 battle->stats->exp -= (long int)(battle->stats->exp * .10);
235
236 if (ni->stats->exp < 0 || ni->stats->exp > 2000000000)
237 ni->stats->exp = 2000000000;
238
239 if (2000000000 - ni->stats->gold > battle->stats->gold)
240 {
241 notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\
242 "all gold on hand!");
243 ni->stats->gold += battle->stats->gold;
244 battle->stats->gold = 0;
245 }
246 else
247 {
248 battle->stats->gold = 2000000000 - ni->stats->gold;
249 notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!");
250
251 notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\
252 "gold.", ni->stats->name.c_str());
253
254 notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
255 "left. All is not lost!", battle->stats->gold);
256
257 ni->stats->gold = 2000000000;
258 }
259 clearYourTurn(ni->stats);
260 clearYourTurn(battle->stats);
261 battle->stats->battle = NULL;
262 ni->stats->battle = NULL;
263 return;
264 }
265 else
266 {
267 if (hit > 0)
268 battle->stats->hp -= hit;
269 clearYourTurn(ni->stats);
270 setYourTurn(battle->stats);
271 display_players(battle);
272 notice(s_GameServ, u, "Please wait while %s decides what to do!",
273 battle->stats->name.c_str());
274 return;
275 }
276 }
277 }
278}