]> jfr.im git - irc/gameservirc.git/commitdiff
still working on stuff for the items classes
authorkainazzzo <redacted>
Thu, 30 Jun 2005 19:54:09 +0000 (19:54 +0000)
committerkainazzzo <redacted>
Thu, 30 Jun 2005 19:54:09 +0000 (19:54 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@346 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/data/items/masteritems.dat
gameserv/devel.cpp
gameserv/item.cpp
gameserv/item.h

index e7136d5f722dbbd7c04c42657c558cf2542a54e8..5b7501284ea2b59b2ba1b702ae70b707f841f355 100644 (file)
@@ -1,36 +1,36 @@
-# ID~type~name~price~uses~strengthmod~defensemod~maxhpmod~hpmod~forestfightsmod~playerfightsmod~goldmod~bankbalmod
+# type~ID~name~price~uses~strengthmod~defensemod~maxhpmod~hpmod~forestfightsmod~playerfightsmod~goldmod~bankbalmod
 # Weapons 1-3000
-1~1~Stick~200~10~0~0~0~0~0~0~0
-2~1~Dagger~1000~15~0~0~0~0~0~0
-3~1~Quarterstaff~3000~25~0~0~0~0~0
-4~1~Short Sword~10000~35~0~0~0~0~0
-5~1~Long Sword~30000~45~0~0~0~0~0
-6~1~Silver Spear~100000~65~0~0~0~0~0
-7~1~Battle Axe~150000~85~0~0~0~0~0
-8~1~The Ragnarok~200000~125~0~0~0~0~0
-9~1~Chain Saw~400000~185~0~0~0~0~0
-10~1~Poison Sword~1000000~255~0~0~0~0~0
-11~1~Flame Sword~4000000~355~0~0~0~0~0
-12~1~Earth Hammer~10000000~505~0~0~0~0~0
-13~1~Light Saber~40000000~805~0~0~0~0~0
-14~1~Masamune~100000000~1205~0~0~0~0~0
-15~1~Excalibur~400000000~1805~0~0~0~0~0
+1~1~Stick~200~-1~10~0~0~0
+1~2~1~Dagger~1000~-1~15~0~0~0
+1~3~1~Quarterstaff~3000~-1~25~0~0~0
+1~4~1~Short Sword~10000~-1~35~0~0~0
+1~5~Long Sword~30000~-1~45~0~0~0
+1~6~Silver Spear~100000~-1~65~0~0~0
+1~7~Battle Axe~150000~-1~85~0~0~0
+1~8~The Ragnarok~200000~-1~125~0~0~0
+1~9~Chain Saw~400000~185~-1~0~0~0
+1~10~Poison Sword~1000000~-1~255~0~0~0
+1~11~Flame Sword~4000000~-1~355~0~0~0
+1~12~Earth Hammer~10000000~-1~505~0~0~0
+1~13~Light Saber~40000000~-1~805~0~0~0
+1~14~Masamune~100000000~-1~1205~0~0~0
+1~15~Excalibur~400000000~-1~1805~0~0~0
 # Armor 3001-6000
-3001~2~Clothes~0~3~0~0~0~0
-3002~2~Leather Vest~0~5~0~0~0~0
-3003~2~Chain Mail~0~10~0~0~0~0
-3004~2~Plate Armor~0~15~0~0~0~0
-3005~2~Full Body Armor~0~25~0~0~0~0
-3006~2~Magic Mail~0~35~0~0~0~0
-3007~2~Graphite Suit~0~50~0~0~0~0
-3008~2~Steel Suit~0~75~0~0~0~0
-3009~2~Force Field~0~100~0~0~0~0
-3010~2~Armor of Light~0~150~0~0~0~0
-3011~2~Mythril Vest~0~225~0~0~0~0
-3012~2~DemiGod Armor~0~300~0~0~0~0
-3013~2~Hades' Cloak~0~400~0~0~0~0
-3014~2~Dragon Scales~0~600~0~0~0~0
-3015~2~Adamantium~0~1000~0~0~0~0
+2~3001~Clothes~0~3~0~0~0~0
+2~3002~Leather Vest~0~5~0~0~0~0
+2~3003~Chain Mail~0~10~0~0~0~0
+2~3004~Plate Armor~0~15~0~0~0~0
+2~3005~Full Body Armor~0~25~0~0~0~0
+2~3006~Magic Mail~0~35~0~0~0~0
+2~3007~Graphite Suit~0~50~0~0~0~0
+2~3008~Steel Suit~0~75~0~0~0~0
+2~3009~Force Field~0~100~0~0~0~0
+2~3010~Armor of Light~0~150~0~0~0~0
+2~3011~Mythril Vest~0~225~0~0~0~0
+2~3012~DemiGod Armor~0~300~0~0~0~0
+2~3013~Hades' Cloak~0~400~0~0~0~0
+2~3014~Dragon Scales~0~600~0~0~0~0
+2~3015~Adamantium~0~1000~0~0~0~0
 # Potions 6001-9000
 
 # Miscellaneous 9001-12000
index be44dae41bb569cd53f7bd2dc8c7155810194f34..70e9fc799abfd2251632474a63bec4d6df1cde17 100644 (file)
@@ -20,12 +20,13 @@ char *VERSION = "1.2.6 +devel";
 long lastrefresh;
 
 List<aClient> clients[U_TABLE_SIZE];
+list <item*> items;
 
 void save_lastrefresh();
 void load_lastrefresh();
 void prettyIntro();
 void check_idles();
-
+void testitems();
 
 int main(int argc, char *argv[])
 {
@@ -119,40 +120,40 @@ int main(int argc, char *argv[])
     }
 
  // This loop will retry the connection 3 times
+      connected = 1;
+      load_lastrefresh();
  
-    connected = 1;
-    load_lastrefresh();
+    {
+      testitems();
+      item *tester = items.front();
+      cout << tester->getName() << endl;
+      item *tester2 = items.back();
+      cout << tester2->getName() << endl;
+      items.clear();
+    }
 
     {
       // This is where you can test stuff
-
-      string playername;
-      Player *p;
-      
-      cout << "Enter an name: ";
-      cin >> playername;
-      p = new Player(playername);
-      
-      cout << "You entered: " << p->name << endl;
-      item *testitem, *tempitem;
-      weapon *testweapon;
-      cout << "Enter a weapon name: ";
-      cin >> playername;
-      testitem = new weapon(playername);
-      testweapon = new weapon(playername, 10000);
-
-      cout << "You entered: " << testitem->getName() << endl;
-      cout << "Adding the item to your inventory" << endl;
-      p->inventory->addItem(testitem);
-
-      tempitem = p->inventory->Find(playername)->getItem();
-      cout << "Name: " << tempitem->getName() << endl;
-      tempitem = p->inventory->Find(playername)->getItem();
-      cout << "Name: " << tempitem->getName() << endl;
-      cout << "Testitem: " << &testitem << " Tempitem: " << &tempitem << endl;
-      
-
-      delete p;
+      /*
+       string itemname;
+       item *tempitem;
+       
+       cout << "Enter an item name: ";
+       cin >> itemname;
+       char num[16];
+       for (int x = 1; x < 6000001; x++)
+       {
+       sprintf(num, "%d", x);
+       tempitem = new weapon((itemname + num));
+       items.push_back(tempitem);
+       }
+       
+       item *tester = items.front();
+       cout << tester->getName() << endl;
+       item *tester2 = items.back();
+       cout << tester2->getName() << endl;
+       items.clear();
+      */
     }
 
  end:    
@@ -170,6 +171,31 @@ int main(int argc, char *argv[])
     unload_config_file();
     return 0;
 }
+
+void testitems()
+{
+      // This is where you can test stuff
+      string itemname;
+      item *tempitem;
+
+      cout << "Enter an item name: ";
+      cin >> itemname;
+      char num[16];
+      char *testing;
+      testing = new char[80];
+      strncpy(testing, "1~1~Stick~200~-1~15~0~0~0", 80);
+      for (int x = 1; x < 6000001; x++)
+       {
+         sprintf(num, "%d", x);
+         tempitem = new weapon("blah");
+         if (!tempitem->setData(testing))
+           {
+             cout << "Error in setData()" << endl;
+             break;
+           }
+         items.push_back(tempitem);
+       }
+}
     
 aClient *find(char *nick)
 {
index cf86c764d9f70c8abcf6893313aaf6f54a0286eb..5532ba3175be9014e15404c9f35fbc34781d66b5 100644 (file)
@@ -1,5 +1,6 @@
 #include "item.h"
 #include "player.h"
+#include "extern.h"
 
 item::item()
 {
@@ -79,10 +80,71 @@ bool item::operator!=(const item &right) const
   return myname != right.myname;
 }
 
+item &item::operator=(const item &right)
+{
+  myname = right.myname;
+  myprice = right.myprice;
+  myuses = right.myuses;
+  id = right.id;
+  mytype = right.mytype;
+
+  for (int x = 0; x < 8; x++)
+    {
+      mymodifiers[x] = right.mymodifiers[x];
+    }
+  return *this; // enables cascading x=y=z;
+}
 weapon::~weapon()
 {
 }
 
+bool weapon::setData(char *datastr)
+{
+  try
+    {
+      char *temp;
+      // Get the weapon type, but default to WEAPON since this is a weapon
+      temp = strtok(datastr, "~");
+
+      mytype = WEAPON;
+      // Grab the item's id
+      temp = strtok(NULL, "~");
+      
+      id = stringtoint(temp);
+      
+      // Grab the item's name
+      temp = strtok(NULL, "~");
+      
+      myname = temp;
+      
+      // Grab the item's price
+      temp = strtok(NULL, "~");
+      
+      myprice = stringtoint(temp);
+      
+      // Grab the item's uses
+      temp = strtok(NULL, "~");
+      
+      myuses = stringtoint(temp);
+      
+      // Grab the item's modifiers
+      for (int x = 0; x < 4; x++)
+       {
+         temp = strtok(NULL, "~");
+         
+         mymodifiers[x] = stringtoint(temp);
+       }
+      
+      // If we got here, we were successful
+      return true;
+    }
+  catch (char *str)
+    {
+      log("Exception: %s", str);
+      return false;
+    }
+}
+
 bool weapon::use(Player *p)
 {
   //  weapon(char *name, int p=0, int uses = -1, int strength=0, int defense=0, int maxhp=0)
@@ -109,12 +171,6 @@ void weapon::undo(Player *p)
   p->maxhp -= mymodifiers[2];
 }
 
-bool weapon::setData(const char *dataStr)
-{
-  
-  return true;
-}
-
 armor::~armor()
 {
 }
@@ -126,8 +182,50 @@ void armor::undo(Player *p)
   p->maxhp -= mymodifiers[2];
 }
 
-bool armor::setData(const char *dataStr)
+bool armor::setData(char *datastr)
 {
+  char *temp;
+
+  // Get the weapon type, but default to WEAPON since this is a weapon
+  temp = strtok("~", datastr);
+  if (!temp)
+    return false;
+  mytype = ARMOR;
+
+  // Grab the item's id
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  id = stringtoint(temp);
+
+  // Grab the item's name
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  myname = temp;
+
+  // Grab the item's price
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  myprice = stringtoint(temp);
+
+  // Grab the item's uses
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  myuses = stringtoint(temp);
+
+  // Grab the item's modifiers
+  for (int x = 0; x < 5; x++)
+    {
+      temp = strtok("~", NULL);
+      if (!temp)
+       return false;
+      mymodifiers[x] = stringtoint(temp);
+    }
+
+  // If we got here, we were successful
   return true;
 }
 
@@ -180,9 +278,50 @@ void potion::undo(Player *p)
   return;
 }
 
-bool potion::setData(const char *dataStr)
+bool potion::setData(char *datastr)
 {
-  
+  char *temp;
+
+  // Get the weapon type, but default to WEAPON since this is a weapon
+  temp = strtok("~", datastr);
+  if (!temp)
+    return false;
+  mytype = ARMOR;
+
+  // Grab the item's id
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  id = stringtoint(temp);
+
+  // Grab the item's name
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  myname = temp;
+
+  // Grab the item's price
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  myprice = stringtoint(temp);
+
+  // Grab the item's uses
+  temp = strtok("~", NULL);
+  if (!temp)
+    return false;
+  myuses = stringtoint(temp);
+
+  // Grab the item's modifiers
+  for (int x = 0; x < 5; x++)
+    {
+      temp = strtok("~", NULL);
+      if (!temp)
+       return false;
+      mymodifiers[x] = stringtoint(temp);
+    }
+
+  // If we got here, we were successful
   return true;
 }
 
index 0caed58fb521c306e6dab92829e00dd17a503fb5..6358089ae4fc6d0cc0750ee38d1fdbf074f51f57 100644 (file)
@@ -26,7 +26,7 @@ class item
   
   virtual bool use(Player *p) = 0;
   virtual void undo(Player *p) = 0;
-  virtual bool setData(const char *datastr) = 0;
+  virtual bool setData(char *datastr) = 0;
 
   type getType() {return mytype;};
   void setType(type);
@@ -35,6 +35,7 @@ class item
   bool operator>(const item &right) const;
   bool operator==(const item &right) const;
   bool operator!=(const item &right) const;
+  item &operator=(const item &right);
   
  protected:
   string myname;         // Name to use in game & sorting
@@ -80,9 +81,10 @@ class weapon : public item
   weapon(string name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
   ~weapon();
 
+  bool setData(char *datastr);
   bool use(Player *p);
   void undo(Player *p);
-  bool setData(const char *datastr);
+
 };
 
 class armor : public item
@@ -93,9 +95,9 @@ class armor : public item
   armor(string name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
   ~armor();
 
+  bool setData(char *datastr);
   bool use(Player *p);
   void undo(Player *p);
-  bool setData(const char *datastr);
 };
 
 class potion : public item
@@ -106,9 +108,9 @@ class potion : public item
   potion(string name, int p=0, int uses = 1, long int identifier=0, int strength=0, int defense=0, int maxhp=0, int hp=0, int forest_fights=0, int player_fights=0, int gold=0, int bank=0) : item(name, p, uses, strength, defense, maxhp, hp, forest_fights, player_fights, gold, bank){};
   ~potion();
 
+  bool setData(char *datastr);
   bool use(Player *p);
   void undo(Player *p);
-  bool setData(const char *datastr);
 
  protected:
   range myrange;