ds4/src/dice/slaying-dice-modifier.js
Johannes Loher 7670d7f808
All checks were successful
ci/woodpecker/pr/checks Pipeline was successful
ci/woodpecker/push/checks Pipeline was successful
chore: reformat with 2 spaces
2023-07-10 22:33:01 +02:00

36 lines
1.1 KiB
JavaScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
// SPDX-FileCopyrightText: 2021 Oliver Rümpelein
//
// SPDX-License-Identifier: MIT
import { getGame } from "../utils/utils";
import { DS4Check } from "./check";
export function registerSlayingDiceModifier() {
PoolTerm.MODIFIERS.x = slay;
}
/**
* @this {PoolTerm}
* @param {string} modifier
*/
function slay(modifier) {
const rgx = /[xX]/;
const match = modifier.match(rgx);
if (!match || !this.rolls) return;
let checked = 0;
while (checked < (this.dice.length ?? 0)) {
const diceTerm = this.dice[checked];
checked++;
if (diceTerm instanceof DS4Check && diceTerm.coup) {
const formula = `dsv${diceTerm.checkTargetNumber}c${diceTerm.maximumCoupResult}:${diceTerm.minimumFumbleResult}n`;
const additionalRoll = Roll.create(formula).evaluate({ async: false });
this.rolls.push(additionalRoll);
this.results.push({ result: additionalRoll.total ?? 0, active: true });
this.terms.push(formula);
}
if (checked > 1000) throw new Error(getGame().i18n.localize("DS4.ErrorSlayingDiceRecursionLimitExceeded"));
}
}