mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 11:41:08 +01:00
Add support for changing the tier of an adversary
This commit is contained in:
parent
bca7e0d3c9
commit
ea9edf6f98
3 changed files with 474 additions and 0 deletions
|
|
@ -474,3 +474,38 @@ export async function getCritDamageBonus(formula) {
|
|||
const critRoll = new Roll(formula);
|
||||
return critRoll.dice.reduce((acc, dice) => acc + dice.faces * dice.number, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a simple flavor-less formula with only +/- operators, returns a list of damage partial terms.
|
||||
* All subtracted terms become negative terms.
|
||||
*/
|
||||
export function parseTermsFromSimpleFormula(formula) {
|
||||
const roll = formula instanceof Roll ? formula : new Roll(formula);
|
||||
|
||||
// Parse from right to left so that when we hit an operator, we already have the term.
|
||||
return roll.terms.reduceRight(
|
||||
(result, term) => {
|
||||
// Ignore + terms, we assume + by default
|
||||
if (term.expression === " + ") return result;
|
||||
|
||||
// - terms modify the last term we parsed
|
||||
if (term.expression === " - ") {
|
||||
const termToModify = result[0];
|
||||
if (termToModify) {
|
||||
if (termToModify.modifier) termToModify.modifier *= -1;
|
||||
if (termToModify.dice) termToModify.dice *= -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
result.unshift({
|
||||
modifier: term instanceof foundry.dice.terms.NumericTerm ? term.number : 0,
|
||||
dice: term instanceof foundry.dice.terms.Die ? term.number : 0,
|
||||
faces: term.faces ?? null,
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue