aboutsummaryrefslogtreecommitdiff
path: root/src/creature.h
blob: 1c8db217ed5459b954285f22ea196c520e663294 (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
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include "json.hpp"
#include "jsonable.h"
#include "rules.h"

namespace entry {
    class Feature;
}
namespace entry {
    class Item;
}
class Armor;
class Weapon;

typedef nlohmann::json json;

namespace creature {
    class dmgType : public Jsonable {
        public:
            dmgType(const json& data) : type(data["type"]), qualifiers(data["qualifiers"]) {}
            std::string type;
            std::vector<std::string> qualifiers;
            json toJson(void) const {
                return json({
                        {"type", type},
                        {"qualifiers", qualifiers}
                        });
            }

    };

    class Creature : public Jsonable {
        public:
            Creature(const json& data);
            virtual ~Creature() {};

            // 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;

            // Inline getters
            std::string getCreatureName(void) const {return creatureName;}
            std::string getGivenName(void) const {return givenName;}
            std::string getType(void) const {return type;}
            std::string getSize(void) const {return size;}
            std::string getAlignment(void) const {return alignment;}
            double getCR(void) const {return cr;}
            std::pair<std::string, int> getNaturalArmor(void) const {return {natArmorName, natArmorBonus};}
            std::string getLanguages(void) const {return langs;}
            int getHP(void) const {return hp;}
            int getHPMax(void) const {return hpMax;}
            std::vector<std::string> getSenses(void) const {return senses;}
            std::string getSpeed(void) const {return speed;}
            int getScore(const rules::Ability& ability) const {return stats.at(ability);}
            int getBonus(const rules::Ability& ability) const {return (int) (getScore(ability) - 10) / 2;}
            int getProficiency(void) const {return proficiency;}
            std::vector<std::shared_ptr<entry::Feature>> getFeatures(void) const {return features;}
            std::vector<std::shared_ptr<entry::Item>> getInventory(void) const {return inventory;}


            // Setters (mutators)
            void setGivenName(std::string name) {givenName = name;}
            void applyDamage(int amount, const std::string& type, const std::vector<std::string>& qualifiers);
            void setScore(const rules::Ability& ability, int score);
            void setProfLevel(const rules::Skill& skill, int level);
            void addInventoryItem(std::shared_ptr<entry::Item> item);
            void removeInventoryItem(const std::string& itemName);

            virtual json toJson(void) const;

        private:
            // Mutable variables
            std::string givenName;
            int hpMax;
            int hp;
            std::vector<std::shared_ptr<entry::Item>> inventory;
            std::map<rules::Ability, int> stats;
            std::map<rules::Skill, int> skills;
            
            //Immutable variables
            const std::string creatureName;
            const std::string size;
            const std::string type;
            const std::string alignment;
            const int hdCount;
            const int hdSides;
            const std::string speed;
            const std::vector<rules::Ability> saves;
            const std::vector<std::string> senses;
            const std::string langs;
            const double cr;
            const int proficiency;
            const std::string natArmorName;
            const int natArmorBonus;
            const std::vector<dmgType> dmgImmunities;
            const std::vector<dmgType> dmgResistances;
            const std::vector<dmgType> dmgVulnerabilities;
            const std::vector<dmgType> condImmunities;
            const std::vector<std::shared_ptr<entry::Feature>> features;

    };

    // Convenience function to get any instances of T (subclass of Item) in the inventory
    template<typename T> std::vector<std::shared_ptr<T>> getItems(const Creature& c) {
        std::vector<std::shared_ptr<T>> Ts;
        for(auto item : c.getInventory()) {
            std::shared_ptr<T> t = dynamic_pointer_cast<T>(item);
            if(t) {
                Ts.push_back(t);
            }
        }
        return Ts;
    }

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

    // Convenience function to spit out everything about it
    std::string genText(const Creature& c);
}