#include "item.h"
#include "player.h"
+#include "extern.h"
item::item()
{
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)
p->maxhp -= mymodifiers[2];
}
-bool weapon::setData(const char *dataStr)
-{
-
- return true;
-}
-
armor::~armor()
{
}
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;
}
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;
}