Tweak the dice rolling macro to utilize the multi-input ask dialog

This commit is contained in:
Oliver-Akins 2024-09-21 18:08:50 -06:00
parent dde0b21b19
commit ce148d3ec2

View file

@ -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(`<li class="${classes}">${r.total}</li>`);
}
let content = `Rolls:<div class="dice-tooltip"><ol class="dice-rolls">${results.join(``)}</ol></div><hr>Successes: ${successes}<br>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(`, `))}<br>Successes: ${taf.utils.hideMessageText(successes)}`,
flags: { taf: {
rollModedContent: true,
rollMode,
} },
content,
},
rollMode,
);