]>
jfr.im git - irc/gameservirc.git/blob - gameserv/do_attack.cpp
9 void do_attack(char *u
)
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 hit
= ((ni
->stats
->strength
+ webonus
[ni
->stats
->wea
]) / 2) +
55 (rand() % ((ni
->stats
->strength
+ webonus
[ni
->stats
->wea
]) / 2)) -
59 mhit
= (fight
->strength
/ 2) +
60 (rand() % (fight
->strength
/ 2) - (ni
->stats
->defense
+
61 arbonus
[ni
->stats
->arm
]));
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
]));
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
]));
76 if (!player_fight(ni
))
79 notice(s_GameServ
, u
, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight
->name
.c_str(), hit
);
81 notice(s_GameServ
, u
, "You miss \1f%s\1f completely!", fight
->name
.c_str());
85 if (master_fight(ni
) && !dragon_fight(ni
))
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));
93 notice(s_GameServ
, u
, "You have killed \ 2%s\ 2!", fight
->name
.c_str());
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
);
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
;
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
];
109 dragon
.hp
= ni
->stats
->maxhp
;
110 dragon
.maxhp
= ni
->stats
->maxhp
;
112 clearDragonFight(ni
->stats
);
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;
124 ni
->stats
->gold
+= fight
->gold
;
125 if (ni
->stats
->gold
< 0 || ni
->stats
->gold
> 2000000000)
126 ni
->stats
->gold
= 2000000000;
128 if (master_fight(ni
))
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]);
134 // Increase your level
136 // Increase your maximum hit points
137 ni
->stats
->maxhp
+= hpbonus
[ni
->stats
->level
- 1];
139 // Heal the player by setting hp to their max
140 ni
->stats
->hp
= ni
->stats
->maxhp
;
142 // Add to your strength
143 ni
->stats
->strength
+= strbonus
[ni
->stats
->level
- 1];
145 // Add to your defensive power
146 ni
->stats
->defense
+= defbonus
[ni
->stats
->level
- 1];
150 // Clear the pointer for your master
151 ni
->stats
->master
= NULL
;
154 // They're dead so remove the pointer
155 delete ni
->stats
->fight
;
156 ni
->stats
->fight
= NULL
;
157 ni
->stats
->master
= NULL
;
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
);
171 notice(s_GameServ
, u
, "%s completely misses you!", fight
->name
.c_str());
173 if (mhit
>= ni
->stats
->hp
)
175 if (!master_fight(ni
))
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());
183 ni
->stats
->exp
-= (long int)(ni
->stats
->exp
* .10);
185 ni
->stats
->fight
= NULL
;
186 clearAlive(ni
->stats
);
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
;
203 ni
->stats
->hp
-= mhit
;
209 else if (player_fight(ni
))
211 if (is_playing(battle
))
213 if (!isYourTurn(ni
->stats
))
215 notice(s_GameServ
, u
, "Please wait until %s decides what to do!",
216 battle
->stats
->name
.c_str());
221 notice(s_GameServ
, u
, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle
->stats
->name
.c_str(), hit
);
223 notice(s_GameServ
, battle
->getNick(), "%s has hit you with their %s for "\
224 "^B%d^B damage!", ni
->stats
->name
.c_str(),
225 weapons
[ni
->stats
->wea
], hit
);
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());
233 if (hit
>= battle
->stats
->hp
)
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
);
243 ni
->stats
->exp
+= (long int)(battle
->stats
->exp
* .10);
244 battle
->stats
->exp
-= (long int)(battle
->stats
->exp
* .10);
246 if (ni
->stats
->exp
< 0 || ni
->stats
->exp
> 2000000000)
247 ni
->stats
->exp
= 2000000000;
249 if (2000000000 - ni
->stats
->gold
> battle
->stats
->gold
)
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;
258 battle
->stats
->gold
= 2000000000 - ni
->stats
->gold
;
259 notice(s_GameServ
, battle
->getNick(), "You lose ten percent of your experience!");
261 notice(s_GameServ
, battle
->getNick(), "However, %s could not carry all of your "\
262 "gold.", ni
->stats
->name
.c_str());
264 notice(s_GameServ
, battle
->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
265 "left. All is not lost!", battle
->stats
->gold
);
267 ni
->stats
->gold
= 2000000000;
269 clearYourTurn(ni
->stats
);
270 clearYourTurn(battle
->stats
);
271 battle
->stats
->battle
= NULL
;
272 ni
->stats
->battle
= NULL
;
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());