-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkillComponent.h
91 lines (72 loc) · 1.81 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
#pragma once
enum SKILLS { HEALTH = 0, ATTACK, ACCURACY, ENDURANCE };
class SkillComponent
{
private:
class Skill {
private:
int type;
int value;
int level;
int levelCap;
int exp;
int expNext;
public:
Skill(int type) {
this->type = type;
this->level = 1;
this->levelCap = 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
void setLevel(const int level) { this->level = level; }
void setLevelCap(const int level_cap) { this->levelCap = level_cap; }
// Functions
const void gainExp(const int exp) {
this->exp += exp;
this->updateLevel(true);
}
const void loseExp(const int exp) {
this->exp -= exp;
this->updateLevel(false);
}
void updateLevel(const bool up) {
if (up) {
if (this->level < this->levelCap) {
while (this->exp >= this->expNext) {
if (this->level < this->levelCap) {
this->level++;
this->expNext = static_cast<int>(std::pow(this->level, 2)) + this->level * 10 + this->level * 2;
}
}
}
}
else {
if (this->level > 0) {
while (this->exp < 0) {
if (this->level > 0) {
this->level--;
this->exp = static_cast<int>(std::pow(this->level, 2)) + this->level * 10 + this->level * 2;
}
}
}
}
}
void update() {
}
};
std::vector<Skill> skills;
public:
SkillComponent();
virtual ~SkillComponent();
const int getSkill(const int index) const;
const void gainExp(const int skill, const int exp);
};