Advertisement
Guest User

Untitled

a guest
May 16th, 2024
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main()
  2.  
  3. async function main() {
  4.  
  5.     // Extra mechanic for crits on suppression rolls
  6.     let dialogTemplate = `
  7.     <div style="display:flex">
  8.         <span style="flex:1">
  9.             <label for="scales">Critically stunned?</label>
  10.             <input type="checkbox" id="stunnedCheckBoxId">
  11.       </span>
  12.     </div>
  13.     `
  14.  
  15.     // Is Activated by shift click on macro. Normal click to roll normally
  16.     const shiftClick = event.shiftKey;
  17.     if (!shiftClick) {
  18.         await executeSuppressionCheckRoll(0);
  19.         return;
  20.     }
  21.  
  22.     // Execute roll and print message
  23.     new Dialog({
  24.         title: "Suppression Check Roll",
  25.         buttons: {
  26.             withdraw_custom: {
  27.                 label: "Roll Suppression Check",
  28.                 callback: (html) => {
  29.                     const isCriticallyStunned = html.find("#stunnedCheckBoxId")[0].checked;
  30.                     let modifier = (isCriticallyStunned == null || isCriticallyStunned === false) ? 0 : 2;
  31.  
  32.                     executeSuppressionCheckRoll(modifier);
  33.                 }
  34.             }
  35.         },
  36.         content: dialogTemplate
  37.     }).render(true);
  38.  
  39.  
  40. }
  41.  
  42. async function executeSuppressionCheckRoll(modifier) {
  43.  
  44.     // Get Table by name (unique)
  45.     const table = game.tables.getName("Suppression Check");
  46.     if (table == null) {
  47.         ui.notifications.error("Suppression Check Table not found");
  48.         return;
  49.     }
  50.  
  51.     // Get single controlled (selected) actor, error otherwise
  52.     if (canvas.tokens.controlled.length == 0 || canvas.tokens.controlled.length > 1) {
  53.         ui.notifications.error("Please select a single actor");
  54.         return;
  55.     }
  56.     const actor = canvas.tokens.controlled[0].actor;
  57.  
  58.     // Get actor attributes
  59.     const mindPointsMax = actor.system.mindPoints.max;
  60.     const mindPointsCurrent = actor.system.mindPoints.value;
  61.     const stress = mindPointsMax - mindPointsCurrent;
  62.  
  63.     // Continuation of extra mechanic for crits on suppression rolls
  64.     const finalMod = modifier == null ? 0 : modifier;
  65.  
  66.     // Execute roll
  67.     const roll = new Roll("1d6 + " + stress + " + " + finalMod);
  68.  
  69.     // Roll on table and get result
  70.     var total;
  71.     await table.draw({roll}).then(r => total = r.roll._total);
  72.  
  73.     console.log("total: " + total);
  74.  
  75.     // Get mind points and update. On my table, it always subtracts 1 but you could make multiple ifs based on total
  76.     var currentMp = actor.system.mindPoints.value;
  77.     if (currentMp > 0 && total > 3) {
  78.         actor.update({"system.mindPoints.value": parseInt(currentMp) - parseInt(1)});
  79.     }
  80.  
  81.     // Extra message if mind points reach 0
  82.     if (currentMp - 1 <= 0) {
  83.  
  84.         let chatContent = "Nervous breakdown!";
  85.         ChatMessage.create({
  86.             speaker: {
  87.                 alias: actor.name
  88.             },
  89.             content: chatContent
  90.         });
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement