aboutsummaryrefslogtreecommitdiff
path: root/src/armor.cc
blob: cb73cb133dc0d2db9240ed3e8ecddcbe622024f5 (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
#include "armor.h"
#include "creature.h"
#include "entry.h"
#include "rules.h"
#include <string>
#include <sstream>

using namespace std;

namespace entry{
    struct armorImpl {
        int ac;
        std::string armor_type;
        int strength;
        bool disadvantage;
    };
    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(armorImpl, ac, armor_type, strength, disadvantage);

    NLOHMANN_FRIEND_DEFS(Item, Armor, data);

    Armor::Armor() : data(new armorImpl()) {}

    int Armor::getACBonus(void) const {return data->ac;}
    std::string Armor::getArmorType(void) const {return data->armor_type;}
    int Armor::getStrRequirement(void) const {return data->strength;}
    bool Armor::stealthDisadvantage(void) const {return data->disadvantage;}

    string getTextHelper(const Armor& a, string dexBonusLight, string dexBonusMedium) {
        stringstream text;
        text << "AC: " << a.getACBonus();
        if(a.getArmorType() == "light") {
            text << " + dex" << dexBonusLight;
        } else if(a.getArmorType() == "medium") {
            text << " + dex max 2" << dexBonusMedium;
        }
        if(a.getStrRequirement() > 0) {
            text << ", Mininum str: " << a.getStrRequirement();
        }
        if(a.stealthDisadvantage()) {
            text << ", Imposes stealth disadvantage";
        }
        text << ". " << a.getCostWeightText();
        return text.str();
    }

    string Armor::getText() const {
        return getTextHelper(*this, "", "");
    }

    string Armor::getText(const creature::Creature& c) const {
        stringstream text;
        text << getName() << " (" << getType() << "): ";
        int dex = c.getBonus(rules::Ability::Dex());
        string dexBonusLight = " (i.e., " + to_string(getACBonus() + dex) + ")";
        string dexBonusMedium = " (i.e., " + to_string(getACBonus() + ((dex > 2)? 2 : dex)) + ")";
        text << getTextHelper(*this, dexBonusLight, dexBonusMedium);
        return text.str();
    }
}