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 {
|
import { rollCheckSingleDie, RollOptions, RollResult, RollResultStatus } from "../../src/module/rolls/roll-executor";
|
||||||
rollCheckSingleDie,
|
import { RollProvider } from "../../src/module/rolls/roll-provider";
|
||||||
RollOptions,
|
|
||||||
RollProvider,
|
|
||||||
RollResult,
|
|
||||||
RollResultStatus,
|
|
||||||
} from "../../src/module/rolls/ds4rolls";
|
|
||||||
|
|
||||||
describe("DS4 Rolls", () => {
|
describe("DS4 Rolls", () => {
|
||||||
it("Should do a proper single success role", () => {
|
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 {
|
export function ds4test(testValue: number, rollOptions: RollOptions = new RollOptions()): RollResult {
|
||||||
const finalRollValue = testValue;
|
const finalRollValue = testValue;
|
||||||
if (finalRollValue <= 20) {
|
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(
|
export function rollCheckSingleDie(
|
||||||
testValue: number,
|
testValue: number,
|
||||||
rollOptions: RollOptions,
|
rollOptions: RollOptions,
|
||||||
|
@ -33,14 +18,14 @@ export function rollCheckSingleDie(
|
||||||
const dice = [roll];
|
const dice = [roll];
|
||||||
|
|
||||||
if (roll <= rollOptions.maxCritSucc) {
|
if (roll <= rollOptions.maxCritSucc) {
|
||||||
return createRollResult(testValue, RollResultStatus.CRITICAL_SUCCESS, dice);
|
return new RollResult(testValue, RollResultStatus.CRITICAL_SUCCESS, dice);
|
||||||
} else if (roll >= rollOptions.minCritFail) {
|
} else if (roll >= rollOptions.minCritFail) {
|
||||||
return createRollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
return new RollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||||
} else {
|
} else {
|
||||||
if (roll <= testValue) {
|
if (roll <= testValue) {
|
||||||
return createRollResult(roll, RollResultStatus.SUCCESS, dice);
|
return new RollResult(roll, RollResultStatus.SUCCESS, dice);
|
||||||
} else {
|
} 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];
|
const firstResult = dice[1];
|
||||||
|
|
||||||
// TODO: Special stuff (Gnomes!)
|
if (firstResult >= rollOptions.minCritFail) {
|
||||||
if (firstResult == 20) {
|
return new RollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||||
createRollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const [otherRolls, critSuccesses] = dice
|
const [otherRolls, critSuccesses] = dice
|
||||||
|
@ -87,11 +71,7 @@ function rollCheckMultipleDice(testValue: number, rollOptions: RollOptions): Rol
|
||||||
})
|
})
|
||||||
.reduce((a, b) => a + b);
|
.reduce((a, b) => a + b);
|
||||||
|
|
||||||
return createRollResult(evaluationResult, RollResultStatus.SUCCESS, sortedRollResults);
|
return new RollResult(evaluationResult, RollResultStatus.SUCCESS, sortedRollResults);
|
||||||
}
|
|
||||||
|
|
||||||
function createRollResult(totalValue: number, rollResult: RollResultStatus, dice: Array<number>): RollResult {
|
|
||||||
return new RollResult(totalValue, RollResultStatus.SUCCESS, dice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RollOptions {
|
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