Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main()
- async function main() {
- // Extra mechanic for crits on suppression rolls
- let dialogTemplate = `
- <div style="display:flex">
- <span style="flex:1">
- <label for="scales">Critically stunned?</label>
- <input type="checkbox" id="stunnedCheckBoxId">
- </span>
- </div>
- `
- // Is Activated by shift click on macro. Normal click to roll normally
- const shiftClick = event.shiftKey;
- if (!shiftClick) {
- await executeSuppressionCheckRoll(0);
- return;
- }
- // Execute roll and print message
- new Dialog({
- title: "Suppression Check Roll",
- buttons: {
- withdraw_custom: {
- label: "Roll Suppression Check",
- callback: (html) => {
- const isCriticallyStunned = html.find("#stunnedCheckBoxId")[0].checked;
- let modifier = (isCriticallyStunned == null || isCriticallyStunned === false) ? 0 : 2;
- executeSuppressionCheckRoll(modifier);
- }
- }
- },
- content: dialogTemplate
- }).render(true);
- }
- async function executeSuppressionCheckRoll(modifier) {
- // Get Table by name (unique)
- const table = game.tables.getName("Suppression Check");
- if (table == null) {
- ui.notifications.error("Suppression Check Table not found");
- return;
- }
- // Get single controlled (selected) actor, error otherwise
- if (canvas.tokens.controlled.length == 0 || canvas.tokens.controlled.length > 1) {
- ui.notifications.error("Please select a single actor");
- return;
- }
- const actor = canvas.tokens.controlled[0].actor;
- // Get actor attributes
- const mindPointsMax = actor.system.mindPoints.max;
- const mindPointsCurrent = actor.system.mindPoints.value;
- const stress = mindPointsMax - mindPointsCurrent;
- // Continuation of extra mechanic for crits on suppression rolls
- const finalMod = modifier == null ? 0 : modifier;
- // Execute roll
- const roll = new Roll("1d6 + " + stress + " + " + finalMod);
- // Roll on table and get result
- var total;
- await table.draw({roll}).then(r => total = r.roll._total);
- console.log("total: " + total);
- // Get mind points and update. On my table, it always subtracts 1 but you could make multiple ifs based on total
- var currentMp = actor.system.mindPoints.value;
- if (currentMp > 0 && total > 3) {
- actor.update({"system.mindPoints.value": parseInt(currentMp) - parseInt(1)});
- }
- // Extra message if mind points reach 0
- if (currentMp - 1 <= 0) {
- let chatContent = "Nervous breakdown!";
- ChatMessage.create({
- speaker: {
- alias: actor.name
- },
- content: chatContent
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement