-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monster.cpp
77 lines (68 loc) · 2.07 KB
/
Monster.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
#include "Monster.h"
#include "Dice.h"
#include <string>
Monster::Monster(){}
Monster::~Monster(){
for (size_t i = 0; i < actions.size(); i++)
{
delete(actions[i]);
}
}
Monster::Monster(const json & monsterData ){
name = monsterData["name"];
type = monsterData["type"];
alignment = monsterData["alignment"];
armor_class = monsterData["armor_class"];
hit_dice = Dice(monsterData["hit_dice"].get<std::string>());
strength = monsterData["strength"];
dexterity = monsterData["dexterity"];
constitution = monsterData["constitution"];
intelligence = monsterData["intelligence"];
wisdom = monsterData["wisdom"];
charisma = monsterData["charisma"];
hit_points = this->hit_dice.roll();
actions = parseActions(monsterData);
challenge_rating = parseChallengeRating(monsterData["challenge_rating"].get<std::string>());
alive = true;
}
Monster& Monster::operator=(const Monster &monster){
name = monster.name;
type = monster.type;
alignment = monster.alignment;
armor_class = monster.armor_class;
hit_dice = monster.hit_dice;
strength = monster.strength;
dexterity = monster.dexterity;
constitution = monster.constitution;
intelligence = monster.intelligence;
wisdom = monster.wisdom;
charisma = monster.charisma;
hit_points = monster.hit_points;
challenge_rating = monster.challenge_rating;
alive = monster.alive;
for (size_t i = 0; i < monster.actions.size(); i++)
{
actions.push_back(new Ability(*(monster.actions[i])));
}
return *this;
}
std::vector<Ability*> Monster::parseActions(const json & monsterData){
json actions = monsterData["actions"];
Ability* currentAbility;
std::vector<Ability*> abilityContainer;
for (size_t i = 0; i < actions.size(); i++)
{
currentAbility = new Ability(actions[i]);
abilityContainer.push_back(currentAbility);
}
return abilityContainer;
}
double Monster::parseChallengeRating(std::string CRS){
size_t slash = CRS.find("/");
if(slash == std::string::npos) {
return std::stod(CRS);
}
double numerator = std::stod(CRS.substr(0,slash));
double denominator = std::stod(CRS.substr(slash + 1));
return numerator / denominator;
}