]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
Updated monsters a bit and changed the last armor
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 45057bc5c624175965fd11a50803654f72d66d1e..7587f7d6a189b78d95c2d46255f961f4678773c8 100644 (file)
@@ -54,9 +54,6 @@ bool is_playing(aClient *user);
 bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
 bool is_fighting(aClient *user);
 
-bool is_alive(char *u); // True if the given nick is playing and is alive
-bool is_alive(aClient *user); 
-
 bool player_fight(char *u); // True if the player is fighting another player.
 bool player_fight(aClient *user);
 
@@ -77,7 +74,7 @@ long int stringtoint(char *number);
 char *spaces(int len, char *seperator);
 void refresh(Player *p);
 void refreshall();
-void reset(aClient *ni);
+void reset(Player *p);
 void init_masters();
 void init_monsters();
 bool load_monsters();
@@ -120,7 +117,7 @@ char *weapons[WNA] = {  "Fists", "Stick", "Dagger", "Quarterstaff",  "Short Swor
 char *armors[WNA] = { "Nothing", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor", 
                      "Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit", 
                      "Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor", 
-                     "Hades' Cloak", "Dragon Scales", "Mystical Armor"};
+                     "Hades' Cloak", "Dragon Scales", "Adamantium"};
 
 int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000, 
                        1000000, 4000000, 10000000, 40000000, 100000000, 400000000};
@@ -186,6 +183,8 @@ void gameserv(char *source, char *buf)
        do_admin(source);
     } else if (stricmp(cmd, "REFRESH") == 0) {
        do_refresh(source);
+    } else if (stricmp(cmd, "RESET") == 0) {
+       do_reset(source);
     } else if (stricmp(cmd, "TAVERN") == 0) {
        do_tavern(source);
     } else if (stricmp(cmd, "PRINT") == 0) {
@@ -193,6 +192,15 @@ void gameserv(char *source, char *buf)
        clients.print();
        cout << "\nPrinting Player List: " << endl;
        players.print();
+       cout << "\nPrinting Level 1 of monsters:" << endl;
+       for (int xx = 0; xx < 12; xx++)
+       {
+           cout << monsters[0][xx]->name << ' ' <<
+monsters[0][xx]->weapon << ' ' << monsters[0][xx]->hp << '/' <<
+monsters[0][xx]->maxhp << ' ' <<
+monsters[0][xx]->strength << ' ' << monsters[0][xx]->exp << ' ' <<
+monsters[0][xx]->gold << ' ' << monsters[0][xx]->death << endl;
+       }
     } else if (stricmp(cmd, "LIST") == 0) {
        do_list(source);
     } else if (stricmp(cmd, "REGISTER") == 0) {
@@ -657,7 +665,7 @@ void init_masters()
 
     strcpy(masters[3]->name, "Mr. Miagi");
     strcpy(masters[3]->weapon, "Petrified Bonsai");
-    masters[3]->strength = 100;
+    masters[3]->strength = 120;
     masters[3]->gold = 0;
     masters[3]->exp = 0;
     masters[3]->maxhp = 120;
@@ -666,7 +674,7 @@ void init_masters()
 
     strcpy(masters[4]->name, "Jackie Chan");
     strcpy(masters[4]->weapon, "Kung Fu Kick");
-    masters[4]->strength = 125;
+    masters[4]->strength = 135;
     masters[4]->gold = 0;
     masters[4]->exp = 0;
     masters[4]->maxhp = 200;
@@ -675,7 +683,7 @@ void init_masters()
 
     strcpy(masters[5]->name, "Jet Li");
     strcpy(masters[5]->weapon, "Motorcycle");
-    masters[5]->strength = 150;
+    masters[5]->strength = 160;
     masters[5]->gold = 0;
     masters[5]->exp = 0;
     masters[5]->maxhp = 400;
@@ -685,7 +693,7 @@ void init_masters()
 
     strcpy(masters[6]->name, "Muhammad Ali");
     strcpy(masters[6]->weapon, "Quick Jab");
-    masters[6]->strength = 175;
+    masters[6]->strength = 185;
     masters[6]->gold = 0;
     masters[6]->exp = 0;
     masters[6]->maxhp = 600;
@@ -694,7 +702,7 @@ void init_masters()
 
     strcpy(masters[7]->name, "Li Mu Bai");
     strcpy(masters[7]->weapon, "Green Destiny");
-    masters[7]->strength = 200;
+    masters[7]->strength = 210;
     masters[7]->gold = 0;
     masters[7]->exp = 0;
     masters[7]->maxhp = 800;
@@ -713,7 +721,7 @@ void init_masters()
 
     strcpy(masters[9]->name, "Wong Fei Hung");
     strcpy(masters[9]->weapon, "Drunken Boxing");
-    masters[9]->strength = 350;
+    masters[9]->strength = 360;
     masters[9]->gold = 0;
     masters[9]->exp = 0;
     masters[9]->maxhp = 1800;
@@ -1979,25 +1987,6 @@ bool is_playing(aClient *user)
     return user->stats != NULL && (stricmp(user->getNick(), "!NULL!") != 0);
 }
 
-bool is_alive(char *u)
-{
-    aClient *user;
-    if (!(user = find(u)))
-       return false;
-    else if (user->stats == NULL)
-       return false;
-    else
-       return user->stats->alive;
-}
-
-bool is_alive(aClient *user)
-{
-    if (user->stats == NULL)
-       return false;
-    else
-       return user->stats->alive;
-}
-       
 bool is_fighting(char *u)
 {
     aClient *user;
@@ -2098,7 +2087,7 @@ void do_fight(char *u)
  *       display_players(u);
  *   }
  */
-    else if (!is_alive(ni))
+    else if (!isAlive(ni->stats))
     {
        notice(s_GameServ, u, "You are dead. Wait until tomorrow to fight others!");
        return;
@@ -2122,8 +2111,8 @@ void do_fight(char *u)
         battle->stats->battle = ni;
 
        // The initiator gets the first move (perhaps this should be 50/50)
-        ni->stats->yourturn = 1;
-        battle->stats->yourturn = 0;
+       setYourTurn(ni->stats);
+       clearYourTurn(battle->stats);
 
        // Initiate Battle sequence!
         notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getNick());
@@ -2183,7 +2172,7 @@ void do_use(char *u)
        int oldstrength = user->stats->strength;
        notice(s_GameServ, u, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!");
        notice(s_GameServ, u, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!");
-       user->stats->strength += rand() % 3;
+       user->stats->strength += 1 + rand() % 2; // 1 - 2 Strength Added
        notice(s_GameServ, u, "You gain %d Strength points!", user->stats->strength - oldstrength);
        p->decStrength();
     }
@@ -2194,13 +2183,31 @@ void do_use(char *u)
            notice(s_GameServ, u, "You are out of Defense Potions!");
            return;
        }
-       int olddefense = user->stats->strength;
+       int olddefense = user->stats->defense;
        notice(s_GameServ, u, "You drink the foul tasting viscous liquid while pinching your nose in disgust.");
        notice(s_GameServ, u, "It tasted bad, but you feel like you are unbeatable!");
-       user->stats->defense += rand() % 3;
+       user->stats->defense += 1 + rand() % 2; // 1 - 2 Defense Added
        notice(s_GameServ, u, "You gain %d Defense points!", user->stats->defense - olddefense);
        p->decDefense();
     }
+    else if (stricmp(item, "HP") == 0)
+    {
+       if (p->HP() <= 0)
+       {
+           notice(s_GameServ, u, "You are out of HP Potions!");
+           return;
+       }
+       int oldHP = user->stats->maxhp;
+       notice(s_GameServ, u, "You feel your life growing longer as you drink the green glowing liquid.");
+       user->stats->maxhp += 1 + rand() % 5; // 1 - 5 Maxhp
+       notice(s_GameServ, u, "You gain %d Maximum hit points!", user->stats->maxhp - oldHP);
+       p->decHP();
+    }
+    else
+    {
+       notice(s_GameServ, u, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}");
+       return;
+    }
 
     end_turn(user); // If they're fighting, end their turn
 }
@@ -2228,13 +2235,13 @@ void do_run(char *u)
        delete p->fight;
        p->fight = NULL;
     }
-    else if (player_fight(user) && p->yourturn)
+    else if (player_fight(user) && isYourTurn(p))
     {
        notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->name);
        notice(s_GameServ, p->battle->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->name);
        p2->battle = NULL;
     }
-    else if (player_fight(user) && !p->yourturn)
+    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);
     }
@@ -2298,7 +2305,7 @@ void end_turn(aClient *user)
                 user->stats->gold = 0;
                 user->stats->exp -= (long int)(user->stats->exp * .10);
                 user->stats->fight = NULL;
-               user->stats->alive = false;
+               clearAlive(user->stats);
                 goto endturn;
             }
             else
@@ -2320,8 +2327,8 @@ void end_turn(aClient *user)
     }
     else
     {
-        user->stats->yourturn = 0;
-        battle->stats->yourturn = 1;
+       clearYourTurn(user->stats);
+       setYourTurn(battle->stats);
         display_players(battle);
     }
 endturn:
@@ -2410,6 +2417,7 @@ void do_attack(char *u)
        // Unsigned long int maybe? Leave it for now.
         ni->stats->exp = ( (ni->stats->exp + fight->exp) > 2000000000 ? 2000000000 : 
                                ni->stats->exp + fight->exp);
+
         ni->stats->gold = (ni->stats->gold + fight->gold > 2000000000 ? 2000000000 : 
                                ni->stats->gold + fight->gold);
 
@@ -2468,7 +2476,7 @@ void do_attack(char *u)
                 ni->stats->gold = 0;
                 ni->stats->exp -= (long int)(ni->stats->exp * .10);
                 ni->stats->fight = NULL;
-               ni->stats->alive = false;
+               clearAlive(ni->stats);
                 return;
             }
             else
@@ -2577,7 +2585,7 @@ void do_attack(char *u)
 
    if (is_playing(battle->getNick()))
    {
-    if (ni->stats->yourturn == 0)
+    if (!isYourTurn(ni->stats))
     {
         notice(s_GameServ, u, "Please wait until %s decides what to do!", 
                battle->getNick());
@@ -2590,16 +2598,16 @@ void do_attack(char *u)
         notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
                                              "\ 2%d\ 2 damage!", u, weapons[ni->stats->weapon], 
                                              hit);
-        ni->stats->yourturn = 0;
-        battle->stats->yourturn = 1;
+       clearYourTurn(ni->stats);
+       setYourTurn(battle->stats);
         display_players(battle->getNick());
     }
     else
     {
         notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->getNick());
         notice(s_GameServ, battle->getNick(), "%s misses you completely!", u);
-        ni->stats->yourturn = 0;
-        battle->stats->yourturn = 1;
+       clearYourTurn(ni->stats);
+       setYourTurn(battle->stats);
         display_players(battle->getNick());
     }
     if (hit >= battle->stats->hp)
@@ -2609,7 +2617,7 @@ void do_attack(char *u)
                 (long int)(battle->stats->exp * .10), battle->stats->gold);
         notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", u);
         battle->stats->hp = 0;
-        battle->stats->alive = false;
+        clearAlive(battle->stats);
 
         if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
         {
@@ -2650,9 +2658,8 @@ void do_attack(char *u)
     {
         if (hit > 0)
             battle->stats->hp -= hit;
-        //display_players(battle->getNick());
-        ni->stats->yourturn = 0;
-        battle->stats->yourturn = 1;
+       clearYourTurn(ni->stats);
+       setYourTurn(battle->stats);
         notice(s_GameServ, u, "Please wait while %s decides what to do!", 
                battle->getNick());
 
@@ -2681,7 +2688,7 @@ void do_heal(char *u)
        notice(s_GameServ, u, "You aren't playing!");
        return;
     }
-    else if (!is_alive(ni))
+    else if (!isAlive(ni->stats))
     {
        notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing.");
        return;
@@ -2812,9 +2819,10 @@ int save_gs_dbase()
        it = ptr->getData()->stats;
        outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' '
                << it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' '
-               << it->armor << ' ' << it->weapon << ' ' << (it->alive ? "alive" : "dead") << ' '
+               << it->armor << ' ' << it->weapon << ' '
                << it->forest_fights << ' ' << it->player_fights <<  ' ' 
-               << it->getFlags() << ' ' << it->password << endl;
+               << it->getFlags() << ' ' << it->password << ' ' << it->inventory.Healing()
+               << ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << endl;
        ptr = ptr->Next();
     }
 outfile.close();
@@ -2826,7 +2834,7 @@ int load_gs_dbase()
     ifstream infile;
     aClient *temp;
     Player *p;
-    char *alive, *tempname, *buf, *password;
+    char *tempname, *buf, *password;
     buf = new char[1023];
 
     infile.open(playerdata);
@@ -2854,18 +2862,22 @@ int load_gs_dbase()
        p->defense = stringtoint(strtok(NULL, " "));
        p->armor = stringtoint(strtok(NULL, " "));
        p->weapon = stringtoint(strtok(NULL, " "));
-       alive = strtok(NULL, " ");
-       p->alive = (stricmp(alive, "ALIVE") == 0 ? true : false);
        p->forest_fights = stringtoint(strtok(NULL, " "));
        p->player_fights = stringtoint(strtok(NULL, " "));
        p->setFlags(stringtoint(strtok(NULL, " ")));
+
        password = strtok(NULL, " ");
        strcpy(p->password, password);
        temp->setNick("!NULL!");
 
-       printf("%s %d %ld %ld %ld %d %d %d %d %d %d %s %d %d %s\n", p->name, p->level, 
-       p->exp, p->gold, p->bank, p->hp, p->maxhp, p->strength, p->defense, p->armor, p->weapon, 
-       alive, p->forest_fights, p->player_fights, p->password);
+       // Old player databases didn't have these three extra values
+       // If they come up null, leave them to 0 as the default.
+       // On the next gameserv database save, it will save the values.
+       tempname = strtok(NULL, " ");
+       cout << tempname << endl;
+       p->inventory.setHealing(stringtoint(tempname));
+       p->inventory.setStrength(stringtoint(strtok(NULL, " ")));
+       p->inventory.setDefense(stringtoint(strtok(NULL, " ")));
 
        players.insertAtBack(temp);
        delete temp;
@@ -2927,7 +2939,7 @@ void do_store(char *u)
     }
     else if (!(user = find(u)) || !is_playing(user))
        notice(s_GameServ, u, "You must be playing to use the store!");
-    else if (!is_alive(user))
+    else if (!isAlive(user->stats))
     {
        notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!");
        return;
@@ -3154,6 +3166,7 @@ void do_tavern(char *u)
        notice(s_GameServ, u, "1. Healing Potions for %ld Gold", 1000 * p->level + (p->exp / 10));
        notice(s_GameServ, u, "2. Strength Potions for %ld Gold", 2050 * p->level + (p->exp / 10));
        notice(s_GameServ, u, "3. Defense Potions for %ld Gold", 2000 * p->level + (p->exp / 10));
+       notice(s_GameServ, u, "4. HP Potions for %ld Gold", 2300 * p->level + (p->exp / 10));
        notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #");
        notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!");
        notice(s_GameServ, u, "By something will ya!");
@@ -3169,15 +3182,17 @@ void do_tavern(char *u)
            notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1");
            return;
        }
-       if (num < 1 || num > 3)
+       if (num < 1 || num > 4)
        {
            notice(s_GameServ, u, "Invalid Choice!");
            notice(s_GameServ, u, "Here is a list of what we have to offer:");
            notice(s_GameServ, u, "1. Healing Potions for %ld Gold", 1000 * p->level + (p->exp / 10));
            notice(s_GameServ, u, "2. Strength Potions for %ld Gold", 2050 * p->level + (p->exp / 10));
            notice(s_GameServ, u, "3. Defense Potions for %ld Gold", 2000 * p->level + (p->exp / 10));
+           notice(s_GameServ, u, "4. HP Potions for %ld Gold", 2300 * p->level + (p->exp / 10));
            notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #");
            notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!");
+           return;
        }
        switch(num)
        {
@@ -3187,6 +3202,7 @@ void do_tavern(char *u)
                {
                    notice(s_GameServ, u, "One healing potion coming right up!");
                    p->inventory.incHealing();
+                   p->gold -= price;
                } 
                else
                    notice(s_GameServ, u, "You don't have enough gold!");
@@ -3197,6 +3213,7 @@ void do_tavern(char *u)
                {
                    notice(s_GameServ, u, "One strength boost coming right up!");
                    p->inventory.incStrength();
+                   p->gold -= price;
                }
                else
                    notice(s_GameServ, u, "You don't have enough gold!");
@@ -3207,6 +3224,18 @@ void do_tavern(char *u)
                {
                    notice(s_GameServ, u, "One defense boost coming right up!");
                    p->inventory.incDefense();
+                   p->gold -= price;
+               }
+               else
+                   notice(s_GameServ, u, "You don't have enough gold!");
+               break;
+           case 4:
+               price = (2300 * p->level) + (p->exp / 10);
+               if (p->gold >= price)
+               {
+                   notice(s_GameServ, u, "One HP Potion coming right up!");
+                   p->inventory.incHP();
+                   p->gold -= price;
                }
                else
                    notice(s_GameServ, u, "You don't have enough gold!");
@@ -3232,7 +3261,7 @@ void do_bank(char *u)
     aClient *user;
     Player *p;
 
-    if (!cmd || !amount || (stricmp(cmd, "TRANSFER") == 0 && !nick))
+    if (!cmd || (!amount && stricmp(cmd, "BALANCE") != 0) || (stricmp(cmd, "TRANSFER") == 0 && !nick))
     {
        notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}");
        notice (s_GameServ, u, "BANK BALANCE");
@@ -3245,7 +3274,7 @@ void do_bank(char *u)
        notice(s_GameServ, u, "You must be playing to use the bank!");
        return;
     }
-    else if (!is_alive(user))
+    else if (!isAlive(user->stats))
     {
        notice(s_GameServ, u, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!");
        return;
@@ -3382,7 +3411,7 @@ void do_master(char *u)
        notice(s_GameServ, u, "You're in the middle of a fight! Pay attention!");
        return;
     }
-    else if (!is_alive(user))
+    else if (!isAlive(user->stats))
     {
        notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!");
        return;
@@ -3537,10 +3566,11 @@ void refresh(Player *p)
     if (!p)
        return;
 
-    p->hp = p->maxhp;
+    if (p->hp < p->maxhp)
+       p->hp = p->maxhp;
     p->forest_fights = forestfights;
     p->player_fights = 3;
-    p->alive = true;
+    setAlive(p);
     clearMaster(p);
 }
 
@@ -3589,6 +3619,75 @@ void do_refresh(char *u)
     }
 }
 
+
+void resetall()
+{
+    ListNode <aClient> *it;
+    Player *p;
+
+    it = players.First();
+
+    while (it)
+    {
+       p = it->getData()->stats;
+       reset(p);
+       it = it->Next();
+    }
+}
+
+void reset(Player *p)
+{
+    if (!p)
+       return;
+
+    p->reset();
+}
+
+void do_reset(char *u)
+{
+    char *nick = strtok(NULL, " ");
+    aClient *user;
+
+    if (!(user = find(u)))
+    {
+       notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
+       cout << "Error: aClient not found: " << u << endl;
+       return;
+    }
+    else if (!isAdmin(user))
+    {
+       notice(s_GameServ, u, "You must be a %S admin to use this command!");
+       return;
+    }
+    if (!nick)
+    {
+       notice(s_GameServ, u, "SYNTAX: RESET {ALL | NICK}");
+       return;
+    }
+    else if (stricmp(nick, "ALL") == 0)
+    {
+       notice(s_GameServ, u, "Resetting everyone's stats!");
+       resetall();
+    }
+    else if ((user = find(nick)))
+    {
+       if (is_playing(user))
+       {
+           notice(s_GameServ, u, "Resetting %s.", user->getNick());
+           reset(user->stats);
+       }
+       else
+       {
+           notice(s_GameServ, u, "%s is not playing.", user->getNick());
+       }
+    }
+    else
+    {
+       notice(s_GameServ, u, "Nick %s not found.", nick);
+       return;
+    }
+}
+
 void do_help(char *u)
 {
     char *cmd = strtok(NULL, " ");
@@ -3716,6 +3815,7 @@ bool load_monsters()
            monsters[l][m]->gold = stringtoint(strtok(NULL, "~"));
            monsters[l][m]->exp = stringtoint(strtok(NULL, "~"));
            monsters[l][m]->maxhp = stringtoint(strtok(NULL, "~"));
+           monsters[l][m]->hp = monsters[l][m]->maxhp;
            strcpy(monsters[l][m]->death, strtok(NULL, ""));
            m++;
        }