From 88754c5a805d257d100f3291a85797f48ae50393 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sat, 18 Jul 2026 15:32:57 +0200 Subject: [PATCH] Fixed GroupAttack and DirectDamage --- module/applications/dialogs/tagTeamDialog.mjs | 82 +++++++++++++------ module/data/action/attackAction.mjs | 17 ++-- module/data/action/baseAction.mjs | 11 ++- module/dice/damageRoll.mjs | 8 +- 4 files changed, 72 insertions(+), 46 deletions(-) diff --git a/module/applications/dialogs/tagTeamDialog.mjs b/module/applications/dialogs/tagTeamDialog.mjs index c54720f4..594b136f 100644 --- a/module/applications/dialogs/tagTeamDialog.mjs +++ b/module/applications/dialogs/tagTeamDialog.mjs @@ -553,8 +553,10 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio const { memberKey } = button.dataset; this.updatePartyData( { - [`system.tagTeam.members.${memberKey}.damageRollData.types`]: - _replace({}) + [`system.tagTeam.members.${memberKey}.damageRollData`]: { + main: null, + resources: _replace({}) + } }, this.getUpdatingParts(button) ); @@ -577,19 +579,19 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio async getCriticalDamage(origDamage) { const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null; - for (let key in newDamage?.types ?? {}) { - const criticalDamage = await getCritDamageBonus(newDamage.types[key].formula); - if (!criticalDamage) continue; - - const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true }); - criticalTerm.evaluate(); - newDamage.types[key] = await Roll.fromTerms([ - ...origDamage.types[key].terms, - new foundry.dice.terms.OperatorTerm({ operator: '+' }), - criticalTerm - ]); - newDamage.types[key].options = foundry.utils.deepClone(origDamage.types[key].options); - } + if (newDamage?.main) { + const criticalDamage = await getCritDamageBonus(newDamage.main.formula); + if (criticalDamage) { + const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true }); + criticalTerm.evaluate(); + newDamage.main = await Roll.fromTerms([ + ...origDamage.main.terms, + new foundry.dice.terms.OperatorTerm({ operator: '+' }), + criticalTerm + ]); + newDamage.main.options = foundry.utils.deepClone(origDamage.main.options); + } + } return newDamage; } @@ -644,25 +646,47 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio ? await this.getCriticalDamage(secondaryRoll.damageRollData) : secondaryRoll.damageRollData; if (mainRoll.damageRollData) { - for (const [key, damage] of Object.entries(secondaryDamage.types ?? {})) { - if (key in mainRoll.damageRollData.types) { - mainRoll.damageRollData.types[key] = Roll.fromTerms([ - ...baseMainRoll.damageRollData.types[key].terms, + if (secondaryDamage.main) { + if (mainRoll.damageRollData.main) { + mainRoll.damageRollData.main = Roll.fromTerms([ + ...baseMainRoll.damageRollData.main.terms, new foundry.dice.terms.OperatorTerm({ operator: '+' }), - ...baseSecondaryRoll.damageRollData.types[key].terms + ...baseSecondaryRoll.damageRollData.main.terms ]); /* Joining the roll.options of both rolls */ const joinedDamageTypes = new Set([ - ...baseMainRoll.damageRollData.types[key].options.damageTypes, - ...baseSecondaryRoll.damageRollData.types[key].options.damageTypes + ...baseMainRoll.damageRollData.main.options.damageTypes, + ...baseSecondaryRoll.damageRollData.main.options.damageTypes ]); - mainRoll.damageRollData.types[key].options = { - ...baseMainRoll.damageRollData.types[key].options, + mainRoll.damageRollData.main.options = { + ...baseMainRoll.damageRollData.main.options, damageTypes: [...joinedDamageTypes] }; } else { - mainRoll.damageRollData.types[key] = damage; + mainRoll.damageRollData.main = secondaryDamage.main; + } + } + + for (const [key, damage] of Object.entries(secondaryDamage.resources ?? {})) { + if (key in mainRoll.damageRollData.resources) { + mainRoll.damageRollData.resources[key] = Roll.fromTerms([ + ...baseMainRoll.damageRollData.resources[key].terms, + new foundry.dice.terms.OperatorTerm({ operator: '+' }), + ...baseSecondaryRoll.damageRollData.resources[key].terms + ]); + + /* Joining the roll.options of both rolls */ + const joinedDamageTypes = new Set([ + ...baseMainRoll.damageRollData.resources[key].options.damageTypes, + ...baseSecondaryRoll.damageRollData.resources[key].options.damageTypes + ]); + mainRoll.damageRollData.resources[key].options = { + ...baseMainRoll.damageRollData.resources[key].options, + damageTypes: [...joinedDamageTypes] + }; + } else { + mainRoll.damageRollData.resources[key] = damage; } } } else { @@ -727,8 +751,12 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio ...mainRoll.options, damage: joinedRoll.damageRollData?.toJSON() }; - for (const type of Object.keys(joinedRoll.damageRollData?.types ?? {})) { - systemData.damage.types[type] = joinedRoll.damageRollData.types[type].toJSON(); + + if (joinedRoll.damageRollData.main) { + systemData.damage.main = joinedRoll.damageRollData.toJSON(); + } + for (const type of Object.keys(joinedRoll.damageRollData?.resources ?? {})) { + systemData.damage.resources[type] = joinedRoll.damageRollData.resources[type].toJSON(); } const cls = getDocumentClass('ChatMessage'), diff --git a/module/data/action/attackAction.mjs b/module/data/action/attackAction.mjs index 6c205de6..dadc85f0 100644 --- a/module/data/action/attackAction.mjs +++ b/module/data/action/attackAction.mjs @@ -13,18 +13,19 @@ export default class DHAttackAction extends DHDamageAction { if (this.damage.includeBase) { const baseDamage = this.getParentHitPointDamage(); if (baseDamage) { - if (!this.damage.parts.hitPoints) { - this.damage.parts.hitPoints = baseDamage; + if (!this.damage.main) { + this.damage.main = baseDamage; } else { - for (const type of baseDamage.type) this.damage.parts.hitPoints.type.add(type); + for (const type of baseDamage.type) this.damage.main.type.add(type); - this.damage.parts.hitPoints.value.custom = { + this.damage.main.value.custom = { enabled: true, - formula: `${baseDamage.value.getFormula()} + ${this.damage.parts.hitPoints.value.getFormula()}` + formula: `${baseDamage.value.getFormula()} + ${this.damage.main.value.getFormula()}` }; } } } + if (this.roll.useDefault) { this.roll.trait = this.item.system.attack.roll.trait; this.roll.type = 'attack'; @@ -33,18 +34,18 @@ export default class DHAttackAction extends DHDamageAction { } getParentHitPointDamage() { - return this.item?.system?.attack.damage.parts.hitPoints; + return this.item?.system?.attack.damage.main; } get damageFormula() { - const hitPointsPart = this.damage.parts.hitPoints; + const hitPointsPart = this.damage.main; if (!hitPointsPart) return '0'; return hitPointsPart.value.getFormula(); } get altDamageFormula() { - const hitPointsPart = this.damage.parts.hitPoints; + const hitPointsPart = this.damage.main; if (!hitPointsPart) return '0'; return hitPointsPart.valueAlt.getFormula(); diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index 8789c859..a94d7d61 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -288,7 +288,6 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel hasEffect: this.hasEffect, hasSave: this.hasSave, onSave: this.save?.damageMod, - isDirect: !!this.damage?.direct, selectedMessageMode: game.settings.get('core', 'messageMode'), data: this.getRollData(), evaluate: this.hasRoll, @@ -306,20 +305,20 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel }; if (this.damage) { - config.isDirect = this.damage.direct; + config.isDirect = !!this.damage.main?.direct; - const groupAttackTokens = this.damage.groupAttack + const groupAttackTokens = this.damage.main?.groupAttack ? game.system.api.fields.ActionFields.DamageField.getGroupAttackTokens( this.actor.id, - this.damage.groupAttack + this.damage.main.groupAttack ) : null; config.damageOptions = { - groupAttack: this.damage.groupAttack + groupAttack: this.damage.main?.groupAttack ? { numAttackers: Math.max(groupAttackTokens.length, 1), - range: this.damage.groupAttack + range: this.damage.main.groupAttack } : null }; diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 79b9f653..c78a42e9 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -120,12 +120,10 @@ export default class DamageRoll extends DHRoll { const type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage'); const changeKeys = []; - for (const roll of this.options.roll) { - for (const damageType of roll.damageTypes?.values?.() ?? []) { - changeKeys.push(`system.bonuses.${type}.${damageType}`); - } + for (const damageType of this.options.damageFormula?.damageTypes?.values?.() ?? []) { + changeKeys.push(`system.bonuses.${type}.${damageType}`); } - + const item = this.data.parent?.items?.get(this.options.source.item); if (item) { switch (item.type) {