[#6261] Add modifiers to DamageData#6834
Conversation
Adds a new modifiers field for damage that is applied automatically to the formula. The `DamageData` model now automatically adds these modifiers to the formula, attaching to the first roll (if one can be found when using a custom formula). The `DamageData#scaledFormula` supports passing in additional modifiers that are also appended. This is to support a future Rule active effect that adds modifiers to certain rolls at evaluation time (such as Elemental Adept, which would add `min2` to all damage rolls from spells that deal a certain damage type). Closes #6261
| get formula() { | ||
| if ( this.custom.enabled ) return this.custom.formula ?? ""; | ||
| if ( this.custom.enabled ) return this._manualFormula(); | ||
| return this._automaticFormula(); |
There was a problem hiding this comment.
Also something I missed from my original round of feedback, was that we use formula for display on sheets as well. This isn't a new problem because AEs will also cause this, but it would be nice if we just had the 'pristine' formula on display, and any modifiers omitted.
There was a problem hiding this comment.
Added the ability to pass modifiers: false into the formula methods and tied that into the label generation for the damage parts. It doesn't strip out existing modifiers from custom formulas, but it does avoid adding new modifiers.
Passing through DamageFormulaOptions is also going to be necessary in the future for rule AEs that add modifiers so it is good to get it piped in now.
| if ( number && this.denomination ) formula = `${number}d${this.denomination}`; | ||
| if ( number && this.denomination ) { | ||
| formula = `${number}d${this.denomination}${modifiers !== false | ||
| ? Array.from(this.modifiers).concat(modifiers ?? []).join("") : ""}`; |
There was a problem hiding this comment.
DamageFormulaOptions has modifiers as a Set, so this will concat the whole set into the array I think.
| ? Array.from(this.modifiers).concat(modifiers ?? []).join("") : ""}`; | |
| ? Array.from(this.modifiers).concat(...(modifiers ?? [])).join("") : ""}`; |
| _manualFormula({ modifiers }={}) { | ||
| if ( !this.custom.formula ) return ""; | ||
| if ( modifiers === false ) return this.custom.formula; | ||
| modifiers = Array.from(this.modifiers).concat(modifiers ?? []).join(""); |
There was a problem hiding this comment.
| modifiers = Array.from(this.modifiers).concat(modifiers ?? []).join(""); | |
| modifiers = Array.from(this.modifiers).concat(...(modifiers ?? [])).join(""); |
| @@ -1,8 +1,13 @@ | |||
| import simplifyRollFormula from "../../dice/simplify-roll-formula.mjs"; | |||
Adds a new modifiers field for damage that is applied automatically to the formula. The
DamageDatamodel now automatically adds these modifiers to the formula, attaching to the first roll (if one can be found when using a custom formula).The
DamageData#scaledFormulasupports passing in additional modifiers that are also appended. This is to support a future Rule active effect that adds modifiers to certain rolls at evaluation time (such as Elemental Adept, which would addmin2to all damage rolls from spells that deal a certain damage type).Closes #6261