try
{
char *temp;
- // Get the weapon type, but default to WEAPON since this is a weapon
- temp = strtok(datastr, "~");
+ temp = strtok(datastr, "~"); // Type
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;
}
}
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;
+ try
+ {
+ char *temp;
+ strtok(datastr, "~"); // Type
- // Grab the item's price
- temp = strtok("~", NULL);
- if (!temp)
- return false;
- myprice = stringtoint(temp);
+ mytype = ARMOR;
- // Grab the item's uses
- temp = strtok("~", NULL);
- if (!temp)
- return false;
- myuses = stringtoint(temp);
+ // Grab the item's id
+ temp = strtok(NULL, "~");
+ id = stringtoint(temp);
- // Grab the item's modifiers
- for (int x = 0; x < 5; x++)
+ // 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)
{
- 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)
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)
return false;
else
{
- p->strength += mymodifiers[0];
- p->defense += mymodifiers[1];
- p->maxhp += mymodifiers[2];
- p->hp += mymodifiers[3];
- p->forest_fights += mymodifiers[4];
- p->player_fights += mymodifiers[5];
- p->gold += mymodifiers[6];
- p->bank += mymodifiers[7];
+ p->strength += myranges[0].random();
+ p->defense += myranges[1].random();
+ p->maxhp += myranges[2].random();
+ p->hp += myranges[3].random();
+ p->forest_fights += myranges[4].random();
+ p->player_fights += myranges[5].random();
+ p->gold += myranges[6].random();
+ p->bank += myranges[7].random();
}
if (myuses > 0)
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);
+ try
+ {
+ char *temp;
- // Grab the item's uses
- temp = strtok("~", NULL);
- if (!temp)
- return false;
- myuses = stringtoint(temp);
+ temp = strtok(datastr, "~"); // Type
- // Grab the item's modifiers
- for (int x = 0; x < 5; x++)
+ 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 < 8; x++)
+ {
+ temp = strtok(NULL, "~");
+ myranges[x].low = stringtoint(temp);
+ temp = strtok(NULL, "~");
+ myranges[x].high = stringtoint(temp);
+ }
+ }
+ catch(char *str)
{
- temp = strtok("~", NULL);
- if (!temp)
- return false;
- mymodifiers[x] = stringtoint(temp);
+ log("Exception setting potion data: %s", str);
+ return false;
}
-
// If we got here, we were successful
return true;
}
myitem = NULL;
}
-itemContainer::itemContainer(item *i)
-{
+itemContainer::itemContainer(item *i){
myuses = i->uses();
myitem = i;
}
{
return (*myitem == *right.myitem);
}
+
+void itemContainer::setUses(int uses)
+{
+ myuses = uses;
+}