Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save antonioeduardofernandes/f67647cf2b1c949b0b2034840b226297 to your computer and use it in GitHub Desktop.
Save antonioeduardofernandes/f67647cf2b1c949b0b2034840b226297 to your computer and use it in GitHub Desktop.
//function to use simple d12's
async function convertEyeOfSauron(diceResult) {
diceResult = Number(diceResult)
return diceResult === 11 ? 0 : diceResult
}
//the main journeyRoll function
async function journeyRoll(dicePool = "1d12", rollBonus = 0) {
//roll the dice
let targetDiceRoll = await new Roll("1d3").evaluate()
let journeyDiceRoll = await new Roll(dicePool).evaluate()
//get only the result of the roll
let targetDiceResult = await targetDiceRoll.result
let journeyDiceResult = await convertEyeOfSauron(journeyDiceRoll.result) + rollBonus
//roll on the right tables to determine the event and the targets
const eventTargets = await game.tables.getName("alvo de evento de jornada").getResultsForRoll(targetDiceResult)[0].data.text
const journeyEvent = await game.tables.getName("eventos de jornada").getResultsForRoll(journeyDiceResult)[0].data.text
//display the result just for the loremaster (or anyone who triggered this macro)
const content = `<div style="text-align:center">
<p style="font-size:22px;">Alvos do Evento:<\p> <span>${eventTargets}</span>
<h2 style="font-size:22px;">Evento de Jornada:<\h2>
<p style="color:#941b0c;font-size:14px;">${journeyEvent}<\p>
</div>`;
ChatMessage.create({ content, whisper: [game.user] });
}
//Dialog that sets the bonus and the Region of the journey, by default wild region is selected
let regionDialog = await Dialog.prompt({
content: `
<style>
#journeyBonusForm {
display:flex;
flex-flow:column;
row-gap:1rem;
}
#journeyBonusForm input {
width:30px;
}
#journeyBonusForm .regions {
margin-bottom:1rem;
}
#journeyBonusForm .regions, #journeyBonusForm .regions div {
display:flex;
}
</style>
<div id="journeyBonusForm">
<div>
<label for="bonus"><h3>Bonus</h3></label>
<input type="number" id="bonus" autofocus="true"></input>
</div>
<div class="regions">
<div>
<input name="region" type="radio" id="free" value="2d12kh"></input>
<label for="free">Fronteira</label>
</div>
<div>
<input name="region" type="radio" id="wild" value="1d12" checked></input>
<label for="wild">Ermo</label>
</div>
<div>
<input name="region" type="radio" id="shadow" value="2d12kl"></input>
<label for="shadow">Sombra</label>
</div>
</div>
</div>
`,
callback: html => {
let inputRegion = html.find('[name="region"]').val();
let inputBonus = html.find('[id="bonus"]').val();
journeyRoll(inputRegion, inputBonus)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment