Tweak the dice rolling macro to utilize the multi-input ask dialog
This commit is contained in:
parent
dde0b21b19
commit
ce148d3ec2
1 changed files with 30 additions and 11 deletions
|
|
@ -6,48 +6,67 @@ async function rollDice() {
|
||||||
question: `Set up your dice pool:`,
|
question: `Set up your dice pool:`,
|
||||||
inputs: [
|
inputs: [
|
||||||
{
|
{
|
||||||
|
key: `statBase`,
|
||||||
inputType: `number`,
|
inputType: `number`,
|
||||||
defaultValue: 2,
|
defaultValue: 2,
|
||||||
label: `Number of Dice`,
|
label: `Number of Dice`,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
key: `successThreshold`,
|
||||||
inputType: `number`,
|
inputType: `number`,
|
||||||
defaultValue: 4,
|
defaultValue: 3,
|
||||||
label: `Success Threshold (d${sidesOnDice} >= X)`,
|
label: `Success Threshold (d${sidesOnDice} > X)`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
key: `critsEnabled`,
|
||||||
inputType: `checkbox`,
|
inputType: `checkbox`,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
label: `Enable Criticals`,
|
label: `Enable Criticals`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const [ statBase, successThreshold, critsEnabled ] = Object.values(answers);
|
const { statBase, successThreshold, critsEnabled } = answers;
|
||||||
const rollMode = game.settings.get(`core`, `rollMode`);
|
let rollMode = game.settings.get(`core`, `rollMode`);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let successes = 0;
|
let successes = 0;
|
||||||
|
let critsOnly = 0;
|
||||||
const results = [];
|
const results = [];
|
||||||
for (let i = statBase; i > 0; i--) {
|
for (let i = statBase; i > 0; i--) {
|
||||||
let r = new Roll(`1d${sidesOnDice}`);
|
let r = new Roll(`1d${sidesOnDice}`);
|
||||||
await r.evaluate();
|
await r.evaluate();
|
||||||
results.push(r.total);
|
let classes = `roll die d6`;
|
||||||
if (r.total >= successThreshold) {
|
|
||||||
|
// Determine the success count and class modifications for the chat
|
||||||
|
if (r.total > successThreshold) {
|
||||||
successes++;
|
successes++;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
classes += ` failure`
|
||||||
|
}
|
||||||
if (r.total === sidesOnDice && critsEnabled) {
|
if (r.total === sidesOnDice && critsEnabled) {
|
||||||
successes++;
|
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(
|
const chatData = ChatMessage.applyRollMode(
|
||||||
{
|
{
|
||||||
title: `Dice Pool`,
|
title: `Dice Pool`,
|
||||||
content: `Rolled: ${taf.utils.hideMessageText(results.join(`, `))}<br>Successes: ${taf.utils.hideMessageText(successes)}`,
|
content,
|
||||||
flags: { taf: {
|
|
||||||
rollModedContent: true,
|
|
||||||
rollMode,
|
|
||||||
} },
|
|
||||||
},
|
},
|
||||||
rollMode,
|
rollMode,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue