-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.h
123 lines (100 loc) · 3.62 KB
/
Item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef ITEM_H
#define ITEM_H
#include "Type.h"
#include "Player.h"
#include "Config.h"
#include <string>
using namespace std;
// Usage: The effect when the use() function of an item is called
class Item: public Type {
protected:
string name; //name of the object
string type; //type of the object (Weapon (Player)/Weapon (Splash)/Healing/Energy)
int cost; //monetary cost of the object
int energyCost; //energy cost of the object
int stat; //damage/heal/max energy, depending on the type of item
int durability; //number of uses before the item expires
public:
Item(): Type(), name(""), type(), cost(0), energyCost(0), stat(0), durability(0) {} //default constructor
Item(int id, string name, string type, int cost, int energyCost, int stat, int durability)
: Type(id), name(name), type(type), cost(cost), energyCost(energyCost), stat(stat), durability(durability) {}
//accessor functions
inline string getName() const {
return name;
}
inline string getType() const {
return type;
}
inline int getCost() const {
return cost;
}
inline int getEnergyCost() const {
return energyCost;
}
inline int getStat() const {
return stat;
}
inline int getDurability() const {
return durability;
}
inline virtual int getRange() const {
return 0;
}
inline virtual int getRadius() const {
return 0;
}
//adds the item to player
void buyItem(Player* const player) const;
//return value: dead players indices caused by item use
virtual vector<int> use(Player* const user, vector<Player>& playerList) const = 0;
};
class WeaponItem: public Item {
protected:
int range; //max Manhattan distance between the user and the selected target player/location
public:
WeaponItem(): range(0) {}
WeaponItem(int id, string name, string type, int cost, int energyCost, int stat, int durability, int range)
: Item(id, name, type, cost, energyCost, stat, durability), range(range) {}
inline int getRange() const override {
return range;
}
};
//Usage: Damages a single player by stat
class PlayerWeaponItem: public WeaponItem {
public:
PlayerWeaponItem(){}
PlayerWeaponItem(int id, string name, int cost, int energyCost, int stat, int durability, int range)
: WeaponItem(id, name, string("Weapon (Player)"), cost, energyCost, stat, durability, range) {}
vector<int> use(Player* const user, vector<Player>& playerList) const override;
};
//Usage: Damages all players within the area of effect
class CubeWeaponItem: public WeaponItem {
private:
int radius; //area of effect: A square centered at selected coordinates with side length (2*radius-1)
public:
CubeWeaponItem(): radius(0) {}
CubeWeaponItem(int id, string name, int cost, int energyCost, int stat, int durability, int range, int radius)
: WeaponItem(id, name, string("Weapon (Splash)"), cost, energyCost, stat, durability, range), radius(radius) {}
inline int getRadius() const override {
return radius;
}
vector<int> use(Player* const, vector<Player>& playerList) const override;
};
//Note: Healing and energy items have no energy cost
//Usage: Increases current HP by stat (max HP capped at DEFAULT_HP)
class HealingItem: public Item {
public:
HealingItem(){}
HealingItem(int id, string name, int cost, int stat)
: Item(id, name, "Healing", cost, 0, stat, 1) {}
vector<int> use(Player* const user, vector<Player>& playerList) const override;
};
//Usage: Increases current max energy by stat; can be stacked
class EnergyItem: public Item {
public:
EnergyItem(){}
EnergyItem(int id, string name, int cost, int stat, int durability)
: Item(id, name, "Energy", cost, 0, stat, durability) {}
vector<int> use(Player* const user, vector<Player>& playerList) const override;
};
#endif