From 5d6fac39fea7d7c20035c3f0ca91dc7f204f8257 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sun, 27 Jul 2025 21:07:10 +0200 Subject: [PATCH] . --- module/data/actor/character.mjs | 12 +++++++++--- module/data/fields/formulaField.mjs | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 2a585e95..989e4519 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -471,6 +471,12 @@ export default class DhCharacter extends BaseDataActor { }; } + get basicAttackDamageDice() { + const diceTypes = Object.keys(CONFIG.DH.GENERAL.diceTypes); + const attackDiceIndex = Math.max(Math.min(this.rules.attack.damage.diceIndex, 5), 0); + return diceTypes[attackDiceIndex]; + } + static async unequipBeforeEquip(itemToEquip) { const primary = this.primaryWeapon, secondary = this.secondaryWeapon; @@ -557,15 +563,15 @@ export default class DhCharacter extends BaseDataActor { this.resources.hope.value = Math.min(baseHope, this.resources.hope.max); this.attack.roll.trait = this.rules.attack.roll.trait ?? this.attack.roll.trait; - const diceTypes = Object.keys(CONFIG.DH.GENERAL.diceTypes); - const attackDiceIndex = Math.max(Math.min(this.rules.attack.damage.diceIndex, 5), 0); - this.attack.damage.parts[0].value.custom.formula = `@prof${diceTypes[attackDiceIndex]}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`; + this.attack.damage.parts[0].value.custom.formula = `@prof${this.basicAttackDamageDice}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`; } getRollData() { const data = super.getRollData(); + return { ...data, + basicAttackDamageDice: this.basicAttackDamageDice, tier: this.tier, level: this.levelData.level.current }; diff --git a/module/data/fields/formulaField.mjs b/module/data/fields/formulaField.mjs index 68c26efc..85922f1f 100644 --- a/module/data/fields/formulaField.mjs +++ b/module/data/fields/formulaField.mjs @@ -35,7 +35,13 @@ export default class FormulaField extends foundry.data.fields.StringField { /** @inheritDoc */ _validateType(value) { - const roll = new Roll(value.replace(/@([a-z.0-9_-]+)/gi, '1')); + /* A bit suss, but seems to work */ + let roll = null; + try { + roll = new Roll(value.replace(/@([a-z.0-9_-]+)/gi, '1')); + } catch (_) { + roll = new Roll(value.replace(/@([a-z.0-9_-]+)/gi, 'd6')); + } roll.evaluateSync({ strict: false }); if (this.options.deterministic && !roll.isDeterministic) throw new Error(`must not contain dice terms: ${value}`);