aboutsummaryrefslogtreecommitdiff
path: root/src/weapon.cc
blob: 3a42e80d6e9eeb7d6127ca5d6caf0dcd75cc9883 (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
#include "weapon.h"
#include "creature.h"
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

namespace entry {
    int Weapon::getDamageDieSides(bool versatile) const {
        if(versatile && getProperties().count("versatile")) {
            return damageDieSides + 2;
        }
        return damageDieSides;
    }

    string Weapon::getText(const creature::Creature& c) const {
        return genText(*this, c);
    }

    string genText(const Weapon& w, const creature::Creature& c) {
        stringstream text;
        text << genText(static_cast<const Item&>(w), c);
        // Determine best ability bonus
        int abilityBonus = c.getBonus("str");
        if(w.getProperties().count("finesse")) {
            abilityBonus = max(abilityBonus, c.getBonus("dex"));
        }
        text << ": +" << abilityBonus + c.getProficiency() << " to hit, ";
        if(w.getReach() > 0) {
            text << "reach " << w.getReach() << " ft.";
            if(w.getRange().second > 0) {
                text << " or ";
            }
        }
        if(w.getRange().second > 0) {
            text << "range " << w.getRange().first << "/" << w.getRange().second << " ft.";
        }
        text << " Hit: " << w.getDamageDieCount() << "d" << w.getDamageDieSides() << " + " << abilityBonus << " " << w.getDamageType() << " damage";
        if(w.getProperties().count("versatile")) {
            text << " (or " << w.getDamageDieCount() << "d" << w.getDamageDieSides(true) << " + " << abilityBonus << " " << w.getDamageType() << " damage if two-handed)";
        }
        text << ".";
        auto props = w.getProperties();
        // We don't care about finesse nor versatile because they're already handled
        props.erase("finesse");
        props.erase("versatile");
        if(! props.empty()) {
            text << " Additional properties: " << utils::join(props, ", ") << ".";
        }
        text << " " << genText(static_cast<const Substantial&>(w));
        return text.str();
    }
}