Fixed ChatMessage damage creation

This commit is contained in:
WBHarry 2026-07-18 03:09:37 +02:00
parent 1f12a98c63
commit 42ec4f8c30
8 changed files with 152 additions and 113 deletions

View file

@ -429,11 +429,11 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
}
get hasDamage() {
return Boolean(Object.keys(this.damage?.parts ?? {}).length) && this.type !== 'healing';
return this.type !== 'healing' && Boolean(this.damage.main) || Boolean(this.damage.resources.length);
}
get hasHealing() {
return Boolean(Object.keys(this.damage?.parts ?? {}).length) && this.type === 'healing';
return this.type === 'healing' && Boolean(this.damage.main) || Boolean(this.damage.resources.length);
}
get hasSave() {

View file

@ -8,11 +8,8 @@ export default class DHDamageAction extends DHBaseAction {
* @returns Formula string
*/
getDamageFormula() {
const strings = [];
for (const { value } of this.damage.parts) {
strings.push(Roll.replaceFormulaData(value.getFormula(), this.actor?.getRollData() ?? {}));
}
if (!this.damage.main) return '';
return strings.join(' + ');
return Roll.replaceFormulaData(this.damage.main.value.getFormula(), this.actor?.getRollData() ?? {});
}
}

View file

@ -17,7 +17,7 @@ export class ChatDamageData extends foundry.abstract.DataModel {
}
get active() {
return Boolean(Object.keys(this.types).length);
return !!this.main || Boolean(Object.keys(this.resources).length);
}
static #validateRoll(rollJSON) {
@ -28,12 +28,12 @@ export class ChatDamageData extends foundry.abstract.DataModel {
}
_prepareRolls() {
for (const key of Object.keys(this.types)) {
const type = this.types[key];
try {
this.types[key] = Roll.fromData(type);
this.types[key].options.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(type);
} catch {}
if (this.main) {
this.main = Roll.fromData(this.main);
}
for (const key of Object.keys(this.resources)) {
this.resources[key] = Roll.fromData(this.resources[key]);
}
}

View file

@ -32,25 +32,23 @@ export default class DamageField extends fields.SchemaField {
this.hasRoll &&
DamageField.getAutomation() === CONFIG.DH.SETTINGS.actionAutomationChoices.never.id &&
!force
)
) {
return;
}
let formulas = this.damage.parts.map(p => ({
formula: DamageField.getFormulaValue.call(this, p, config).getFormula(this.actor),
damageTypes: p.applyTo === 'hitPoints' && !p.type.size ? new Set(['physical']) : p.type,
applyTo: p.applyTo
}));
const damageFormula = this.damage.main ?
DamageField.formatFormulas.call(this, [this.damage.main], config)[0] : null;
const resourceFormulas = DamageField.formatFormulas.call(this, this.damage.resources, config);
if (!formulas.length) return false;
formulas = DamageField.formatFormulas.call(this, formulas, config);
if (!damageFormula && !resourceFormulas.length) return false;
messageId = config.message?._id ?? messageId;
const message = game.messages.get(messageId);
const damageConfig = {
dialog: {},
...config,
roll: formulas,
damageFormula,
resourceFormulas,
data: this.getRollData(),
isCritical: Boolean(message?.system.roll?.isCritical)
};
@ -175,11 +173,17 @@ export default class DamageField extends fields.SchemaField {
/**
* Prepare formulas for Damage Roll
* Must be called within Action context or similar.
* @param {object[]} formulas Array of formatted formulas object
* @param {DHResourceData[]} damageData Array of DHResourceData
* @param {object} data Action getRollData
* @returns
*/
static formatFormulas(formulas, data) {
static formatFormulas(damageData, data) {
const formulas = damageData.map(x => ({
formula: DamageField.getFormulaValue.call(this, x, data).getFormula(this.actor),
damageTypes: x.applyTo === 'hitPoints' && !x.type.size ? new Set(['physical']) : x.type,
applyTo: x.applyTo
}));
const formattedFormulas = [];
formulas.forEach(formula => {
if (isNaN(formula.formula))
@ -190,6 +194,7 @@ export default class DamageField extends fields.SchemaField {
if (same) same.formula += ` + ${formula.formula}`;
else formattedFormulas.push(formula);
});
return formattedFormulas;
}