mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Compute modifiers using deterministic terms
This commit is contained in:
parent
714d4edc16
commit
186a01eec3
3 changed files with 16 additions and 22 deletions
|
|
@ -217,7 +217,7 @@ export default class D20Roll extends DHRoll {
|
||||||
results: d.results
|
results: d.results
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
data.modifierTotal = this.calculateTotalModifiers(roll);
|
data.modifierTotal = roll.modifierTotal;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ export default class DHRoll extends Roll {
|
||||||
return game.i18n.localize('DAGGERHEART.GENERAL.Roll.basic');
|
return game.i18n.localize('DAGGERHEART.GENERAL.Roll.basic');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get modifierTotal() {
|
||||||
|
return this.constructor.calculateTotalModifiers(this);
|
||||||
|
}
|
||||||
|
|
||||||
static messageType = 'adversaryRoll';
|
static messageType = 'adversaryRoll';
|
||||||
|
|
||||||
static CHAT_TEMPLATE = 'systems/daggerheart/templates/ui/chat/roll.hbs';
|
static CHAT_TEMPLATE = 'systems/daggerheart/templates/ui/chat/roll.hbs';
|
||||||
|
|
@ -242,16 +246,21 @@ export default class DHRoll extends Roll {
|
||||||
return (this._formula = this.constructor.getFormula(this.terms));
|
return (this._formula = this.constructor.getFormula(this.terms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate total modifiers of any rolls, including non-dh rolls.
|
||||||
|
* This exists because damage rolls still may receive base roll classes
|
||||||
|
*/
|
||||||
static calculateTotalModifiers(roll) {
|
static calculateTotalModifiers(roll) {
|
||||||
let modifierTotal = 0;
|
let modifierTotal = 0;
|
||||||
for (let i = 0; i < roll.terms.length; i++) {
|
for (let i = 0; i < roll.terms.length; i++) {
|
||||||
if (
|
if (!roll.terms[i].isDeterministic) continue;
|
||||||
roll.terms[i] instanceof foundry.dice.terms.NumericTerm &&
|
const termTotal = roll.terms[i].total;
|
||||||
!!roll.terms[i - 1] &&
|
if (typeof termTotal === 'number') {
|
||||||
roll.terms[i - 1] instanceof foundry.dice.terms.OperatorTerm
|
const multiplier = roll.terms[i - 1]?.operator === " - " ? -1 : 1;
|
||||||
)
|
modifierTotal += multiplier * termTotal;
|
||||||
modifierTotal += Number(`${roll.terms[i - 1].operator}${roll.terms[i].total}`);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return modifierTotal;
|
return modifierTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,21 +72,6 @@ export default class DualityRoll extends D20Roll {
|
||||||
return this.dice.filter(x => ![DualityDie, AdvantageDie, DisadvantageDie].some(die => x instanceof die));
|
return this.dice.filter(x => ![DualityDie, AdvantageDie, DisadvantageDie].some(die => x instanceof die));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This isn't fullproof, but trying to cover parathetical situations is ridiculously complex */
|
|
||||||
get modifierTotal() {
|
|
||||||
let modifierTotal = 0;
|
|
||||||
for (let i = 0; i < this.terms.length; i++) {
|
|
||||||
if (
|
|
||||||
this.terms[i] instanceof foundry.dice.terms.NumericTerm &&
|
|
||||||
!!this.terms[i - 1] &&
|
|
||||||
this.terms[i - 1] instanceof foundry.dice.terms.OperatorTerm
|
|
||||||
)
|
|
||||||
modifierTotal += Number(`${this.terms[i - 1].operator}${this.terms[i].total}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return modifierTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
setRallyChoices() {
|
setRallyChoices() {
|
||||||
return this.data?.parent?.appliedEffects.reduce((a, c) => {
|
return this.data?.parent?.appliedEffects.reduce((a, c) => {
|
||||||
const change = c.system.changes.find(ch => ch.key === 'system.bonuses.rally');
|
const change = c.system.changes.find(ch => ch.key === 'system.bonuses.rally');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue