X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/af1570c1998a6d7fa0f40ed4583927bb4aee4b54..fbb87959e7ab36dfb676c456f9ae28b8b5d945ec:/gameserv/do_attack.cpp diff --git a/gameserv/do_attack.cpp b/gameserv/do_attack.cpp index a45e9f1..1f6b9c6 100644 --- a/gameserv/do_attack.cpp +++ b/gameserv/do_attack.cpp @@ -11,7 +11,7 @@ void do_attack(char *u) int hit = 0, mhit = 0; 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."); @@ -19,9 +19,9 @@ void do_attack(char *u) } else if (isIgnore(ni)) { - #ifdef DEBUGMODE +#ifdef DEBUGMODE log("Ignoring %s.", ni->getNick()); - #endif +#endif return; } else if (!is_playing(ni)) @@ -36,264 +36,239 @@ void do_attack(char *u) } else { - if (!ni->stats->master) // This is not a master fight - fight = ni->stats->fight; // Monster Could be NULL + if (!ni->stats->getMaster()) // This is not a master fight + fight = ni->stats->getMonster(); // 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 - + fight = ni->stats->getMaster(); // Master Could be NULL + + battle = ni->stats->getBattle(); // 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 - if ((ni->stats->strength / 2) == 0) - { - hit = 0; - } + if ((ni->stats->getStrength() / 2) == 0) + { + hit = 0; + } else - { - hit = (ni->stats->strength / 2) + (rand() % (ni->stats->strength / 2)) - fight->defense; - } - + { + hit = (ni->stats->getStrength()/ 2) + (rand() % (ni->stats->getStrength() / 2)) - fight->defense; + } + // Opponent's Hit if ((fight->strength / 2) == 0) - { - mhit = 0; - } + { + mhit = 0; + } else - { - mhit = (fight->strength / 2) + - (rand() % (fight->strength / 2) - (ni->stats->defense)); - } + { + mhit = (fight->strength / 2) + + (rand() % (fight->strength / 2) - (ni->stats->getDefense())); + } } else { // Opponent's Hit - mhit = (((battle->stats->strength) / 2) + - (rand() % ((battle->stats->strength)) / 2) - - (ni->stats->defense)); - + mhit = (((battle->stats->getStrength()) / 2) + + (rand() % ((battle->stats->getStrength())) / 2) - + (ni->stats->getDefense())); + // Player's Hit - hit = (((ni->stats->strength) / 2) + - (rand() % ((ni->stats->strength)) / 2) - - (battle->stats->defense)); + hit = (((ni->stats->getStrength()) / 2) + + (rand() % ((ni->stats->getStrength())) / 2) - + (battle->stats->getDefense())); } - + if (!player_fight(ni)) { if (hit > 0) notice(s_GameServ, u, "You attack %s for %d hp!", fight->name.c_str(), hit); else notice(s_GameServ, u, "You miss %s completely!", fight->name.c_str()); - + if (hit >= fight->hp) - { - if (master_fight(ni) && !dragon_fight(ni)) - { - notice(s_GameServ, u, "You have bested %s!", fight->name.c_str()); - addNews(todaysnews, "%s has bested %s and moved "\ - "to level %d", ni->stats->name.c_str(), fight->name.c_str(), - (ni->stats->level + 1)); - } - else + { + if (master_fight(ni) && !dragon_fight(ni)) + { + notice(s_GameServ, u, "You have bested %s!", fight->name.c_str()); + addNews(todaysnews, "%s has bested %s and moved "\ + "to level %d", ni->stats->getName().c_str(), fight->name.c_str(), + (ni->stats->getLevel() + 1)); + } + else notice(s_GameServ, u, "You have killed %s!", fight->name.c_str()); - - notice(s_GameServ, u, "%s", fight->death.c_str()); - notice(s_GameServ, u, "You recieve %d experience and %d gold!", + + notice(s_GameServ, u, "%s", fight->death.c_str()); + notice(s_GameServ, u, "You recieve %d experience and %d gold!", fight->exp, fight->gold); - - if (dragon_fight(ni)) - { - addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!"\ - " %s is now watching over the Dragon's lair!", - ni->stats->name.c_str(), ni->stats->name.c_str(), - ni->stats->fight->name.c_str(), ni->stats->name.c_str()); - dragon.name = "DRAGON-" + ni->stats->name; - dragon.weapon = "Breath of Fire"; - dragon.strength = ni->stats->strength; - dragon.defense = ni->stats->defense; - dragon.hp = ni->stats->maxhp; - dragon.maxhp = ni->stats->maxhp; - save_dragon(); - clearDragonFight(ni->stats); - reset(ni->stats); - } - - // If your new experience (or gold) will be greater than 2 billion, - // then set your exp to 2bil. (2 billion max)... otherwise add them. - // This could be a problem with overflowing out of the sign bit. - // Unsigned long int maybe? Leave it for now. - ni->stats->exp += fight->exp; - if (ni->stats->exp < 0 || ni->stats->exp > 2000000000) - ni->stats->exp = 2000000000; - - ni->stats->gold += fight->gold; - if (ni->stats->gold < 0 || ni->stats->gold > 2000000000) - ni->stats->gold = 2000000000; - - if (master_fight(ni)) - { - notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1); - notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!", - strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]); - - // Increase your level - - // Increase your maximum hit points - ni->stats->maxhp += hpbonus[ni->stats->level - 1]; - - // Heal the player by setting hp to their max - ni->stats->hp = ni->stats->maxhp; - - // Add to your strength - ni->stats->strength += strbonus[ni->stats->level - 1]; - - // Add to your defensive power - ni->stats->defense += defbonus[ni->stats->level - 1]; - - ni->stats->level++; - - // Clear the pointer for your master - ni->stats->master = NULL; - } - - // They're dead so remove the pointer - delete ni->stats->fight; - ni->stats->fight = NULL; - ni->stats->master = NULL; - - return; - } + + if (dragon_fight(ni)) + { + addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!"\ + " %s is now watching over the Dragon's lair!", + ni->stats->getName().c_str(), ni->stats->getName().c_str(), + ni->stats->getMonster()->name.c_str(), ni->stats->getName().c_str()); + dragon.name = "DRAGON-" + ni->stats->getName(); + dragon.weapon = "Breath of Fire"; + dragon.strength = ni->stats->getStrength(); + dragon.defense = ni->stats->getDefense(); + dragon.hp = ni->stats->getMaxHP(); + dragon.maxhp = ni->stats->getMaxHP(); + save_dragon(); + clearDragonFight(ni->stats); + reset(ni->stats); + } + + ni->stats->addExp(fight->exp); + ni->stats->addGold(fight->gold); + + if (master_fight(ni)) + { + notice(s_GameServ, u, "You are now level %d!", ni->stats->getLevel() + 1); + notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!", + strbonus[ni->stats->getLevel() - 1], defbonus[ni->stats->getLevel() - 1]); + + // Increase your level + + // Increase your maximum hit points + ni->stats->addMaxHP(hpbonus[ni->stats->getLevel() - 1]); + + // Heal the player by setting hp to their max + ni->stats->healall(); + + // Add to your strength + ni->stats->addStrength(strbonus[ni->stats->getLevel() - 1]); + + // Add to your defensive power + ni->stats->addDefense(defbonus[ni->stats->getLevel() - 1]); + + ni->stats->addLevel(1); + + } + + // They're dead so remove the pointer + ni->stats->delMonster(); + + // Clear the pointer for your master + ni->stats->delMaster(); + + return; + } else - { - if (hit > 0) + { + if (hit > 0) fight->hp -= hit; - if (mhit > 0) - { - notice(s_GameServ, u, "%s attacks with their %s for %d damage!", + if (mhit > 0) + { + notice(s_GameServ, u, "%s attacks with their %s for %d damage!", fight->name.c_str(), fight->weapon.c_str(), mhit); - } - else if (mhit <= 0) + } + else if (mhit <= 0) notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str()); - - if (mhit >= ni->stats->hp) - { - if (!master_fight(ni)) - { - notice(s_GameServ, u, "You have been killed by %s!", fight->name.c_str()); - notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ - "of your experience!"); - addNews(todaysnews, "%s has been killed by %s!", - ni->stats->name.c_str(), fight->name.c_str()); - ni->stats->gold = 0; - ni->stats->exp -= (long int)(ni->stats->exp * .10); - ni->stats->hp = 0; - ni->stats->fight = NULL; - clearAlive(ni->stats); - return; + + if (mhit >= ni->stats->getHP()) + { + if (!master_fight(ni)) + { + notice(s_GameServ, u, "You have been killed by %s!", fight->name.c_str()); + notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ + "of your experience!"); + addNews(todaysnews, "%s has been killed by %s!", + ni->stats->getName().c_str(), fight->name.c_str()); + ni->stats->setGold(0); + ni->stats->subtractExp((long int)(ni->stats->getExp() * .10)); + ni->stats->setHP(0); + ni->stats->delMonster(); + clearAlive(ni->stats); + return; + } + else + { + notice(s_GameServ, u, "%s has bested you! You will have to wait "\ + "until tomorrow to try again", ni->stats->getMaster()->name.c_str()); + addNews(todaysnews, "%s tried to best %s and failed!", + ni->stats->getName().c_str(), fight->name.c_str()); + ni->stats->delMonster(); + ni->stats->delMaster(); + return; + } + } + else + { + if (mhit > 0) + ni->stats->subtractHP(mhit); + display_monster(u); + return; + } } - else - { - notice(s_GameServ, u, "%s has bested you! You will have to wait "\ - "until tomorrow to try again", ni->stats->master->name.c_str()); - addNews(todaysnews, "%s tried to best %s and failed!", - ni->stats->name.c_str(), fight->name.c_str()); - ni->stats->fight = NULL; - ni->stats->master = NULL; - return; - } - } - else - { - if (mhit > 0) - ni->stats->hp -= mhit; - display_monster(u); - return; - } - } } else if (player_fight(ni)) { if (is_playing(battle)) - { - if (!isYourTurn(ni->stats)) - { - notice(s_GameServ, u, "Please wait until %s decides what to do!", - battle->stats->name.c_str()); - return; - } - if (hit > 0) - { - notice(s_GameServ, u, "You attack %s for %d points!", battle->stats->name.c_str(), hit); - - notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\ - "%d damage!", ni->stats->name.c_str(), - (ni->stats->getWeapon() ? ni->stats->getWeapon()->getName().c_str() : "Fists"), hit); - } - else - { - notice(s_GameServ, u, "You miss %s completely!", battle->stats->name.c_str()); - notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name.c_str()); - } - - if (hit >= battle->stats->hp) - { - notice(s_GameServ, u, "You have killed %s!", battle->stats->name.c_str()); - notice(s_GameServ, u, "You recieve %d experience and %ld gold!", - (long int)(battle->stats->exp * .10), battle->stats->gold); - notice(s_GameServ, battle->getNick(), "You have been killed by %s!", - ni->stats->name.c_str()); - battle->stats->hp = 0; - clearAlive(battle->stats); - - ni->stats->exp += (long int)(battle->stats->exp * .10); - battle->stats->exp -= (long int)(battle->stats->exp * .10); - - if (ni->stats->exp < 0 || ni->stats->exp > 2000000000) - ni->stats->exp = 2000000000; - - if (2000000000 - ni->stats->gold > battle->stats->gold) - { - notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\ - "all gold on hand!"); - ni->stats->gold += battle->stats->gold; - battle->stats->gold = 0; - } - else { - battle->stats->gold = 2000000000 - ni->stats->gold; - notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!"); - - notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\ - "gold.", ni->stats->name.c_str()); - - notice(s_GameServ, battle->getNick(), "Luckily, you still have %ld gold "\ - "left. All is not lost!", battle->stats->gold); - - ni->stats->gold = 2000000000; + if (!isYourTurn(ni->stats)) + { + notice(s_GameServ, u, "Please wait until %s decides what to do!", + battle->stats->getName().c_str()); + return; + } + if (hit > 0) + { + notice(s_GameServ, u, "You attack %s for %d points!", battle->stats->getName().c_str(), hit); + + notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\ + "%d damage!", ni->stats->getName().c_str(), + (ni->stats->getWeapon() ? ni->stats->getWeapon()->getName().c_str() : "Fists"), hit); + } + else + { + notice(s_GameServ, u, "You miss %s completely!", battle->stats->getName().c_str()); + notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->getName().c_str()); + } + + if (hit >= battle->stats->getHP()) + { + notice(s_GameServ, u, "You have killed %s!", battle->stats->getName().c_str()); + notice(s_GameServ, u, "You recieve %d experience and %ld gold!", + (long int)(battle->stats->getExp() * .10), battle->stats->getGold()); + addNews(todaysnews, "%s has defeated %s, leaving %s in a pool of blood", ni->stats->getName().c_str(), battle->stats->getName().c_str()); /* DrLnet - Modified by kain for news instead of just a message */ + notice(s_GameServ, battle->getNick(), "You have been killed by %s!", + ni->stats->getName().c_str()); + battle->stats->setHP(0); + clearAlive(battle->stats); + + ni->stats->addHP((long int)(battle->stats->getExp() * .10)); + battle->stats->subtractExp((long int)(battle->stats->getExp() * .10)); + + notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\ + "all gold on hand!"); + ni->stats->addGold(battle->stats->getGold()); + battle->stats->setGold(0); + + + clearYourTurn(ni->stats); + clearYourTurn(battle->stats); + + battle->stats->delBattle(); + ni->stats->delBattle(); + return; + } + else + { + if (hit > 0) + battle->stats->subtractHP(hit); + clearYourTurn(ni->stats); + setYourTurn(battle->stats); + display_players(battle); + notice(s_GameServ, u, "Please wait while %s decides what to do!", + battle->stats->getName().c_str()); + return; + } } - clearYourTurn(ni->stats); - clearYourTurn(battle->stats); - battle->stats->battle = NULL; - ni->stats->battle = NULL; - return; - } - else - { - if (hit > 0) - battle->stats->hp -= hit; - clearYourTurn(ni->stats); - setYourTurn(battle->stats); - display_players(battle); - notice(s_GameServ, u, "Please wait while %s decides what to do!", - battle->stats->name.c_str()); - return; - } - } } }