diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 7dc06741..e9c447e4 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -185,10 +185,8 @@ export default class D20Roll extends DHRoll { return changeKeys; } - static async buildEvaluate(roll, config = {}, message = {}) { - await super.buildEvaluate(roll, config, message); - - const data = config.roll; + static postEvaluate(roll, config = {}) { + const data = super.postEvaluate(roll, config); data.type = config.actionType; data.difficulty = config.roll.difficulty; if (config.targets?.length) { @@ -224,6 +222,7 @@ export default class D20Roll extends DHRoll { }; }); data.modifierTotal = roll.modifierTotal; + return data; } resetFormula() { diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 3f2f79e0..ef810ed7 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -13,38 +13,32 @@ export default class DamageRoll extends DHRoll { static DefaultDialog = DamageDialog; - /** @inheritdoc */ static async buildEvaluate(roll, config = {}, message = {}) { if (config.dialog.configure === false) roll.constructFormula(config); - for (const roll of config.roll) await roll.roll.evaluate(); + if (config.evaluate !== false) for (const roll of config.roll) await roll.roll.evaluate(); roll._evaluated = true; const parts = []; - for (const rollData of config.roll) { - const roll = rollData.roll; - parts.push({ - ...rollData, - ...roll.options.roll, - total: roll.total, - formula: roll.formula, - dice: roll.dice.map(d => ({ - dice: d.denomination, - total: d.total, - formula: d.formula, - results: d.results - })), - damageTypes: [...(rollData.damageTypes ?? [])], - roll, - type: config.type, - modifierTotal: this.calculateTotalModifiers(roll) - }); - rollData.roll = JSON.stringify(roll.toJSON()); + for (const roll of config.roll) { + parts.push(this.postEvaluate(roll)); + roll.roll = JSON.stringify(roll.roll.toJSON()); } config.damage = this.unifyDamageRoll(parts); } + static postEvaluate(roll, config = {}) { + return { + ...roll, + ...super.postEvaluate(roll.roll, config), + damageTypes: [...(roll.damageTypes ?? [])], + roll: roll.roll, + type: config.type, + modifierTotal: this.calculateTotalModifiers(roll.roll) + }; + } + static async buildPost(roll, config, message) { const chatMessage = config.source?.message ? ui.chat.collection.get(config.source.message) diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 16472fea..1c6ec829 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -33,9 +33,7 @@ export default class DHRoll extends Roll { if (config.skips?.createMessage) config.messageRoll = roll; - if (config.evaluate !== false) { - await this.buildEvaluate(roll, config, (message = {})); - } + await this.buildEvaluate(roll, config, (message = {})); await this.buildPost(roll, config, (message = {})); return config; } @@ -74,30 +72,13 @@ export default class DHRoll extends Roll { return roll; } - /** - * Evaluates the roll and assigns roll data into the config. - * This is only called if config.evaluate is not set to false - * @protected - */ static async buildEvaluate(roll, config = {}, message = {}) { - await roll.evaluate(); - config.roll = { - ...roll.options.roll, - total: roll.total, - formula: roll.formula, - dice: roll.dice.map(d => ({ - dice: d.denomination, - total: d.total, - formula: d.formula, - results: d.results - })) - }; + if (config.evaluate !== false) { + await roll.evaluate(); + config.roll = this.postEvaluate(roll, config); + } } - /** - * Runs any post configuration events that need to happen towards the end, such as hooks and dice so nice - * @protected - */ static async buildPost(roll, config, message) { for (const hook of config.hooks) { if (Hooks.call(`${CONFIG.DH.id}.postRoll${hook.capitalize()}`, config, message) === false) return null; @@ -110,6 +91,20 @@ export default class DHRoll extends Roll { } } + static postEvaluate(roll, config = {}) { + return { + ...roll.options.roll, + total: roll.total, + formula: roll.formula, + dice: roll.dice.map(d => ({ + dice: d.denomination, + total: d.total, + formula: d.formula, + results: d.results + })) + }; + } + static async toMessage(roll, config) { const item = config.data.parent?.items?.get?.(config.source.item) ?? null; const action = item ? item.system.actions.get(config.source.action) : null; diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index 38d9315f..e2d967a3 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -232,41 +232,9 @@ export default class DualityRoll extends D20Roll { return changeKeys; } - /** @inheritdoc */ static async buildEvaluate(roll, config = {}, message = {}) { await super.buildEvaluate(roll, config, message); - config.roll.hope = { - dice: roll.dHope.denomination, - value: this.guaranteedCritical ? 0 : roll.dHope.total, - rerolled: { - any: roll.dHope.results.some(x => x.rerolled), - rerolls: roll.dHope.results.filter(x => x.rerolled) - } - }; - config.roll.fear = { - dice: roll.dFear.denomination, - value: this.guaranteedCritical ? 0 : roll.dFear.total, - rerolled: { - any: roll.dFear.results.some(x => x.rerolled), - rerolls: roll.dFear.results.filter(x => x.rerolled) - } - }; - config.roll.rally = { - dice: roll.dRally?.denomination, - value: roll.dRally?.total - }; - config.roll.result = { - duality: roll.withHope ? 1 : roll.withFear ? -1 : 0, - total: this.guaranteedCritical ? 0 : roll.dHope.total + roll.dFear.total, - label: roll.totalLabel - }; - if (roll._rallyIndex && roll.data?.parent) - roll.data.parent.deleteEmbeddedDocuments('ActiveEffect', [roll._rallyIndex]); - } - - /** @inheritdoc */ - static async buildPost(roll, config, message) { await setDiceSoNiceForDualityRoll( roll, config.roll.advantage.type, @@ -274,7 +242,44 @@ export default class DualityRoll extends D20Roll { config.roll.fear.dice, config.roll.advantage.dice ); + } + static postEvaluate(roll, config = {}) { + const data = super.postEvaluate(roll, config); + + data.hope = { + dice: roll.dHope.denomination, + value: this.guaranteedCritical ? 0 : roll.dHope.total, + rerolled: { + any: roll.dHope.results.some(x => x.rerolled), + rerolls: roll.dHope.results.filter(x => x.rerolled) + } + }; + data.fear = { + dice: roll.dFear.denomination, + value: this.guaranteedCritical ? 0 : roll.dFear.total, + rerolled: { + any: roll.dFear.results.some(x => x.rerolled), + rerolls: roll.dFear.results.filter(x => x.rerolled) + } + }; + data.rally = { + dice: roll.dRally?.denomination, + value: roll.dRally?.total + }; + data.result = { + duality: roll.withHope ? 1 : roll.withFear ? -1 : 0, + total: this.guaranteedCritical ? 0 : roll.dHope.total + roll.dFear.total, + label: roll.totalLabel + }; + + if (roll._rallyIndex && roll.data?.parent) + roll.data.parent.deleteEmbeddedDocuments('ActiveEffect', [roll._rallyIndex]); + + return data; + } + + static async buildPost(roll, config, message) { await super.buildPost(roll, config, message); await DualityRoll.dualityUpdate(config); diff --git a/module/dice/fateRoll.mjs b/module/dice/fateRoll.mjs index f8276ce1..114fad59 100644 --- a/module/dice/fateRoll.mjs +++ b/module/dice/fateRoll.mjs @@ -75,23 +75,25 @@ export default class FateRoll extends D20Roll { this.terms[0] = new foundry.dice.terms.Die({ faces: 12 }); } - /** @inheritdoc */ static async buildEvaluate(roll, config = {}, message = {}) { await super.buildEvaluate(roll, config, message); - config.roll.fate = { - dice: roll.fateDie === 'Hope' ? roll.dHope.denomination : roll.dFear.denomination, - value: roll.fateDie === 'Hope' ? roll.dHope.total : roll.dFear.total, - fateDie: roll.fateDie - }; - } - /** @inheritdoc */ - static async buildPost(roll, config, message) { if (roll.fateDie === 'Hope') { await setDiceSoNiceForHopeFateRoll(roll, config.roll.fate.dice); } else { await setDiceSoNiceForFearFateRoll(roll, config.roll.fate.dice); } - return super.buildPost(roll, config, message); + } + + static postEvaluate(roll, config = {}) { + const data = super.postEvaluate(roll, config); + + data.fate = { + dice: roll.fateDie === 'Hope' ? roll.dHope.denomination : roll.dFear.denomination, + value: roll.fateDie === 'Hope' ? roll.dHope.total : roll.dFear.total, + fateDie: roll.fateDie + }; + + return data; } } diff --git a/system.json b/system.json index 3f1b49a6..d754b8bf 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "id": "daggerheart", "title": "Daggerheart", "description": "An unofficial implementation of the Daggerheart system", - "version": "2.5.1", + "version": "2.5.0", "compatibility": { "minimum": "14.364", "verified": "14.364", @@ -10,7 +10,7 @@ }, "url": "https://github.com/Foundryborne/daggerheart", "manifest": "https://raw.githubusercontent.com/Foundryborne/daggerheart/v14/system.json", - "download": "https://github.com/Foundryborne/daggerheart/releases/download/2.5.1/system.zip", + "download": "https://github.com/Foundryborne/daggerheart/releases/download/2.5.0/system.zip", "authors": [ { "name": "WBHarry"