Skip to content

Commit 5db0e45

Browse files
committed
FIX - discarded dice don't count for fumble
1 parent e611e18 commit 5db0e45

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/module/combat/ABFCombat.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class ABFCombat extends Combat {
77
*/
88
constructor(data, context) {
99
super(data, context);
10-
this.setFlag('world', 'newRound', true);
10+
this.updateSource({ 'flags.world.newRound': true });
1111
}
1212

1313
async startCombat() {
@@ -75,7 +75,8 @@ export default class ABFCombat extends Combat {
7575
for (const id of ids) {
7676
const combatant = this.combatants.get(id);
7777

78-
const baseInit = combatant.actor.system.characteristics.secondaries.initiative.final.value || 0;
78+
const baseInit =
79+
combatant.actor.system.characteristics.secondaries.initiative.final.value || 0;
7980
const formula = `${combatant._getInitiativeFormula()} + ${baseInit} + ${mod}`;
8081
await super.rollInitiative(id, { formula, updateTurn, messageOptions });
8182
}

src/module/rolls/ABFInitiativeRoll/ABFInitiativeRoll.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@ export default class ABFInitiativeRoll extends ABFExploderRoll {
1313
});
1414
}
1515

16+
/** @private */
17+
_getFinalDieResult() {
18+
const d100 = this.foundryRoll.dice?.[0];
19+
if (!d100 || !Array.isArray(d100.results)) return null;
20+
21+
const kept = d100.results.filter(
22+
r => !r.discarded && r.active !== false && (r.count ?? 1) > 0
23+
);
24+
25+
if (!kept.length) return null;
26+
27+
return kept[0].result;
28+
}
29+
1630
/** @private */
1731
calculateFumbledInitiativeMod() {
18-
if (this.foundryRoll.firstResult === 1) return -126;
19-
if (this.foundryRoll.firstResult === 2) return -102;
20-
if (this.foundryRoll.firstResult <= this.fumbleRange)
21-
return -75 - this.foundryRoll.firstResult;
32+
const value = this._getFinalDieResult();
33+
if (value == null) return 0;
34+
35+
if (value === 1) return -126;
36+
if (value === 2) return -102;
37+
if (value <= this.fumbleRange) return -75 - value;
2238

2339
return 0;
2440
}

0 commit comments

Comments
 (0)