Fixed TagTeamDialog

This commit is contained in:
WBHarry 2026-07-19 22:13:37 +02:00
parent d33277f2be
commit bbf27e5b4d
4 changed files with 48 additions and 25 deletions

View file

@ -6,6 +6,7 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
this.roll = roll; this.roll = roll;
this.config = config; this.config = config;
this.originalIsCritical = config.isCritical;
this.selectedEffects = this.config.bonusEffects; this.selectedEffects = this.config.bonusEffects;
} }
@ -121,13 +122,16 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
} }
static async submitRoll() { static async submitRoll() {
const isCritical = this.config.isCritical;
const { damageFormula, resourceFormulas } = this.roll.constructFormulas({ ...this.config, isCritical: false }); const { damageFormula, resourceFormulas } = this.roll.constructFormulas({ ...this.config, isCritical: false });
/* Sideeffect occuring in constructFormulas that sets this.config.isCritical to the false value. Can remove the below if it can be prevented */ /* Sideeffect occuring in constructFormulas that sets this.config.isCritical to the false value. Can remove the below if it can be prevented */
this.config.isCritical = isCritical; this.config.isCritical = this.originalIsCritical;
damageFormula.roll.options.isCritical = isCritical;
for (const formula of resourceFormulas) /* If a critical has been forced in the Dialog, save that forced state to the damage roll */
formula.roll.options.isCritical = isCritical; if (this.config.isCritical && !this.originalIsCritical) {
damageFormula.roll.options.isCritical = true;
for (const formula of resourceFormulas)
formula.roll.options.isCritical = true;
}
this.config.damageFormula = damageFormula; this.config.damageFormula = damageFormula;
this.config.resourceFormulas = resourceFormulas; this.config.resourceFormulas = resourceFormulas;

View file

@ -1,6 +1,7 @@
import { ResourceUpdateMap } from '../../data/action/baseAction.mjs'; import { ResourceUpdateMap } from '../../data/action/baseAction.mjs';
import { ChatDamageData } from '../../data/chat-message/chatDamageData.mjs'; import { ChatDamageData } from '../../data/chat-message/chatDamageData.mjs';
import { MemberData } from '../../data/tagTeamData.mjs'; import { MemberData } from '../../data/tagTeamData.mjs';
import DamageRoll from '../../dice/damageRoll.mjs';
import { getCritDamageBonus, shouldUseHopeFearAutomation } from '../../helpers/utils.mjs'; import { getCritDamageBonus, shouldUseHopeFearAutomation } from '../../helpers/utils.mjs';
import { emitGMUpdate, GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs'; import { emitGMUpdate, GMUpdateEvent, RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
import PartySheet from '../sheets/actors/party.mjs'; import PartySheet from '../sheets/actors/party.mjs';
@ -235,8 +236,12 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
} }
} }
const selectedRoll = Object.values(this.party.system.tagTeam.members).find(member => member.selected); if (data.damageRollData.main) {
const critSelected = !selectedRoll ? undefined : (selectedRoll?.roll?.isCritical ?? false); const selectedRoll = Object.values(this.party.system.tagTeam.members).find(member => member.selected);
const critSelected = !selectedRoll ? undefined : (selectedRoll?.roll?.isCritical ?? false);
const useCritDamage = critSelected || (critSelected === undefined && data.roll?.isCritical);
data.damageRollData.main.options.isCritical = useCritDamage;
}
return { return {
...data, ...data,
@ -249,7 +254,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
damageRollOptions, damageRollOptions,
damage: data.damageRollData, damage: data.damageRollData,
critDamage: this.getCriticalDamage(data.damageRollData), critDamage: this.getCriticalDamage(data.damageRollData),
useCritDamage: critSelected || (critSelected === undefined && data.roll?.isCritical) useCritDamage: false
}; };
} }
@ -640,17 +645,13 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
secondaryRoll.damageRollData = baseSecondaryRoll.damageRollData ? secondaryRoll.damageRollData = baseSecondaryRoll.damageRollData ?
ChatDamageData.fromJSON(JSON.stringify(baseSecondaryRoll.damageRollData)) : null; ChatDamageData.fromJSON(JSON.stringify(baseSecondaryRoll.damageRollData)) : null;
const isCritical = overrideIsCritical ?? mainRoll.roll.isCritical;
if (isCritical) mainRoll.damageRollData = this.getCriticalDamage(mainRoll.damageRollData);
if (secondaryRoll.damageRollData) { if (secondaryRoll.damageRollData) {
const secondaryDamage = (displayVersion ? overrideIsCritical : isCritical) const secondaryDamage = secondaryRoll.damageRollData;
? this.getCriticalDamage(secondaryRoll.damageRollData)
: secondaryRoll.damageRollData;
if (mainRoll.damageRollData) { if (mainRoll.damageRollData) {
if (secondaryDamage.main) { if (secondaryDamage.main) {
if (mainRoll.damageRollData.main) { if (mainRoll.damageRollData.main) {
mainRoll.damageRollData.main = Roll.fromTerms([ mainRoll.damageRollData.main = DamageRoll.fromTerms([
...baseMainRoll.damageRollData.main.terms, ...baseMainRoll.damageRollData.main.terms,
new foundry.dice.terms.OperatorTerm({ operator: '+' }), new foundry.dice.terms.OperatorTerm({ operator: '+' }),
...baseSecondaryRoll.damageRollData.main.terms ...baseSecondaryRoll.damageRollData.main.terms
@ -672,7 +673,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
for (const [key, damage] of Object.entries(secondaryDamage.resources ?? {})) { for (const [key, damage] of Object.entries(secondaryDamage.resources ?? {})) {
if (key in mainRoll.damageRollData.resources) { if (key in mainRoll.damageRollData.resources) {
mainRoll.damageRollData.resources[key] = Roll.fromTerms([ mainRoll.damageRollData.resources[key] = DamageRoll.fromTerms([
...baseMainRoll.damageRollData.resources[key].terms, ...baseMainRoll.damageRollData.resources[key].terms,
new foundry.dice.terms.OperatorTerm({ operator: '+' }), new foundry.dice.terms.OperatorTerm({ operator: '+' }),
...baseSecondaryRoll.damageRollData.resources[key].terms ...baseSecondaryRoll.damageRollData.resources[key].terms
@ -696,6 +697,12 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
} }
} }
if (mainRoll.damageRollData.main) {
const isCritical = overrideIsCritical ?? mainRoll.roll.isCritical;
mainRoll.damageRollData.main.options.isCritical = isCritical;
}
return mainRoll; return mainRoll;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -755,7 +762,11 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
}; };
if (joinedRoll.damageRollData.main) { if (joinedRoll.damageRollData.main) {
systemData.damage.main = joinedRoll.damageRollData.toJSON(); systemData.damage.main = joinedRoll.damageRollData.main.toJSON();
// isCritical is used internally in TagTeamDialog to force-flip damage from normal to critical and vice versa.
// It's deleted here to avoid interupting normal critical damage logic in the chatMessage.
// If someone explicitly set their own damage roll to be a forced critical, then I think it's fine that isn't transmitted to the final joined roll.
delete systemData.damage.main.options.isCritical;
} }
for (const type of Object.keys(joinedRoll.damageRollData?.resources ?? {})) { for (const type of Object.keys(joinedRoll.damageRollData?.resources ?? {})) {
systemData.damage.resources[type] = joinedRoll.damageRollData.resources[type].toJSON(); systemData.damage.resources[type] = joinedRoll.damageRollData.resources[type].toJSON();

View file

@ -41,11 +41,12 @@ export class ChatDamageData extends foundry.abstract.DataModel {
} }
_prepareRolls() { _prepareRolls() {
this.main &&= Roll.fromData({ this.main &&= Roll.fromData({
...this.main, ...this.main,
options: { options: {
...this.main.options, ...this.main.options,
isCritical: this.main.options.isCritical || this.isCritical isCritical:
this.main.options.isCritical === false ? false : (this.main.options.isCritical || this.isCritical)
} }
}); });

View file

@ -18,11 +18,11 @@
{{#if joinedRoll.damageRollData}} {{#if joinedRoll.damageRollData}}
<div class="result-container"> <div class="result-container">
<span class="result-section-label">{{localize "DAGGERHEART.GENERAL.damage"}}</span> <span class="result-section-label">{{localize "DAGGERHEART.GENERAL.damage"}}</span>
{{#each joinedRoll.damageRollData.types as |damage key|}} {{#if joinedRoll.damageRollData.main}}
<div class="result-info"> {{> damageSummary roll=joinedRoll.damageRollData.main label=(localize "DAGGERHEART.GENERAL.damage")}}
<div>{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}</div> {{/if}}
<div class="damage-info">{{damage.total}}</div> {{#each joinedRoll.damageRollData.resources as |roll key|}}
</div> {{> damageSummary roll=roll label=(localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name"))}}
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}
@ -38,4 +38,11 @@
</button> </button>
</div> </div>
</div> </div>
</section> </section>
{{#*inline "damageSummary"}}
<div class="result-info">
<div>{{label}}</div>
<div class="damage-info">{{roll.total}}</div>
</div>
{{/inline}}