aboutsummaryrefslogtreecommitdiff
path: root/src/weapon.h
blob: da6700cc4828efffc6a03313ca27e2e449deafcd (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
#pragma once
#include "item.h"
#include "rules.h"
#include <nlohmann/json.hpp>
#include <set>

namespace creature {
    class Creature;
}

namespace entry {
    class Weapon;
    class Damage;

    std::vector<rules::Ability> getAbilityOptions(const Weapon& w);
    std::vector<Damage> rollDmg(const Weapon& w, bool versatile=false);
    std::string formatDmg(const Weapon& w, const creature::Creature& c);

    struct Damage {
        int dmg_die_count;
        int dmg_die_sides;
        std::string dmg_type;
        bool is_or;
        int rolled = 0;
    };
    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Damage, dmg_die_count, dmg_die_sides, dmg_type, is_or);

    class Weapon : public Item, public Substantial {
        public:
            std::vector<Damage> getDamage(void) const {return damage;}
            std::set<std::string> getProperties(void) const {return properties;}
            std::string getWeaponType(void) const {return weapon_type;}
            std::pair<int, int> getRange(void) const {return range;}
            int getReach(void) const {return reach;}
            int getCost(void) const {return cost;}
            double getWeight(void) const {return weight;}

            virtual std::string getText() const override;
            virtual std::string getText(const creature::Creature& c) const override;

            NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(Item, Weapon, damage, properties, weapon_type, range, reach, cost, weight);

        private:
            std::vector<Damage> damage;
            std::set<std::string> properties;
            std::string weapon_type;
            std::pair<int, int> range;
            int reach;
            int cost;
            double weight;
    };
}