Browse Source

Calculate the actual Universalis' complication rules

Group dice in "white" and "red" and show successes for each group,
and the winner group.
universalis
parent
commit
64ac4710e8
2 changed files with 22 additions and 11 deletions
  1. +2
    -2
      dice/dice.js
  2. +20
    -9
      dice/main.js

+ 2
- 2
dice/dice.js View File

@@ -649,11 +649,11 @@
this.pane.position.set(0, 0, 1);
this.scene.add(this.pane);

var die1 = createDie('d10', '#202020', '#aaaaaa');
var die1 = createDie('d10', '#202020', '#aaaaaa', {group: 'white'});
die1.position.set(step * -2, 0, step * 0.5);
this.dice.push(die1); this.scene.add(die1);

var die2 = createDie('d10', '#aaaaaa', '#880000');
var die2 = createDie('d10', '#aaaaaa', '#880000', {group: 'red'});
die2.position.set(step * 2, 0, step * 0.5);
this.dice.push(die2); this.scene.add(die2);



+ 20
- 9
dice/main.js View File

@@ -43,16 +43,27 @@ function diceInitialize(container, w, h) {
selectorDiv.style.display = 'none';
}

function afterRoll(notation, result) {
var res = result.join(' ');
if (notation.constant) {
res += ' +' + notation.constant;
}
if (result.length > 1) {
res += ' = ' +
(result.reduce(function(s, a) { return s + a; }) + notation.constant);
function afterRoll(dieSpec, results) {
var groups = {}, topScore = 0, topGroup = null;
for (var i = 0, len = dieSpec.set.length; i < len; i++) {
var currentGroup = dieSpec.set[i].group;
groups[currentGroup] = groups[currentGroup] || 0;
if ((results[i] || 10) < 6) {
groups[currentGroup]++;
if (groups[currentGroup] === topScore) {
topGroup = null;
} else if (groups[currentGroup] > topScore) {
topGroup = currentGroup;
topScore = groups[currentGroup];
}
}
}
label.innerHTML = res;

var resultString = Object.keys(groups).map(function(group) {
return group + ": " + groups[group];
}).join("; ");
resultString += "<br/>Winner: " + (topGroup ? topGroup.toUpperCase() : "<i>none</i>");
label.innerHTML = resultString;
infoDiv.style.display = 'inline-block';
}



Loading…
Cancel
Save