Skip to content

Commit 0e1a4bc

Browse files
authored
Ensure when reducing hit / wound counts, that they are lower bound (#72)
- When doing any reductions to hit / wound counts, ensure that the result has a minimum of 0 (don't allow negatives) (fixes #71)
1 parent fc9fa1a commit 0e1a4bc

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

api/processors/averageDamageProcessor.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ export default class AverageDamageProcessor {
4949
if (mwModifier) {
5050
const mortalHits = attacks * mwModifier.resolve(this.profile);
5151
mortalDamage += mortalHits * mwModifier.getMortalWounds();
52-
mortalDamage -= mortalDamage * this.target.resolveMortalSave(this.profile);
53-
hits -= !mwModifier.inAddition ? mortalHits : 0;
52+
mortalDamage = Math.max(mortalDamage - mortalDamage * this.target.resolveMortalSave(this.profile), 0);
53+
if (!mwModifier.inAddition) {
54+
hits = Math.max(hits - mortalHits, 0);
55+
}
5456
}
5557

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

6668
return this.resolveWounds(hits) + mortalDamage + splitDamage;
@@ -76,8 +78,10 @@ export default class AverageDamageProcessor {
7678
if (mwModifier) {
7779
const mortalToWounds = hits * mwModifier.resolve(this.profile);
7880
mortalDamage += mortalToWounds * mwModifier.getMortalWounds();
79-
mortalDamage -= mortalDamage * this.target.resolveMortalSave(this.profile);
80-
wounds -= !mwModifier.inAddition ? mortalToWounds : 0;
81+
mortalDamage = Math.max(mortalDamage - mortalDamage * this.target.resolveMortalSave(this.profile), 0);
82+
if (!mwModifier.inAddition) {
83+
wounds = Math.max(wounds - mortalToWounds, 0);
84+
}
8185
}
8286

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

9397
return this.resolveSaves(wounds) + mortalDamage + splitDamage;
@@ -102,6 +106,6 @@ export default class AverageDamageProcessor {
102106
resolveDamage(successful: number) {
103107
const damage = successful * this.profile.getDamage();
104108
const saves = damage * this.target.resolveFNP(this.profile);
105-
return damage - saves;
109+
return Math.max(damage - saves, 0);
106110
}
107111
}

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "statshammer",
3-
"version": "2.1.4",
3+
"version": "2.1.5",
44
"private": true,
55
"proxy": "http://localhost:5000/",
66
"dependencies": {

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"*",
44
"."
55
],
6-
"version": "2.1.4",
6+
"version": "2.1.5",
77
"npmClient": "yarn"
88
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "statshammer-express",
33
"private": true,
4-
"version": "2.1.4",
4+
"version": "2.1.5",
55
"engines": {
66
"node": "12.18.3",
77
"yarn": "1.22.4"

0 commit comments

Comments
 (0)