This commit is contained in:
WBHarry 2026-01-07 11:31:58 +01:00
parent 9564edb244
commit 80595f4e79
12 changed files with 182 additions and 25 deletions

View file

@ -136,6 +136,13 @@ export default class D20Roll extends DHRoll {
return modifiers;
}
bonusEffectBuilder(config) {
const changeKeys = [`roll.${this.options.actionType}`, `roll.${this.options.roll.type}`];
config.bonusEffects = foundry.utils.deepClone(
config.effects.filter(x => x.changes.some(x => changeKeys.includes(x.key)))
);
}
static postEvaluate(roll, config = {}) {
const data = super.postEvaluate(roll, config);
data.type = config.actionType;

View file

@ -93,7 +93,6 @@ export default class DamageRoll extends DHRoll {
type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage'),
options = part ?? this.options;
modifiers.push(...this.getBonus(`${type}`, `${type.capitalize()} Bonus`));
if (!this.options.hasHealing) {
options.damageTypes?.forEach(t => {
modifiers.push(...this.getBonus(`${type}.${t}`, `${t.capitalize()} ${type.capitalize()} Bonus`));
@ -108,6 +107,25 @@ export default class DamageRoll extends DHRoll {
return modifiers;
}
bonusEffectBuilder() {
const type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage');
return this.options.effects.reduce((acc, effect) => {
if (effect.changes.some(x => x.key.includes(`system.bonuses.${type}`))) {
acc[effect.id] = {
id: effect.id,
name: effect.name,
description: effect.description,
changes: effect.changes,
origEffect: effect,
selected: !effect.disabled
};
}
return acc;
}, {});
}
constructFormula(config) {
this.options.roll.forEach((part, index) => {
part.roll = new Roll(Roll.replaceFormulaData(part.formula, config.data));

View file

@ -1,9 +1,11 @@
import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs';
import { BonusFields } from '../data/actor/character.mjs';
export default class DHRoll extends Roll {
baseTerms = [];
constructor(formula, data = {}, options = {}) {
super(formula, data, options);
options.bonusEffects = this.bonusEffectBuilder();
if (!this.data || !Object.keys(this.data).length) this.data = options.data;
}
@ -164,12 +166,18 @@ export default class DHRoll extends Roll {
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
...this.constructor.parse(modifier.join(' + '), this.options.data)
];
} else {
} else if (Number.isNumeric(modifier)) {
const numTerm = modifier < 0 ? '-' : '+';
return [
new foundry.dice.terms.OperatorTerm({ operator: numTerm }),
new foundry.dice.terms.NumericTerm({ number: Math.abs(modifier) })
];
} else {
const numTerm = modifier < 0 ? '-' : '+';
return [
new foundry.dice.terms.OperatorTerm({ operator: numTerm }),
...this.constructor.parse(modifier, this.options.data)
];
}
}
@ -185,18 +193,22 @@ export default class DHRoll extends Roll {
}
getBonus(path, label) {
const bonus = foundry.utils.getProperty(this.data.bonuses, path),
modifiers = [];
if (bonus?.bonus)
modifiers.push({
label: label,
value: bonus?.bonus
});
if (bonus?.dice?.length)
modifiers.push({
label: label,
value: bonus?.dice
});
const modifiers = [];
for (const effect of Object.values(this.options.bonusEffects)) {
if (effect.selected) {
for (const change of effect.changes) {
if (change.key.includes(path)) {
const changeValue = game.system.api.documents.DhActiveEffect.getChangeValue(
this.data,
change,
effect.origEffect
);
modifiers.push({ label: label, value: changeValue });
}
}
}
}
return modifiers;
}
@ -235,4 +247,8 @@ export default class DHRoll extends Roll {
static temporaryModifierBuilder(config) {
return {};
}
bonusEffectBuilder() {
return [];
}
}

View file

@ -173,6 +173,23 @@ export default class DualityRoll extends D20Roll {
return modifiers;
}
bonusEffectBuilder() {
return this.options.effects.reduce((acc, effect) => {
if (effect.changes.some(x => x.key.includes(`system.bonuses.roll`))) {
acc[effect.id] = {
id: effect.id,
name: effect.name,
description: effect.description,
changes: effect.changes,
origEffect: effect,
selected: !effect.disabled
};
}
return acc;
}, {});
}
static async buildEvaluate(roll, config = {}, message = {}) {
await super.buildEvaluate(roll, config, message);