blob: f73942f875457f1471426b4fc4701620b3421d85 (
plain)
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
|
#pragma once
#include "json.hpp"
#include "jsonable.h"
namespace feature {
class Feature;
}
namespace item {
class Item;
}
class Armor;
class Weapon;
typedef nlohmann::json json;
namespace creature {
class dmgType : public Jsonable {
public:
dmgType(const json& data) : type(data["type"]), qualifiers(data["qualifiers"]) {}
std::string type;
std::vector<std::string> qualifiers;
json toJson(void) const {
return json({
{"type", type},
{"qualifiers", qualifiers}
});
}
};
class Creature : public Jsonable {
public:
Creature(json data);
virtual ~Creature();
// Getters
std::string getCreatureName(void) const;
std::string getGivenName(void) const;
std::string getType(void) const;
std::string getSize(void) const;
std::string getAlignment(void) const;
double getCR(void) const;
std::string getLanguages(void) const;
int getHP(void) const;
int getHPMax(void) const;
std::vector<std::string> getSenses(void) const;
std::string getSpeed(void) const;
int getScore(const std::string& ability) const;
int getSkillBonus(const std::string& skill) const;
int getAbilitySaveBonus(const std::string& ability) const;
int getProficiency(void) const;
std::map<std::string, int> getSkills(void) const;
std::map<std::string, int> getSaves(void) const;
std::vector<std::shared_ptr<feature::Feature>> getFeatures(void) const;
std::vector<std::shared_ptr<item::Item>> getInventory(void) const;
// Inline getters
int getBonus(const std::string& ability) const {
return (int) (getScore(ability) - 10) / 2;
}
// Setters (mutators)
void setGivenName(std::string);
void applyDamage(int amount, const std::string& type, const std::vector<std::string>& qualifiers);
void setScore(const std::string& ability, int score);
void addInventoryItem(std::shared_ptr<item::Item> item);
void removeInventoryItem(const std::string& itemName);
virtual json toJson(void) const;
private:
const std::string creatureName;
std::string givenName;
const std::string size;
const std::string type;
const std::string alignment;
int hdCount;
const int hdSides;
int hpMax;
int hp;
const std::string speed;
std::map<std::string, int> stats;
std::map<std::string, int> skills;
std::vector<std::string> saves;
const std::vector<std::string> senses;
const std::string langs;
const double cr;
int proficiency;
const std::vector<dmgType> dmgImmunities;
const std::vector<dmgType> dmgResistances;
const std::vector<dmgType> dmgVulnerabilities;
const std::vector<dmgType> condImmunities;
std::vector<std::shared_ptr<item::Item>> inventory;
std::vector<std::shared_ptr<feature::Feature>> features;
};
// Convenience function to get any instances of T (subclass of Item) in the inventory
template<typename T> std::vector<std::shared_ptr<T>> getItems(const Creature& c) {
std::vector<std::shared_ptr<T>> Ts;
for(auto item : c.getInventory()) {
std::shared_ptr<T> t = dynamic_pointer_cast<T>(item);
if(t) {
Ts.push_back(t);
}
}
return Ts;
}
// Convenience function to calculate AC
const int getAC(const Creature& c);
}
|