Last active
May 22, 2023 22:06
-
-
Save drewfranz/6462f921aaac66fe22ce3cafa0cff414 to your computer and use it in GitHub Desktop.
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
var d6 = {} | |
d6.answers = [ | |
"Hell no!", | |
"No", | |
"No, but...", | |
"Yes, but...", | |
"Yes", | |
"Hell yes!" | |
] | |
d6.doubles = [ | |
"Very Negative", | |
"Negative", | |
"Negative but...", | |
"Positive but...", | |
"Positive", | |
"Positive and..." | |
] | |
let checkDoubles = dice => { | |
if (dice && dice.number > 1) { | |
var prevDie = null | |
var isDouble = dice.results.filter(el => { | |
var isSame = false; | |
if (el.result === prevDie) { | |
isSame = !isSame | |
} | |
prevDie = el.result | |
return isSame | |
}) | |
return isDouble | |
} | |
} | |
let roll = async (N = 1, keep = "") => { | |
let roller = new Roll(`${N}d6${keep}`) | |
let theAnswer = await roller.evaluate({async: true}) | |
let theResult = d6.answers[theAnswer.total - 1] | |
var message = `The answer is ${theResult}` | |
let isDouble = checkDoubles(theAnswer.dice[0]) | |
if (isDouble && isDouble.length) { | |
message = `${message} and ${d6.doubles[isDouble[0].result - 1]}` | |
} | |
ChatMessage.create({content:message}) | |
} | |
const configDialog = ` | |
<form> | |
<label for="dieConfig">How likely is it?</label> | |
<select name="dieConfig" id="die_config"> | |
<option value="1">Don't think so</option> | |
<option value="2">Unlikely</option> | |
<option value="3">Who knows?</option> | |
<option value="4">Probably</option> | |
<option value="5">Definitely</option> | |
</select> | |
</form> | |
` | |
let dialog = new Dialog({ | |
title:"D6 Oracle", | |
content:configDialog, | |
buttons: { | |
submit: { | |
label:"D6 Oracle", | |
callback:async (html) => { | |
const dieSelect = html.find("#die_config").children("option:selected").val() | |
console.log(dieSelect) | |
switch (dieSelect) { | |
case "1": | |
roll(3, "kl") | |
break; | |
case "2": | |
roll(2, "kl") | |
break; | |
case "3": | |
roll() | |
break; | |
case "4": | |
roll(2, "kh") | |
break; | |
case "5": | |
roll(3, "kh") | |
break; | |
} | |
} | |
} | |
} | |
}) | |
dialog.render(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment