Skip to content

Commit

Permalink
Ensure when reducing hit / wound counts, that they are lower bound (#72)
Browse files Browse the repository at this point in the history
- When doing any reductions to hit / wound counts, ensure that the result has a minimum of 0 (don't allow negatives) (fixes #71)
  • Loading branch information
damonhook authored Aug 11, 2021
1 parent fc9fa1a commit 0e1a4bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions api/processors/averageDamageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ export default class AverageDamageProcessor {
if (mwModifier) {
const mortalHits = attacks * mwModifier.resolve(this.profile);
mortalDamage += mortalHits * mwModifier.getMortalWounds();
mortalDamage -= mortalDamage * this.target.resolveMortalSave(this.profile);
hits -= !mwModifier.inAddition ? mortalHits : 0;
mortalDamage = Math.max(mortalDamage - mortalDamage * this.target.resolveMortalSave(this.profile), 0);
if (!mwModifier.inAddition) {
hits = Math.max(hits - mortalHits, 0);
}
}

const cbModifier = this.profile.modifiers.getModifier(m.CONDITIONAL_BONUS, C.TO_HIT);
Expand All @@ -60,7 +62,7 @@ export default class AverageDamageProcessor {
const cbModHits = attacks * cbModifier.resolve(this.profile);
const splitProcessor = new AverageDamageProcessor(newProfile, this.target);
splitDamage = splitProcessor.resolveWounds(cbModHits);
hits -= cbModHits;
hits = Math.max(hits - cbModHits, 0);
}

return this.resolveWounds(hits) + mortalDamage + splitDamage;
Expand All @@ -76,8 +78,10 @@ export default class AverageDamageProcessor {
if (mwModifier) {
const mortalToWounds = hits * mwModifier.resolve(this.profile);
mortalDamage += mortalToWounds * mwModifier.getMortalWounds();
mortalDamage -= mortalDamage * this.target.resolveMortalSave(this.profile);
wounds -= !mwModifier.inAddition ? mortalToWounds : 0;
mortalDamage = Math.max(mortalDamage - mortalDamage * this.target.resolveMortalSave(this.profile), 0);
if (!mwModifier.inAddition) {
wounds = Math.max(wounds - mortalToWounds, 0);
}
}

const cbModifier = this.profile.modifiers.getModifier(m.CONDITIONAL_BONUS, C.TO_WOUND);
Expand All @@ -87,7 +91,7 @@ export default class AverageDamageProcessor {
const cbModWounds = hits * cbModifier.resolve(this.profile);
const splitProcessor = new AverageDamageProcessor(newProfile, this.target);
splitDamage = splitProcessor.resolveSaves(cbModWounds);
wounds -= cbModWounds;
wounds = Math.max(wounds - cbModWounds, 0);
}

return this.resolveSaves(wounds) + mortalDamage + splitDamage;
Expand All @@ -102,6 +106,6 @@ export default class AverageDamageProcessor {
resolveDamage(successful: number) {
const damage = successful * this.profile.getDamage();
const saves = damage * this.target.resolveFNP(this.profile);
return damage - saves;
return Math.max(damage - saves, 0);
}
}
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "statshammer",
"version": "2.1.4",
"version": "2.1.5",
"private": true,
"proxy": "http://localhost:5000/",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"*",
"."
],
"version": "2.1.4",
"version": "2.1.5",
"npmClient": "yarn"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "statshammer-express",
"private": true,
"version": "2.1.4",
"version": "2.1.5",
"engines": {
"node": "12.18.3",
"yarn": "1.22.4"
Expand Down

0 comments on commit 0e1a4bc

Please sign in to comment.