void Player::reset()
{
- exp = 1;
- gold = 0;
- bank = 500;
- hp = 10;
- maxhp = 10;
- strength = 2;
- defense = 1;
- level = 1;
- forest_fights = forestfights;
- player_fights = 3;
- fight = NULL;
- master = NULL;
- battle = NULL;
- flags = 0;
- lastcommand = 0;
- lastlogin = time(NULL);
- setAlive(this);
- clearMaster(this);
- w = NULL;
- a = NULL;
- inventory->clear();
+ exp = 1;
+ gold = 0;
+ bank = 500;
+ hp = 10;
+ maxhp = 10;
+ strength = 2;
+ defense = 1;
+ level = 1;
+ forest_fights = forestfights;
+ player_fights = 3;
+ fight = NULL;
+ master = NULL;
+ battle = NULL;
+ flags = 0;
+ lastcommand = 0;
+ lastlogin = time(NULL);
+ setAlive(this);
+ clearMaster(this);
+ w = NULL;
+ a = NULL;
+ inventory->clear();
}
Player::Player()
{
- inventory = new pouch();
- setData(NULL);
+ inventory = new pouch();
+ setData(NULL);
#ifdef DEBUGMODE
- log("New Player: %s", name.c_str());
+ log("New Player: %s", name.c_str());
#endif
}
Player::Player(char *n)
{
- inventory = new pouch();
- reset(); // Set defaults
-
- name = n;
+ inventory = new pouch();
+ reset(); // Set defaults
+
+ name = n;
#ifdef DEBUGMODE
- log("New Player: %s", name.c_str());
+ log("New Player: %s", name.c_str());
#endif
}
Player::Player(string n)
{
- inventory = new pouch();
- reset();
- name = n;
+ inventory = new pouch();
+ reset();
+ name = n;
#ifdef DEBUGMODE
- log("New Player: %s", name.c_str());
+ log("New Player: %s", name.c_str());
#endif
}
Player::~Player()
{
- if (inventory != NULL)
- delete inventory;
+ if (inventory != NULL)
+ delete inventory;
- delMonster();
- delMaster();
- delBattle();
+ delMonster();
+ delMaster();
+ delBattle();
#ifdef DEBUGMODE
- string *output;
- output = new string("Deleting Player");
- *output += ": " + name;
- *output += " Password: " + password;
- log ("%s", output->c_str());
- delete output;
+ string *output;
+ output = new string("Deleting Player");
+ *output += ": " + name;
+ *output += " Password: " + password;
+ log ("%s", output->c_str());
+ delete output;
#endif
}
void Player::setPassword(const char *p)
{
- static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV\
-WXYZ0123456789./";
- static char salt[3];
+ static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV\
+ WXYZ0123456789./";
+ static char salt[3];
- salt[0] = saltChars[rand() % strlen(saltChars)];
- salt[1] = saltChars[rand() % strlen(saltChars)];
- salt[2] = '\0';
+ salt[0] = saltChars[rand() % strlen(saltChars)];
+ salt[1] = saltChars[rand() % strlen(saltChars)];
+ salt[2] = '\0';
- password = crypt(p, salt);
+ password = crypt(p, salt);
}
void Player::setRawPassword(const char *p)
{
- password = p;
+ password = p;
}
void Player::setData(Player *right)
{
- if (right)
+ if (right)
{
- name = right->name;
- password = right->password;
- exp = right->exp;
- gold = right->gold;
- bank = right->bank;
- hp = right->hp;
- maxhp = right->maxhp;
- strength = right->strength;
- defense = right->defense;
- level = right->level;
- forest_fights = right->forest_fights;
- player_fights = right->player_fights;
- flags = right->flags;
- *inventory = *right->inventory;
- client = right->client;
- lastcommand = right->lastcommand;
- lastlogin = right->lastlogin;
- w = right->w;
- a = right->a;
+ name = right->name;
+ password = right->password;
+ exp = right->exp;
+ gold = right->gold;
+ bank = right->bank;
+ hp = right->hp;
+ maxhp = right->maxhp;
+ strength = right->strength;
+ defense = right->defense;
+ level = right->level;
+ forest_fights = right->forest_fights;
+ player_fights = right->player_fights;
+ flags = right->flags;
+ *inventory = *right->inventory;
+ client = right->client;
+ lastcommand = right->lastcommand;
+ lastlogin = right->lastlogin;
+ w = right->w;
+ a = right->a;
}
- else
+ else
{
- char *temp;
- reset();
- temp = new char[16];
- client = NULL;
- int num = rand() % 32767;
- snprintf(temp, 16, "Player: %d", num);
- name = temp;
- delete []temp;
+ char *temp;
+ reset();
+ temp = new char[16];
+ client = NULL;
+ int num = rand() % 32767;
+ snprintf(temp, 16, "Player: %d", num);
+ name = temp;
+ delete []temp;
}
#ifdef DEBUGMODE
- log("Setting Player data for %s", name.c_str());
+ log("Setting Player data for %s", name.c_str());
#endif
}
Monster::Monster()
{
- name.erase();
- weapon.erase();
- death.erase();
- strength = 0;
- defense = 0;
- exp = 0;
- gold = 0;
- maxhp = hp = 0;
+ name.erase();
+ weapon.erase();
+ death.erase();
+ strength = 0;
+ defense = 0;
+ exp = 0;
+ gold = 0;
+ maxhp = hp = 0;
}
Monster::Monster(Monster *m)
{
- name = m->name;
- weapon = m->weapon;
- death = m->death;
- strength = m->strength;
- defense = m->defense;
- maxhp = m->maxhp;
- hp = m->hp;
- gold = m->gold;
- exp = m->exp;
+ name = m->name;
+ weapon = m->weapon;
+ death = m->death;
+ strength = m->strength;
+ defense = m->defense;
+ maxhp = m->maxhp;
+ hp = m->hp;
+ gold = m->gold;
+ exp = m->exp;
}
Monster::Monster(Monster &m)
{
- name = m.name;
- weapon = m.weapon;
- death = m.death;
- strength = m.strength;
- defense = m.defense;
- maxhp = m.maxhp;
- hp = m.hp;
- gold = m.gold;
- exp = m.exp;
+ name = m.name;
+ weapon = m.weapon;
+ death = m.death;
+ strength = m.strength;
+ defense = m.defense;
+ maxhp = m.maxhp;
+ hp = m.hp;
+ gold = m.gold;
+ exp = m.exp;
}
Monster::Monster(const Monster &m)
{
- name = m.name;
- weapon = m.weapon;
- death = m.death;
- strength = m.strength;
- defense = m.defense;
- maxhp = m.maxhp;
- hp = m.hp;
- gold = m.gold;
- exp = m.exp;
+ name = m.name;
+ weapon = m.weapon;
+ death = m.death;
+ strength = m.strength;
+ defense = m.defense;
+ maxhp = m.maxhp;
+ hp = m.hp;
+ gold = m.gold;
+ exp = m.exp;
}
long int Player::setFlags(long int newflags)
{
- flags = newflags;
- return getFlags();
+ flags = newflags;
+ return getFlags();
}
long int Player::addFlag(long int flag)
{
- flags |= flag;
- return getFlags();
+ flags |= flag;
+ return getFlags();
}
long int Player::remFlag(long int flag)
{
- flags &= ~flag;
- return getFlags();
+ flags &= ~flag;
+ return getFlags();
}
void Player::setWeapon(item &weap)
{
- w = &weap;
+ w = &weap;
}
void Player::setArmor(item &arm)
{
- a = &arm;
+ a = &arm;
}
void Player::setName(string &n)
{
- name = n;
+ name = n;
}
void Player::setName(const char *n)
{
- name = n;
+ name = n;
}
void Player::setLevel(int l)
{
- if (l > 0 && l <= REALLEVELS)
- {
- level = l;
- }
+ if (l > 0 && l <= REALLEVELS)
+ {
+ level = l;
+ }
}
void Player::setExp(long int e)
{
- if (e <= 2000000000 && e > 0)
- {
- exp = e;
- }
+ if (e <= 2000000000 && e > 0)
+ {
+ exp = e;
+ }
}
void Player::setGold(long int g)
{
- if (g <= 2000000000 && g >= 0)
- {
- gold = g;
- }
- else if (g > 2000000000)
- {
- gold = 2000000000;
- }
+ if (g <= 2000000000 && g >= 0)
+ {
+ gold = g;
+ }
+ else if (g > 2000000000)
+ {
+ gold = 2000000000;
+ }
}
void Player::setBank(long int b)
{
- if (b <= 2000000000 && b >= 0)
- {
- bank = b;
- }
- else if (b > 2000000000)
- {
- bank = 2000000000;
- }
+ if (b <= 2000000000 && b >= 0)
+ {
+ bank = b;
+ }
+ else if (b > 2000000000)
+ {
+ bank = 2000000000;
+ }
}
void Player::setHP(int h)
{
- hp = h;
+ hp = h;
- if (hp < 0)
- {
- hp = 0;
- }
- else if (hp > maxhp)
- {
- hp = maxhp; // You can't go higher than your maxhp
- }
+ if (hp < 0)
+ {
+ hp = 0;
+ }
+ else if (hp > maxhp)
+ {
+ hp = maxhp; // You can't go higher than your maxhp
+ }
}
void Player::setMaxHP(int m)
{
- maxhp = m;
+ maxhp = m;
- if (maxhp < 0)
- {
- maxhp = 10;
- }
- else if (maxhp > 32000)
- {
- maxhp = 32000;
- }
+ if (maxhp < 0)
+ {
+ maxhp = 10;
+ }
+ else if (maxhp > 32000)
+ {
+ maxhp = 32000;
+ }
}
void Player::setStrength(int s)
{
- strength = s;
- if (strength < 0)
- {
- strength = 1;
- }
- else if (strength > 32000)
- {
- strength = 32000;
- }
+ strength = s;
+ if (strength < 0)
+ {
+ strength = 1;
+ }
+ else if (strength > 32000)
+ {
+ strength = 32000;
+ }
}
void Player::setDefense(int d)
{
- defense = d;
+ defense = d;
- if (defense < 0)
- {
- defense = 1;
- }
- else if (defense > 32000)
- {
- defense = 32000;
- }
+ if (defense < 0)
+ {
+ defense = 1;
+ }
+ else if (defense > 32000)
+ {
+ defense = 32000;
+ }
}
void Player::setForestFights(int ff)
{
- forest_fights = ff;
+ forest_fights = ff;
- if (forest_fights < 0)
- {
- forest_fights = 0;
- }
- else if (forest_fights > 32000)
- {
- forest_fights = 32000;
- }
+ if (forest_fights < 0)
+ {
+ forest_fights = 0;
+ }
+ else if (forest_fights > 32000)
+ {
+ forest_fights = 32000;
+ }
}
void Player::setPlayerFights(int pf)
{
- player_fights = pf;
+ player_fights = pf;
- if (player_fights < 0)
- {
- player_fights = 0;
- }
- else if (player_fights > 32000)
- {
+ if (player_fights < 0)
+ {
+ player_fights = 0;
+ }
+ else if (player_fights > 32000)
+ {
player_fights = 32000;
- }
+ }
}
void Player::setClient(aClient *c)
{
- client = c;
+ client = c;
}
void Player::setMonster(Monster *m)
{
- fight = new Monster(m);
+ fight = new Monster(m);
}
void Player::setMyMaster(Monster *m)
{
- master = new Monster(m);
+ master = new Monster(m);
}
void Player::setBattle(aClient *b)
{
- battle = b;
+ battle = b;
}
void Player::addExp(int e)
{
- setExp(getExp() + e);
+ setExp(getExp() + e);
}
void Player::addGold(int g)
{
- setGold(getGold() + g);
+ setGold(getGold() + g);
}
void Player::addBank(int b)
{
- setBank(getBank() + b);
+ setBank(getBank() + b);
}
void Player::addHP(int h)
{
- setHP(getHP() + h);
+ setHP(getHP() + h);
}
void Player::addMaxHP(int m)
{
- setMaxHP(getMaxHP() + m);
+ setMaxHP(getMaxHP() + m);
}
void Player::addStrength(int s)
{
- setStrength(getStrength() + s);
+ setStrength(getStrength() + s);
}
void Player::addDefense(int d)
{
- setDefense(getDefense() + d);
+ setDefense(getDefense() + d);
}
void Player::addForestFights(int ff)
{
- setForestFights(getForestFights() + ff);
+ setForestFights(getForestFights() + ff);
}
void Player::addPlayerFights(int pf)
{
- setPlayerFights(getPlayerFights() + pf);
+ setPlayerFights(getPlayerFights() + pf);
}
void Player::addLevel(int l)
{
- setLevel(getLevel() + l);
+ setLevel(getLevel() + l);
}
void Player::subtractLevel(int l)
{
- setLevel(getLevel() - l);
+ setLevel(getLevel() - l);
}
void Player::subtractExp(long int e)
{
- setExp(getExp() - e);
+ setExp(getExp() - e);
}
void Player::subtractGold(long int g)
{
- setGold(getGold() - g);
+ setGold(getGold() - g);
}
void Player::subtractBank(long int b)
{
- setBank(getBank() - b);
+ setBank(getBank() - b);
}
void Player::subtractHP(int h)
{
- setHP(getHP() - h);
+ setHP(getHP() - h);
}
void Player::subtractMaxHP(int m)
{
- setMaxHP(getMaxHP() - m);
+ setMaxHP(getMaxHP() - m);
}
void Player::subtractStrength(int s)
{
- setStrength(getStrength() - s);
+ setStrength(getStrength() - s);
}
void Player::subtractDefense(int d)
{
- setDefense(getDefense() - d);
+ setDefense(getDefense() - d);
}
void Player::subtractForestFights(int ff)
{
- setForestFights(getForestFights() - ff);
+ setForestFights(getForestFights() - ff);
}
void Player::subtractPlayerFights(int pf)
{
- setPlayerFights(getPlayerFights() - pf);
+ setPlayerFights(getPlayerFights() - pf);
}
void Player::delMonster()
{
- if (fight)
- delete fight;
+ if (fight)
+ delete fight;
- fight = NULL;
+ fight = NULL;
}
void Player::delMaster()
{
- if (master)
- delete master;
+ if (master)
+ delete master;
- master = NULL;
+ master = NULL;
}
void Player::delBattle()
{
- // Don't delete the other player's aClient
- battle = NULL;
-}
-
-bool Player::operator <(Player &right)
-{
- if (getLevel() < right.getLevel())
- {
- return true;
- }
- else if (getExp() < right.getExp())
- {
- return true;
- }
- else if (getStrength() < right.getStrength() && getDefense() < right.getDefense())
- {
- return true;
- }
- else
- {
- return false;
- }
+ // Don't delete the other player's aClient
+ battle = NULL;
+}
+
+bool Player::operator < (Player &right)
+{
+ if (getLevel() < right.getLevel())
+ {
+ return true;
+ }
+ else if (getExp() < right.getExp())
+ {
+ return true;
+ }
+ else if (getStrength() < right.getStrength() && getDefense() < right.getDefense())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}