Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/diceRoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,13 @@ export class DiceRoller {
let explodeCount = 0;

while (targetMethod(roll) && explodeCount++ < 1000) {
const newRoll = this.reRoll(rolls[i], ++i);
const newRoll = this.reRoll(roll,i+1);
rollValue += newRoll.roll;
roll = newRoll;
}

roll.value = rollValue;
roll.roll = rollValue;
rolls[i].value = rollValue;
rolls[i].roll = rollValue;
}

return rolls;
Expand Down
24 changes: 24 additions & 0 deletions test/rollerTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,28 @@ testRolls.forEach(([roll, expectedValue]) => {
test(roll, () => {
expect(roller.rollValue(roll)).toBe(expectedValue)
});
});

const testFixedRolls: [string, number, number[]][] = [
['1d6!!', 14, [.84, .84, .17]], // value = [6,6,2]
['4d6!!', 24, [.84, .67, .5, .17, .84, 0]] // value = [6,5,4,2,6,1]
]

let externalCount: number = 0
let rollsAsFloats: Array<number> = []
const fixedRoller = new dist.DiceRoller((rolls: Array<number> = rollsAsFloats)=>{
if(rolls.length > 0) {
return rolls[externalCount++]
} else {
console.warn("No results passed to the dice-roller-parser. Using fallback Math.random")
return Math.random()
}
})

testFixedRolls.forEach(([roll, expectedValue, values]) => {
test(roll, () => {
externalCount = 0
rollsAsFloats = values
expect(fixedRoller.rollValue(roll)).toBe(expectedValue)
});
});