-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributeComponent.cpp
More file actions
120 lines (94 loc) · 2.33 KB
/
AttributeComponent.cpp
File metadata and controls
120 lines (94 loc) · 2.33 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
#include "stdafx.h"
#include "AttributeComponent.h"
//Construcrors and Destructor:
AttributeComponent::AttributeComponent(int level)
{
//Leveling
this->level = level;
this->exp = 0;
this->expNext = static_cast<int>((50 / 3) * (std::pow(this->level + 1, 3) - 6 * std::pow(this->level + 1, 2) + ((this->level + 1) * 17) - 12));
this->attributePoints = 2;
//Attributes
this->vitality = 1;
this->strength = 22;
this->dexterity = 24;
this->agility = 1;
this->intelligence = 26;
this->updateLevel();
this->updateStats(true);
}
AttributeComponent::~AttributeComponent()
{
}
//Accessors:
const bool AttributeComponent::isDead() const
{
return this->hp <= 0;
}
//Functions:
std::string AttributeComponent::debugPrint() const
{
std::stringstream ss;
ss << "Level: " << this->level
<< "\n" << "Exp: " << this->exp
<< "\n" << "Exp Next: " << this->expNext
<< "\n" << "Attribute points: " << this->attributePoints
<< "\n";
return ss.str();
}
void AttributeComponent::loseHp(const int hp)
{
this->hp -= hp;
if (this->hp < 0)
{
this->hp = 0;
}
}
void AttributeComponent::gainHp(const int hp)
{
this->hp += hp;
if (this->hp > this->hpMax)
{
this->hp = this->hpMax;
}
}
void AttributeComponent::loseExp(const int exp)
{
this->exp -= exp;
if (this->exp < 0)
{
this->exp = 0;
}
}
void AttributeComponent::gainExp(const int exp)
{
this->exp += exp;
this->updateLevel();
}
void AttributeComponent::updateStats(const bool reset)
{
this->hpMax = 100 + this->vitality * 5 + this->vitality + this->strength / 2 + this->intelligence / 5;
this->damageMin = this->strength * 2 + this->strength / 4 + this->intelligence / 5;
this->damageMax = this->strength * 2 + this->strength / 2 + this->intelligence / 5;
this->accuracy = this->dexterity * 5 + this->dexterity / 2 + this->intelligence / 5;
this->defence = this->agility * 2 + this->agility / 4 + this->intelligence / 5;
this->luck = this->intelligence * 2 + this->intelligence / 5;
if (reset)
{
this->hp = this->hpMax;
}
}
void AttributeComponent::updateLevel()
{
if (this->exp >= this->expNext)
{
++this->level;
this->exp -= this->expNext;
this->expNext = static_cast<int>((50 / 3) * (std::pow(this->level, 3) - 6 * std::pow(this->level, 2) + (this->level * 17) - 12));
++this->attributePoints;
}
}
void AttributeComponent::update()
{
this->updateLevel();
}