219-fix weapon action damage and display of calculation. (#250)

* fix weapon action damage and display of calculation.

* modify weapon data to split formula.

* remove unused field
This commit is contained in:
IrkTheImp 2025-07-03 18:02:44 -05:00 committed by GitHub
parent 122621a57a
commit c4448226e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 36 additions and 29 deletions

View file

@ -39,7 +39,6 @@ export class DHRoll extends Roll {
if (config.dialog.configure !== false) {
// Open Roll Dialog
const DialogClass = config.dialog?.class ?? this.DefaultDialog;
console.log(roll, config);
const configDialog = await DialogClass.configure(roll, config, message);
if (!configDialog) return;
}
@ -124,6 +123,18 @@ export class DHRoll extends Roll {
}
return (this._formula = this.constructor.getFormula(this.terms));
}
static calculateTotalModifiers(roll, config) {
config.roll.modifierTotal = 0;
for (let i = 0; i < roll.terms.length; i++) {
if (
roll.terms[i] instanceof foundry.dice.terms.NumericTerm &&
!!roll.terms[i - 1] &&
roll.terms[i - 1] instanceof foundry.dice.terms.OperatorTerm
)
config.roll.modifierTotal += Number(`${roll.terms[i - 1].operator}${roll.terms[i].total}`);
}
}
}
export class DualityDie extends foundry.dice.terms.Die {
@ -299,15 +310,8 @@ export class D20Roll extends DHRoll {
value: d.total
};
});
config.roll.modifierTotal = 0;
for (let i = 0; i < roll.terms.length; i++) {
if (
roll.terms[i] instanceof foundry.dice.terms.NumericTerm &&
!!roll.terms[i - 1] &&
roll.terms[i - 1] instanceof foundry.dice.terms.OperatorTerm
)
config.roll.modifierTotal += Number(`${roll.terms[i - 1].operator}${roll.terms[i].total}`);
}
this.calculateTotalModifiers(roll, config);
}
resetFormula() {
@ -468,6 +472,7 @@ export class DamageRoll extends DHRoll {
static async postEvaluate(roll, config = {}) {
super.postEvaluate(roll, config);
config.roll.type = config.type;
this.calculateTotalModifiers(roll, config);
if (config.source?.message) {
const chatMessage = ui.chat.collection.get(config.source.message);
chatMessage.update({ 'system.damage': config });