diff --git a/module/data/actor/base.mjs b/module/data/actor/base.mjs index 772a5af3..c7f7ee75 100644 --- a/module/data/actor/base.mjs +++ b/module/data/actor/base.mjs @@ -106,6 +106,21 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel { return data; } + async _preDelete() { + /* Clear all partyMembers from tagTeam setting.*/ + /* Revisit this when tagTeam is improved for many parties */ + if (this.parent.parties.size > 0) { + const tagTeam = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll); + await tagTeam.updateSource({ + initiator: this.parent.id === tagTeam.initiator ? null : tagTeam.initiator, + members: Object.keys(tagTeam.members).find(x => x === this.parent.id) + ? { [`-=${this.parent.id}`]: null } + : {} + }); + await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll, tagTeam); + } + } + async _preUpdate(changes, options, userId) { const allowed = await super._preUpdate(changes, options, userId); if (allowed === false) return; diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 638da365..c5ab914c 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -678,6 +678,8 @@ export default class DhCharacter extends BaseDataActor { } async _preDelete() { + super._preDelete(); + if (this.companion) { this.companion.updateLevel(1); } diff --git a/module/data/actor/party.mjs b/module/data/actor/party.mjs index 06731246..18fe9959 100644 --- a/module/data/actor/party.mjs +++ b/module/data/actor/party.mjs @@ -36,6 +36,23 @@ export default class DhParty extends BaseDataActor { } } + async _preDelete() { + /* Clear all partyMembers from tagTeam setting.*/ + /* Revisit this when tagTeam is improved for many parties */ + const tagTeam = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll); + await tagTeam.updateSource({ + initiator: this.partyMembers.some(x => x.id === tagTeam.initiator) ? null : tagTeam.initiator, + members: Object.keys(tagTeam.members).reduce((acc, key) => { + if (this.partyMembers.find(x => x.id === key)) { + acc[`-=${key}`] = null; + } + + return acc; + }, {}) + }); + await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll, tagTeam); + } + _onDelete(options, userId) { super._onDelete(options, userId); diff --git a/module/data/fields/action/effectsField.mjs b/module/data/fields/action/effectsField.mjs index d9658736..2233a383 100644 --- a/module/data/fields/action/effectsField.mjs +++ b/module/data/fields/action/effectsField.mjs @@ -51,7 +51,7 @@ export default class EffectsField extends fields.ArrayField { let effects = this.effects; const messageTargets = []; targets.forEach(async baseToken => { - if (this.hasSave && token.saved.success === true) effects = this.effects.filter(e => e.onSave === true); + if (this.hasSave && baseToken.saved.success === true) effects = this.effects.filter(e => e.onSave === true); if (!effects.length) return; const token = diff --git a/module/systemRegistration/migrations.mjs b/module/systemRegistration/migrations.mjs index 00b07dc1..b3116459 100644 --- a/module/systemRegistration/migrations.mjs +++ b/module/systemRegistration/migrations.mjs @@ -191,6 +191,25 @@ export async function runMigrations() { lastMigrationVersion = '1.2.0'; } + + if (foundry.utils.isNewerVersion('1.2.7', lastMigrationVersion)) { + const tagTeam = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll); + const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator); + const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => { + if (!game.actors.some(actor => actor.id === id)) { + acc[`-=${id}`] = null; + } + return acc; + }, {}); + + await tagTeam.updateSource({ + initiator: initatorMissing ? null : tagTeam.initiator, + members: missingMembers + }); + await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll, tagTeam); + + lastMigrationVersion = '1.2.7'; + } //#endregion await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LastMigrationVersion, lastMigrationVersion); diff --git a/system.json b/system.json index bfcf2a31..4972a395 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "id": "daggerheart", "title": "Daggerheart", "description": "An unofficial implementation of the Daggerheart system", - "version": "1.2.6", + "version": "1.2.7", "compatibility": { "minimum": "13", "verified": "13.351",