Skip to content

Commit

Permalink
fix: fixes issue with calculating Fate results
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Oct 15, 2023
1 parent 1f37579 commit 7388384
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/roller/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export class DiceRoller {
.replace(/[\[\]\s]/g, "")
.split(",")
.map((v) => Number(v));
} else if (maxStr === "F") {
this.possibilities = [-1, 0, 1];
this.fudge = true;
} else {
if (maxStr === "%") {
max = 100;
} else if (maxStr === "F") {
this.possibilities = [-1, 0, 1];
this.fudge = true;
} else {
max = Number(maxStr);
}
Expand Down Expand Up @@ -337,7 +337,8 @@ export class DiceRoller {
);
}
canRender() {
if (this.possibilities.length !== this.faces.max) return false;
if (this.possibilities.length !== this.faces.max && !this.fudge)
return false;
const arr = [...Array(this.faces.max).keys()].map(
(k) => this.faces.min + k
);
Expand All @@ -353,10 +354,7 @@ export class DiceRoller {
}
}
getValueSync() {
return (
this.multiplier *
this.getRandomBetween(this.faces.min, this.faces.max)
);
return this.multiplier * this.getRandomValue();
}
#resolveShapeValue(shapes: DiceShape[] = []) {
if (!shapes.length) return this.getValueSync();
Expand Down Expand Up @@ -606,7 +604,7 @@ export class DiceRoller {
this.possibilities.length
);
}
getRandomBetween(min: number, max: number): number {
getRandomValue(): number {
const index = Math.floor(Math.random() * this.possibilities.length);
return this.possibilities[index];
}
Expand Down

0 comments on commit 7388384

Please sign in to comment.