diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index b829b2e7..7036a5df 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -108,7 +108,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo icon: '', visible: li => { const message = game.messages.get(li.dataset.messageId); - return game.user.isGM || message.isAuthor; + return message.system.hasRoll && (game.user.isGM || message.isAuthor); }, callback: async li => { const message = game.messages.get(li.dataset.messageId); @@ -128,10 +128,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo }, callback: async li => { const message = game.messages.get(li.dataset.messageId); - const damageRoll = new game.system.api.dice.DamageRoll(message.system.damage.hitPoints.roll); - await message.system.action.workflow.get('damage')?.execute(message.system, message.id, true); - // message.update({ rolls: [reroll] }); - console.log('test'); + const update = await message.system.getRerolledDamage(); + message.update(update); } } ]; diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index eaa1cdc2..caffde09 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -130,6 +130,41 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { }); } + /* TODO: Change how damage data is stored somehow to enable better rerolling */ + async getRerolledDamage() { + if (!this.damage) return; + + const rerolls = []; + const update = { system: { damage: {} } }; + for (const partKey in this.damage) { + const part = this.damage[partKey]; + const testRoll = Roll.fromData(part.parts[0].roll); + const rerolled = await testRoll.reroll(); + rerolls.push(rerolled); + + if (!update.system.damage[partKey]) update.system.damage[partKey] = { parts: [part.parts[0]] }; + const partData = update.system.damage[partKey].parts[0]; + update.system.damage[partKey].total = rerolled.total; + partData.modifierTotal = rerolled.terms.reduce((acc, x) => { + if (x.isDeterministic && !x.operator) acc += x.total; + return acc; + }, 0); + partData.dice = rerolled.dice; + partData.total = rerolled.total; + partData.roll = rerolled.toJSON(); + } + + if (game.modules.get('dice-so-nice')?.active) { + for (const roll of rerolls) { + await game.dice3d.showForRoll(roll, game.user, true); + } + } else { + foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice }); + } + + return update; + } + registerTargetHook() { if (!this.parent.isAuthor || !this.hasTarget) return; if (this.targetMode && this.parent.targetHook !== null) { diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 509f5d69..2cc6baf6 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -224,4 +224,19 @@ export default class D20Roll extends DHRoll { resetFormula() { return (this._formula = this.constructor.getFormula(this.terms)); } + + async reroll(options) { + const result = await super.reroll(options); + if (this instanceof game.system.api.dice.DualityRoll) return result; + + if (options?.liveRoll) { + if (game.modules.get('dice-so-nice')?.active) { + await game.dice3d.showForRoll(result, game.user, true); + } else { + foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice }); + } + } + + return result; + } } diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 98fd8401..1fc30d29 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -18,7 +18,12 @@ export default class DamageRoll extends DHRoll { if (config.evaluate !== false) for (const roll of config.roll) await roll.roll.evaluate(); roll._evaluated = true; - const parts = config.roll.map(r => this.postEvaluate(r)); + + const parts = []; + for (const roll of config.roll) { + parts.push(this.postEvaluate(roll)); + roll.roll = JSON.stringify(roll.roll.toJSON()); + } config.damage = this.unifyDamageRoll(parts); }