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
|
#pragma once
#include "feature.h"
#include "json.hpp"
#include "spell.h"
#include "jsonable.h"
#include "rules.h"
#include "utils.h"
#include <memory>
typedef nlohmann::json json;
namespace entry {
struct SlotLevel : public Jsonable {
SlotLevel(const json& data) : numSlots(data["slots"]), spells(utils::jsonList2ptrvec<Spell>("spells", data["spells"])) {}
SlotLevel() : numSlots(0) {}
virtual ~SlotLevel() {}
int numSlots;
std::vector<std::shared_ptr<Spell>> spells;
static std::shared_ptr<SlotLevel> create(const nlohmann::json& data);
json toJson(void) const {
std::vector<std::string> s;
for(auto spell : spells) {
s.push_back(spell->getName());
}
return json({
{"slots", numSlots},
{"spells", s}
});
}
};
class Spellcasting : public Feature {
public:
Spellcasting(const json& data, const json& base) : Feature(base), innate(data["innate"]), ability(rules::Ability(data["spellcasting_ability"])), spellsBySlot(utils::json2ptrvec<SlotLevel>(data["levels"])) {}
// Can also be instantiated programatically
Spellcasting(const std::string& entry, const std::string& name, const std::string& type, const std::string& text, const rules::Ability& ability, bool isInnate) : Feature(entry, name, type, text), innate(isInnate), ability(ability) {}
virtual ~Spellcasting() {}
bool isInnate(void) const {return innate;}
rules::Ability getAbility(void) const {return ability;}
const std::vector<std::shared_ptr<SlotLevel>>& getSlotLevels(void) const {return spellsBySlot;}
void addSlotLevel(void) {spellsBySlot.push_back(std::shared_ptr<SlotLevel>(new SlotLevel()));}
std::vector<std::shared_ptr<Spell>> getSpells(void) const;
virtual std::string getText(const creature::Creature& c) const;
virtual json toJson(void) const {
auto data = Feature::toJson();
data["innate"] = innate;
data["spellcasting_ability"] = ability;
data["levels"] = utils::ptrvec2json(spellsBySlot);
return data;
}
private:
const bool innate;
const rules::Ability ability;
std::vector<std::shared_ptr<SlotLevel>> spellsBySlot;
};
std::string genText(const Spellcasting& s, const creature::Creature& c);
}
|