#include "weapon.h" #include "creature.h" #include "rules.h" #include #include #include using namespace std; namespace entry { int Weapon::getDamageDieSides(bool versatile) const { if(versatile && getProperties().count("versatile")) { return damageDieSides + 2; } return damageDieSides; } string getTextHelper(const Weapon& w, string toHitBonus, string damageBonus) { stringstream text; text << "+" << toHitBonus << " 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() << " + " << damageBonus << " " << w.getDamageType() << " damage"; if(w.getProperties().count("versatile")) { text << " (or " << w.getDamageDieCount() << "d" << w.getDamageDieSides(true) << " + " << damageBonus << " " << 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(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(); } }