-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.cpp
117 lines (107 loc) · 2.88 KB
/
Item.cpp
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
#include "Item.h"
#include <sstream>
#include "Life.h"
#include "Hero.h"
#include "Monster.h"
bool Item::operator< (const Item &right) const
{
return (this->buyInPrice < right.buyInPrice);
}
string Item::ToString() const
{
std::ostringstream out;
//oss << text << i;
//std::cout << oss.str();
out << this->name;
for (int i = 0; i< 20 - this->name.size(); i++)
{
out << " ";
}
//out+=this->GetDescription();
//out+="\n";
//out+="Sell out for: "
for (int i = 0; i < 4/*-(this->count/10)*/; i++)
{
out << " ";
}
out<<this->count;
out<<" "; // 10 spaces
out<<this->sellOutPrice;
return out.str();
}
int Item::TrueVal(Life &l, int original, int symbol, int amount)
{
// Calculate new attribute depending on original value, operator(symbol), and the amount of change
// symbol(operator): 0 for +, 1 for *
int trueVal = original + amount;
if (symbol == 1)
{
trueVal = original * amount;
}
return trueVal;
}
bool Item::Use(Hero &h, Monster &m)
{
if (this->GetCount() > 0)
{
for (int i = 0; i < this->modifyAttributes.size(); i++)
{
// symbol(operator): 0 for +, 1 for *
char symbol = modifyAttributes[i].first;
char amount = modifyAttributes[i].second;
//int heroVal = TrueVal(h,symbol,amount);
//int monsterVal = TrueVal(m,symbol,amount);
switch(i){
case '0':
h.SetAtt(TrueVal(h,h.GetAtt(),symbol,amount));
break;
case '1':
h.SetDef(TrueVal(h,h.GetDef(),symbol,amount));
break;
case '2':
h.SetStam(TrueVal(h,h.GetStam(),symbol,amount));
break;
case '3':
h.SetIntl(TrueVal(h,h.GetIntl(),symbol,amount));
break;
case '4':
h.SetStun(TrueVal(h,h.GetStun(),symbol,amount));
break;
case '5':
h.SetWeak(TrueVal(h,h.GetWeak(),symbol,amount));
break;
case '6':
h.SetHP(TrueVal(h,h.GetHP(),symbol,amount));
break;
case '7':
h.SetMP(TrueVal(h,h.GetMP(),symbol,amount));
break;
case '8':
m.SetAtt(TrueVal(h,h.GetAtt(),symbol,amount));
break;
case '9':
m.SetDef(TrueVal(h,h.GetDef(),symbol,amount));
break;
case '10':
m.SetStam(TrueVal(h,h.GetStam(),symbol,amount));
break;
case '11':
m.SetIntl(TrueVal(h,h.GetIntl(),symbol,amount));
break;
case '12':
m.SetStun(TrueVal(h,h.GetStun(),symbol,amount));
break;
case '13':
m.SetWeak(TrueVal(h,h.GetWeak(),symbol,amount));
break;
case '14':
m.SetHP(TrueVal(h,h.GetHP(),symbol,amount));
break;
case '15':
m.SetMP(TrueVal(h,h.GetMP(),symbol,amount));
break;
}
}
}
return false;
}