Skip to content

Commit 2107d7d

Browse files
authored
Merge pull request #675 from MetaMorphic-Digital/dev
13.27.3 - Prevent Combat Tracker failing
2 parents b31a117 + 18ec9ee commit 2107d7d

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# TORG Eternity Changelog
22

3+
## 13.27.3 - Prevent Combat Tracker errors
4+
5+
- Deleting an Actor whilst its token was in the Combat Tracker was causing errors in the Combat Tracker.
6+
- Added some extra checks to prevent a combatant without a valid token or actor from breaking the Combat Tracker.
7+
- Context Menu in an Encounter should show the Torg options under the correct dynamic conditions now.
8+
39
## 13.27.2 - Fix defenses using only attribute values
410

511
- Fixes a bug where the defensees were based on the skill values BEFORE adds were added to the skill values.

module/dramaticScene/torgeternityCombat.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export default class TorgCombat extends Combat {
7878
const whoFirst = await this.getFlag('torgeternity', 'combatFirstDisposition');
7979
combatant.update({ initiative: this.#getInitiative(combatant, whoFirst) });
8080

81-
if (combatant.token.disposition === CONST.TOKEN_DISPOSITIONS.FRIENDLY && this.heroConflict === 'confused') {
82-
const hand = combatant.actor.getDefaultHand();
81+
if (combatant.token?.disposition === CONST.TOKEN_DISPOSITIONS.FRIENDLY && this.heroConflict === 'confused') {
82+
const hand = combatant.actor?.getDefaultHand();
8383
if (hand) hand.setFlag('torgeternity', 'disablePlayCards', true)
8484
}
8585

@@ -95,7 +95,7 @@ export default class TorgCombat extends Combat {
9595
async _onExit(combatant) {
9696
// Cancel "cannot play cards"
9797
if (combatant.token?.disposition === CONST.TOKEN_DISPOSITIONS.FRIENDLY && this.heroConflict === 'confused') {
98-
const hand = combatant.actor.getDefaultHand();
98+
const hand = combatant.actor?.getDefaultHand();
9999
if (hand) hand.setFlag('torgeternity', 'disablePlayCards', false)
100100
}
101101
combatant.token?.object?.renderFlags.set({ refreshTurnMarker: true })
@@ -311,7 +311,7 @@ export default class TorgCombat extends Combat {
311311
* DRAMA DECK HANDLING
312312
*/
313313
getCombatantFaction(combatant) {
314-
return (combatant.token.disposition === CONST.TOKEN_DISPOSITIONS.FRIENDLY) ? 'heroes' : 'villains';
314+
return (combatant.token?.disposition === CONST.TOKEN_DISPOSITIONS.FRIENDLY) ? 'heroes' : 'villains';
315315
}
316316
getFactionActors(faction) {
317317
const disposition = (faction === 'heroes') ? CONST.TOKEN_DISPOSITIONS.FRIENDLY : CONST.TOKEN_DISPOSITIONS.HOSTILE;
@@ -510,12 +510,12 @@ export default class TorgCombat extends Combat {
510510
// Find first combatant whose turn has NOT been taken (after sorting).
511511
const old = this.#currentDisposition;
512512
const firstNotTaken = this.turns?.find(combatant => !combatant.turnTaken && !combatant.isWaiting);
513-
this.#currentDisposition = firstNotTaken?.token.disposition ?? CONST.TOKEN_DISPOSITIONS.SECRET;
513+
this.#currentDisposition = firstNotTaken?.token?.disposition ?? CONST.TOKEN_DISPOSITIONS.SECRET;
514514

515515
// Combat.updateTurnMarkers won't add new ones!
516516
if (this.#currentDisposition != old)
517517
for (const combatant of this.turns)
518-
if (combatant.token.rendered)
518+
if (combatant.token?.rendered)
519519
combatant.token?.object?.renderFlags.set({ refreshTurnMarker: true });
520520
}
521521

module/dramaticScene/torgeternityCombatTracker.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ export default class torgeternityCombatTracker extends foundry.applications.side
8181

8282
async _prepareTrackerContext(context, options) {
8383
await super._prepareTrackerContext(context, options);
84-
if (!this.viewed) return;
85-
this.viewed.updateCurrentDisposition();
8684
const combat = this.viewed;
8785
if (!combat) return;
86+
combat.updateCurrentDisposition();
8887

8988
await this._prepareGroupContext(context, combat);
9089

@@ -188,22 +187,22 @@ export default class torgeternityCombatTracker extends foundry.applications.side
188187
options.unshift({
189188
name: "torgeternity.dramaCard.replaceDrama",
190189
icon: '<i class="fa-solid fa-rotate-right"></i>',
191-
condition: game.user.isGM && !!this.viewed,
190+
condition: () => game.user.isGM && !!this.viewed,
192191
callback: () => this.viewed.drawDramaCard()
193192
}, {
194193
name: "torgeternity.dramaCard.getPreviousDrama",
195194
icon: '<i class="fa-solid fa-up-down"></i>',
196-
condition: game.user.isGM && !!this.viewed,
195+
condition: () => game.user.isGM && !!this.viewed,
197196
callback: () => this.viewed.restorePreviousDrama()
198197
}, {
199198
name: "torgeternity.dramaCard.shuffleDeck",
200199
icon: '<i class="fa-solid fa-random"></i>',
201-
condition: game.user.isGM && !!this.viewed,
200+
condition: () => game.user.isGM && !!this.viewed,
202201
callback: () => this.viewed.resetDramaDeck()
203202
}, {
204203
name: "torgeternity.CombatantGroup.newGroup",
205204
icon: '<i class="fa-solid fa-random"></i>',
206-
condition: game.user.isGM && !!this.viewed,
205+
condition: () => game.user.isGM && !!this.viewed,
207206
callback: async () => {
208207
const groupName = await foundry.applications.api.DialogV2.prompt({
209208
window: { title: "Combatant Group Creation" },
@@ -223,7 +222,7 @@ export default class torgeternityCombatTracker extends foundry.applications.side
223222
const getCombatant = li => this.viewed.combatants.get(li.dataset.combatantId);
224223
function canAddToGroup(li) {
225224
const combatant = getCombatant(li);
226-
return !combatant?.group &&
225+
return !combatant?.group && combatant.token &&
227226
!!combatant.combat.groups.find(group => group.disposition === undefined || group.disposition === combatant.token.disposition);
228227
}
229228

@@ -331,7 +330,7 @@ export default class torgeternityCombatTracker extends foundry.applications.side
331330
const { combatantId } = button.closest("[data-combatant-id]")?.dataset ?? {};
332331
const combatant = this.viewed?.combatants.get(combatantId);
333332
if (!combatant) return;
334-
await combatant.actor.toggleStatusEffect('waiting');
333+
await combatant.actor?.toggleStatusEffect('waiting');
335334
}
336335

337336
updateStage(document, force) {
@@ -530,24 +529,26 @@ export default class torgeternityCombatTracker extends foundry.applications.side
530529
static async #onToggleWaitingGroup(event, button) {
531530
const group = this.viewed.groups.get(button.closest('li.combatantGroup')?.dataset.groupId);
532531
if (group) group.isOpen = !button.open;
533-
return Promise.all(group.members.map(combatant => combatant.actor.toggleStatusEffect('waiting')))
532+
return Promise.all(group.members.map(combatant => combatant.actor?.toggleStatusEffect('waiting')))
534533
}
535534

536535
static async #askAddToGroup(askAll, li) {
537536
const combat = this.viewed;
538537
const combatant = combat.combatants.get(li.dataset.combatantId); // getCombatant(li)
539538
let combatants;
540539
if (askAll) {
541-
if (combatant.actor.type === 'stormknight') {
542-
combatants = combat.combatants.filter(combatant => combatant.actor.type === 'stormknight');
540+
const actor = combatant.actor;
541+
if (!actor) return;// The Actor has been deleted.
542+
if (actor.type === 'stormknight') {
543+
combatants = combat.combatants.filter(combatant => actor.type === 'stormknight');
543544
} else {
544-
const matchid = combatant.actor._source._id;
545-
combatants = combat.combatants.filter(combatant => combatant.actor._source._id === matchid);
545+
const matchid = actor._source._id;
546+
combatants = combat.combatants.filter(combatant => actor._source._id === matchid);
546547
}
547548
} else
548549
combatants = [combatant];
549550

550-
const validDisposition = combatant.token.disposition;
551+
const validDisposition = combatant.token?.disposition;
551552
const validGroups = combat.groups.filter(group => group.disposition === undefined || group.disposition === validDisposition);
552553
if (validGroups.length < 1)
553554
return ui.notifications.info('torgeternity.CombatantGroup.noValidGroup', { localize: true });

module/dramaticScene/torgeternityCombatant.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export default class TorgCombatant extends Combatant {
2727
'system.multiAction': null,
2828
}, { combatTurn: this.combat.turn + 1 });
2929

30-
await this.actor.toggleStatusEffect('waiting', { active: false });
31-
await this.actor.decayEffects();
30+
// If the actor of a linked token is deleted, this.actor will be undefiend.
31+
await this.actor?.toggleStatusEffect('waiting', { active: false });
32+
await this.actor?.decayEffects();
3233
} else {
3334
// Step backwards
3435
await this.update({ 'system.turnTaken': value }, { combatTurn: this.combat.turn - 1 });

0 commit comments

Comments
 (0)