]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/do_attack.cpp
Refactored playerGO a bit
[irc/gameservirc.git] / gameserv / do_attack.cpp
index 1f53b24bac46eae7b84c4782626e601faed04d50..e123d276bbcffa7f8c3b87ef54b186c27d9087fa 100644 (file)
@@ -1,27 +1,28 @@
-
 #include "aClient.h"
 #include "extern.h"
+#include "options.h"
 #include "flags.h"
 #include "level.h"
 #include "player.h"
+#include "item.h"
 
 
 void do_attack(char *u)
 {
-  int hit, mhit;
+  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.");
+      notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) <S admin for help.");
       return;
     }
   else if (isIgnore(ni))
     {
-        #ifdef DEBUGMODE
+#ifdef DEBUGMODE
       log("Ignoring %s.", ni->getNick());
-        #endif
+#endif
       return;
     }
   else if (!is_playing(ni))
@@ -36,243 +37,244 @@ void do_attack(char *u)
     }
   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
 
+         fight = ni->stats->getMonster();       // Monster      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
-      hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
-       (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
-
+      if ((ni->stats->getStrength() / 2) == 0)
+               {
+                 hit = 0;
+               }
+      else
+               {
+                 hit = (ni->stats->getStrength()/ 2) + (rand() % (ni->stats->getStrength() / 2)) - fight->defense;
+               }
+         
       // Opponent's Hit
-      mhit = (fight->strength / 2) +
-       (rand() % (fight->strength / 2) - (ni->stats->defense +
-                                          arbonus[ni->stats->armor]));
+      if ((fight->strength / 2) == 0)
+               {
+                 mhit = 0;
+               }
+      else
+               {
+                 mhit = (fight->strength / 2) +
+                       (rand() % (fight->strength / 2) - (ni->stats->getDefense()));
+               }
     }
   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]));
-
+      mhit = (((battle->stats->getStrength()) / 2) +
+                         (rand() % ((battle->stats->getStrength())) / 2) -
+                         (ni->stats->getDefense()));
+         
       // 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]));
+      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 \1f%s\1f for \ 2%d\ 2 points!", fight->name.c_str(), hit);
+        notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 hp!", fight->name.c_str(), hit);
       else
         notice(s_GameServ, u, "You miss \1f%s\1f 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 \ 2%s\ 2!", fight->name.c_str());
-
-         notice(s_GameServ, u, "%s", fight->death.c_str());
-         notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
+                 
+                 notice(s_GameServ, u, "%s", fight->death.c_str());
+                 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
                  fight->exp, fight->gold);
-
-         if (dragon_fight(ni))
-           {
-             addNews(todaysnews, "%s is a true warrior! %s has beaten %s!!",
-                     ni->stats->name.c_str(), ni->stats->name.c_str(),
-                     ni->stats->master->name.c_str());
-             ni->stats->master = NULL; // Don't progress in levels
-           }
-
-         // 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->delMonster();
+                         return;
+                       }
+                 
+                 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, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
+                 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)
+                       }
+                 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 \ 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!");
-                 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 \ 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!");
+                                 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 \1f%s\1f for \ 2%d\ 2 points!", battle->stats->name.c_str(), hit);
-
-             notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
-                    "^B%d^B damage!", ni->stats->name.c_str(),
-                    weapons[ni->stats->weapon], hit);
-           }
-         else
-           {
-             notice(s_GameServ, u, "You miss \1f%s\1f 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 ^\ 2%s\ 2!", battle->stats->name.c_str());
-             notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
-                    (long int)(battle->stats->exp * .10), battle->stats->gold);
-             notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!",
-                    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 \ 2%ld\ 2 gold "\
-                        "left. All is not lost!", battle->stats->gold);
-
-                 ni->stats->gold = 2000000000;
+                 if (!isYourTurn(ni->stats) && isYourTurn(battle->stats))
+                       {
+                         notice(s_GameServ, u, "Please wait until %s decides what to do!",
+                                        battle->stats->getName().c_str());
+                         return;
+                       }
+                 else if (!isYourTurn(ni->stats) && !isYourTurn(battle->stats))
+                       {
+                         // If somehow the player vs. player fight hangs, give the turn to the first attacker
+                         setYourTurn(ni->stats);
+                       }
+                if (hit > 0)
+                       {
+                         notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->getName().c_str(), hit);
+                         
+                         notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
+                                        "\ 2%d\ 2 damage!", ni->stats->getName().c_str(),
+                                        (ni->stats->getWeapon() ? ni->stats->getWeapon()->getName().c_str() : "Fists"), hit);
+                       }
+                 else
+                       {
+                         notice(s_GameServ, u, "You miss \1f%s\1f 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 \ 2%s\ 2!", battle->stats->getName().c_str());
+                         notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 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(), 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 \ 2%s\ 2!",
+                                        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;
-           }
-       }
     }
 }