- aClient *user;
- Player *p, *p2 = NULL;
-
- if (!(user = find(u)))
- {
- notice(s_GameServ, u, "Couldn't find you. Error. Contact a %S admin");
- return;
- }
- else if (isIgnore(user))
- {
- #ifdef DEBUGMODE
- log("Ignoring %s.", user->getNick());
- #endif
- return;
- }
- else if (!is_playing(user))
- {
- notice(s_GameServ, u, "You must be playing to run!");
- return;
- }
-
- updateTS(user->stats);
- p = user->stats;
-
- if (p->battle)
- p2 = p->battle->stats;
-
- if (!is_fighting(user))
- notice(s_GameServ, u, "You run in place... try fighting next time.");
- else if (!player_fight(user) && !master_fight(user))
- {
- notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->fight->name.c_str());
- delete p->fight;
- p->fight = NULL;
- }
- else if (player_fight(user) && isYourTurn(p))
- {
- notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->name.c_str());
- notice(s_GameServ, p->battle->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->name.c_str());
- p2->battle = NULL;
- }
- else if (player_fight(user) && !isYourTurn(p))
- {
- notice(s_GameServ, u, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2->name.c_str());
- }
- else if (master_fight(user))
- {
- notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->master->name.c_str());
- }
- p->battle = NULL;
-}
-
-void end_turn(aClient *user)
-{
- char *nick, *u = user->getNick();
- Monster *fight;
- aClient *battle;
- int mhit;
-
- nick = new char[strlen(user->getNick()) + 1];
-
- if (!user || !is_playing(user) || !is_fighting(user))
- goto endturn;
-
- if (!player_fight(user) && !master_fight(user))
- fight = user->stats->fight;
- else
- fight = user->stats->master;
- battle = user->stats->battle;
-
- if (!player_fight(user))
- {
- // Opponent's Hit
- mhit = (fight->strength / 2) +
- (rand() % (fight->strength / 2) - (user->stats->defense +
- arbonus[user->stats->armor]));
- }
- else
- {
- // Opponent's Hit
- mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
- (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
- (user->stats->defense + arbonus[user->stats->armor]));
- }
- if (!player_fight(user))
- {
-
- if (mhit > 0)
- {
- notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
- fight->name.c_str(), fight->weapon.c_str(), mhit);
- }
- else if (mhit <= 0)
- notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str());
-
- if (mhit >= user->stats->hp)
- {
- if (!master_fight(user))
- {
- notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name.c_str());
- notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
- "of your experience!");
- user->stats->gold = 0;
- user->stats->exp -= (long int)(user->stats->exp * .10);
- user->stats->hp = 0;
- user->stats->fight = NULL;
- clearAlive(user->stats);
- goto endturn;
- }
- else
- {
- notice(s_GameServ, u, "%s has bested you! You will have to wait "\
- "until tomorrow to try again", user->stats->master->name.c_str());
- user->stats->fight = NULL;
- user->stats->master = NULL;
- goto endturn;
- }
- }
- else
- {
- if (mhit > 0)
- user->stats->hp -= mhit;
- display_monster(u);
- goto endturn;
- }
- }
- else
- {
- clearYourTurn(user->stats);
- setYourTurn(battle->stats);
- display_players(battle);
- }
-endturn:
- delete nick;
-}
-
-void do_attack(char *u)
-{
- int hit, mhit;
- aClient *ni, *battle; // The player and perhaps the player they're fighting
- Monster *fight; // The monster they may be fighting
-
- if (!(ni = find(u)))
- {
- notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) %S admin for help.");
- return;
- }
- else if (isIgnore(ni))
- {
- #ifdef DEBUGMODE
- log("Ignoring %s.", ni->getNick());
- #endif
- return;
- }
- else if (!is_playing(ni))
- {
- notice(s_GameServ, u, "You're not playing!");
- return;
- }
- else if (!is_fighting(ni))
- {
- notice(s_GameServ, u, "You're not in battle!");
- return;
- }
- else
- {
- if (!ni->stats->master) // This is not a master fight
- fight = ni->stats->fight; // Monster Could be NULL
- else // This IS a master fight
- fight = ni->stats->master; // Master Could be NULL
-
- battle = ni->stats->battle; // Player Could be NULL
-
- // One has to be !NULL based on the previous else if
- // We wouldn't be here if they were all NULL
- }
- updateTS(ni->stats);
-
- if (!player_fight(ni))
- {
- // Player's Hit
- hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
- (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
-
- // Opponent's Hit
- mhit = (fight->strength / 2) +
- (rand() % (fight->strength / 2) - (ni->stats->defense +
- arbonus[ni->stats->armor]));
- }
- else
- {
- // Opponent's Hit
- mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
- (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
- (ni->stats->defense + arbonus[ni->stats->armor]));
-
- // Player's Hit
- hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
- (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) -
- (battle->stats->defense + arbonus[battle->stats->armor]));
- }
-
- if (!player_fight(ni))
- {
- if (hit > 0)
- notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name.c_str(), hit);
- else
- notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name.c_str());
-
- if (hit >= fight->hp)