]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_attack.cpp
Consolidated monster data into a single .dat file
[irc/gameservirc.git] / gameserv / do_attack.cpp
1 #include "aClient.h"
2 #include "extern.h"
3 #include "options.h"
4 #include "flags.h"
5 #include "level.h"
6 #include "player.h"
7 #include "item.h"
8
9
10 void do_attack(char *u)
11 {
12 int hit = 0, mhit = 0;
13 aClient *ni, *battle; // The player and perhaps the player they're fighting
14 Monster *fight; // The monster they may be fighting
15
16 if (!(ni = find(u)))
17 {
18 notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) <S admin for help.");
19 return;
20 }
21 else if (isIgnore(ni))
22 {
23 #ifdef DEBUGMODE
24 log("Ignoring %s.", ni->getNick());
25 #endif
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 {
40
41 fight = ni->stats->getMonster(); // Monster Could be NULL
42 battle = ni->stats->getBattle(); // Player Could be NULL
43
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);
48
49 if (!player_fight(ni))
50 {
51 // Player's Hit
52 if ((ni->stats->getStrength() / 2) == 0)
53 {
54 hit = 0;
55 }
56 else
57 {
58 hit = (ni->stats->getStrength()/ 2) + (rand() % (ni->stats->getStrength() / 2)) - fight->defense;
59 }
60
61 // Opponent's Hit
62 if ((fight->strength / 2) == 0)
63 {
64 mhit = 0;
65 }
66 else
67 {
68 mhit = (fight->strength / 2) +
69 (rand() % (fight->strength / 2) - (ni->stats->getDefense()));
70 }
71 }
72 else
73 {
74 // Opponent's Hit
75 mhit = (((battle->stats->getStrength()) / 2) +
76 (rand() % ((battle->stats->getStrength())) / 2) -
77 (ni->stats->getDefense()));
78
79 // Player's Hit
80 hit = (((ni->stats->getStrength()) / 2) +
81 (rand() % ((ni->stats->getStrength())) / 2) -
82 (battle->stats->getDefense()));
83 }
84
85 if (!player_fight(ni))
86 {
87 if (hit > 0)
88 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 hp!", fight->name.c_str(), hit);
89 else
90 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name.c_str());
91
92 if (hit >= fight->hp)
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
102 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name.c_str());
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!",
106 fight->exp, fight->gold);
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());
114 dragon.name = "Dragon " + ni->stats->getName();
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);
123 ni->stats->delMonster();
124 return;
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 }
162 else
163 {
164 if (hit > 0)
165 fight->hp -= hit;
166 if (mhit > 0)
167 {
168 notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
169 fight->name.c_str(), fight->weapon.c_str(), mhit);
170 }
171 else if (mhit <= 0)
172 notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str());
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 }
208 }
209 }
210 else if (player_fight(ni))
211 {
212 if (is_playing(battle))
213 {
214 if (!isYourTurn(ni->stats) && isYourTurn(battle->stats))
215 {
216 notice(s_GameServ, u, "Please wait until %s decides what to do!",
217 battle->stats->getName().c_str());
218 return;
219 }
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)
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());
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 */
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);
270
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 }
278 }
279 }
280 }