Created
May 27, 2024 07:03
-
-
Save Cussa/895eec9a35e60fdb4a0f464672b722ab to your computer and use it in GitHub Desktop.
d6 Legends Roller macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
// Prompt the user for the number of dice | |
let diceRoll = new Dialog({ | |
title: "Dice Roll", | |
content: `<p>Enter the number of dice:</p><input type="number" id="numDice" value="1" min="1">`, | |
buttons: { | |
roll: { | |
label: "Roll", | |
callback: async (html) => { | |
try { | |
// Retrieve the number of dice from the input | |
let numDice = parseInt(html.find("#numDice").val()); | |
// Roll the specified number of d6 minus 1 | |
let roll = new Roll(`${numDice - 1}d6`); | |
await roll.evaluate({async: true}); | |
let tasks = []; | |
if (game.dice3d) { | |
tasks.push(game.dice3d.showForRoll(roll, game.user, true)); | |
} | |
// Count the number of successes | |
let diceResults = roll.dice[0].results; | |
let successes = diceResults.filter(die => die.result > 3).length; | |
// Report the results of the initial roll | |
let messageContent = `<p>Rolled ${numDice - 1}d6: ${diceResults.map(die => die.result).join(', ')}</p>`; | |
messageContent += `<p>Initial Successes: ${successes}</p>`; | |
// Roll the Wild Die | |
let wildDieRoll = new Roll(`1d6`); | |
await wildDieRoll.evaluate({async: true}); | |
if (game.dice3d) { | |
tasks.push(game.dice3d.showForRoll(wildDieRoll, game.user, true)); | |
} | |
let wildDieResult = wildDieRoll.dice[0].results[0].result; | |
messageContent += `<p>Wild Die: ${wildDieResult}</p>`; | |
// Check the result of the Wild Die | |
if (wildDieResult > 3) { | |
successes += 1; | |
messageContent += `<p>Wild Die Success! Total Successes: ${successes}</p>`; | |
// Roll again if the Wild Die is 6 | |
while (wildDieResult === 6) { | |
wildDieRoll = new Roll(`1d6`); | |
await wildDieRoll.evaluate({async: true}); | |
if (game.dice3d) { | |
tasks.push(game.dice3d.showForRoll(wildDieRoll, game.user, true)); | |
} | |
wildDieResult = wildDieRoll.dice[0].results[0].result; | |
messageContent += `<p>Wild Die Reroll: ${wildDieResult}</p>`; | |
if (wildDieResult > 3) { | |
successes += 1; | |
messageContent += `<p>Additional Wild Die Success! Total Successes: ${successes}</p>`; | |
} | |
} | |
} | |
// Report the final number of successes | |
messageContent += `<p>Final Successes: ${successes}</p>`; | |
await Promise.all(tasks); | |
// Send the results to chat | |
ChatMessage.create({ | |
user: game.user.id, | |
content: messageContent | |
}); | |
} catch (error) { | |
console.error("Error during dice roll:", error); | |
} | |
} | |
} | |
} | |
}).render(true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment