]>
jfr.im git - irc/gameservirc.git/blob - gameserv/misc.cpp
1 /* This file includes miscellaneous functions that shouldn't be in gameserv.cpp */
13 void see_master(char *u
)
17 if (!(user
= find(u
)))
19 notice(s_GameServ
, u
, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL
, ""));
23 if (!is_fighting(user
) && is_playing(user
))
25 Player
*p
= user
->stats
;
26 p
->setMyMaster(&levels
[p
->getLevel() - 1].master
);
27 p
->setMonster(&levels
[p
->getLevel() - 1].master
);
28 display_monster(u
); // Since master is the same structure, use this function
34 list
<Player
*>::iterator iter
;
35 for (unsigned long x
= 0; x
< U_TABLE_SIZE
; x
++)
37 for (iter
= players
[x
].begin(); iter
!= players
[x
].end(); iter
++)
45 list
<Player
*>::iterator iter
;
46 for (unsigned long x
= 0; x
< U_TABLE_SIZE
; x
++)
48 for (iter
= players
[x
].begin(); iter
!= players
[x
].end(); iter
++)
55 void rollover(Player
*p
)
60 p
->addForestFights(numrolloverfights
);
62 if (p
->getForestFights() > maxforestfights
)
63 p
->setForestFights(maxforestfights
);
66 void refresh(Player
*p
)
71 if (p
->getHP() < p
->getMaxHP())
73 if (p
->getForestFights() < forestfights
)
75 p
->setForestFights(forestfights
);
78 p
->setPlayerFights(3);
88 list
<Player
*>::iterator iter
;
89 for (unsigned long x
= 0; x
< U_TABLE_SIZE
; x
++)
91 for (iter
= players
[x
].begin(); iter
!= players
[x
].end(); iter
++)
106 // Add the stick and clothes
107 tempItem
= findItemByID(3001);
108 p
->inventory
->addItem((*Items
.begin()))->use(p
); // Add the stick
109 p
->inventory
->addItem(tempItem
)->use(p
); // Add Clothes
112 void updateTS(Player
*p
)
118 log("Old timestamp for %s: %ld", p
->getName().c_str(), p
->lastcommand
);
120 p
->lastcommand
= time(NULL
);
122 log("New timestamp for %s: %ld", p
->getName().c_str(), p
->lastcommand
);
130 void timeOutEvent(Player
*p
)
132 if (!p
|| !is_playing(p
->getClient())) // then they're not playing
135 char *nick
= p
->getClient()->getNick();
137 if (player_fight(p
->getClient()) && isYourTurn(p
))
139 // Check to see if they were the idler or if it was the other
141 if (!PF_timedout(p
->getBattle()->stats
))
143 // This person's last command was given earlier,
144 // so this person is the idler
145 notice(s_GameServ
, nick
, "You timed out "\
146 "during a fight. You lose your turn!");
147 notice(s_GameServ
, p
->getBattle()->getNick(),
148 "%s hesitated for too long. Your move.", p
->getName().c_str());
150 setYourTurn(p
->getBattle()->stats
);
152 // Update the TS for both players to give them another
153 // Chance to wake up, but if the other player doesn't
154 // Attack now, they both get logged out.
157 display_players(p
->getBattle());
162 notice(s_GameServ
, p
->getBattle()->getNick(),
163 "You and %s timed out at the same time."\
164 " Don't fight if you're just going to "\
165 "sit there!", p
->getName().c_str());
166 notice(s_GameServ
, p
->getClient()->getNick(),
167 "You and %s timed out at the same time."\
168 " Don't fight if you're just going to "\
169 "sit there!", p
->getBattle()->stats
->getName().c_str());
170 logout(p
->getBattle());
171 logout(p
->getClient());
173 clearYourTurn(p
->getBattle()->stats
);
177 else if (!player_fight(p
->getClient()))
179 if (isAlive(p
) && p
->getGold() > 0)
181 // Place fun stuff here :)
182 int randnum
= 1 + rand() % 100; // 1-100
183 #define GSN(s) notice(s_GameServ, nick, s)
184 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
188 // 35-100% of your gold goes pffft - kain
189 int stolen
= (35 + (rand() % 66)) * (p
->getGold() / 100);
191 GSN("You stop for a moment to rest on the "\
192 "street corner. All of a sudden, you "\
193 "are ambushed from all sides by a hoarde "\
194 "of knife wielding thugs.");
195 GSN2("The thugs beat you into utter submission "\
196 "and steal %ld gold from you!", stolen
);
197 p
->subtractGold(stolen
);
199 else if (randnum
>= 50 && randnum
< 75)
201 // 25-65% of your gold goes pffft - kain
202 int stolen
= (25 + (rand() % 41)) * (p
->getGold() / 100);
203 GSN("While dilly dallying around, you lose "\
204 "your sense of time. Little did you know, "\
205 "but thieves lifted your gold while you "\
206 "weren't watching.");
207 GSN2("Better luck next time... you lose %d gold", stolen
);
208 p
->subtractGold(stolen
);
210 else if (randnum
>= 75)
212 // 25-75% of your gold goes pffft - kain
213 int stolen
= (25 + (rand() % 51)) * (p
->getGold() / 100);
214 GSN("Good grief! A gaggle of gooey green ghostlike "\
215 "goblins grabbed your gold!");
216 GSN2("They stole %d gold from you!", stolen
);
217 p
->subtractGold(stolen
);
221 // Always log out the user
222 logout(p
->getClient());
225 void logout(aClient
*user
)
229 if (user
->stats
!= NULL
)
232 list
<Player
*>::iterator iter
;
233 unsigned long hv
= iHASH((unsigned char *) user
->stats
->getName().c_str());
234 iter
= find(players
[hv
].begin(), players
[hv
].end(), user
->stats
);
236 if (iter
== players
[hv
].end())
238 notice(s_GameServ
, user
->getNick(), "Fatal error. Contact "\
239 "<S Admin. Cannot find you in the players list. This should NEVER happen");
240 log("Error on logout(). Can't find %s in the players list",
251 user
->stats
->delMonster();
252 user
->stats
->delMaster();
253 user
->stats
->delBattle();
254 clearDragonFight(user
->stats
);
255 clearYourTurn(user
->stats
);
258 user
->stats
->setClient(NULL
);
261 if (player_fight(user
))
263 clearYourTurn(user
->stats
->getBattle()->stats
);
264 user
->stats
->getBattle()->stats
->delBattle();
268 log("Logged out player %s",
282 void end_turn(aClient
*user
)
284 char *nick
, *u
= user
->getNick();
289 nick
= new char[strlen(user
->getNick()) + 1];
291 if (!user
|| !is_playing(user
) || !is_fighting(user
))
294 if (!player_fight(user
) && !master_fight(user
))
295 fight
= user
->stats
->getMonster();
297 fight
= user
->stats
->getMaster();
298 battle
= user
->stats
->getBattle();
300 if (!player_fight(user
))
303 mhit
= (fight
->strength
/ 2) + (rand() % (fight
->strength
/ 2)) - (user
->stats
->getDefense());
308 mhit
= (battle
->stats
->getStrength() / 2) + (rand() % (battle
->stats
->getStrength() / 2)) - user
->stats
->getDefense();
310 if (!player_fight(user
))
315 notice(s_GameServ
, u
, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
316 fight
->name
.c_str(), fight
->weapon
.c_str(), mhit
);
319 notice(s_GameServ
, u
, "%s completely misses you!", fight
->name
.c_str());
321 if (mhit
>= user
->stats
->getHP())
323 if (!master_fight(user
))
325 notice(s_GameServ
, u
, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight
->name
.c_str());
326 notice(s_GameServ
, u
, "You lose all gold on hand and lose 10 percent "\
327 "of your experience!");
328 user
->stats
->setGold(0);
329 user
->stats
->subtractExp((long int)(user
->stats
->getExp() * .10));
330 user
->stats
->setHP(0);
331 user
->stats
->delMonster();
332 clearAlive(user
->stats
);
337 notice(s_GameServ
, u
, "%s has bested you! You will have to wait "\
338 "until tomorrow to try again", user
->stats
->getMaster()->name
.c_str());
339 user
->stats
->delMonster();
340 user
->stats
->delMaster();
347 user
->stats
->subtractHP(mhit
);
354 clearYourTurn(user
->stats
);
355 setYourTurn(battle
->stats
);
356 display_players(battle
);