diff --git a/module/applications/dialogs/damageDialog.mjs b/module/applications/dialogs/damageDialog.mjs index 841de805..1b61b96d 100644 --- a/module/applications/dialogs/damageDialog.mjs +++ b/module/applications/dialogs/damageDialog.mjs @@ -43,6 +43,7 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application async _prepareContext(_options) { const context = await super._prepareContext(_options); + context.config = CONFIG.DH; context.title = this.config.title ? this.config.title : game.i18n.localize('DAGGERHEART.EFFECTS.ApplyLocations.damageRoll.name'); @@ -55,7 +56,6 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application label, icon })); - return context; } diff --git a/module/data/action/actionDice.mjs b/module/data/action/actionDice.mjs index 80115c6d..c3c28247 100644 --- a/module/data/action/actionDice.mjs +++ b/module/data/action/actionDice.mjs @@ -128,8 +128,7 @@ export class DHDamageData extends DHResourceData { required: true }), { - label: 'Type', - initial: 'physical' + label: 'Type' } ) } diff --git a/module/data/action/damageAction.mjs b/module/data/action/damageAction.mjs index 099ec283..13461d30 100644 --- a/module/data/action/damageAction.mjs +++ b/module/data/action/damageAction.mjs @@ -34,16 +34,10 @@ export default class DHDamageAction extends DHBaseAction { async rollDamage(event, data) { const systemData = data.system ?? data; - /* let formula = this.damage.parts.map(p => this.getFormulaValue(p, data).getFormula(this.actor)).join(' + '), - damageTypes = [...new Set(this.damage.parts.reduce((a, c) => a.concat([...c.type]), []))]; - - damageTypes = !damageTypes.length ? ['physical'] : damageTypes; - - if (!formula || formula == '') return; */ let formulas = this.damage.parts.map(p => ({ formula: this.getFormulaValue(p, data).getFormula(this.actor), - damageTypes: p.type, + damageTypes: p.applyTo === 'hitPoints' && !p.type.size ? new Set(['physical']) : p.type, applyTo: p.applyTo })); @@ -51,21 +45,14 @@ export default class DHDamageAction extends DHBaseAction { formulas = this.formatFormulas(formulas, systemData); - /* let roll = { formula: formula, total: formula }; - - if (isNaN(formula)) formula = Roll.replaceFormulaData(formula, this.getRollData(systemData)); */ - const config = { title: game.i18n.format('DAGGERHEART.UI.Chat.damageRoll.title', { damage: this.name }), - // roll: { formula }, - // roll: { formulas }, roll: formulas, targets: systemData.targets.filter(t => t.hit) ?? data.targets, hasSave: this.hasSave, isCritical: systemData.roll?.isCritical ?? false, source: systemData.source, data: this.getRollData(), - // damageTypes, event }; if (this.hasSave) config.onSave = this.save.damageMod; @@ -76,7 +63,6 @@ export default class DHDamageAction extends DHBaseAction { config.directDamage = true; } - // roll = CONFIG.Dice.daggerheart.DamageRoll.build(config); - CONFIG.Dice.daggerheart.DamageRoll.build(config); + return CONFIG.Dice.daggerheart.DamageRoll.build(config); } } diff --git a/module/data/action/healingAction.mjs b/module/data/action/healingAction.mjs index 4c1366a1..ddae314a 100644 --- a/module/data/action/healingAction.mjs +++ b/module/data/action/healingAction.mjs @@ -19,14 +19,14 @@ export default class DHHealingAction extends DHBaseAction { formula = formulaValue.getFormula(this.actor); if (!formula || formula == '') return; - let roll = { formula: formula, total: formula }, - bonusDamage = []; + let roll = { formula: formula, total: formula }; const config = { title: game.i18n.format('DAGGERHEART.UI.Chat.healingRoll.title', { healing: game.i18n.localize(CONFIG.DH.GENERAL.healingTypes[this.healing.type].label) }), - roll: { formula }, + // roll: { formula }, + roll: [ formula ], targets: (data.system?.targets ?? data.targets).filter(t => t.hit), messageType: 'healing', type: this.healing.type, diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index b9ce18ce..74de0a25 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -10,10 +10,19 @@ export default class DamageRoll extends DHRoll { static DefaultDialog = DamageDialog; - static async postEvaluate(roll, config = {}) { - super.postEvaluate(roll, config); - config.roll.type = config.type; - config.roll.modifierTotal = this.calculateTotalModifiers(roll); + static async buildEvaluate(rolls, config = {}, message = {}) { + if ( config.evaluate !== false ) { + for ( const roll of config.roll ) await roll.roll.evaluate(); + } + config.roll = config.roll.map(r => this.postEvaluate(r.roll)); + } + + static postEvaluate(roll, config = {}) { + return { + ...super.postEvaluate(roll, config), + type: config.type, + modifierTotal: this.calculateTotalModifiers(roll) + } } static async buildPost(roll, config, message) { @@ -75,38 +84,4 @@ export default class DamageRoll extends DHRoll { } return (part.roll._formula = this.constructor.getFormula(part.roll.terms)); } - - async evaluate({minimize=false, maximize=false, allowStrings=false, allowInteractive=true, ...options}={}) { - if ( this._evaluated ) { - throw new Error(`The ${this.constructor.name} has already been evaluated and is now immutable`); - } - this._evaluated = true; - if ( CONFIG.debug.dice ) console.debug(`Evaluating roll with formula "${this.formula}"`); - - // Migration path for async rolls - if ( "async" in options ) { - foundry.utils.logCompatibilityWarning("The async option for Roll#evaluate has been removed. " - + "Use Roll#evaluateSync for synchronous roll evaluation."); - } - - this.options.roll.forEach( async part => { - await part.roll.evaluate({minimize, maximize, allowStrings, allowInteractive, ...options}) - }) - // return this._evaluate({minimize, maximize, allowStrings, allowInteractive}); - } - - static postEvaluate(roll, config = {}) { - if (!config.roll) config.roll = {}; - config.roll.total = roll.total; - config.roll.formula = roll.formula; - config.roll.dice = []; - roll.dice.forEach(d => { - config.roll.dice.push({ - dice: d.denomination, - total: d.total, - formula: d.formula, - results: d.results - }); - }); - } } diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 3590baf3..84c14f43 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -57,6 +57,10 @@ export default class DHRoll extends Roll { // Create Chat Message if (config.source?.message) { + if(Array.isArray(config.roll)) { + const pool = foundry.dice.terms.PoolTerm.fromRolls(config.roll); + roll = Roll.fromTerms([pool]); + } if (game.modules.get('dice-so-nice')?.active) await game.dice3d.showForRoll(roll, game.user, true); } else { config.message = await this.toMessage(roll, config); diff --git a/styles/less/global/dialog.less b/styles/less/global/dialog.less index 11a4eee9..8c86e825 100644 --- a/styles/less/global/dialog.less +++ b/styles/less/global/dialog.less @@ -56,4 +56,15 @@ color: light-dark(@dark, @beige); } + + .damage-formula { + display: flex; + justify-content: space-between; + .damage-details { + font-style: italic; + display: flex; + align-items: center; + gap: 5px; + } + } } diff --git a/templates/dialogs/dice-roll/damageSelection.hbs b/templates/dialogs/dice-roll/damageSelection.hbs index fee74582..d31a31ec 100644 --- a/templates/dialogs/dice-roll/damageSelection.hbs +++ b/templates/dialogs/dice-roll/damageSelection.hbs @@ -3,7 +3,22 @@

{{title}}

{{#each @root.formula}} - Formula: {{roll.formula}} +
+ Formula: {{roll.formula}} + {{!-- {{localize (concat 'CONFIG.DH.GENERAL.healingTypes.' applyTo '.label')}} --}} + + {{#with (lookup @root.config.GENERAL.healingTypes applyTo)}} + {{localize label}} + {{/with}} + {{#if damageTypes}} + {{#each damageTypes as | type | }} + {{#with (lookup @root.config.GENERAL.damageTypes type)}} + + {{/with}} + {{/each}} + {{/if}} + +
diff --git a/templates/ui/chat/parts/damage-chat.hbs b/templates/ui/chat/parts/damage-chat.hbs index f8d7cfed..18041d80 100644 --- a/templates/ui/chat/parts/damage-chat.hbs +++ b/templates/ui/chat/parts/damage-chat.hbs @@ -1,4 +1,5 @@
+ {{log damage}} {{#unless noTitle}}
{{damage.title}}
{{/unless}}
{{damage.roll.formula}}