From 5a813a75412ac9b8fadb90c9abd46dd95aee8e9b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 Apr 2021 14:17:08 -0400 Subject: Removed data files from repo --- src/weapon.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 14 deletions(-) (limited to 'src/weapon.cc') 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(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(w)); return text.str(); } + + vector 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(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(); + } } -- cgit v1.2.3