Ruhu, Cleanups!
This commit is contained in:
parent
1c0ca4ff47
commit
8d274ed830
3 changed files with 27 additions and 36 deletions
|
@ -1,10 +1,5 @@
|
|||
import {
|
||||
rollCheckSingleDie,
|
||||
RollOptions,
|
||||
RollProvider,
|
||||
RollResult,
|
||||
RollResultStatus,
|
||||
} from "../../src/module/rolls/ds4rolls";
|
||||
import { rollCheckSingleDie, RollOptions, RollResult, RollResultStatus } from "../../src/module/rolls/roll-executor";
|
||||
import { RollProvider } from "../../src/module/rolls/roll-provider";
|
||||
|
||||
describe("DS4 Rolls", () => {
|
||||
it("Should do a proper single success role", () => {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { DS4RollProvider, RollProvider } from "./roll-provider";
|
||||
|
||||
export function ds4test(testValue: number, rollOptions: RollOptions = new RollOptions()): RollResult {
|
||||
const finalRollValue = testValue;
|
||||
if (finalRollValue <= 20) {
|
||||
|
@ -7,23 +9,6 @@ export function ds4test(testValue: number, rollOptions: RollOptions = new RollOp
|
|||
}
|
||||
}
|
||||
|
||||
export class DS4RollProvider {
|
||||
getNextRoll(): number {
|
||||
return new Roll("1d20").roll().total;
|
||||
}
|
||||
|
||||
getNextRolls(amount: number): Array<number> {
|
||||
return Array(amount)
|
||||
.fill(0)
|
||||
.map(() => this.getNextRoll());
|
||||
}
|
||||
}
|
||||
|
||||
export interface RollProvider {
|
||||
getNextRoll(): number;
|
||||
getNextRolls(number): Array<number>;
|
||||
}
|
||||
|
||||
export function rollCheckSingleDie(
|
||||
testValue: number,
|
||||
rollOptions: RollOptions,
|
||||
|
@ -33,14 +18,14 @@ export function rollCheckSingleDie(
|
|||
const dice = [roll];
|
||||
|
||||
if (roll <= rollOptions.maxCritSucc) {
|
||||
return createRollResult(testValue, RollResultStatus.CRITICAL_SUCCESS, dice);
|
||||
return new RollResult(testValue, RollResultStatus.CRITICAL_SUCCESS, dice);
|
||||
} else if (roll >= rollOptions.minCritFail) {
|
||||
return createRollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||
return new RollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||
} else {
|
||||
if (roll <= testValue) {
|
||||
return createRollResult(roll, RollResultStatus.SUCCESS, dice);
|
||||
return new RollResult(roll, RollResultStatus.SUCCESS, dice);
|
||||
} else {
|
||||
return createRollResult(0, RollResultStatus.FAILURE, dice);
|
||||
return new RollResult(0, RollResultStatus.FAILURE, dice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,9 +43,8 @@ function rollCheckMultipleDice(testValue: number, rollOptions: RollOptions): Rol
|
|||
|
||||
const firstResult = dice[1];
|
||||
|
||||
// TODO: Special stuff (Gnomes!)
|
||||
if (firstResult == 20) {
|
||||
createRollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||
if (firstResult >= rollOptions.minCritFail) {
|
||||
return new RollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||
}
|
||||
|
||||
const [otherRolls, critSuccesses] = dice
|
||||
|
@ -87,11 +71,7 @@ function rollCheckMultipleDice(testValue: number, rollOptions: RollOptions): Rol
|
|||
})
|
||||
.reduce((a, b) => a + b);
|
||||
|
||||
return createRollResult(evaluationResult, RollResultStatus.SUCCESS, sortedRollResults);
|
||||
}
|
||||
|
||||
function createRollResult(totalValue: number, rollResult: RollResultStatus, dice: Array<number>): RollResult {
|
||||
return new RollResult(totalValue, RollResultStatus.SUCCESS, dice);
|
||||
return new RollResult(evaluationResult, RollResultStatus.SUCCESS, sortedRollResults);
|
||||
}
|
||||
|
||||
export class RollOptions {
|
16
src/module/rolls/roll-provider.ts
Normal file
16
src/module/rolls/roll-provider.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
export class DS4RollProvider {
|
||||
getNextRoll(): number {
|
||||
return new Roll("1d20").roll().total;
|
||||
}
|
||||
|
||||
getNextRolls(amount: number): Array<number> {
|
||||
return Array(amount)
|
||||
.fill(0)
|
||||
.map(() => this.getNextRoll());
|
||||
}
|
||||
}
|
||||
|
||||
export interface RollProvider {
|
||||
getNextRoll(): number;
|
||||
getNextRolls(number): Array<number>;
|
||||
}
|
Loading…
Reference in a new issue