diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index e601f86d..b0e122d1 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -40,7 +40,6 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { hasSave: new fields.BooleanField({ initial: false }), hasTarget: new fields.BooleanField({ initial: false }), isDirect: new fields.BooleanField({ initial: false }), - isCritical: new fields.BooleanField({ initial: false }), onSave: new fields.StringField(), source: new fields.SchemaField({ actor: new fields.StringField(), diff --git a/module/data/fields/action/damageField.mjs b/module/data/fields/action/damageField.mjs index b7ef852e..94f70e68 100644 --- a/module/data/fields/action/damageField.mjs +++ b/module/data/fields/action/damageField.mjs @@ -49,11 +49,14 @@ export default class DamageField extends fields.SchemaField { formulas = DamageField.formatFormulas.call(this, formulas, config); + messageId = config.message?._id ?? messageId; + const message = game.messages.get(messageId); const damageConfig = { dialog: {}, ...config, roll: formulas, - data: this.getRollData() + data: this.getRollData(), + isCritical: message?.system.roll.isCritical }; delete damageConfig.evaluate; @@ -61,7 +64,7 @@ export default class DamageField extends fields.SchemaField { damageConfig.dialog.configure = false; if (config.hasSave) config.onSave = damageConfig.onSave = this.save.damageMod; - damageConfig.source.message = config.message?._id ?? messageId; + damageConfig.source.message = messageId; damageConfig.directDamage = !!damageConfig.source?.message; // if(damageConfig.source?.message && game.modules.get('dice-so-nice')?.active) diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 6c1082f0..509f5d69 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -207,7 +207,7 @@ export default class D20Roll extends DHRoll { rerolls: dice.results.filter(x => x.rerolled) } })); - data.isCritical = config.isCritical = roll.isCritical; + data.isCritical = roll.isCritical; data.extra = roll.dice .filter(d => !roll.baseTerms.includes(d)) .map(d => { diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 58c0cd02..bb9e31c7 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -138,57 +138,52 @@ export default class DamageRoll extends DHRoll { } constructFormula(config) { - this.options.roll.forEach((part, index) => { + for (const [index, part] of this.options.roll.entries()) { part.roll = new Roll(Roll.replaceFormulaData(part.formula, config.data)); - this.constructFormulaPart(config, part, index); - }); + part.roll.terms = Roll.parse(part.roll.formula, config.data); + if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + part.modifiers = this.applyBaseBonus(part); + this.addModifiers(part); + part.modifiers?.forEach(m => { + part.roll.terms.push(...this.formatModifier(m.value)); + }); + } + + /* To Remove When Reaction System */ + if (index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + for (const mod in config.modifiers) { + const modifier = config.modifiers[mod]; + if (modifier.beforeCrit === true && (modifier.enabled || modifier.value)) modifier.callback(part); + } + } + + if (part.extraFormula) { + part.roll.terms.push( + new foundry.dice.terms.OperatorTerm({ operator: '+' }), + ...this.constructor.parse(part.extraFormula, this.options.data) + ); + } + + if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + const total = part.roll.dice.reduce((acc, term) => acc + term._faces * term._number, 0); + if (total > 0) { + part.roll.terms.push(...this.formatModifier(total)); + } + } + + /* To Remove When Reaction System */ + if (index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + for (const mod in config.modifiers) { + const modifier = config.modifiers[mod]; + if (!modifier.beforeCrit && (modifier.enabled || modifier.value)) modifier.callback(part); + } + } + + part.roll._formula = this.constructor.getFormula(part.roll.terms); + } return this.options.roll; } - constructFormulaPart(config, part, index) { - part.roll.terms = Roll.parse(part.roll.formula, config.data); - - if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { - part.modifiers = this.applyBaseBonus(part); - this.addModifiers(part); - part.modifiers?.forEach(m => { - part.roll.terms.push(...this.formatModifier(m.value)); - }); - } - - /* To Remove When Reaction System */ - if (index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { - for (const mod in config.modifiers) { - const modifier = config.modifiers[mod]; - if (modifier.beforeCrit === true && (modifier.enabled || modifier.value)) modifier.callback(part); - } - } - - if (part.extraFormula) { - part.roll.terms.push( - new foundry.dice.terms.OperatorTerm({ operator: '+' }), - ...this.constructor.parse(part.extraFormula, this.options.data) - ); - } - - if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { - const total = part.roll.dice.reduce((acc, term) => acc + term._faces * term._number, 0); - if (total > 0) { - part.roll.terms.push(...this.formatModifier(total)); - } - } - - /* To Remove When Reaction System */ - if (index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { - for (const mod in config.modifiers) { - const modifier = config.modifiers[mod]; - if (!modifier.beforeCrit && (modifier.enabled || modifier.value)) modifier.callback(part); - } - } - - return (part.roll._formula = this.constructor.getFormula(part.roll.terms)); - } - /* To Remove When Reaction System */ static temporaryModifierBuilder(config) { const mods = {};