Last active
November 6, 2018 03:40
-
-
Save lord-xaphan/153370abf40ca781933b7f3c2cc2cc8c 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', function(){ | |
'use strict'; | |
var diceResults = diceAction(8,7,true); | |
var actionResult = diceResults.RollResult; | |
var damage = diceResults.DamageResult; | |
sendChat("","New Result"); | |
sendChat("","Action Result: "+actionResult); | |
sendChat("","Damage Result: "+damage); | |
function diceAction(nDice,targetNumber,damageFlag){ | |
var diceCounter = nDice; | |
var actionTotal = 0; | |
var diceResults =""; | |
var rollFinal = {}; | |
//var damageResult = ""; | |
//var contentArray = ""; | |
while (diceCounter>0){ | |
sendChat("", "/r"+diceCounter+"d10>"+targetNumber, function(obs){ | |
var rollOnce = obs; | |
}); | |
var 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); | |
sendChat('','/roll '+damageDice+'d10',function(obs){ | |
var rollDamage = 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