Skip to content

Commit 3ed9238

Browse files
committed
FIX - dice custom formulas not working on automatic combat
1 parent f994bb9 commit 3ed9238

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

src/module/dialogs/combat/CombatAttackDialog.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ export class CombatAttackDialog extends FormApplication {
226226
this.render(true);
227227
}
228228

229+
// Helper: get base dice formula from actor settings
230+
getBaseCombatDiceFormula(actor) {
231+
const diceSettings = actor.system.general.diceSettings;
232+
return diceSettings?.abilityDie.value ?? '1d100xa';
233+
}
234+
235+
// Helper: remove first dice term when rolling "withoutRoll"
236+
removeFirstDiceTerm(formula) {
237+
// Replace everything hasta el primer '+' por '0'
238+
return formula.replace(/^[^+]+/, '0');
239+
}
240+
229241
static get defaultOptions() {
230242
return foundry.utils.mergeObject(super.defaultOptions, {
231243
classes: ['animabf-dialog combat-attack-dialog no-close'],
@@ -335,9 +347,13 @@ export class CombatAttackDialog extends FormApplication {
335347
for (const key in attackerCombatMod)
336348
combatModifier += attackerCombatMod[key]?.value ?? 0;
337349

338-
let formula = `1d100xa + ${counterAttackBonus} + ${attack} + ${combatModifier}`;
339-
if (this.modalData.attacker.withoutRoll)
340-
formula = formula.replace('1d100xa', '0');
350+
const baseDice = this.getBaseCombatDiceFormula(this.attackerActor);
351+
let formula = `${baseDice} + ${counterAttackBonus} + ${attack} + ${combatModifier}`;
352+
353+
if (this.modalData.attacker.withoutRoll) {
354+
formula = this.removeFirstDiceTerm(formula);
355+
}
356+
341357
if (this.attackerActor.system.combat.attack.base.value >= 200) {
342358
formula = formula.replace('xa', 'xamastery');
343359
}
@@ -364,7 +380,8 @@ export class CombatAttackDialog extends FormApplication {
364380

365381
// New fields
366382
const reducedArmorFinal = weapon?.system?.reducedArmor?.final?.value ?? 0;
367-
const weaponName = weapon?.name ?? game.i18n.localize('macros.combat.unarmed') ?? 'Unarmed';
383+
const weaponName =
384+
weapon?.name ?? game.i18n.localize('macros.combat.unarmed') ?? 'Unarmed';
368385

369386
const critic = criticSelected ?? game.animabf.weapon.WeaponCritic.IMPACT;
370387

src/module/dialogs/combat/CombatDefenseDialog.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ export class CombatDefenseDialog extends FormApplication {
245245
this.render(true);
246246
}
247247

248+
// Helper: get base dice formula from actor settings
249+
getBaseCombatDiceFormula(actor) {
250+
const diceSettings = actor.system.general.diceSettings;
251+
return diceSettings?.abilityDie.value ?? '1d100xa';
252+
}
253+
254+
// Helper: remove first dice term when rolling "withoutRoll"
255+
removeFirstDiceTerm(formula) {
256+
// Replace everything hasta el primer '+' por '0'
257+
return formula.replace(/^[^+]+/, '0');
258+
}
259+
248260
static get defaultOptions() {
249261
return foundry.utils.mergeObject(super.defaultOptions, {
250262
classes: ['animabf-dialog combat-defense-dialog no-close'],
@@ -376,13 +388,13 @@ export class CombatDefenseDialog extends FormApplication {
376388
for (const key in defenderCombatMod) {
377389
combatModifier += defenderCombatMod[key]?.value ?? 0;
378390
}
379-
let formula = `1d100xa + ${combatModifier} + ${value}`;
391+
const baseDice = this.getBaseCombatDiceFormula(this.defenderActor);
392+
let formula = `${baseDice} + ${combatModifier} + ${value}`;
393+
380394
if (this.modalData.defender.withoutRoll) {
381-
// Remove the dice from the formula
382-
formula = formula.replace('1d100xa', '0');
395+
formula = this.removeFirstDiceTerm(formula);
383396
}
384397
if (baseDefense >= 200) {
385-
// Mastery reduces the fumble range
386398
formula = formula.replace('xa', 'xamastery');
387399
}
388400

0 commit comments

Comments
 (0)