ds4/spec/support/ds4rolls.spec.ts

278 lines
10 KiB
TypeScript

import {
rollCheckMultipleDice,
rollCheckSingleDie,
RollOptions,
RollResult,
RollResultStatus,
} from "../../src/module/rolls/roll-executor";
import { RollProvider } from "../../src/module/rolls/roll-provider";
import "jasmine";
function mockSingleThrow(value: number): RollProvider {
const rollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(value);
return rollProvider;
}
function mockMultipleThrows(values: Array<number>): RollProvider {
const rollProvider = jasmine.createSpyObj("rollProvider", ["getNextRolls"]);
rollProvider.getNextRolls = jasmine.createSpy("getNextRolls").and.returnValue(values);
return rollProvider;
}
describe("DS4 Rolls with one die and no modifications.", () => {
it("Should do a regular success roll.", () => {
const rollProvider = mockSingleThrow(4);
expect(rollCheckSingleDie(12, new RollOptions(), rollProvider)).toEqual(
new RollResult(4, RollResultStatus.SUCCESS, [4]),
);
});
it("Should do a single success roll on success upper edge case.", () => {
const rollProvider = mockSingleThrow(4);
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
new RollResult(4, RollResultStatus.SUCCESS, [4]),
);
});
it("Should do a single failure roll on lower edge case.", () => {
const rollProvider = mockSingleThrow(5);
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
new RollResult(0, RollResultStatus.FAILURE, [5]),
);
});
it("Should do a single failure roll on upper edge case '19'.", () => {
const rollProvider = mockSingleThrow(19);
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
new RollResult(0, RollResultStatus.FAILURE, [19]),
);
});
it("Should do a single crit success roll on '1'.", () => {
const rollProvider = mockSingleThrow(1);
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
);
});
it("Should do a single crit failure roll on '20'.", () => {
const rollProvider = mockSingleThrow(20);
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
);
});
});
describe("DS4 Rolls with one die and slaying dice, first throw.", () => {
it("Should do a crit success on `1`", () => {
const rollProvider = mockSingleThrow(1);
expect(rollCheckSingleDie(4, { useSlayingDice: true } as RollOptions, rollProvider)).toEqual(
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
);
});
it("Should do a crit fail on `20`", () => {
const rollProvider = mockSingleThrow(20);
expect(rollCheckSingleDie(4, { useSlayingDice: true } as RollOptions, rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
);
});
});
describe("DS4 Rolls with one die and slaying dice, followup throw.", () => {
it("Should do a crit success on `1`", () => {
const rollProvider = mockSingleThrow(1);
expect(
rollCheckSingleDie(4, { useSlayingDice: true, slayingDiceRepetition: true } as RollOptions, rollProvider),
).toEqual(new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]));
});
it("Should do a regular fail on `20`", () => {
const rollProvider = mockSingleThrow(20);
expect(
rollCheckSingleDie(4, { useSlayingDice: true, slayingDiceRepetition: true } as RollOptions, rollProvider),
).toEqual(new RollResult(0, RollResultStatus.FAILURE, [20]));
});
it("Should do a regular success on `20` with a test value of 20", () => {
const rollProvider = mockSingleThrow(20);
expect(
rollCheckSingleDie(20, { useSlayingDice: true, slayingDiceRepetition: true } as RollOptions, rollProvider),
).toEqual(new RollResult(20, RollResultStatus.SUCCESS, [20]));
});
});
describe("DS4 Rolls with one die and crit roll modifications.", () => {
it("Should do a crit success on `1`.", () => {
const rollProvider = mockSingleThrow(1);
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
);
});
it("Should do a crit success on `maxCritSucc`.", () => {
const rollProvider = mockSingleThrow(2);
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [2]),
);
});
it("Should do a success on lower edge case `3`.", () => {
const rollProvider = mockSingleThrow(3);
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(3, RollResultStatus.SUCCESS, [3]),
);
});
it("Should do a success on upper edge case `18`.", () => {
const rollProvider = mockSingleThrow(18);
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(0, RollResultStatus.FAILURE, [18]),
);
});
it("Should do a crit fail on `minCritFail`.", () => {
const rollProvider = mockSingleThrow(19);
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19]),
);
});
it("Should do a crit fail on `20`", () => {
const rollProvider = mockSingleThrow(20);
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
);
});
});
describe("DS4 Rools with multiple dice and no modifiers.", () => {
it("Should do a crit fail on `20` for first roll.", () => {
const rollProvider = mockMultipleThrows([20, 15, 6]);
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20, 15, 6]),
);
});
it("Should succeed with all rolls crit successes.", () => {
const rollProvider = mockMultipleThrows([1, 1, 1]);
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
new RollResult(48, RollResultStatus.SUCCESS, [1, 1, 1]),
);
});
it("Should succeed with the last roll not being suficient.", () => {
const rollProvider = mockMultipleThrows([15, 15, 15]);
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
new RollResult(30, RollResultStatus.SUCCESS, [15, 15, 15]),
);
});
it("Should succeed with the last roll a crit success.", () => {
const rollProvider = mockMultipleThrows([15, 15, 1]);
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
new RollResult(35, RollResultStatus.SUCCESS, [1, 15, 15]),
);
});
it("Should succeed with the last roll being 20 and one crit success.", () => {
const rollProvider = mockMultipleThrows([15, 1, 20]);
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
new RollResult(40, RollResultStatus.SUCCESS, [1, 20, 15]),
);
});
});
describe("DS4 Rools with multiple dice and min/max modifiers.", () => {
it("Should do a crit fail on `19` for first roll.", () => {
const rollProvider = mockMultipleThrows([19, 15, 6]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19, 15, 6]),
);
});
it("Should succeed with all rolls crit successes (1 and 2).", () => {
const rollProvider = mockMultipleThrows([2, 1, 2]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(48, RollResultStatus.SUCCESS, [2, 2, 1]),
);
});
it("Should succeed with the last roll not being suficient.", () => {
const rollProvider = mockMultipleThrows([15, 15, 15]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(30, RollResultStatus.SUCCESS, [15, 15, 15]),
);
});
it("Should succeed with the last roll a crit success `2`.", () => {
const rollProvider = mockMultipleThrows([15, 15, 2]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(35, RollResultStatus.SUCCESS, [2, 15, 15]),
);
});
it("Should succeed with the last roll being `20` and one crit success '2'.", () => {
const rollProvider = mockMultipleThrows([15, 2, 20]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(40, RollResultStatus.SUCCESS, [2, 20, 15]),
);
});
it("Should succeed with the last roll being `19` and one crit success '2'.", () => {
const rollProvider = mockMultipleThrows([15, 2, 19]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(39, RollResultStatus.SUCCESS, [2, 19, 15]),
);
});
});
describe("DS4 Rools with multiple dice and fail modifiers.", () => {
it("Should do a crit fail on `19` for first roll.", () => {
const rollProvider = mockMultipleThrows([19, 15, 6]);
expect(rollCheckMultipleDice(48, { minCritFail: 19 } as RollOptions, rollProvider)).toEqual(
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19, 15, 6]),
);
});
});
describe("DS4 Rools with multiple dice and success modifiers.", () => {
it("Should succeed with all rolls crit successes (1 and 2).", () => {
const rollProvider = mockMultipleThrows([2, 1, 2]);
expect(rollCheckMultipleDice(48, { maxCritSucc: 2 } as RollOptions, rollProvider)).toEqual(
new RollResult(48, RollResultStatus.SUCCESS, [2, 2, 1]),
);
});
});