aboutsummaryrefslogtreecommitdiff
path: root/src/spellcasting.h
blob: 654a3861e881f8ec46e278e0f502c2b9f71d32e8 (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
#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<spell::Spell>("spellcasting", data["spells"])) {}
        virtual ~SlotLevel() {}
        const int numSlots;
        const std::vector<spell::Spell> spells;

        json toJson(void) const {
            return json({
                    {"slots", numSlots},
                    {"spells", spells}
                    });
        }
    };

    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"])) {}
            virtual ~Spellcasting() {}

            bool isInnate(void) const {return innate;}
            rules::Ability getAbility(void) const {return ability;}
            std::vector<SlotLevel> 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<SlotLevel> spellsBySlot;
    };

    std::string genText(const Spellcasting& s, const creature::Creature& c);
}