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