diff options
Diffstat (limited to 'src/spellcasting.cc')
-rw-r--r-- | src/spellcasting.cc | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/spellcasting.cc b/src/spellcasting.cc index db8e71a..6315446 100644 --- a/src/spellcasting.cc +++ b/src/spellcasting.cc @@ -8,6 +8,20 @@ using namespace std; namespace entry { + // Slot level serialization + void to_json(nlohmann::json& j, const SlotLevel& sl) { + std::vector<std::string> s; + for(auto spell : sl.spells) { + s.push_back(spell->getName()); + } + j = {{"slots", sl.numSlots}, {"spells", s}}; + } + + void from_json(const nlohmann::json& j, SlotLevel& sl) { + j.at("slots").get_to(sl.numSlots); + sl.spells = utils::instantiateNames<Spell>("spells", j["spells"]); + } + shared_ptr<SlotLevel> SlotLevel::create(const json& data) { return shared_ptr<SlotLevel>(new SlotLevel(data)); } @@ -23,20 +37,16 @@ namespace entry { } string Spellcasting::getText(const creature::Creature& c) const { - return genText(*this, c); - } - - string genText(const Spellcasting& s, const creature::Creature& c) { stringstream text; - text << s.getName() << " (" << s.getType() << "): "; - text << "The " << c.getCreatureName() << "'s spellcasting ability is " << s.getAbility().getFull(); - text << " (spell save DC " << 8 + c.getBonus(s.getAbility()) + c.getProficiency(); - text << ", +" << c.getBonus(s.getAbility()) + c.getProficiency() << " to hit with spell attacks)."; - if(s.isInnate()) { + text << getName() << " (" << getType() << "): "; + text << "The " << c.getCreatureName() << "'s spellcasting ability is " << getAbility().getFull(); + text << " (spell save DC " << 8 + c.getBonus(getAbility()) + c.getProficiency(); + text << ", +" << c.getBonus(getAbility()) + c.getProficiency() << " to hit with spell attacks)."; + if(isInnate()) { text << " Spellcasting is innate."; } int levelNumber = -1; - for(auto level : s.getSlotLevels()) { + for(auto level : getSlotLevels()) { levelNumber++; // Skip if it's empty if(level->numSlots == 0 && level->spells.empty()) { @@ -44,13 +54,13 @@ namespace entry { } text << endl; if(levelNumber == 0) { - if(s.isInnate()) { + if(isInnate()) { text << " At will: "; } else { text << " Cantrips: "; } } else { - if(s.isInnate()) { + if(isInnate()) { text << " " << level->numSlots << "/day each: "; } else { text << " " << utils::toOrdinal(levelNumber) << " level (" << level->numSlots << " slots): "; |