-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.cpp
More file actions
207 lines (175 loc) · 4.85 KB
/
item.cpp
File metadata and controls
207 lines (175 loc) · 4.85 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "rpg_lib.hpp"
using std::string;
Item::Item(const string& _name, const int price, const int lvl)
: name(_name)
, buy_price(price)
, min_level(lvl)
{
}
string Item::get_name() const
{
return name;
}
int Item::getPrice() const
{
return buy_price;
}
int Item::get_minlvl() const
{
return min_level;
}
Weapon::Weapon(const string& _name, const int price, const int lvl, const int damage, const bool grip)
: Item(_name, price, lvl)
, dmg(damage)
, two_handed(grip)
{
}
void Weapon::print() const
{
std::cout << name << " | Price: " << buy_price << " | Damage: " << dmg << (two_handed == true ? " | Two Handed" : " | One Handed") << " | Minimum level: " << min_level << std::endl;
}
int Weapon::getDamage(void) const
{
return dmg;
}
std::string Weapon::get_grip() const
{
if (two_handed == true)
return "Two Handed";
return "One Handed";
}
bool Weapon::isTwoHanded() const
{
return two_handed;
}
Armor::Armor(const string& _name, const int price, const int lvl, const int defense)
: Item(_name, price, lvl)
, def(defense)
{
}
int Armor::get_def() const
{
return def;
}
void Armor::print() const
{
std::cout << name << " | Price: " << buy_price << " | Defense: " << def << " | Minimum level: " << min_level << std::endl;
}
// make the enum-type printable
string Potion::typeToString() const
{
switch (potion_type) {
case (potionType::HP):
return "HP";
case (potionType::MP):
return "MP";
case (potionType::AGIL):
return "AGIL";
case (potionType::DEX):
return "DEXT";
case (potionType::STR):
return "STR";
}
return "BAD_TYPE";
}
Potion::Potion(const string& _name, const int price, const int lvl, potionType type)
: Item(_name, price, lvl)
, potion_type(type)
{
}
int Potion::get_buff_amount() const
{
return buffAmount;
}
void Potion::print() const
{
std::cout << name << " | Price: " << buy_price << " | Buff: " << typeToString() << " | Buff Amount: " << buffAmount << " | Minimum level: " << min_level << std::endl;
}
void Potion::buff(Hero* h)
{
if (potion_type == potionType::HP) {
std::cout << h->get_name() << " uses potion and replenishes " << buffAmount << " HP\n";
h->HPbuff(buffAmount);
} else if (potion_type == potionType::MP) {
std::cout << h->get_name() << " uses potion and replenishes " << buffAmount << " MP\n";
h->MPbuff(buffAmount);
} else if (potion_type == potionType::AGIL) {
std::cout << h->get_name() << " uses potion and replenishes " << buffAmount << " AGILITY\n";
h->AGILbuff(buffAmount);
} else if (potion_type == potionType::DEX) {
std::cout << h->get_name() << " uses potion and replenishes " << buffAmount << " DEXTERITY\n";
h->DEXbuff(buffAmount);
} else {
std::cout << h->get_name() << " uses potion and replenishes " << buffAmount << " STRENGTH\n";
h->STRbuff(buffAmount);
}
}
Spell::Spell(const string& _name, const int price, const int lvl, const int mindmg, const int maxdmg, const int mp, const int dur)
: Item(_name, price, lvl)
, min_dmg(mindmg)
, max_dmg(maxdmg)
, duration(dur)
, mp_cost(mp) {};
int Spell::get_mindmg() const
{
return min_dmg;
}
int Spell::get_maxdmg() const
{
return max_dmg;
}
int Spell::get_duration() const
{
return duration;
}
int Spell::getMPcost(void) const
{
return mp_cost;
}
int Spell::getSpellDmg(void) const
{
return (std::rand() % (max_dmg - min_dmg + 1) + min_dmg);
}
void Spell::print() const
{
std::cout << name << " | Price: " << buy_price << " | Damage Range: " << min_dmg << " - " << max_dmg << " | MP cost: " << mp_cost << " | Duration: " << duration << " | Minimum level: " << min_level;
}
IceSpell::IceSpell(const string& _name, const int price, const int lvl, const int mindmg, const int maxdmg, const int mp, const int dur)
: Spell(_name, price, lvl, mindmg, maxdmg, mp, dur)
{
}
void IceSpell::apply_effect(Monster* m)
{
m->ice_debuff(duration);
}
void IceSpell::print() const
{
Spell::print();
std::cout << " [ Ice Spell ]" << std::endl;
}
FireSpell::FireSpell(const string& _name, const int price, const int lvl, const int mindmg, const int maxdmg, const int mp, const int dur)
: Spell(_name, price, lvl, mindmg, maxdmg, mp, dur)
{
}
void FireSpell::print() const
{
Spell::print();
std::cout << " [ Fire Spell ]" << std::endl;
}
void FireSpell::apply_effect(Monster* m)
{
m->fire_debuff(duration);
}
LightningSpell::LightningSpell(const string& _name, const int price, const int lvl, const int mindmg, const int maxdmg, const int mp, const int dur)
: Spell(_name, price, lvl, mindmg, maxdmg, mp, dur)
{
}
void LightningSpell::print() const
{
Spell::print();
std::cout << " [ Lightning Spell ]" << std::endl;
}
void LightningSpell::apply_effect(Monster* m)
{
m->li_debuff(duration);
}