aboutsummaryrefslogtreecommitdiff
path: root/src/weapon.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-12-23 20:43:29 -0500
committerYour Name <you@example.com>2021-12-23 20:43:29 -0500
commitd8d1056af0383f0ef67c6d70d1594bcb430d7281 (patch)
tree2a57e74603af6da70d0df2f4b91d68ac7830f482 /src/weapon.cc
parent3632c99f94b762da6c069da10f830f63017dd1c8 (diff)
downloaddmtool-d8d1056af0383f0ef67c6d70d1594bcb430d7281.tar.gz
dmtool-d8d1056af0383f0ef67c6d70d1594bcb430d7281.tar.bz2
dmtool-d8d1056af0383f0ef67c6d70d1594bcb430d7281.zip
Fixed handling of ability override
Diffstat (limited to 'src/weapon.cc')
-rw-r--r--src/weapon.cc38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/weapon.cc b/src/weapon.cc
index cdf4657..7ae597f 100644
--- a/src/weapon.cc
+++ b/src/weapon.cc
@@ -87,6 +87,8 @@ namespace entry {
char first = w.Entry::getText()[0];
if('a' <= first and 'z' >= first) {
text << ' ';
+ } else if('A' <= first and 'Z' >= first) {
+ text << ". ";
}
text << w.Entry::getText();
}
@@ -124,7 +126,7 @@ namespace entry {
stringstream text;
vector<Damage> dmgsNoVersatile = rollDmg(w, false);
vector<Damage> dmgsVersatile = rollDmg(w, true);
- int abilityBonus = c.getBonus(creature::getBestAbility(getAbilityOptions(w), c));
+ int abilityBonus = w.getDamageBonus(c);
for(size_t i = 0; i < dmgsNoVersatile.size(); i++) {
if(i == 0 and w.getType() == "weapons" and dmgsNoVersatile[0].dmg_die_sides != 1) {
text << dmgsNoVersatile[i].rolled + abilityBonus;
@@ -163,6 +165,27 @@ namespace entry {
// Default to str
return {rules::Ability::Str()};
}
+
+ int getAbilityBonus(const creature::Creature& c, const Weapon& w, std::shared_ptr<weaponImpl> data) {
+ if(data->abilityOverride) {
+ return c.getBonus(*data->abilityOverride);
+ }
+ return c.getBonus(creature::getBestAbility(getAbilityOptions(w), c));
+ }
+
+ int Weapon::getToHitBonus(const creature::Creature& c) const {
+ if(data->toHitOverride) {
+ return *data->toHitOverride;
+ }
+ return getAbilityBonus(c, *this, data) + c.getProficiency();
+ }
+
+ int Weapon::getDamageBonus(const creature::Creature& c) const {
+ if(data->dmgBonusOverride) {
+ return *data->dmgBonusOverride;
+ }
+ return getAbilityBonus(c, *this, data);
+ }
string Weapon::getText() const {
auto abilities = getAbilityOptions(*this);
@@ -184,16 +207,9 @@ namespace entry {
string Weapon::getText(const creature::Creature& c) const {
stringstream text;
text << getName() << " (" << getType() << "): ";
- // Determine best ability bonus
- int abilityBonus = c.getBonus(creature::getBestAbility(getAbilityOptions(*this), c));
- if(data->abilityOverride) {
- abilityBonus = c.getBonus(*data->abilityOverride);
- }
- string toHitString = data->toHitOverride ? to_string(*data->toHitOverride) : to_string(abilityBonus + c.getProficiency());
- if(data->dmgBonusOverride) {
- abilityBonus = *data->dmgBonusOverride;
- }
- text << getTextHelper(*this, toHitString, to_string(abilityBonus));
+ string toHitString = to_string(getToHitBonus(c));
+ string dmgBonus = to_string(getDamageBonus(c));
+ text << getTextHelper(*this, toHitString, dmgBonus);
return text.str();
}
}