Fixed GroupAttack and DirectDamage

This commit is contained in:
WBHarry 2026-07-18 15:32:57 +02:00
parent 6273394db8
commit 88754c5a80
4 changed files with 72 additions and 46 deletions

View file

@ -553,8 +553,10 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
const { memberKey } = button.dataset; const { memberKey } = button.dataset;
this.updatePartyData( this.updatePartyData(
{ {
[`system.tagTeam.members.${memberKey}.damageRollData.types`]: [`system.tagTeam.members.${memberKey}.damageRollData`]: {
_replace({}) main: null,
resources: _replace({})
}
}, },
this.getUpdatingParts(button) this.getUpdatingParts(button)
); );
@ -577,19 +579,19 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
async getCriticalDamage(origDamage) { async getCriticalDamage(origDamage) {
const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null; const newDamage = origDamage ? ChatDamageData.fromJSON(JSON.stringify(origDamage)) : null;
for (let key in newDamage?.types ?? {}) { if (newDamage?.main) {
const criticalDamage = await getCritDamageBonus(newDamage.types[key].formula); const criticalDamage = await getCritDamageBonus(newDamage.main.formula);
if (!criticalDamage) continue; if (criticalDamage) {
const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true });
const criticalTerm = new foundry.dice.terms.NumericTerm({ number: criticalDamage, evaluated: true }); criticalTerm.evaluate();
criticalTerm.evaluate(); newDamage.main = await Roll.fromTerms([
newDamage.types[key] = await Roll.fromTerms([ ...origDamage.main.terms,
...origDamage.types[key].terms, new foundry.dice.terms.OperatorTerm({ operator: '+' }),
new foundry.dice.terms.OperatorTerm({ operator: '+' }), criticalTerm
criticalTerm ]);
]); newDamage.main.options = foundry.utils.deepClone(origDamage.main.options);
newDamage.types[key].options = foundry.utils.deepClone(origDamage.types[key].options); }
} }
return newDamage; return newDamage;
} }
@ -644,25 +646,47 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
? await this.getCriticalDamage(secondaryRoll.damageRollData) ? await this.getCriticalDamage(secondaryRoll.damageRollData)
: secondaryRoll.damageRollData; : secondaryRoll.damageRollData;
if (mainRoll.damageRollData) { if (mainRoll.damageRollData) {
for (const [key, damage] of Object.entries(secondaryDamage.types ?? {})) { if (secondaryDamage.main) {
if (key in mainRoll.damageRollData.types) { if (mainRoll.damageRollData.main) {
mainRoll.damageRollData.types[key] = Roll.fromTerms([ mainRoll.damageRollData.main = Roll.fromTerms([
...baseMainRoll.damageRollData.types[key].terms, ...baseMainRoll.damageRollData.main.terms,
new foundry.dice.terms.OperatorTerm({ operator: '+' }), new foundry.dice.terms.OperatorTerm({ operator: '+' }),
...baseSecondaryRoll.damageRollData.types[key].terms ...baseSecondaryRoll.damageRollData.main.terms
]); ]);
/* Joining the roll.options of both rolls */ /* Joining the roll.options of both rolls */
const joinedDamageTypes = new Set([ const joinedDamageTypes = new Set([
...baseMainRoll.damageRollData.types[key].options.damageTypes, ...baseMainRoll.damageRollData.main.options.damageTypes,
...baseSecondaryRoll.damageRollData.types[key].options.damageTypes ...baseSecondaryRoll.damageRollData.main.options.damageTypes
]); ]);
mainRoll.damageRollData.types[key].options = { mainRoll.damageRollData.main.options = {
...baseMainRoll.damageRollData.types[key].options, ...baseMainRoll.damageRollData.main.options,
damageTypes: [...joinedDamageTypes] damageTypes: [...joinedDamageTypes]
}; };
} else { } 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 { } else {
@ -727,8 +751,12 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
...mainRoll.options, ...mainRoll.options,
damage: joinedRoll.damageRollData?.toJSON() 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'), const cls = getDocumentClass('ChatMessage'),

View file

@ -13,18 +13,19 @@ export default class DHAttackAction extends DHDamageAction {
if (this.damage.includeBase) { if (this.damage.includeBase) {
const baseDamage = this.getParentHitPointDamage(); const baseDamage = this.getParentHitPointDamage();
if (baseDamage) { if (baseDamage) {
if (!this.damage.parts.hitPoints) { if (!this.damage.main) {
this.damage.parts.hitPoints = baseDamage; this.damage.main = baseDamage;
} else { } 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, 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) { if (this.roll.useDefault) {
this.roll.trait = this.item.system.attack.roll.trait; this.roll.trait = this.item.system.attack.roll.trait;
this.roll.type = 'attack'; this.roll.type = 'attack';
@ -33,18 +34,18 @@ export default class DHAttackAction extends DHDamageAction {
} }
getParentHitPointDamage() { getParentHitPointDamage() {
return this.item?.system?.attack.damage.parts.hitPoints; return this.item?.system?.attack.damage.main;
} }
get damageFormula() { get damageFormula() {
const hitPointsPart = this.damage.parts.hitPoints; const hitPointsPart = this.damage.main;
if (!hitPointsPart) return '0'; if (!hitPointsPart) return '0';
return hitPointsPart.value.getFormula(); return hitPointsPart.value.getFormula();
} }
get altDamageFormula() { get altDamageFormula() {
const hitPointsPart = this.damage.parts.hitPoints; const hitPointsPart = this.damage.main;
if (!hitPointsPart) return '0'; if (!hitPointsPart) return '0';
return hitPointsPart.valueAlt.getFormula(); return hitPointsPart.valueAlt.getFormula();

View file

@ -288,7 +288,6 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
hasEffect: this.hasEffect, hasEffect: this.hasEffect,
hasSave: this.hasSave, hasSave: this.hasSave,
onSave: this.save?.damageMod, onSave: this.save?.damageMod,
isDirect: !!this.damage?.direct,
selectedMessageMode: game.settings.get('core', 'messageMode'), selectedMessageMode: game.settings.get('core', 'messageMode'),
data: this.getRollData(), data: this.getRollData(),
evaluate: this.hasRoll, evaluate: this.hasRoll,
@ -306,20 +305,20 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
}; };
if (this.damage) { 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( ? game.system.api.fields.ActionFields.DamageField.getGroupAttackTokens(
this.actor.id, this.actor.id,
this.damage.groupAttack this.damage.main.groupAttack
) )
: null; : null;
config.damageOptions = { config.damageOptions = {
groupAttack: this.damage.groupAttack groupAttack: this.damage.main?.groupAttack
? { ? {
numAttackers: Math.max(groupAttackTokens.length, 1), numAttackers: Math.max(groupAttackTokens.length, 1),
range: this.damage.groupAttack range: this.damage.main.groupAttack
} }
: null : null
}; };

View file

@ -120,12 +120,10 @@ export default class DamageRoll extends DHRoll {
const type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage'); const type = this.options.messageType ?? (this.options.hasHealing ? 'healing' : 'damage');
const changeKeys = []; const changeKeys = [];
for (const roll of this.options.roll) { for (const damageType of this.options.damageFormula?.damageTypes?.values?.() ?? []) {
for (const damageType of roll.damageTypes?.values?.() ?? []) { changeKeys.push(`system.bonuses.${type}.${damageType}`);
changeKeys.push(`system.bonuses.${type}.${damageType}`);
}
} }
const item = this.data.parent?.items?.get(this.options.source.item); const item = this.data.parent?.items?.get(this.options.source.item);
if (item) { if (item) {
switch (item.type) { switch (item.type) {