aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd_query.cc3
-rw-r--r--src/weapon.cc38
-rw-r--r--src/weapon.h3
3 files changed, 31 insertions, 13 deletions
diff --git a/src/cmd_query.cc b/src/cmd_query.cc
index deff049..5172cda 100644
--- a/src/cmd_query.cc
+++ b/src/cmd_query.cc
@@ -39,8 +39,7 @@ namespace cmd {
for(auto w : creature::getAttacks(*c)) {
if(w->getName() == rollName) {
text << w->getText(*c) << std::endl;
- int abilityBonus = c->getBonus(creature::getBestAbility(getAbilityOptions(*w), *c));
- int bonus = abilityBonus + c->getProficiency();
+ int bonus = w->getToHitBonus(*c);
printResults(w->getName(), "attack", rolled, bonus);
text << " on hit: " << entry::formatDmg(*w, *c) << std::endl;
break;
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();
}
}
diff --git a/src/weapon.h b/src/weapon.h
index 707edd9..fc58262 100644
--- a/src/weapon.h
+++ b/src/weapon.h
@@ -38,6 +38,9 @@ namespace entry {
int getCost(void) const;
double getWeight(void) const;
+ int getToHitBonus(const creature::Creature& c) const;
+ int getDamageBonus(const creature::Creature& c) const;
+
virtual std::string getText() const override;
virtual std::string getText(const creature::Creature& c) const override;