Created
August 18, 2024 21:50
-
-
Save jonstodle/b157df0e5391d69e6028df48f8f50847 to your computer and use it in GitHub Desktop.
Power Roll for Foundry VTT
This file contains hidden or 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
// Original work done by Acehigh | |
// Modified by Jon de Nor | |
const callback = (html, event) => ({ | |
value: html.find('input').val() || '0', | |
action: event?.currentTarget.dataset.button ?? 'normal', | |
}); | |
const buttons = { | |
dblbane: { label: "Double Bane", callback }, | |
bane: { label: "Bane", callback }, | |
normal: { label: "Normal", callback }, | |
edge: { label: "Edge", callback }, | |
dbledge: { label: "Double Edge", callback } | |
}; | |
let rollConfig = await Dialog.wait({ | |
title: 'Roll', | |
content: '<form><div class="form-group"><label>Modifier:</label><div class="form-fields"><input type="number" value="2" /></div></div></form>', | |
buttons, | |
default: 'normal', | |
}).catch(_ => null); | |
if (!rollConfig) | |
return; | |
edgeBaneMod = | |
rollConfig.action == 'edge' ? '+ 2' : | |
rollConfig.action == 'bane' ? '- 2' : | |
""; | |
const roll = await new Roll(`2d10 ${edgeBaneMod} + ${rollConfig.value}`).evaluate(); | |
if (roll.total < 12) | |
tier = 1 | |
else if (roll.total < 17) | |
tier = 2 | |
else | |
tier = 3 | |
if (rollConfig.action == 'dbledge' && tier < 3) | |
tier++; | |
if (rollConfig.action == 'dblbane' && tier > 1) | |
tier--; | |
//Always get a tier 3 result on roll of 20 | |
if (roll.dice[0].total === 20) | |
tier = 3; | |
const critMessage = roll.dice[0].total > 18 | |
? '<br />Critical Success!' | |
: ''; | |
await roll.toMessage({ | |
speaker: ChatMessage.implementation.getSpeaker({ actor }), | |
flavor: `<div style="text-align:center; margin-top: .5em"><h1>Tier: ${tier}${critMessage}</h1><p>${buttons[rollConfig.action].label}</p></div>` | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment