]> jfr.im git - irc/gameservirc.git/blob - gameserv/item.h
got tavern load and list working for the most part
[irc/gameservirc.git] / gameserv / item.h
1 #ifndef ITEM_H
2 #define ITEM_H
3
4
5 #include <string>
6 #include "level.h"
7
8 using namespace std;
9
10 class Player; // Forward declaration
11 enum type { WEAPON, ARMOR, POTION };
12
13 class item
14 {
15 public:
16 item();
17 item(const char *name, long int p=0, int uses=1, long int identifier=0, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0);
18 item(string name, long int p=0, int uses=1, long int identifier=0, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0);
19
20 virtual ~item();
21
22 int uses() { return myuses; };
23 long int price() { return myprice; };
24
25 string getName () { return myname; };
26
27 virtual bool use(Player *p) = 0;
28 virtual void undo(Player *p) = 0;
29 virtual bool setData(char *datastr) = 0;
30
31 type getType() {return mytype;};
32 void setType(type);
33 long int getID() {return id;};
34
35 bool operator<(const item &right) const;
36 bool operator>(const item &right) const;
37 bool operator==(const item &right) const;
38 bool operator!=(const item &right) const;
39 item &operator=(const item &right);
40
41 protected:
42 string myname; // Name to use in game & sorting
43 long int myprice; // How much does this item cost to buy (half to sell)
44 int mymodifiers[8]; // Up to 8 different modifiers handled in the sub-classes
45 int myuses; // How many times this item can be used by default
46 long int id; // Unique identifier for the item
47 type mytype;
48 };
49
50 class itemContainer
51 {
52 public:
53 itemContainer();
54 itemContainer(item *);
55 itemContainer(const itemContainer &);
56 ~itemContainer();
57
58 itemContainer &operator ++();
59 itemContainer operator ++(int);
60
61 itemContainer &operator --();
62 itemContainer operator --(int);
63
64 bool operator <(const itemContainer &right) const;
65 bool operator >(const itemContainer &right) const;
66 bool operator ==(const itemContainer &right) const;
67 bool operator !=(const itemContainer &right) const;
68
69 item *getItem() {return myitem;};
70 void setItem(item *);
71
72 int getUses() { return myuses; };
73 void setUses(int);
74
75 private:
76 int myuses; // How many times this item can be used
77 item *myitem;
78 };
79
80 class weapon : public item
81 {
82 public:
83 weapon() : item() {myname = "New Weapon";};
84 weapon(const char *name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
85 weapon(string name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
86 ~weapon();
87
88 bool setData(char *datastr);
89 bool use(Player *p);
90 void undo(Player *p);
91
92 };
93
94 class armor : public item
95 {
96 public:
97 armor() : item(){};
98 armor(const char *name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
99 armor(string name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){};
100 ~armor();
101
102 bool setData(char *datastr);
103 bool use(Player *p);
104 void undo(Player *p);
105 };
106
107 class potion : public item
108 {
109 public:
110 potion() : item(){};
111 potion(const char *name, int p=0, int uses = 1, long int identifier=0, 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) : item(name, p, uses, strength, defense, maxhp, hp, forest_fights, player_fights, gold, bank){};
112 potion(string name, int p=0, int uses = 1, long int identifier=0, 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) : item(name, p, uses, strength, defense, maxhp, hp, forest_fights, player_fights, gold, bank){};
113 ~potion();
114
115 bool setData(char *datastr);
116 bool use(Player *p);
117 void undo(Player *p);
118
119 protected:
120 range myranges[8];
121 };
122
123 class tavernItem
124 {
125 public:
126 tavernItem();
127 tavernItem(item *, int);
128
129
130 void setItem(item*);
131 item *getItem() { return myItem; };
132
133 void setLevel(int);
134 int getLevel() { return myLevel; };
135
136 bool visible(Player *);
137
138
139 private:
140 item *myItem; // The item this actually points to
141 int myLevel; // The level the item shows up
142 };
143 #endif