ds4/src/module/rolls/roll-provider.ts
2021-01-04 21:21:06 +01:00

25 lines
670 B
TypeScript

/**
* Runtime-implementation of the {@link RollProvider}.
*
* @remarks
* Do not use for tests, it will inevitably fail because the `Roll` class is only provided from declarations, not as implementation!
*/
export class DS4RollProvider implements RollProvider {
getNextRoll(): number {
return new Roll("1d20").roll().total;
}
getNextRolls(amount: number): Array<number> {
return Array(amount)
.fill(0)
.map(() => this.getNextRoll());
}
}
/**
* Provides methods to fetch one or multiple rolls.
*/
export interface RollProvider {
getNextRoll(): number;
getNextRolls(amount: number): Array<number>;
}