Last active
October 27, 2019 07:49
A script to roll a version of exploding dices. For each 6 rolled on D6 that 6 is removed and replaced with 2 new D6. This keeps going until there are no more sixes.
This file contains 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("chat:message", function(msg) { | |
const AddTurn = (token_id, page_id, value) => { | |
let turnOrderEntries=JSON.parse(Campaign().get('turnorder'))||[]; | |
turnOrderEntries.push({ | |
id: token_id, | |
pr: value, | |
pageid: page_id | |
}); | |
Campaign().set({ | |
turnorder: JSON.stringify( | |
_.sortBy(turnOrderEntries,(o)=>-o.pr) | |
) | |
}); | |
}; | |
if (msg.type != "api") { | |
return; | |
} | |
var message = msg.content; | |
var command = message.split(" ")[0]; | |
var numrolls = parseInt(message.split(" ")[1]); | |
var outroll = "ob" + message.split(" ")[1] + ": "; | |
var plus = 0; | |
var times = 0; | |
var ids = message.split(/--/)[1]; | |
if(message.search(/\+/g)!=-1){ | |
plus = parseInt(message.split("+")[1]); | |
} | |
else if(message.search(/\*/g)!=-1){ | |
times = parseInt(message.split("*")[1]); | |
} | |
if (command == "!ob") { | |
var count = 0; | |
var total = 0; | |
var roll = 0; | |
var first = true; | |
var output = "" + outroll + "" ; | |
while (count < numrolls) { | |
roll = randomInteger(6); | |
if (roll === 6) { | |
if(first == true){ | |
output = output + "[6]"; | |
first = false; | |
numrolls = numrolls + 2; | |
} | |
else{ | |
output = output + ",[6]"; | |
numrolls = numrolls + 2; | |
} | |
} else { | |
total += roll; | |
if(first == true){ | |
output = output + roll; | |
first = false; | |
} | |
else{ | |
output = output + "," + roll; | |
} | |
} | |
count++; | |
} | |
let turnValue = 0; | |
if(plus > 0 && times == 0){ | |
sendChat(msg.who, output + " = " + total + "+" + plus + " Total: " + (total+plus) + ""); | |
turnValue = (total+plus); | |
} | |
else if(plus == 0 && times > 0){ | |
sendChat(msg.who, output + " = " + total + "*" + times + " Total: " + (total*times) + ""); | |
turnValue = (total*times); | |
} | |
else{ | |
sendChat(msg.who, output + "Total: " + (total) + ""); | |
turnValue = total; | |
} | |
_.chain(msg.selected) | |
.pluck('_id') | |
.union((ids && ids.length) ? ids.split(/\s+/) : []) | |
.map((id)=>getObj('graphic',id)) | |
.reject(_.isUndefined) | |
.each((t)=>{ | |
AddTurn(t.id,t.get('pageid'),turnValue); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment