diff options
author | Your Name <you@example.com> | 2021-04-29 14:17:08 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-04-29 14:17:08 -0400 |
commit | 5a813a75412ac9b8fadb90c9abd46dd95aee8e9b (patch) | |
tree | 75c5466d459c793430a6481cd276a624cd843794 /src/weapon.cc | |
parent | cd57ad6e208728bafcbc8c7d7b85d88603706978 (diff) | |
download | dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.tar.gz dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.tar.bz2 dmtool-5a813a75412ac9b8fadb90c9abd46dd95aee8e9b.zip |
Removed data files from repo
Diffstat (limited to 'src/weapon.cc')
-rw-r--r-- | src/weapon.cc | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/src/weapon.cc b/src/weapon.cc index af75736..b3dad1d 100644 --- a/src/weapon.cc +++ b/src/weapon.cc @@ -15,19 +15,9 @@ namespace entry { return damageDieSides; } - string Weapon::getText(const creature::Creature& c) const { - return genText(*this, c); - } - - string genText(const Weapon& w, const creature::Creature& c) { + string getTextHelper(const Weapon& w, string toHitBonus, string damageBonus) { stringstream text; - text << genText(static_cast<const Item&>(w), c); - // Determine best ability bonus - int abilityBonus = c.getBonus(rules::Ability::Str()); - if(w.getProperties().count("finesse")) { - abilityBonus = max(abilityBonus, c.getBonus(rules::Ability::Dex())); - } - text << ": +" << abilityBonus + c.getProficiency() << " to hit, "; + text << "+" << toHitBonus << " to hit, "; if(w.getReach() > 0) { text << "reach " << w.getReach() << " ft."; if(w.getRange().second > 0) { @@ -37,9 +27,9 @@ namespace entry { 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"; + text << " Hit: " << w.getDamageDieCount() << "d" << w.getDamageDieSides() << " + " << damageBonus << " " << w.getDamageType() << " damage"; if(w.getProperties().count("versatile")) { - text << " (or " << w.getDamageDieCount() << "d" << w.getDamageDieSides(true) << " + " << abilityBonus << " " << w.getDamageType() << " damage if two-handed)"; + text << " (or " << w.getDamageDieCount() << "d" << w.getDamageDieSides(true) << " + " << damageBonus << " " << w.getDamageType() << " damage if two-handed)"; } text << "."; auto props = w.getProperties(); @@ -52,4 +42,46 @@ namespace entry { text << " " << genText(static_cast<const Substantial&>(w)); return text.str(); } + + vector<rules::Ability> getAbilityOptions(const Weapon& w) { + // Do finesse + if(w.getProperties().count("finesse")) { + return {rules::Ability::Str(), rules::Ability::Dex()}; + } + // Do melee weapons + if(w.getReach() > 0) { + return {rules::Ability::Str()}; + } + // Do range weapons (thrown melee were done above) + if(w.getRange().second > 0) { + return {rules::Ability::Dex()}; + } + cerr << "Error processing weapon!" << endl; + return {rules::Ability::Str()}; + } + + string Weapon::getText() const { + auto abilities = getAbilityOptions(*this); + string abilityString; + if(abilities.size() == 1) { + abilityString = abilities[0]; + } else { + abilityString = "max(" + utils::join(abilities, ", ") + ")"; + } + return getTextHelper(*this, "(" + abilityString + " + prof)", abilityString); + + } + + string genText(const Weapon& w, const creature::Creature& c) { + stringstream text; + text << genText(static_cast<const Item&>(w), c); + // Determine best ability bonus + auto abilities = getAbilityOptions(w); + int abilityBonus = c.getBonus(abilities[0]); + if(abilities.size() == 2) { + abilityBonus = max(abilityBonus, c.getBonus(abilities[1])); + } + text << ": " << getTextHelper(w, to_string(abilityBonus + c.getProficiency()), to_string(abilityBonus)); + return text.str(); + } } |