From ce148d3ec28b200ce05a3a82b800612b3bb65902 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 21 Sep 2024 18:08:50 -0600 Subject: [PATCH] Tweak the dice rolling macro to utilize the multi-input ask dialog --- scripts/macros/rollDice.mjs | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/scripts/macros/rollDice.mjs b/scripts/macros/rollDice.mjs index 2519669..b2d99b2 100644 --- a/scripts/macros/rollDice.mjs +++ b/scripts/macros/rollDice.mjs @@ -6,48 +6,67 @@ async function rollDice() { question: `Set up your dice pool:`, inputs: [ { + key: `statBase`, inputType: `number`, defaultValue: 2, label: `Number of Dice`, autofocus: true, }, { + key: `successThreshold`, inputType: `number`, - defaultValue: 4, - label: `Success Threshold (d${sidesOnDice} >= X)`, + defaultValue: 3, + label: `Success Threshold (d${sidesOnDice} > X)`, }, { + key: `critsEnabled`, inputType: `checkbox`, defaultValue: true, label: `Enable Criticals`, }, ], }); - const [ statBase, successThreshold, critsEnabled ] = Object.values(answers); - const rollMode = game.settings.get(`core`, `rollMode`); + const { statBase, successThreshold, critsEnabled } = answers; + let rollMode = game.settings.get(`core`, `rollMode`); + + let successes = 0; + let critsOnly = 0; const results = []; for (let i = statBase; i > 0; i--) { let r = new Roll(`1d${sidesOnDice}`); await r.evaluate(); - results.push(r.total); - if (r.total >= successThreshold) { + let classes = `roll die d6`; + + // Determine the success count and class modifications for the chat + if (r.total > successThreshold) { successes++; } + else { + classes += ` failure` + } if (r.total === sidesOnDice && critsEnabled) { successes++; + critsOnly++; + classes += ` success`; } + + results.push(`
  • ${r.total}
  • `); + } + + let content = `Rolls:
      ${results.join(``)}

    Successes: ${successes}
    Crits: ${critsOnly}`; + + + if (rollMode === CONST.DICE_ROLL_MODES.BLIND) { + ui.notifications.warn(`Cannot make a blind roll from the macro, rolling with mode "Private GM Roll" instead`); + rollMode = CONST.DICE_ROLL_MODES.PRIVATE; } const chatData = ChatMessage.applyRollMode( { title: `Dice Pool`, - content: `Rolled: ${taf.utils.hideMessageText(results.join(`, `))}
    Successes: ${taf.utils.hideMessageText(successes)}`, - flags: { taf: { - rollModedContent: true, - rollMode, - } }, + content, }, rollMode, );