From 52b91a1aca6640b1797a63afc8a9e9a778b0964a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 25 Dec 2021 16:52:34 -0500 Subject: Added capability to cause two npcs to attack each other --- src/weapon.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/weapon.cc') diff --git a/src/weapon.cc b/src/weapon.cc index 7ae597f..e5f04f2 100644 --- a/src/weapon.cc +++ b/src/weapon.cc @@ -110,27 +110,24 @@ namespace entry { bool first = true; for(Damage& d : dmgs) { d.rolled = 0; - int sides = d.dmg_die_sides; if(first && versatile && w.getProperties().count("versatile")) { - sides += 2; + d.dmg_die_sides += 2; } first = false; for(int i = 0; i < d.dmg_die_count; i++) { - d.rolled += dice::roll(sides); + d.rolled += dice::roll(d.dmg_die_sides); } } return dmgs; } - string formatDmg(const Weapon& w, const creature::Creature& c) { + string formatDmgHelper(const Weapon& w, const creature::Creature& c, const std::vector& dmgsNoVersatile, const std::vector& dmgsVersatile) { stringstream text; - vector dmgsNoVersatile = rollDmg(w, false); - vector dmgsVersatile = rollDmg(w, true); 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; - if(w.getProperties().count("versatile")) { + if(w.getProperties().count("versatile") and ! dmgsVersatile.empty()) { text << " (or " << dmgsVersatile[i].rolled + abilityBonus << " if two-handed)"; } } else { @@ -148,6 +145,16 @@ namespace entry { return text.str(); } + string formatDmg(const Weapon& w, const creature::Creature& c) { + vector dmgsNoVersatile = rollDmg(w, false); + vector dmgsVersatile = rollDmg(w, true); + return formatDmgHelper(w, c, dmgsNoVersatile, dmgsVersatile); + } + + string formatDmg(const Weapon& w, const creature::Creature& c, const std::vector& dmgs) { + return formatDmgHelper(w, c, dmgs, {}); + } + vector getAbilityOptions(const Weapon& w) { // Do finesse if(w.getProperties().count("finesse")) { -- cgit v1.2.3