2021-01-02 16:12:16 +01:00
|
|
|
import { rollCheckMultipleDice, rollCheckSingleDie } from "../../../src/module/rolls/roll-executor";
|
2020-12-30 21:27:41 +01:00
|
|
|
|
2020-12-31 02:29:27 +01:00
|
|
|
import "jasmine";
|
2021-01-02 16:12:16 +01:00
|
|
|
import { RollResult, RollResultStatus } from "../../../src/module/rolls/roll-data";
|
2020-12-31 02:29:27 +01:00
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
describe("DS4 Rolls with one die and no modifications.", () => {
|
|
|
|
it("Should do a regular success roll.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(12, {}, [4])).toEqual(new RollResult(4, RollResultStatus.SUCCESS, [4], true));
|
2020-12-30 21:27:41 +01:00
|
|
|
});
|
2020-12-30 22:19:36 +01:00
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single success roll on success upper edge case.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, {}, [4])).toEqual(new RollResult(4, RollResultStatus.SUCCESS, [4], true));
|
2020-12-30 22:19:36 +01:00
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single failure roll on lower edge case.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, {}, [5])).toEqual(new RollResult(0, RollResultStatus.FAILURE, [5], true));
|
2020-12-30 22:19:36 +01:00
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single failure roll on upper edge case '19'.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, {}, [19])).toEqual(new RollResult(0, RollResultStatus.FAILURE, [19]));
|
2020-12-30 22:19:36 +01:00
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single crit success roll on '1'.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, {}, [1])).toEqual(new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1], true));
|
2020-12-30 22:19:36 +01:00
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single crit failure roll on '20'.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, {}, [20])).toEqual(new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]));
|
2020-12-30 22:19:36 +01:00
|
|
|
});
|
2020-12-30 23:58:01 +01:00
|
|
|
});
|
2020-12-30 23:03:08 +01:00
|
|
|
|
2021-01-02 13:16:08 +01:00
|
|
|
describe("DS4 Rolls with one die and slaying dice, first throw.", () => {
|
|
|
|
it("Should do a crit success on `1`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { useSlayingDice: true }, [1])).toEqual(
|
2021-01-02 13:16:08 +01:00
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should do a crit fail on `20`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { useSlayingDice: true }, [20])).toEqual(
|
2021-01-02 13:16:08 +01:00
|
|
|
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`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { useSlayingDice: true, slayingDiceRepetition: true }, [1])).toEqual(
|
2021-01-02 16:12:16 +01:00
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
|
|
|
|
);
|
2021-01-02 13:16:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should do a regular fail on `20`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { useSlayingDice: true, slayingDiceRepetition: true }, [20])).toEqual(
|
2021-01-02 16:12:16 +01:00
|
|
|
new RollResult(0, RollResultStatus.FAILURE, [20]),
|
|
|
|
);
|
2021-01-02 13:16:08 +01:00
|
|
|
});
|
|
|
|
|
2021-01-04 19:38:26 +01:00
|
|
|
it("Should do a regular success on `20` with a CTN of 20", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(20, { useSlayingDice: true, slayingDiceRepetition: true }, [20])).toEqual(
|
2021-01-02 16:12:16 +01:00
|
|
|
new RollResult(20, RollResultStatus.SUCCESS, [20]),
|
|
|
|
);
|
2021-01-02 13:16:08 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
describe("DS4 Rolls with one die and crit roll modifications.", () => {
|
|
|
|
it("Should do a crit success on `1`.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, [1])).toEqual(
|
2020-12-30 23:03:08 +01:00
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a crit success on `maxCritSucc`.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, [2])).toEqual(
|
2020-12-30 23:03:08 +01:00
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [2]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a success on lower edge case `3`.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, [3])).toEqual(
|
2020-12-30 23:03:08 +01:00
|
|
|
new RollResult(3, RollResultStatus.SUCCESS, [3]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a success on upper edge case `18`.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, [18])).toEqual(
|
2020-12-30 23:03:08 +01:00
|
|
|
new RollResult(0, RollResultStatus.FAILURE, [18]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a crit fail on `minCritFail`.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, [19])).toEqual(
|
2020-12-30 23:03:08 +01:00
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a crit fail on `20`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, [20])).toEqual(
|
2020-12-30 23:03:08 +01:00
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
|
|
|
|
);
|
|
|
|
});
|
2020-12-30 21:27:41 +01:00
|
|
|
});
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2021-01-02 16:12:16 +01:00
|
|
|
describe("DS4 Rolls with multiple dice and no modifiers.", () => {
|
2020-12-31 00:47:31 +01:00
|
|
|
it("Should do a crit fail on `20` for first roll.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, {}, [20, 15, 6])).toEqual(
|
2020-12-31 00:47:31 +01:00
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20, 15, 6]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-02 13:54:59 +01:00
|
|
|
it("Should succeed normally with all rolls crit successes.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, {}, [1, 1, 1])).toEqual(
|
2020-12-31 00:47:31 +01:00
|
|
|
new RollResult(48, RollResultStatus.SUCCESS, [1, 1, 1]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll not being suficient.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, {}, [15, 15, 15])).toEqual(
|
2020-12-31 00:47:31 +01:00
|
|
|
new RollResult(30, RollResultStatus.SUCCESS, [15, 15, 15]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll a crit success.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, {}, [15, 15, 1])).toEqual(
|
2021-01-02 16:12:16 +01:00
|
|
|
new RollResult(38, RollResultStatus.SUCCESS, [15, 15, 1]),
|
2020-12-31 00:47:31 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll being 20 and one crit success.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, {}, [15, 1, 20])).toEqual(
|
|
|
|
new RollResult(43, RollResultStatus.SUCCESS, [15, 1, 20]),
|
2020-12-31 00:47:31 +01:00
|
|
|
);
|
|
|
|
});
|
2021-01-02 13:55:18 +01:00
|
|
|
|
|
|
|
it("Should properly maximize throw result with all dice success.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(46, {}, [15, 4, 12])).toEqual(
|
|
|
|
new RollResult(31, RollResultStatus.SUCCESS, [15, 4, 12]),
|
2021-01-02 13:55:18 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should properly maximize throw result with one dice a failure.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(46, {}, [15, 8, 20])).toEqual(
|
|
|
|
new RollResult(35, RollResultStatus.SUCCESS, [15, 8, 20]),
|
2021-01-02 13:55:18 +01:00
|
|
|
);
|
|
|
|
});
|
2021-01-02 16:12:16 +01:00
|
|
|
|
2021-01-04 19:38:26 +01:00
|
|
|
it("Should maximize on 'lowest dice higher than last CTN and crit success thrown'-Edge case, no change required.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(46, {}, [15, 1, 8])).toEqual(
|
|
|
|
new RollResult(35, RollResultStatus.SUCCESS, [15, 1, 8]),
|
2021-01-02 16:12:16 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-04 19:38:26 +01:00
|
|
|
it("Should maximize on 2-dice 'lowest dice higher than last CTN and crit success thrown'-Edge case, no change required.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(24, {}, [1, 8])).toEqual(new RollResult(20, RollResultStatus.SUCCESS, [1, 8]));
|
2021-01-02 16:12:16 +01:00
|
|
|
});
|
|
|
|
|
2021-01-04 19:38:26 +01:00
|
|
|
it("Should maximize on 2-dice 'lowest dice higher than last CTN and crit success thrown'-Edge case, change required.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(38, {}, [1, 19])).toEqual(new RollResult(37, RollResultStatus.SUCCESS, [1, 19]));
|
2021-01-02 16:12:16 +01:00
|
|
|
});
|
2021-01-03 15:08:38 +01:00
|
|
|
|
|
|
|
it("Should maximize correctly when swapping with more than one crit success", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, {}, [1, 1, 15])).toEqual(
|
|
|
|
new RollResult(43, RollResultStatus.SUCCESS, [1, 1, 15]),
|
2021-01-03 15:08:38 +01:00
|
|
|
);
|
|
|
|
});
|
2020-12-31 00:47:31 +01:00
|
|
|
});
|
2020-12-31 00:52:59 +01:00
|
|
|
|
2021-01-02 16:12:16 +01:00
|
|
|
describe("DS4 Rolls with multiple dice and min/max modifiers.", () => {
|
2020-12-31 00:52:59 +01:00
|
|
|
it("Should do a crit fail on `19` for first roll.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 }, [19, 15, 6])).toEqual(
|
2020-12-31 00:52:59 +01:00
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19, 15, 6]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with all rolls crit successes (1 and 2).", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 }, [2, 1, 2])).toEqual(
|
|
|
|
new RollResult(48, RollResultStatus.SUCCESS, [2, 1, 2]),
|
2020-12-31 00:52:59 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:49:21 +01:00
|
|
|
it("Should succeed with the last roll not being sufficient.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 }, [15, 15, 15])).toEqual(
|
2020-12-31 00:52:59 +01:00
|
|
|
new RollResult(30, RollResultStatus.SUCCESS, [15, 15, 15]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll a crit success `2`.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 }, [15, 15, 2])).toEqual(
|
2021-01-02 16:12:16 +01:00
|
|
|
new RollResult(38, RollResultStatus.SUCCESS, [15, 15, 2]),
|
2020-12-31 00:52:59 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll being `20` and one crit success '2'.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 }, [15, 2, 20])).toEqual(
|
|
|
|
new RollResult(43, RollResultStatus.SUCCESS, [15, 2, 20]),
|
2020-12-31 00:52:59 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll being `19` and one crit success '2'.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2, minCritFail: 19 }, [15, 2, 19])).toEqual(
|
|
|
|
new RollResult(42, RollResultStatus.SUCCESS, [15, 2, 19]),
|
2020-12-31 00:52:59 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-12-31 02:27:21 +01:00
|
|
|
|
2021-01-02 16:12:16 +01:00
|
|
|
describe("DS4 Rolls with multiple dice and fail modifiers.", () => {
|
2020-12-31 02:27:21 +01:00
|
|
|
it("Should do a crit fail on `19` for first roll.", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { minCritFail: 19 }, [19, 15, 6])).toEqual(
|
2020-12-31 02:27:21 +01:00
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19, 15, 6]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-02 16:12:16 +01:00
|
|
|
describe("DS4 Rolls with multiple dice and success modifiers.", () => {
|
2020-12-31 02:27:21 +01:00
|
|
|
it("Should succeed with all rolls crit successes (1 and 2).", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { maxCritSucc: 2 }, [2, 1, 2])).toEqual(
|
|
|
|
new RollResult(48, RollResultStatus.SUCCESS, [2, 1, 2]),
|
2020-12-31 02:27:21 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-01-02 16:12:16 +01:00
|
|
|
|
|
|
|
describe("DS4 Rolls with multiple and slaying dice, first throw", () => {
|
|
|
|
it("Should fail with the first roll being a `20`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { useSlayingDice: true }, [20, 2, 19])).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20, 2, 19], true),
|
2021-01-02 16:12:16 +01:00
|
|
|
);
|
|
|
|
});
|
2021-01-03 15:08:38 +01:00
|
|
|
|
|
|
|
it("Should issue a critical success, even with resorting dice", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { useSlayingDice: true, maxCritSucc: 2 }, [2, 19, 15])).toEqual(
|
|
|
|
new RollResult(42, RollResultStatus.CRITICAL_SUCCESS, [2, 19, 15]),
|
2021-01-03 15:08:38 +01:00
|
|
|
);
|
|
|
|
});
|
2021-01-02 16:12:16 +01:00
|
|
|
});
|
|
|
|
|
2021-01-02 16:40:30 +01:00
|
|
|
describe("DS4 Rolls with multiple and slaying dice, recurrent throw", () => {
|
2021-01-02 16:12:16 +01:00
|
|
|
it("Should regularly succeed with the first roll being a `20`", () => {
|
2021-01-06 18:27:22 +01:00
|
|
|
expect(rollCheckMultipleDice(48, { useSlayingDice: true, slayingDiceRepetition: true }, [20, 2, 19])).toEqual(
|
|
|
|
new RollResult(41, RollResultStatus.SUCCESS, [20, 2, 19]),
|
2021-01-02 16:12:16 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|