]>
jfr.im git - irc/gameservirc.git/blob - gameserv/do_attack.cpp
9 void do_attack(char *u
)
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
17 notice(s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help.");
20 else if (isIgnore(ni
))
23 log("Ignoring %s.", ni
->getNick());
27 else if (!is_playing(ni
))
29 notice(s_GameServ
, u
, "You're not playing!");
32 else if (!is_fighting(ni
))
34 notice(s_GameServ
, u
, "You're not in battle!");
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
44 battle
= ni
->stats
->battle
; // Player Could be NULL
46 // One has to be !NULL based on the previous else if
47 // We wouldn't be here if they were all NULL
51 if (!player_fight(ni
))
54 if ((ni
->stats
->strength
/ 2) == 0)
60 hit
= (ni
->stats
->strength
/ 2) + (rand() % (ni
->stats
->strength
/ 2)) - fight
->defense
;
64 if ((fight
->strength
/ 2) == 0)
70 mhit
= (fight
->strength
/ 2) +
71 (rand() % (fight
->strength
/ 2) - (ni
->stats
->defense
));
77 mhit
= (((battle
->stats
->strength
) / 2) +
78 (rand() % ((battle
->stats
->strength
)) / 2) -
79 (ni
->stats
->defense
));
82 hit
= (((ni
->stats
->strength
) / 2) +
83 (rand() % ((ni
->stats
->strength
)) / 2) -
84 (battle
->stats
->defense
));
87 if (!player_fight(ni
))
90 notice(s_GameServ
, u
, "You attack \1f%s\1f for \ 2%d\ 2 hp!", fight
->name
.c_str(), hit
);
92 notice(s_GameServ
, u
, "You miss \1f%s\1f completely!", fight
->name
.c_str());
96 if (master_fight(ni
) && !dragon_fight(ni
))
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));
104 notice(s_GameServ
, u
, "You have killed \ 2%s\ 2!", fight
->name
.c_str());
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
);
110 if (dragon_fight(ni
))
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
;
123 clearDragonFight(ni
->stats
);
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;
135 ni
->stats
->gold
+= fight
->gold
;
136 if (ni
->stats
->gold
< 0 || ni
->stats
->gold
> 2000000000)
137 ni
->stats
->gold
= 2000000000;
139 if (master_fight(ni
))
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]);
145 // Increase your level
147 // Increase your maximum hit points
148 ni
->stats
->maxhp
+= hpbonus
[ni
->stats
->level
- 1];
150 // Heal the player by setting hp to their max
151 ni
->stats
->hp
= ni
->stats
->maxhp
;
153 // Add to your strength
154 ni
->stats
->strength
+= strbonus
[ni
->stats
->level
- 1];
156 // Add to your defensive power
157 ni
->stats
->defense
+= defbonus
[ni
->stats
->level
- 1];
161 // Clear the pointer for your master
162 ni
->stats
->master
= NULL
;
165 // They're dead so remove the pointer
166 delete ni
->stats
->fight
;
167 ni
->stats
->fight
= NULL
;
168 ni
->stats
->master
= NULL
;
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
);
182 notice(s_GameServ
, u
, "%s completely misses you!", fight
->name
.c_str());
184 if (mhit
>= ni
->stats
->hp
)
186 if (!master_fight(ni
))
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());
194 ni
->stats
->exp
-= (long int)(ni
->stats
->exp
* .10);
196 ni
->stats
->fight
= NULL
;
197 clearAlive(ni
->stats
);
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
;
214 ni
->stats
->hp
-= mhit
;
220 else if (player_fight(ni
))
222 if (is_playing(battle
))
224 if (!isYourTurn(ni
->stats
))
226 notice(s_GameServ
, u
, "Please wait until %s decides what to do!",
227 battle
->stats
->name
.c_str());
232 notice(s_GameServ
, u
, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle
->stats
->name
.c_str(), hit
);
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
);
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());
244 if (hit
>= battle
->stats
->hp
)
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
);
254 ni
->stats
->exp
+= (long int)(battle
->stats
->exp
* .10);
255 battle
->stats
->exp
-= (long int)(battle
->stats
->exp
* .10);
257 if (ni
->stats
->exp
< 0 || ni
->stats
->exp
> 2000000000)
258 ni
->stats
->exp
= 2000000000;
260 if (2000000000 - ni
->stats
->gold
> battle
->stats
->gold
)
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;
269 battle
->stats
->gold
= 2000000000 - ni
->stats
->gold
;
270 notice(s_GameServ
, battle
->getNick(), "You lose ten percent of your experience!");
272 notice(s_GameServ
, battle
->getNick(), "However, %s could not carry all of your "\
273 "gold.", ni
->stats
->name
.c_str());
275 notice(s_GameServ
, battle
->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
276 "left. All is not lost!", battle
->stats
->gold
);
278 ni
->stats
->gold
= 2000000000;
280 clearYourTurn(ni
->stats
);
281 clearYourTurn(battle
->stats
);
282 battle
->stats
->battle
= NULL
;
283 ni
->stats
->battle
= NULL
;
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());