Completed finish method

This commit is contained in:
WBHarry 2026-03-15 17:43:53 +01:00
parent d9e36e3a23
commit b5cd5b3bcd
2 changed files with 62 additions and 55 deletions

View file

@ -46,7 +46,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
makeDamageRoll: TagTeamDialog.#makeDamageRoll, makeDamageRoll: TagTeamDialog.#makeDamageRoll,
removeDamageRoll: TagTeamDialog.#removeDamageRoll, removeDamageRoll: TagTeamDialog.#removeDamageRoll,
selectRoll: TagTeamDialog.#selectRoll, selectRoll: TagTeamDialog.#selectRoll,
cancelRoll: TagTeamDialog.#cancelRoll, cancelRoll: TagTeamDialog.#onCancelRoll,
finishRoll: TagTeamDialog.#finishRoll finishRoll: TagTeamDialog.#finishRoll
}, },
form: { handler: this.updateData, submitOnChange: true, closeOnSubmit: false } form: { handler: this.updateData, submitOnChange: true, closeOnSubmit: false }
@ -219,6 +219,17 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
return super.close(options); return super.close(options);
} }
checkInitiatorHopeError(initiator) {
if (initiator.cost && initiator.memberId) {
const actor = game.actors.get(initiator.memberId);
if (actor.system.resources.hope.value < initiator.cost) {
return ui.notifications.warn(
game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.insufficientHope')
);
}
}
}
//#region Initialization //#region Initialization
static #toggleSelectMember(_, button) { static #toggleSelectMember(_, button) {
const member = this.partyMembers.find(x => x.id === button.dataset.id); const member = this.partyMembers.find(x => x.id === button.dataset.id);
@ -229,6 +240,9 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
} }
static async #startTagTeamRoll() { static async #startTagTeamRoll() {
const error = this.checkInitiatorHopeError(this.initiator);
if (error) return error;
await this.party.update({ await this.party.update({
'system.==tagTeam': new game.system.api.data.TagTeamData({ 'system.==tagTeam': new game.system.api.data.TagTeamData({
...this.party.system.tagTeam.toObject(), ...this.party.system.tagTeam.toObject(),
@ -245,15 +259,6 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
}) })
}); });
this.tabGroups.application = 'tagTeamRoll';
// if (this.openForAllplayers) {
// game.socket.emit(`system.${CONFIG.DH.id}`, {
// action: socketEvent.Refresh,
// data: { refreshType: RefreshType.TagTeamRoll, action: 'startTagTeamRoll' }
// });
// }
const hookData = { openForAllPlayers: this.openForAllPlayers, partyId: this.party.id }; const hookData = { openForAllPlayers: this.openForAllPlayers, partyId: this.party.id };
Hooks.callAll(CONFIG.DH.HOOKS.hooksConfig.tagTeamStart, hookData); Hooks.callAll(CONFIG.DH.HOOKS.hooksConfig.tagTeamStart, hookData);
game.socket.emit(`system.${CONFIG.DH.id}`, { game.socket.emit(`system.${CONFIG.DH.id}`, {
@ -527,15 +532,21 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
return mainRoll; return mainRoll;
} }
static async #cancelRoll() { static async #onCancelRoll(options = { confirm: true }) {
const confirmed = await foundry.applications.api.DialogV2.confirm({ this.cancelRoll(options);
window: { }
title: game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.cancelConfirmTitle')
},
content: game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.cancelConfirmText')
});
if (!confirmed) return; async cancelRoll(options = { confirm: true }) {
if (options.confirm) {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.cancelConfirmTitle')
},
content: game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.cancelConfirmText')
});
if (!confirmed) return;
}
await this.updatePartyData( await this.updatePartyData(
{ {
@ -555,17 +566,9 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
} }
static async #finishRoll() { static async #finishRoll() {
// const mainRollId = Object.keys(this.data.members).find(key => this.data.members[key].selected); const error = this.checkInitiatorHopeError(this.party.system.tagTeam.initiator);
// const mainRoll = game.messages.get(this.data.members[mainRollId].messageId); if (error) return error;
// if (this.data.initiator.cost) {
// const initiator = this.party.find(x => x.id === this.data.initiator.id);
// if (initiator.system.resources.hope.value < this.data.initiator.cost) {
// return ui.notifications.warn(
// game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.insufficientHope')
// );
// }
// }
const mainRoll = (await this.getJoinedRoll()).rollData; const mainRoll = (await this.getJoinedRoll()).rollData;
const mainActor = this.party.system.partyMembers.find(x => x.uuid === mainRoll.options.source.actor); const mainActor = this.party.system.partyMembers.find(x => x.uuid === mainRoll.options.source.actor);
@ -584,34 +587,38 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
await cls.create(msgData); await cls.create(msgData);
// const fearUpdate = { key: 'fear', value: null, total: null, enabled: true }; /* Handle resource updates from the finished TagTeamRoll */
// for (let memberId of Object.keys(this.data.members)) { const tagTeamData = this.party.system.tagTeam;
// const resourceUpdates = []; const fearUpdate = { key: 'fear', value: null, total: null, enabled: true };
// const rollGivesHope = systemData.roll.isCritical || systemData.roll.result.duality === 1; for (let memberId in tagTeamData.members) {
// if (memberId === this.data.initiator.id) { const resourceUpdates = [];
// const value = this.data.initiator.cost const rollGivesHope = mainRoll.options.roll.isCritical || mainRoll.options.roll.result.duality === 1;
// ? rollGivesHope if (memberId === tagTeamData.initiator.memberId) {
// ? 1 - this.data.initiator.cost const value = tagTeamData.initiator.cost
// : -this.data.initiator.cost ? rollGivesHope
// : 1; ? 1 - tagTeamData.initiator.cost
// resourceUpdates.push({ key: 'hope', value: value, total: -value, enabled: true }); : -tagTeamData.initiator.cost
// } else if (rollGivesHope) { : 1;
// resourceUpdates.push({ key: 'hope', value: 1, total: -1, enabled: true }); resourceUpdates.push({ key: 'hope', value: value, total: -value, enabled: true });
// } } else if (rollGivesHope) {
// if (systemData.roll.isCritical) resourceUpdates.push({ key: 'stress', value: -1, total: 1, enabled: true }); resourceUpdates.push({ key: 'hope', value: 1, total: -1, enabled: true });
// if (systemData.roll.result.duality === -1) { }
// fearUpdate.value = fearUpdate.value === null ? 1 : fearUpdate.value + 1; if (mainRoll.options.roll.isCritical)
// fearUpdate.total = fearUpdate.total === null ? -1 : fearUpdate.total - 1; resourceUpdates.push({ key: 'stress', value: -1, total: 1, enabled: true });
// } if (mainRoll.options.roll.result.duality === -1) {
fearUpdate.value = fearUpdate.value === null ? 1 : fearUpdate.value + 1;
fearUpdate.total = fearUpdate.total === null ? -1 : fearUpdate.total - 1;
}
// this.party.find(x => x.id === memberId).modifyResource(resourceUpdates); game.actors.get(memberId).modifyResource(resourceUpdates);
// } }
// if (fearUpdate.value) { if (fearUpdate.value) {
// this.party.find(x => x.id === mainRollId).modifyResource([fearUpdate]); mainActor.modifyResource([fearUpdate]);
// } }
/* Clear Party tag Team Data here */ /* Fin */
this.cancelRoll({ confirm: false });
} }
//#endregion //#endregion

View file

@ -80,7 +80,7 @@
<img src="{{concat "systems/daggerheart/assets/icons/dice/fear/" this.fear.dice ".svg"}}" /> <img src="{{concat "systems/daggerheart/assets/icons/dice/fear/" this.fear.dice ".svg"}}" />
</a> </a>
<span class="roll-operator">{{#if (gte this.modifierTotal 0)}}+{{else}}-{{/if}}</span> <span class="roll-operator">{{#if (gte this.modifierTotal 0)}}+{{else}}-{{/if}}</span>
<span class="roll-value">{{this.modifierTotal}}</span> <span class="roll-value">{{positive this.modifierTotal}}</span>
</div> </div>
</div> </div>
{{/with}} {{/with}}
@ -126,7 +126,7 @@
{{/each}} {{/each}}
{{#if part.modifierTotal}} {{#if part.modifierTotal}}
<span class="roll-operator">{{#if (gte part.modifierTotal 0)}}+{{else}}-{{/if}}</span> <span class="roll-operator">{{#if (gte part.modifierTotal 0)}}+{{else}}-{{/if}}</span>
<span class="roll-value">{{part.modifierTotal}}</span> <span class="roll-value">{{positive part.modifierTotal}}</span>
{{/if}} {{/if}}
</div> </div>
{{/each}} {{/each}}