-
Notifications
You must be signed in to change notification settings - Fork 0
/
creature.cpp
171 lines (135 loc) · 4.31 KB
/
creature.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "creature.h"
#include <algorithm> //min
#include <iostream>
using namespace std;
//Calculate & set total attributes
void Creature::calcAttributes() {
//All subject to change
CreaturePoints points = getPointValues();
Stats stats = getStats();
points.maxHP = basePoints.HP + 2*stats["endurance"];
points.maxSP = basePoints.SP + 1*stats["endurance"] + 1*stats["dexterity"];
points.maxMP = basePoints.MP + 2*stats["stability"] + 1* stats["control"];
setPointValues(points);
}
Stats allStats(int s) { //Generate stats all the same (0 for starting, 1 for player, etc)
Stats stats;
//Physical
stats.emplace("strength" , s);
stats.emplace("dexterity" , s);
stats.emplace("endurance" , s);
//Magical
stats.emplace("power" , s);
stats.emplace("control" , s);
stats.emplace("stability" , s);
return stats;
};
Stats Creature::getStats() {
return stats;
}
void Creature::setStats(Stats newStats) {
stats = newStats;
//calcAttributes(); //New maxHP, etc
}
void Creature::increaseStat(std::string stat, int amount) {
stats.at(stat) += amount;
}
CreaturePoints Creature::getPointValues() {
return pointValues;
}
void Creature::setPointValues(CreaturePoints points) {
pointValues = points;
}
void Creature::healAll() {
CreaturePoints points = getPointValues();
points.HP = points.maxHP;
points.SP = points.maxSP;
points.MP = points.maxMP;
setPointValues(points);
}
void Creature::setName(std::string newName) {
name = newName;
}
std::string Creature::getName() {
return name;
}
const char * Creature::getName_c() {
return name.c_str();
}
void Creature::rawDamage(Points dmg) { //Deal raw damage. Should rarely be called directly.
CreaturePoints c = pointValues;
//Limit to between 0 and max
c.HP = max(0, min(c.HP - dmg.HP, c.maxHP));
c.SP = max(0, min(c.SP - dmg.SP, c.maxSP));
c.MP = max(0, min(c.MP - dmg.MP, c.maxMP));
pointValues = c;
}
void Creature::damage(Points dmg, skillDamageType damageType) {
//Currently only HP is affected
//If any multiplier is 0 (ie disarm), damage is 0. "No change" is 1.
dmg.HP *= turnBuffEffects.allDamageTaken;
if (damageType == DMGTYPE_PHYSICAL) {
dmg.HP *= turnBuffEffects.physicalDamageTaken;
}
if (damageType == DMGTYPE_MAGICAL) {
dmg.HP *= turnBuffEffects.magicalDamageTaken;
}
rawDamage(dmg);
}
void Creature::heal(Points healing) {
CreaturePoints c = pointValues;
//Limit to between 0 and max
c.HP = max(0, min(c.HP + healing.HP, c.maxHP));
c.SP = max(0, min(c.SP + healing.SP, c.maxSP));
c.MP = max(0, min(c.MP + healing.MP, c.maxMP));
pointValues = c;
}
void Creature::takeCost(Points cost) {
rawDamage(cost);
}
Points Creature::runDamageMultipliers (Points dmg, skillDamageType damageType) {
//Only HP is affected right now
dmg.HP *= turnBuffEffects.allDamageOutput;
if (damageType == DMGTYPE_PHYSICAL) {
dmg.HP *= turnBuffEffects.physicalDamageOutput;
}
if (damageType == DMGTYPE_MAGICAL) {
dmg.HP *= turnBuffEffects.magicalDamageOutput;
}
return dmg;
}
//void Creature::addBuff(Buff newBuff) {
// buffs.push_back(*newBuff);
//};
bool Creature::isDead() {
if (pointValues.HP <= 0) {
return true;
} else {
return false;
}
}
//Constructors
Creature::Creature() {
}
Creature::Creature(Points basePoints, Stats startingStats, std::string cName) {
name = cName;
this->basePoints = basePoints;
stats = startingStats;
calcAttributes();
healAll();
}
//Extra functions:
//Merge two sets of BuffTurnMultipliers
void Creature::mergeBuffTurnMultipliers (BuffTurnMultipliers changes) {
//TODO: Move to std::map like Stats
this->turnBuffEffects.allDamageOutput *= changes.allDamageOutput;
this->turnBuffEffects.magicalDamageOutput *= changes.magicalDamageOutput;
this->turnBuffEffects.physicalDamageOutput *= changes.physicalDamageOutput;
this->turnBuffEffects.allDamageTaken *= changes.allDamageTaken;
this->turnBuffEffects.magicalDamageTaken *= changes.magicalDamageTaken;
this->turnBuffEffects.physicalDamageTaken *= changes.physicalDamageTaken;
}
void Creature::clearBuffTurnMultipliers() {
BuffTurnMultipliers defaultMults;
this->turnBuffEffects = defaultMults;
};