# 1 "/home/gameserv/gameserv//"
-aClient.o: aClient.cpp aClient.h options.h player.h pouch.h extern.h \
- level.h list.h listnode.h config.h
+aClient.o: aClient.cpp aClient.h options.h item.h player.h pouch.h \
+ extern.h level.h list.h listnode.h config.h
# 1 "/home/gameserv/gameserv//"
-config.o: config.cpp extern.h player.h aClient.h options.h pouch.h \
- level.h list.h listnode.h config.h flags.h
+config.o: config.cpp item.h player.h pouch.h extern.h level.h list.h \
+ listnode.h aClient.h options.h config.h flags.h
# 1 "/home/gameserv/gameserv//"
-c_forest.o: c_forest.cpp sockhelp.h aClient.h options.h player.h pouch.h \
- list.h listnode.h extern.h level.h config.h flags.h
+c_forest.o: c_forest.cpp sockhelp.h aClient.h options.h item.h player.h \
+ pouch.h list.h listnode.h extern.h level.h config.h flags.h
# 1 "/home/gameserv/gameserv//"
-do_attack.o: do_attack.cpp aClient.h options.h player.h pouch.h extern.h \
- level.h list.h listnode.h config.h flags.h
+do_attack.o: do_attack.cpp aClient.h options.h item.h player.h pouch.h \
+ extern.h level.h list.h listnode.h config.h flags.h
# 1 "/home/gameserv/gameserv//"
-gameserv.o: gameserv.cpp aClient.h options.h player.h pouch.h config.h \
- extern.h level.h list.h listnode.h flags.h sockhelp.h
+gameserv.o: gameserv.cpp aClient.h options.h item.h player.h pouch.h \
+ config.h extern.h level.h list.h listnode.h flags.h sockhelp.h
# 1 "/home/gameserv/gameserv//"
-hash.o: hash.cpp extern.h player.h aClient.h options.h pouch.h level.h \
- list.h listnode.h config.h
+hash.o: hash.cpp item.h player.h pouch.h extern.h level.h list.h \
+ listnode.h aClient.h options.h config.h
# 1 "/home/gameserv/gameserv//"
-level.o: level.cpp extern.h player.h aClient.h options.h pouch.h level.h \
- list.h listnode.h config.h
+item.o: item.cpp item.h player.h pouch.h
# 1 "/home/gameserv/gameserv//"
-log.o: log.cpp extern.h player.h aClient.h options.h pouch.h level.h \
- list.h listnode.h config.h
+level.o: level.cpp item.h player.h pouch.h extern.h level.h list.h \
+ listnode.h aClient.h options.h config.h
# 1 "/home/gameserv/gameserv//"
-news.o: news.cpp extern.h player.h aClient.h options.h pouch.h level.h \
- list.h listnode.h config.h
+log.o: log.cpp extern.h item.h player.h pouch.h level.h list.h listnode.h \
+ aClient.h options.h config.h
# 1 "/home/gameserv/gameserv//"
-player.o: player.cpp player.h aClient.h options.h pouch.h extern.h \
- level.h list.h listnode.h config.h flags.h
+news.o: news.cpp extern.h item.h player.h pouch.h level.h list.h \
+ listnode.h aClient.h options.h config.h
# 1 "/home/gameserv/gameserv//"
-sockhelp.o: sockhelp.cpp sockhelp.h extern.h player.h aClient.h options.h \
- pouch.h level.h list.h listnode.h config.h
+player.o: player.cpp item.h player.h pouch.h extern.h level.h list.h \
+ listnode.h aClient.h options.h config.h flags.h
+# 1 "/home/gameserv/gameserv//"
+sockhelp.o: sockhelp.cpp sockhelp.h extern.h item.h player.h pouch.h \
+ level.h list.h listnode.h aClient.h options.h config.h
# 1 "/home/gameserv/gameserv//"
tcpclient.o: tcpclient.cpp sockhelp.h options.h list.h listnode.h \
- aClient.h player.h pouch.h extern.h level.h config.h flags.h
+ aClient.h item.h player.h pouch.h extern.h level.h config.h flags.h
do_attack.cpp \
gameserv.cpp \
hash.cpp \
+ item.cpp \
level.cpp \
log.cpp \
news.cpp \
#define ACLIENT_H
#include <string.h>
+#include "item.h"
#include "options.h"
#include "player.h"
#include <iostream>
+
using std::ostream;
class Player; // forward declaration
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include "item.h"
#include "extern.h"
#include "flags.h"
if (!player_fight(ni))
{
// Player's Hit
- hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
- (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2)) -
+ hit = ((ni->stats->strength + webonus[ni->stats->wea]) / 2) +
+ (rand() % ((ni->stats->strength + webonus[ni->stats->wea]) / 2)) -
fight->defense;
// Opponent's Hit
mhit = (fight->strength / 2) +
(rand() % (fight->strength / 2) - (ni->stats->defense +
- arbonus[ni->stats->armor]));
+ arbonus[ni->stats->arm]));
}
else
{
// Opponent's Hit
- mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
- (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
- (ni->stats->defense + arbonus[ni->stats->armor]));
+ mhit = (((battle->stats->strength + webonus[battle->stats->wea]) / 2) +
+ (rand() % ((battle->stats->strength + webonus[battle->stats->wea])) / 2) -
+ (ni->stats->defense + arbonus[ni->stats->arm]));
// Player's Hit
- hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
- (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) -
- (battle->stats->defense + arbonus[battle->stats->armor]));
+ hit = (((ni->stats->strength + webonus[ni->stats->wea]) / 2) +
+ (rand() % ((ni->stats->strength + webonus[ni->stats->wea])) / 2) -
+ (battle->stats->defense + arbonus[battle->stats->arm]));
}
if (!player_fight(ni))
ni->stats->name.c_str(), ni->stats->name.c_str(),
ni->stats->fight->name.c_str(), ni->stats->name.c_str());
dragon.name = "DRAGON-" + ni->stats->name;
- dragon.weapon = weapons[ni->stats->weapon];
- dragon.strength = ni->stats->strength + webonus[ni->stats->weapon];
- dragon.defense = ni->stats->defense + arbonus[ni->stats->armor];
+ dragon.weapon = weapons[ni->stats->wea];
+ dragon.strength = ni->stats->strength + webonus[ni->stats->wea];
+ dragon.defense = ni->stats->defense + arbonus[ni->stats->arm];
dragon.hp = ni->stats->maxhp;
dragon.maxhp = ni->stats->maxhp;
save_dragon();
notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
"^B%d^B damage!", ni->stats->name.c_str(),
- weapons[ni->stats->weapon], hit);
+ weapons[ni->stats->wea], hit);
}
else
{
#define WNA 16 // Weapons and armor
#include <stdarg.h>
+#include "item.h"
#include "player.h"
#include "level.h"
#include "list.h"
notice(s_GameServ, sender->getNick(), "Hit Points: %d of %d", ni->stats->hp,
ni->stats->maxhp);
- sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->weapon]);
+ sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->wea]);
space = spaces(strlen(buf), " ");
notice(s_GameServ, sender->getNick(), "%s%sDefense: %d",
- buf, space, ni->stats->defense + arbonus[ni->stats->armor]);
+ buf, space, ni->stats->defense + arbonus[ni->stats->arm]);
delete [] space;
- sprintf(buf, "Armor: %s", armors[ni->stats->armor]);
+ sprintf(buf, "Armor: %s", armors[ni->stats->arm]);
space = spaces(strlen(buf), " ");
notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space,
- weapons[ni->stats->weapon]);
+ weapons[ni->stats->wea]);
delete [] space;
sprintf(buf, "Forest Fights: %d", ni->stats->forest_fights);
return;
}
- target->stats->weapon = stringtoint(cmd2);
+ target->stats->wea = stringtoint(cmd2);
- if (target->stats->weapon < 0)
- target->stats->weapon = 0;
- else if (target->stats->weapon >= WNA)
- target->stats->weapon = WNA - 1;
- notice(s_GameServ, u, "Weapon set to %s", weapons[target->stats->weapon]);
+ if (target->stats->wea < 0)
+ target->stats->wea = 0;
+ else if (target->stats->wea >= WNA)
+ target->stats->wea = WNA - 1;
+ notice(s_GameServ, u, "Weapon set to %s", weapons[target->stats->wea]);
return;
}
}
notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] ARMOR <NUMBER>");
return;
}
- target->stats->armor = stringtoint(cmd2);
+ target->stats->arm = stringtoint(cmd2);
- if (target->stats->armor < 0)
- target->stats->armor = 0;
- else if (target->stats->armor >= WNA)
- target->stats->armor = WNA - 1;
+ if (target->stats->arm < 0)
+ target->stats->arm = 0;
+ else if (target->stats->arm >= WNA)
+ target->stats->arm = WNA - 1;
- notice(s_GameServ, u, "Armor set to %s", armors[target->stats->armor]);
+ notice(s_GameServ, u, "Armor set to %s", armors[target->stats->arm]);
return;
}
}
if (!is_playing(user))
{
ListNode<aClient> *temp;
- user->stats = new Player(user);
+ user->stats = new Player();
user->stats->client = user; // Set the backwards pointer
user->stats->reset(); // set the user up
user->stats->setPassword(password);
// Opponent's Hit
mhit = (fight->strength / 2) +
(rand() % (fight->strength / 2) - (user->stats->defense +
- arbonus[user->stats->armor]));
+ arbonus[user->stats->arm]));
}
else
{
// Opponent's Hit
- mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
- (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
- (user->stats->defense + arbonus[user->stats->armor]));
+ mhit = (((battle->stats->strength + webonus[battle->stats->wea]) / 2) +
+ (rand() % ((battle->stats->strength + webonus[battle->stats->wea])) / 2) -
+ (user->stats->defense + arbonus[user->stats->arm]));
}
if (!player_fight(user))
{
clearYourTurn(it);
outfile << it->name.c_str() << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' '
<< it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' '
- << it->armor << ' ' << it->weapon << ' '
+ << it->arm << ' ' << it->wea << ' '
<< it->forest_fights << ' ' << it->player_fights << ' '
<< it->getFlags() << ' ' << it->password << ' ' << it->inventory.Healing()
<< ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << ' ' << it->inventory.HP()
p->maxhp = stringtoint(strtok(NULL, " "));
p->strength = stringtoint(strtok(NULL, " "));
p->defense = stringtoint(strtok(NULL, " "));
- p->armor = stringtoint(strtok(NULL, " "));
- p->weapon = stringtoint(strtok(NULL, " "));
+ p->arm = stringtoint(strtok(NULL, " "));
+ p->wea = stringtoint(strtok(NULL, " "));
p->forest_fights = stringtoint(strtok(NULL, " "));
p->player_fights = stringtoint(strtok(NULL, " "));
p->setFlags(stringtoint(strtok(NULL, " ")));
p = user->stats;
- if (p->weapon != 0)
- notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->weapon]);
+ if (p->wea != 0)
+ notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->wea]);
else if (p->gold < prices[wep - 1])
notice(s_GameServ, u, "You don't have enough gold for %s!", weapons[wep]);
else
{
notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", weapons[wep]);
- p->weapon = wep;
+ p->wea = wep;
p->gold -= prices[wep - 1];
}
}
p = user->stats;
- if (p->armor != 0)
- notice(s_GameServ, u, "You have to sell your %s first!", armors[p->armor]);
+ if (p->arm != 0)
+ notice(s_GameServ, u, "You have to sell your %s first!", armors[p->arm]);
else if (p->gold < prices[wep - 1])
notice(s_GameServ, u, "You don't have enough gold for %s!", armors[wep]);
else
{
notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", armors[wep]);
- p->armor = wep;
+ p->arm = wep;
p->gold -= prices[wep - 1];
}
}
if (stricmp(item, "WEAPON") == 0)
{
- if (p->weapon == 0)
+ if (p->wea == 0)
{
notice(s_GameServ, u, "You want me to chop off your hands?");
return;
else if (p->gold == 2000000000)
{
notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
- p->weapon = 0;
+ p->wea = 0;
}
- else if (2000000000 - p->gold < (prices[p->weapon - 1] / 2))
+ else if (2000000000 - p->gold < (prices[p->wea - 1] / 2))
{
notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
notice(s_GameServ, u, "However, you have no weapon... can I interest you in the %s?", weapons[WNA - 1]);
p->gold = 2000000000;
- p->weapon = 0;
+ p->wea = 0;
}
else
{
- notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->weapon - 1] / 2));
- p->gold += (prices[p->weapon - 1] / 2);
- p->weapon = 0;
+ notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->wea - 1] / 2));
+ p->gold += (prices[p->wea - 1] / 2);
+ p->wea = 0;
}
}
else if (stricmp(item, "ARMOR") == 0)
{
p = user->stats;
- if (p->armor == 0)
+ if (p->arm == 0)
{
notice(s_GameServ, u, "I don't think you can be any more naked...");
return;
if (p->gold == 2000000000)
{
notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
- p->armor = 0;
+ p->arm = 0;
}
- else if (2000000000 - p->gold < (prices[p->armor - 1] / 2))
+ else if (2000000000 - p->gold < (prices[p->arm - 1] / 2))
{
notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
notice(s_GameServ, u, "However, you have no armor... can I interest you in %s?", armors[WNA - 1]);
p->gold = 2000000000;
- p->armor = 0;
+ p->arm = 0;
}
else
{
notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no armor!",
- (prices[p->armor - 1] / 2));
+ (prices[p->arm - 1] / 2));
- p->gold += (prices[p->armor - 1] / 2);
- p->armor = 0;
+ p->gold += (prices[p->arm - 1] / 2);
+ p->arm = 0;
}
}
else
"your %s, and venture into the hot, dark cave. "\
"You are surprised at the angle of descent as you climb "\
"lower and lower, deeper into the dragon's den.",
- armors[p->armor], weapons[p->weapon]);
+ armors[p->arm], weapons[p->wea]);
notice(s_GameServ, u, "You come to the end of the cave to find "\
"a tooth. It is a large tooth... bigger than your torso."\
" Suddenly the darkness lifts from the gleam of an eye "\
+#include "item.h"
#include "extern.h"
#include <ctype.h>
#include "item.h"
-#include "extern.h"
-#include <string.h>
item::item(char *name, int p, int uses, int m1, int m2, int m3, int m4, int m5, int m6, int m7, int m8)
{
{
}
+bool item::operator<(const item &right) const
+{
+ return myname < right.myname;
+}
+
+bool item::operator>(const item &right) const
+{
+ return myname > right.myname;
+}
+
+bool item::operator==(const item &right) const
+{
+ return myname == right.myname;
+}
+
+bool item::operator!=(const item &right) const
+{
+ return myname != right.myname;
+}
+
bool weapon::use(Player *p)
{
// weapon(char *name, int p=0, int uses = -1, int strength=0, int defense=0, int maxhp=0)
#ifndef ITEM_H
#define ITEM_H
-#include "player.h"
+
#include <string.h>
+#include "player.h"
class item
{
public:
- item(char *name, int p=0, int uses = 1, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0);
- item(string name, int p=0, int uses = 1, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0);
+ item(char *name=NULL, int p=0, int uses=1, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0);
+ item(string name=NULL, int p=0, int uses=1, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0);
virtual ~item();
int uses() { return myuses; };
long int price() { return myprice; };
virtual bool use(Player *p) = 0;
- virtual void undo(Player *p) = 0;
+ virtual void undo() = 0;
+
+ bool operator<(const item &right) const;
+ bool operator>(const item &right) const;
+ bool operator==(const item &right) const;
+ bool operator!=(const item &right) const;
protected:
- string myname;
- long int myprice;
- int mymodifiers[8];
- int myuses;
+ string myname; // Name to use in game & sorting
+ long int myprice; // How much does this item cost to buy (half to sell)
+ int mymodifiers[8]; // Up to 8 different modifiers handled in the sub-classes
+ int myuses; // How many times you can use this item
};
class weapon : public item
virtual bool use(Player *p);
virtual void undo(Player *p);
};
-typedef weapon armor; // Weapons and armor are logically the same if they can both modify strength, defense, and maxhp
+
+class armor : public item
+{
+ armor(char *name, int p=0, int uses = -1, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
+ armor(string name, int p=0, int uses = -1, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
+ virtual ~armor();
+
+ virtual bool use(Player *p);
+ virtual void undo(Player *p);
+};
class potion : public item
{
+#include "item.h"
#include "extern.h"
#include <fstream>
#include "level.h"
+#include "item.h"
#include "player.h"
#include "pouch.h"
#include "extern.h"
maxhp = 10;
strength = 0;
defense = 0;
- armor = 1;
- weapon = 1;
+ arm = 1;
+ wea = 1;
level = 1;
forest_fights = forestfights;
player_fights = 3;
#endif
}
-Player::Player(aClient *user)
-{
-
- if (user)
- {
- setData(user->stats);
- name = user->getNick();
- }
- else
- setData(NULL);
-}
-
Player::Player(char *n)
{
reset(); // Set defaults
maxhp = right->maxhp;
strength = right->strength;
defense = right->defense;
- armor = right->armor;
- weapon = right->weapon;
+ arm = right->arm;
+ wea = right->wea;
level = right->level;
forest_fights = right->forest_fights;
player_fights = right->player_fights;
#define PLAYER_H
#include <string>
-#include "aClient.h"
+
#include "pouch.h"
+#include "item.h"
using namespace std;
typedef struct monster_ Monster;
class aClient; // forward declaration
+class item; // forward declaration
+class weapon; // forward declaration
+class armor; // forward declaration
+class potion; // forward declaration
class Player {
public:
Player();
- Player(aClient *);
Player(char *);
Player(string);
~Player();
long int addFlag(long int); // Adds a flag to the client's flags
long int remFlag(long int); // Removes a flag from the client's current flags
+ int wea;
+ int arm; // delete soon
+
+ weapon *getWeapon() { return w; };
+ armor *getArmor() { return a; };
+
+ void setWeapon (weapon &); // Set a player's weapon to some item
+ void setArmor (armor &); // Set a player's weapon to some item
string name; // Player's Name
int level; // Player's level (1-12)
int maxhp; // Maximum Hit Points
int strength; // Player's Strength
int defense; // Player's defensive strength
- int armor; // Number for the player's armor
- int weapon; // Number for the player's weapon
int forest_fights; // Amount of forest fights left today
int player_fights; // Amount of player<->player fights for today
string password; // Player's encrypted password
private:
long int flags; // Player's current flags
+ weapon *w; // Player's weapon
+ armor *a; // Player's armor
};
struct monster_ {