aboutsummaryrefslogtreecommitdiff
path: root/src/spellcasting.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-05 09:44:50 -0400
committerYour Name <you@example.com>2021-05-05 09:44:50 -0400
commit2a9f262e6db5906db445d465e500d7ba8c90fab3 (patch)
tree34f850754b0c9114ede9d7b2bb8da90dffddc4fe /src/spellcasting.h
parent8614137f7f32f2c9f3c11419110cd70dd7f3b505 (diff)
downloaddmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.gz
dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.bz2
dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.zip
Implemented additional commands
Diffstat (limited to 'src/spellcasting.h')
-rw-r--r--src/spellcasting.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/spellcasting.h b/src/spellcasting.h
index 0bbdf84..331a95f 100644
--- a/src/spellcasting.h
+++ b/src/spellcasting.h
@@ -4,20 +4,23 @@
#include "spell.h"
#include "jsonable.h"
#include "rules.h"
+#include <memory>
typedef nlohmann::json json;
namespace entry {
struct SlotLevel : public Jsonable {
- SlotLevel(const json& data) : numSlots(data["slots"]), spells(jsonList2vec<Spell>("spellcasting", data["spells"])) {}
+ SlotLevel(const json& data) : numSlots(data["slots"]), spells(jsonList2ptrvec<Spell>("spells", data["spells"])) {}
+ SlotLevel() : numSlots(0) {}
virtual ~SlotLevel() {}
- const int numSlots;
- const std::vector<Spell> spells;
+ 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());
+ s.push_back(spell->getName());
}
return json({
{"slots", numSlots},
@@ -28,26 +31,30 @@ namespace entry {
class Spellcasting : public Feature {
public:
- Spellcasting(const json& data, const json& base) : Feature(base), innate(data["innate"]), ability(rules::Ability(data["spellcasting_ability"])), spellsBySlot(json2vec<SlotLevel>(data["levels"])) {}
+ Spellcasting(const json& data, const json& base) : Feature(base), innate(data["innate"]), ability(rules::Ability(data["spellcasting_ability"])), spellsBySlot(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;}
- std::vector<SlotLevel> getSpellsBySlot(void) const {return spellsBySlot;}
+ 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"] = spellsBySlot;
+ data["levels"] = ptrvec2json(spellsBySlot);
return data;
}
private:
const bool innate;
const rules::Ability ability;
- const std::vector<SlotLevel> spellsBySlot;
+ std::vector<std::shared_ptr<SlotLevel>> spellsBySlot;
};
std::string genText(const Spellcasting& s, const creature::Creature& c);