3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 04:32:37 +01:00

Merge pull request #21 from psquid/master

Modifier syntax fix
This commit is contained in:
Luke Slater 2012-03-07 15:22:54 -08:00
commit 6444494293

View File

@ -54,9 +54,9 @@ var dice = function(dbot) {
if (diceSpec === false) { if (diceSpec === false) {
rolls.push([params[i], false]); rolls.push([params[i], false]);
} else { } else {
rolls.push([normalizeDiceSpec(params[i]), []]); rolls.push([normalizeDiceSpec(params[i]), [], diceSpec["modifier"]]);
for (var j = 0; j < diceSpec["count"] ; j++) { for (var j = 0; j < diceSpec["count"] ; j++) {
rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"]) + diceSpec["modifier"]); rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"]));
} }
} }
} }
@ -66,7 +66,16 @@ var dice = function(dbot) {
dbot.say(data.channel, rolls[i][0] + ": invalid dice spec"); dbot.say(data.channel, rolls[i][0] + ": invalid dice spec");
} else { } else {
if (rolls[i][1].length > 1) { if (rolls[i][1].length > 1) {
var total = " (total " + rolls[i][1].sum() + ")"; var total = " (total " + rolls[i][1].sum();
if (rolls[i][2] != 0) {
if (rolls[i][2] > 0) {
total += " + ";
} else {
total += " - ";
}
total += Math.abs(rolls[i][2]) + " -> " + (rolls[i][1].sum() + rolls[i][2]);
}
total += ")"
} else { } else {
var total = ""; var total = "";
} }