#pragma once #include "feature.h" #include "json.hpp" #include "spell.h" #include "jsonable.h" #include "rules.h" typedef nlohmann::json json; namespace entry { struct SlotLevel : public Jsonable { SlotLevel(const json& data) : numSlots(data["slots"]), spells(jsonList2vec("spellcasting", data["spells"])) {} virtual ~SlotLevel() {} const int numSlots; const std::vector spells; json toJson(void) const { std::vector 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(json2vec(data["levels"])) {} virtual ~Spellcasting() {} bool isInnate(void) const {return innate;} rules::Ability getAbility(void) const {return ability;} std::vector getSpellsBySlot(void) const {return spellsBySlot;} 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; return data; } private: const bool innate; const rules::Ability ability; const std::vector spellsBySlot; }; std::string genText(const Spellcasting& s, const creature::Creature& c); }