]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_attack.cpp
updated the Change log w/ new additions
[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
40 fight = ni->stats->getMonster(); // Monster Could be NULL
41 battle = ni->stats->getBattle(); // Player Could be NULL
42
43 // One has to be !NULL based on the previous else if
44 // We wouldn't be here if they were all NULL
45 }
46 updateTS(ni->stats);
47
48 if (!player_fight(ni))
49 {
50 // Player's Hit
51 if ((ni->stats->getStrength() / 2) == 0)
52 {
53 hit = 0;
54 }
55 else
56 {
57 hit = (ni->stats->getStrength()/ 2) + (rand() % (ni->stats->getStrength() / 2)) - fight->defense;
58 }
59
60 // Opponent's Hit
61 if ((fight->strength / 2) == 0)
62 {
63 mhit = 0;
64 }
65 else
66 {
67 mhit = (fight->strength / 2) +
68 (rand() % (fight->strength / 2) - (ni->stats->getDefense()));
69 }
70 }
71 else
72 {
73 // Opponent's Hit
74 mhit = (((battle->stats->getStrength()) / 2) +
75 (rand() % ((battle->stats->getStrength())) / 2) -
76 (ni->stats->getDefense()));
77
78 // Player's Hit
79 hit = (((ni->stats->getStrength()) / 2) +
80 (rand() % ((ni->stats->getStrength())) / 2) -
81 (battle->stats->getDefense()));
82 }
83
84 if (!player_fight(ni))
85 {
86 if (hit > 0)
87 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 hp!", fight->name.c_str(), hit);
88 else
89 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name.c_str());
90
91 if (hit >= fight->hp)
92 {
93 if (master_fight(ni) && !dragon_fight(ni))
94 {
95 notice(s_GameServ, u, "You have bested %s!", fight->name.c_str());
96 addNews(todaysnews, "%s has bested %s and moved "\
97 "to level %d", ni->stats->getName().c_str(), fight->name.c_str(),
98 (ni->stats->getLevel() + 1));
99 }
100 else
101 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name.c_str());
102
103 notice(s_GameServ, u, "%s", fight->death.c_str());
104 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
105 fight->exp, fight->gold);
106
107 if (dragon_fight(ni))
108 {
109 addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!"\
110 " %s is now watching over the Dragon's lair!",
111 ni->stats->getName().c_str(), ni->stats->getName().c_str(),
112 ni->stats->getMonster()->name.c_str(), ni->stats->getName().c_str());
113 dragon.name = "Dragon " + ni->stats->getName();
114 dragon.weapon = "Breath of Fire";
115 dragon.strength = ni->stats->getStrength();
116 dragon.defense = ni->stats->getDefense();
117 dragon.hp = ni->stats->getMaxHP();
118 dragon.maxhp = ni->stats->getMaxHP();
119 save_dragon();
120 clearDragonFight(ni->stats);
121 reset(ni->stats);
122 ni->stats->delMonster();
123 return;
124 }
125
126 ni->stats->addExp(fight->exp);
127 ni->stats->addGold(fight->gold);
128
129 if (master_fight(ni))
130 {
131 notice(s_GameServ, u, "You are now level %d!", ni->stats->getLevel() + 1);
132 notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!",
133 strbonus[ni->stats->getLevel() - 1], defbonus[ni->stats->getLevel() - 1]);
134
135 // Increase your level
136
137 // Increase your maximum hit points
138 ni->stats->addMaxHP(hpbonus[ni->stats->getLevel() - 1]);
139
140 // Heal the player by setting hp to their max
141 ni->stats->healall();
142
143 // Add to your strength
144 ni->stats->addStrength(strbonus[ni->stats->getLevel() - 1]);
145
146 // Add to your defensive power
147 ni->stats->addDefense(defbonus[ni->stats->getLevel() - 1]);
148
149 ni->stats->addLevel(1);
150
151 }
152
153 // They're dead so remove the pointer
154 ni->stats->delMonster();
155
156 // Clear the pointer for your master
157 ni->stats->delMaster();
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->getHP())
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->getName().c_str(), fight->name.c_str());
182 ni->stats->setGold(0);
183 ni->stats->subtractExp((long int)(ni->stats->getExp() * .10));
184 ni->stats->setHP(0);
185 ni->stats->delMonster();
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->getMaster()->name.c_str());
193 addNews(todaysnews, "%s tried to best %s and failed!",
194 ni->stats->getName().c_str(), fight->name.c_str());
195 ni->stats->delMonster();
196 ni->stats->delMaster();
197 return;
198 }
199 }
200 else
201 {
202 if (mhit > 0)
203 ni->stats->subtractHP(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->getName().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->getName().c_str(), hit);
222
223 notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
224 "\ 2%d\ 2 damage!", ni->stats->getName().c_str(),
225 (ni->stats->getWeapon() ? ni->stats->getWeapon()->getName().c_str() : "Fists"), hit);
226 }
227 else
228 {
229 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->getName().c_str());
230 notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->getName().c_str());
231 }
232
233 if (hit >= battle->stats->getHP())
234 {
235 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->stats->getName().c_str());
236 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
237 (long int)(battle->stats->getExp() * .10), battle->stats->getGold());
238 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 */
239 notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!",
240 ni->stats->getName().c_str());
241 battle->stats->setHP(0);
242 clearAlive(battle->stats);
243
244 ni->stats->addHP((long int)(battle->stats->getExp() * .10));
245 battle->stats->subtractExp((long int)(battle->stats->getExp() * .10));
246
247 notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\
248 "all gold on hand!");
249 ni->stats->addGold(battle->stats->getGold());
250 battle->stats->setGold(0);
251
252
253 clearYourTurn(ni->stats);
254 clearYourTurn(battle->stats);
255
256 battle->stats->delBattle();
257 ni->stats->delBattle();
258 return;
259 }
260 else
261 {
262 if (hit > 0)
263 battle->stats->subtractHP(hit);
264 clearYourTurn(ni->stats);
265 setYourTurn(battle->stats);
266 display_players(battle);
267 notice(s_GameServ, u, "Please wait while %s decides what to do!",
268 battle->stats->getName().c_str());
269 return;
270 }
271 }
272 }
273 }