aboutsummaryrefslogtreecommitdiff
path: root/src/spellcasting.h
blob: 46d4ba8f80df600545311c601e1aa84f45346e35 (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
#pragma once
#include "features/feature.h"
#include "spell.h"
#include "rules.h"
#include "utils.h"
#include <memory>
#include <nlohmann/json.hpp>

typedef nlohmann::json json;

namespace entry {
    struct SlotLevel;
    struct spellcastingImpl;

    void to_json(nlohmann::json& j, const SlotLevel& sl);
    void from_json(const nlohmann::json& j, SlotLevel& sl);
    
    struct SlotLevel {
        SlotLevel() : numSlots(0) {}
        int numSlots;
        std::vector<std::shared_ptr<Spell>> spells;
        static std::shared_ptr<SlotLevel> create(const nlohmann::json& data);
        nlohmann::json serialize() {
            nlohmann::json ret;
            to_json(ret, *this);
            return ret;
        }
    };

    class Spellcasting : public Feature {
        public:
            Spellcasting();
            bool isInnate(void) const;
            rules::Ability getAbility(void) const;
            void setAbility(const rules::Ability& ability);
            const std::vector<std::shared_ptr<SlotLevel>>& getSlotLevels(void) const;
            void addSlotLevel(void);
            std::vector<std::shared_ptr<Spell>> getSpells(void) const;
            virtual std::string getText(const creature::Creature& c) const;

            NLOHMANN_FRIEND_DECLARES(Spellcasting);

        private:
            std::shared_ptr<spellcastingImpl> data;
    };
}