-
Notifications
You must be signed in to change notification settings - Fork 0
/
attribute_component.inl
83 lines (64 loc) · 1.82 KB
/
attribute_component.inl
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
#include "stdafx.h"
//
#include "component_attribute.h"
AttributeComponent::AttributeComponent(int level) {
level = level;
exp = 0;
next_exp =
static_cast<int>((50 / 3) * (pow(level + 1, 3) - 6 * pow(level + 1, 2) +
((level + 1) * 17) - 12));
attribute_points = 2;
vitality = 1;
strength = 1;
dexterity = 1;
agility = 1;
intelligence = 1;
UpdateLevel();
UpdateStats(true);
}
AttributeComponent::~AttributeComponent() {}
_::AString AttributeComponent::DebugPrint() const {
std::stringstream ss;
ss << "Level: " << level << "\n"
<< "Exp: " << exp << "\n"
<< "Exp Next: " << next_exp << "\n"
<< "Attp: " << attribute_points << "\n";
return ss.str();
}
void AttributeComponent::LoseHP(const int hp) {
hp_ -= hp;
if (hp < 0) hp_ = 0;
}
void AttributeComponent::GainHP(const int hp) {
hp += hp;
if (hp > hp_max) hp = hp_max;
}
void AttributeComponent::LoseEXP(const int exp) {
exp -= exp;
if (exp < 0) exp = 0;
}
void AttributeComponent::GainExp(const int exp) {
exp += exp;
UpdateLevel();
}
void AttributeComponent::UpdateStats(const bool reset) {
hp_max = vitality * 5 + vitality + strength / 2 + intelligence / 5;
damage_min = strength * 2 + strength / 4 + intelligence / 5;
damage_max = strength * 2 + strength / 2 + intelligence / 5;
accuracy = dexterity * 5 + dexterity / 2 + intelligence / 5;
defence = agility * 2 + agility / 4 + intelligence / 5;
luck = intelligence * 2 + intelligence / 5;
if (reset) {
hp = hp_max;
}
}
void AttributeComponent::UpdateLevel() {
while (exp >= next_exp) {
++level;
exp -= next_exp;
next_exp = static_cast<int>(
(50 / 3) * (pow(level, 3) - 6 * pow(level, 2) + (level * 17) - 12));
++attribute_points;
}
}
void AttributeComponent::Update() { UpdateLevel(); }