Skip to content

Commit

Permalink
Display the dice rolled and their results
Browse files Browse the repository at this point in the history
  • Loading branch information
manveti committed Apr 9, 2015
1 parent 0c5bbc8 commit b774fb7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions DiceInTheVineyard/ditv.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ var DitV = DitV || {
rollCounts[roll - 1] = (rollCounts[roll - 1] || 0) + 1;
}
}
return DitV.addChips(name, rollCounts);
var error = DitV.addChips(name, rollCounts);
return error || rollCounts;
},

countChips: function(name){
Expand Down Expand Up @@ -219,7 +220,22 @@ var DitV = DitV || {
error = "The 'roll' command requires two argumenst: character name and dice specification";
break;
}
error = DitV.rollChips(tokens[2], tokens.slice(3).join(" "));
var rollSpec = tokens.slice(3).join(" ");
var rollCounts = DitV.rollChips(tokens[2], rollSpec);
if (typeof(rollCounts) == typeof("")){
error = rollCounts;
}
else{
var rollMsg = tokens[2] + " rolling " + rollSpec.replace(/ /g, "+") + ":";
var joinStr = " ";
for (var i = 0; i <rollCounts.length; i++){
for (var j = 0; j < rollCounts[i]; j++){
rollMsg += joinStr + (i + 1);
joinStr = ", ";
}
}
DitV.write(rollMsg, "", "", msg.who);
}
break;
case "count":
if (tokens.length <= 2){
Expand Down

0 comments on commit b774fb7

Please sign in to comment.