-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkillComponent.h
121 lines (93 loc) · 2.03 KB
/
SkillComponent.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
#pragma once
enum SKILLS
{
HEALTH = 0,
ATTACK,
ACCURACY,
ENDURANCE
};
class SkillComponent
{
private:
class Skill
{
private:
//Variables:
int type;
int level;
int levelMax;
int exp;
int expNext;
public:
//Constructors and Destructor:
Skill(const int type)
{
this->type = type;
this->level = 1;
this->levelMax = 99;
this->exp = 0;
this->expNext = 100;
}
~Skill() {}
//Accessors:
inline const int& getType() const { return this->type; }
inline const int& getLevel() const { return this->level; }
inline const int& getExp() const { return this->exp; }
inline const int& getExpNext() const { return this->expNext; }
//Modifiers:
inline void setLevel(const int level) { this->level = level; }
inline void setLevelMax(const int level_max) { this->levelMax = level_max; }
//Functions:
void gainExp(const int exp)
{
this->exp += exp;
this->updateLevel();
}
void loseExp(const int exp)
{
this->exp -= exp;
}
//Updates level of the skill.
//If "up" is set to TRUE - increases level when exp reaches expNext value.
//If "up" is set to FALSE - decreases level when exp reaches 0.
void updateLevel(const bool up = true)
{
if (up)
{
if (this->level < this->levelMax)
{
if (this->exp >= this->expNext)
{
this->level++;
this->exp -= this->expNext;
this->expNext = static_cast<int>(std::pow(static_cast<float>(this->level), 2.f)) + this->level * 10 + this->level * 2;
}
}
}
else
{
if (this->level > 0)
{
if (this->exp < 0)
{
this->level--;
this->expNext = static_cast<int>(std::pow(static_cast<float>(this->level), 2.f)) + this->level * 10 + this->level * 2;
this->exp += this->expNext;
}
}
}
}
void update()
{
}
};
std::vector<Skill> skills;
public:
//Constructors and Distructors:
SkillComponent();
virtual ~SkillComponent();
//Accessors:
const int getSkillLevel(const int skill) const;
//Functions:
const void gainExp(const int skill, const int exp);
};