-
-
Save Kurohyou/f0b8bdeff3ad780927fbf86bbb7768e6 to your computer and use it in GitHub Desktop.
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
on('ready', async function(){ | |
'use strict'; | |
var diceResults = await diceAction(8,7,true); | |
var actionResult = diceResults.RollResult; | |
var damage = diceResults.DamageResult; | |
sendChat("","New Result"); | |
sendChat("","Action Result: "+actionResult); | |
sendChat("","Damage Result: "+damage); | |
function async diceAction(nDice,targetNumber,damageFlag){ | |
var diceCounter = nDice; | |
var actionTotal = 0; | |
var diceResults =""; | |
var rollFinal = {}; | |
//var damageResult = ""; | |
//var contentArray = ""; | |
while (diceCounter>0){ | |
let rollOnce = await new Promise((resolve,reject)=>{ | |
sendChat("", "/r "+diceCounter+"d10>"+targetNumber, function(obs){ | |
resolve(objs); | |
}); | |
}), | |
contentArray = JSON.parse(rollOnce.content); | |
diceCounter = contentArray.total; | |
diceResults = parseRollArray(contentArray.rolls[0].results); | |
actionTotal += 10; | |
}; | |
actionTotal += Math.max(diceResults); | |
if (damageFlag){ | |
var damageDice = Math.floor(actionTotal/10 %10); | |
let rollDamage = await new Promise((resolve,reject)=>{ | |
sendChat('','/roll '+damageDice+'d10',function(obs){ | |
resolve(obs[0]); | |
}); | |
}); | |
var contentDamage = JSON.parse(rollDamage.content); | |
var damageResult = contentDamage.total; | |
}; | |
diceResults.RollResult = actionTotal; | |
diceResults.DamageResult = damageResult; | |
return diceResults; | |
} | |
function parseRollArray(resultsArray){ | |
var i; | |
var simpleArray=[]; | |
for(i =0; i<resultsArray.length;i++){ | |
simpleArray.push(resultsArray[i].v); | |
} | |
return simpleArray; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment