aboutsummaryrefslogtreecommitdiff
path: root/src/creature.h
blob: de93b0e8508fccbb9c571417f29ea68c394716a2 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include "rules.h"
#include "utils.h"
#include "entry.h"
#include "features/feature.h"
#include "item.h"
#include <nlohmann/json.hpp>

namespace entry {
    class Weapon;
    class Attack;
    class Spell;
    class Spellcasting;
}

namespace creature {
    class Creature;
    struct creatureImpl;

    struct dmgType {
        std::string type;
        std::vector<rules::Qualifier> qualifiers;
        std::string getText() const {
            if(qualifiers.empty()) {
                return type;
            }
            return utils::join(qualifiers, ", ") + " " + type;
        }
    };
    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(dmgType, type, qualifiers);

    struct NatArmor {
        std::string name;
        int bonus;
    };
    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NatArmor, name, bonus);

    // Convenience function to calculate AC
    const int getAC(const Creature& c);

    class Creature : public entry::Entry {
        public:
            Creature();
            virtual ~Creature() {}

            virtual void init() override;

            // Getters
            int getSkillBonus(const rules::Skill& skill) const;
            int getAbilitySaveBonus(const rules::Ability& ability) const;
            std::map<rules::Skill, int> getSkills(void) const;
            std::map<rules::Ability, int> getSaves(void) const;
            //Override getText
            virtual std::string getText() const override;
            std::string getCreatureName(void) const;
            std::string getGivenName(void) const;
            std::string getSize(void) const;
            std::string getAlignment(void) const;
            double getCR(void) const;
            NatArmor getNaturalArmor(void) const;
            std::string getLanguages(void) const;
            int getHP(void) const;
            int getHPMax(void) const;
            std::vector<std::string> getSenses(void) const;
            std::string getSpeed(void) const;
            int getScore(const rules::Ability& ability) const;
            int getBonus(const rules::Ability& ability) const;
            int getProficiency(void) const;
            int getInitiative(void) const;
            std::vector<std::shared_ptr<entry::Feature>> getFeatures(void) const;
            std::shared_ptr<entry::Spellcasting> getSpellcasting(void) const;
            std::vector<std::shared_ptr<entry::Item>> getInventory(void) const;
            std::vector<dmgType> getDmgImmunities(void) const;
            std::vector<dmgType> getDmgResistances(void) const;
            std::vector<dmgType> getDmgVulnerabilities(void) const;
            std::vector<dmgType> getCondImmunities(void) const;

            // Setters (mutators)
            void setGivenName(const std::string& name);
            void setScore(const rules::Ability& ability, int score);
            void setProfLevel(const rules::Skill& skill, int level);
            void setProficiency(int p);
            void addInventoryItem(std::shared_ptr<entry::Item> item);
            void addSpellcasting(void);
            void addSpell(std::shared_ptr<entry::Spell> spell);
            void removeSpell(std::shared_ptr<entry::Spell> spell);
            void removeInventoryItem(std::shared_ptr<entry::Item> item);

            // Events
            void longRest(void);
            void turnStart(void);
            void turnEnd(void);
            void applyDamage(int amount, const std::string& type, const std::vector<rules::Qualifier>& qualifiers);
            // Returns the amount rolled
            int saveOrDamage(const rules::Ability& ability, int DC, int amount, const std::string& type, const std::vector<rules::Qualifier>& qualifiers, bool saveHalves);
            void applyHealing(int amount);
            void opportunityAttack(const creature::Creature& other);

            NLOHMANN_FRIEND_DECLARES(Creature);

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

    // Helper function to get all attacks (weapons and pseudo-weapons included)
    std::vector<std::shared_ptr<entry::Weapon>> getAttacks(const Creature& c);

    // Helper function to get the best ability for this creature (chooses arbitrarily in case of ties)
    rules::Ability getBestAbility(const std::vector<rules::Ability>& abilities, const Creature& c);
}