]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/item.cpp
Items are being loaded from the itemdata file
[irc/gameservirc.git] / gameserv / item.cpp
index 5532ba3175be9014e15404c9f35fbc34781d66b5..a645cf3697e17b45c42802d935517c6f5b83346f 100644 (file)
@@ -103,44 +103,36 @@ 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
+      // If we got here, we're successful
       return true;
     }
   catch (char *str)
     {
-      log("Exception: %s", str);
+      log("Exception setting weapon data: %s", str);
       return false;
     }
 }
@@ -184,49 +176,47 @@ void armor::undo(Player *p)
 
 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);
+  try
+    {
+      char *temp;
+      mytype = ARMOR;
 
-  // Grab the item's modifiers
-  for (int x = 0; x < 5; x++)
+      // Grab the item's id
+      temp = strtok(NULL, "~");
+      id = stringtoint(temp);
+      log("id = %ld", id);
+      
+      // Grab the item's name
+      temp = strtok(NULL, "~");
+      myname = temp;
+      log("name = %s", myname.c_str());
+      
+      // Grab the item's price
+      temp = strtok(NULL, "~");
+      myprice = stringtoint(temp);
+      log("price = %ld", myprice);
+      
+      // Grab the item's uses
+      temp = strtok(NULL, "~");
+      myuses = stringtoint(temp);
+      log("uses = %d", myuses);
+      
+      // Grab the item's modifiers
+      for (int x = 0; x < 4; x++)
+       {
+         temp = strtok(NULL, "~");
+         mymodifiers[x] = stringtoint(temp);
+         log("modifier %d = %ld", x, mymodifiers[x]);
+       }
+      // If we got here, we were successful
+      return true;
+    }
+  catch(char *str)
     {
-      temp = strtok("~", NULL);
-      if (!temp)
-       return false;
-      mymodifiers[x] = stringtoint(temp);
+      log("Exception setting armor data: %s", str);
+      return false;
     }
 
-  // If we got here, we were successful
-  return true;
 }
 
 bool armor::use(Player *p)
@@ -248,6 +238,10 @@ bool armor::use(Player *p)
   return true;
 }
 
+potion::~potion()
+{
+}
+
 bool potion::use(Player *p)
 {
   // potion(char *name, int p=0, int uses = 1, 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)
@@ -280,47 +274,40 @@ void potion::undo(Player *p)
 
 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++)
+  try
     {
-      temp = strtok("~", NULL);
-      if (!temp)
-       return false;
-      mymodifiers[x] = stringtoint(temp);
+      char *temp;
+      
+      mytype = ARMOR;
+      
+      // 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 < 5; x++)
+       {
+         temp = strtok(NULL, "~");
+         mymodifiers[x] = stringtoint(temp);
+       }
+    }
+  catch(char *str)
+    {
+      log("Exception setting potion data: %s", str);
+      return false;
     }
-
   // If we got here, we were successful
   return true;
 }
@@ -332,8 +319,7 @@ itemContainer::itemContainer()
   myitem = NULL;
 }
 
-itemContainer::itemContainer(item *i)
-{
+itemContainer::itemContainer(item *i){
   myuses = i->uses();
   myitem = i;
 }