]> jfr.im git - irc/gameservirc.git/commitdiff
Added everything necessary to save overtop of the old dragon when someone beats the...
authorkainazzzo <redacted>
Tue, 14 Jun 2005 03:14:35 +0000 (03:14 +0000)
committerkainazzzo <redacted>
Tue, 14 Jun 2005 03:14:35 +0000 (03:14 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@327 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/config.cpp
gameserv/do_attack.cpp
gameserv/extern.h
gameserv/flags.h
gameserv/gameserv.cpp
gameserv/player.cpp
gameserv/player.h
gameserv/tcpclient.cpp

index ec3605e033bec55fe2d0f0815826883171964d5c..c9f72304184b1d8f25cd3a39e41043044da28135 100644 (file)
@@ -45,6 +45,8 @@ char *remoteport;             // Port to connect to on remoteserver
 char *remotepass;              // Password for the server link
 
 char *playerdata;              // File to store player data in
+char *dragondata;              // File to store current dragon data in
+char *masterdata;              // File to store the master data in
 char *newsdata;                        // File to store news data in
 char *pidfile;                 // Process ID file
 
@@ -74,6 +76,10 @@ void unload_config_file()
        delete [] remotepass;
     if (playerdata)
        delete [] playerdata;
+    if (dragondata)
+       delete [] dragondata;
+    if (masterdata)
+       delete [] masterdata;
     if (adminpass)
        delete [] adminpass;
     if (welcomemsg)
@@ -96,7 +102,7 @@ int load_config_file(char *config)
 {
     char *buf, *directive, *value;
 
-    #define numdirectives 28
+    #define numdirectives 30
 
     unload_config_file();
 
@@ -149,6 +155,9 @@ int load_config_file(char *config)
                        "GameServ should identify with NickServ";
     directives[26].desc = "NSNAME - Your network's NickServ nickname";
     directives[27].desc = "NSPASS - GameServ's NickServ Password";
+    directives[28].desc = "DRAGONDATA - File to store the current "\
+                       "dragon's stats in";
+    directives[29].desc = "MASTERDATA - File to store the level master stats in";
 
     configflags = 0;
 
@@ -378,6 +387,20 @@ int load_config_file(char *config)
            strcpy(nspass, value);
            directives[27].done = true;
        }
+       else if (stricmp(directive, "DRAGONDATA") == 0)
+       {
+           value = strtok(NULL, "");
+           dragondata = new char[strlen(value) + 1];
+           strcpy(dragondata, value);
+           directives[28].done = true;
+       }
+       else if (stricmp(directive, "MASTERDATA") == 0)
+       {
+           value = strtok(NULL, "");
+           masterdata = new char[strlen(value) + 1];
+           strcpy(masterdata, value);
+           directives[29].done = true;
+       }
        else if (stricmp(directive, "WELCOMEMSG") == 0)
        {
            // This directive is optional
index 1f53b24bac46eae7b84c4782626e601faed04d50..4f1ce64a2884bcc0885cec1d4810f8404d485641 100644 (file)
@@ -52,7 +52,8 @@ void do_attack(char *u)
     {
       // Player's Hit
       hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
-       (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
+       (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2)) - 
+       fight->defense;
 
       // Opponent's Hit
       mhit = (fight->strength / 2) +
@@ -95,13 +96,22 @@ void do_attack(char *u)
          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 (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 = weapons[ni->stats->weapon];
+           dragon.strength = ni->stats->strength + webonus[ni->stats->weapon];
+           dragon.defense = ni->stats->defense + arbonus[ni->stats->armor];
+           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.
index 576be8964c0b5459c8c068ec9f3c9aafde3d45b8..00d1d783dfd2275a293129b14f6375728c25852e 100644 (file)
@@ -52,6 +52,7 @@ E char *pidfile;
 E char *newsdata;
 E char *nsname;
 E char *nspass;
+E Monster dragon;
 
 #if defined(P10)
 E char *gsnum;
@@ -62,6 +63,8 @@ E char *remoteserver;
 E char *remoteport;
 E char *remotepass;
 E char *playerdata;
+E char *dragondata;
+E char *masterdata;
 E char *logfile;
 E char *adminpass;
 E char *VERSION;
@@ -207,6 +210,8 @@ E void showinventory(aClient *from, aClient *to = NULL);
 
 E int save_gs_dbase();
 E int load_gs_dbase();
+E int load_dragon();
+E int save_dragon();
 
 // Log File Stuff
 E void log(const char *fmt, ...);
index 833fbd649e2077d49a52e7c527be183156fb91f5..42d4217f04c5d6302d94e10416055363beec4b53 100644 (file)
@@ -38,6 +38,7 @@
 #define FLAG_ALIVE             0x00000002
 #define FLAG_YOURTURN          0x00000004
 #define FLAG_WONGAME           0x00000008
+#define FLAG_DRAGONFIGHT       0x00000010
 
 // Config File flags
 #define CFLAG_LISTENONCF               0x00000001
 #define setWonGame(x)          ((x)->addFlag(FLAG_WONGAME))
 #define clearWonGame(x)                ((x)->remFlag(FLAG_WONGAME))
 
+#define isDragonFight(x)       ((x)->getFlags() & FLAG_DRAGONFIGHT)
+#define setDragonFight(x)      ((x)->addFlag(FLAG_DRAGONFIGHT))
+#define clearDragonFight(x)    ((x)->remFlag(FLAG_DRAGONFIGHT))
+
 #endif
index 523431f35c26c251008f85c25ed5c4e0a5418b2e..83759229c276f87b1a93ff48696cb755bcb91585 100644 (file)
@@ -24,12 +24,14 @@ using std::ios;
 
 #endif
 
-
+Monster dragon;                                // The current dragon
 Level levels[LEVELS];                  // The newest way to store monsters
 
 // Database functions
 int save_gs_dbase();
 int load_gs_dbase();
+int load_dragon();
+int save_dragon();
 
 // String functions
 #ifndef HAVE_STRTOK
@@ -1383,22 +1385,22 @@ void do_stats(char *u)
 
 bool load_masters()
 {
-    ifstream infile("data/masters.dat");
+    ifstream infile(masterdata);
     char *buf;
     int l = 0;
     buf = new char[1024];
 
     if (infile.fail())
     {
-       log("Error opening data/masters.dat");
+       log("Error opening %s", masterdata);
        return false;
     }
 
     #ifdef DEBUGMODE
-       log("Loading masters from data/masters.dat");
+       log("Loading masters from %s", masterdata);
     #endif
 
-    for (l = 0; l < LEVELS; l++)
+    for (l = 0; l < LEVELS - 1; l++)
     {
        infile.getline(buf, 1024, '\n');
 
@@ -1436,7 +1438,7 @@ bool load_masters()
 
     delete []buf;
 
-    if (l < LEVELS)  // We didn't load a master for every level - check data/masters.dat
+    if (l < LEVELS - 1)  // We didn't load a master for every level - check data/masters.dat
        return false;
     else
        return true;
@@ -1589,7 +1591,7 @@ bool dragon_fight(aClient *user)
     if (!is_playing(user))
        return false;
     else
-       return (user->stats->level == LEVELS && master_fight(user));
+       return (isDragonFight(user->stats));
 }
 void do_fight(char *u)
 {
@@ -2164,13 +2166,75 @@ outfile.close();
 return 1;
 }
 
+int load_dragon()
+{
+    ifstream infile;
+    char *buf;
+
+    infile.open(dragondata);
+
+    if (infile.fail())
+    {
+       infile.clear();
+       log ("Error opening %s. Trying initialdragon.dat", dragondata);
+       infile.open("data/initialdragon.dat");
+       if (infile.fail())
+        {
+           log ("Error opening data/initialdragon.dat");
+           return 0;
+       }
+    }
+
+    buf = new char[1024];
+
+    infile.getline(buf, 1024, '\n');
+    infile.close(); // Done with the file... we have what we want
+
+    dragon.name = strtok(buf, "~");
+    dragon.weapon = strtok(NULL, "~");
+    dragon.gold = 0;
+    dragon.exp = 0;
+    dragon.strength = stringtoint(strtok(NULL, "~"));
+    dragon.hp = stringtoint(strtok(NULL, "~"));
+    dragon.defense = stringtoint(strtok(NULL, "~"));
+    dragon.death = strtok(NULL, "");
+
+    log ("loaded dragon: %s", dragon.name.c_str());
+
+    delete []buf;
+
+return save_dragon();  // Save the dragon file and return the status code :)
+}
+
+int save_dragon()
+{
+    ofstream outfile;
+
+    outfile.open(dragondata);
+
+    if (outfile.fail())
+    {
+       log ("Error opening %s. Exiting.", dragondata);
+       return 0;
+    }
+
+    outfile << dragon.name.c_str() << '~' << dragon.weapon.c_str() << '~' 
+               << dragon.strength << '~' << dragon.hp << '~' 
+               << dragon.defense << '~' << dragon.death.c_str() << "\n^"
+               << endl;
+
+outfile.close();
+
+return 1;
+}
+
 int load_gs_dbase()
 {
     ifstream infile;
     aClient *temp;
     Player *p;
     char *tempname, *buf, *password;
-    buf = new char[1023];
+    buf = new char[1024];
 
     infile.open(playerdata);
 
@@ -2910,7 +2974,9 @@ void do_dragon(char *u)
     notice(s_GameServ, u, "Just then you notice the eye begin to "\
        "glare orange! The tooth is moving... but it is still too "\
        "dark for you to make out.... THE DRAGON! You see it!");
-    see_master(u);
+    p->fight = new Monster(dragon);
+    setDragonFight(p);
+    display_monster(u);
 }
 
 void do_master(char *u)
index df3aaed9c7cd4e8557f2879ae0eb972939cb7d20..372ebe1fbb726ca903065c27fbc6cde467ba5d25 100644 (file)
@@ -153,6 +153,7 @@ monster_::monster_()
     weapon.erase();
     death.erase();
     strength = 0;
+    defense = 0;
     exp = 0;
     gold = 0;
     maxhp = hp = 0;
@@ -164,6 +165,7 @@ monster_::monster_(monster_ *m)
     weapon = m->weapon;
     death = m->death;
     strength = m->strength;
+    defense = m->defense;
     maxhp = m->maxhp;
     hp = m->hp;
     gold = m->gold;
@@ -176,6 +178,7 @@ monster_::monster_(monster_ &m)
     weapon = m.weapon;
     death = m.death;
     strength = m.strength;
+    defense = m.defense;
     maxhp = m.maxhp;
     hp = m.hp;
     gold = m.gold;
index 0425406c2983d5afacbc4aeb92f444d356c0b87d..48fb67e478a99581e0b321d39ff88c4a48876af7 100644 (file)
@@ -61,14 +61,15 @@ struct monster_ {
     monster_(monster_ *);
     monster_(monster_ &);
     ~monster_();
-    string name;    // The monster's name
-    string weapon;  // A name for their weapon. Doesn't have to be in weapons[]
-    int strength;  // Their strength
-    int gold;      // The gold you get when you kill them
-    int exp;       // The experience you get when you kill them
-    int hp;        // Their remaining hitpoints
-    int maxhp;     // Their max hitpoints
-    string death;   // What is said when they die
+    string name;       // The monster's name
+    string weapon;     // A name for their weapon. Doesn't have to be in weapons[]
+    int strength;      // Their strength
+    int gold;          // The gold you get when you kill them
+    int exp;           // The experience you get when you kill them
+    int hp;            // Their remaining hitpoints
+    int maxhp;         // Their max hitpoints
+    int defense;       // Only used seldomly
+    string death;      // What is said when they die
 };
 
 #endif
index fa73761f74c8978c4e8fa7c5306b83e39f93f4af..dccf1c9dd870de905597717546844521c082fdea 100644 (file)
@@ -117,6 +117,12 @@ int main(int argc, char *argv[])
        goto end;
   }
 
+  if (!load_dragon())
+  {
+       log("Error loading dragon");
+       goto end;
+  }
+
   if (load_levels() == false)
   {
        log("Error loading levels");
@@ -584,6 +590,7 @@ int main(int argc, char *argv[])
   end:
 
   save_gs_dbase();
+  save_dragon();
   saveNews(newsdata, todaysnews);
 
   delete_monsters();