From 7d05ef495bdee1868fbfbbf0db0906e2693f111e Mon Sep 17 00:00:00 2001 From: sladecraven Date: Thu, 6 Oct 2022 19:04:53 +0200 Subject: [PATCH] Fix #112 shield/armors for arc --- modules/pegasus-actor.js | 35 ++++++++++++++++++++++++++++++++ modules/pegasus-vehicle-sheet.js | 14 +------------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 09fd40b..41f546e 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -2487,6 +2487,34 @@ export class PegasusActor extends Actor { } } + /* -------------------------------------------- */ + async addVehicleModuleEffects( mod) { + let effects = [] + for (let effect of mod.system.effects) { + if (!effect.system) { + effect.system = effect.data + } + effect.system.effectId = mod.id // Link to the perk, in order to dynamically remove them + effects.push(effect) + } + if (effects.length) { + await this.createEmbeddedDocuments('Item', effects) + } + } + /* -------------------------------------------- */ + async removeVehicleModuleEffects( mod) { + let toRem = [] + for (let item of this.items) { + if (item.type == 'effect' && item.system.effectId == mod.id) { + toRem.push(item.id) + } + } + console.log("TODEL", toRem) + if (toRem.length) { + await this.deleteEmbeddedDocuments('Item', toRem) + } + } + /* -------------------------------------------- */ async activateVehicleModule(itemId) { let mod = this.items.get(itemId) @@ -2503,13 +2531,20 @@ export class PegasusActor extends Actor { pc.maxnrg -= Number(mod.system.nrg) pc.curnrg -= Number(mod.system.nrg) this.update({ 'system.statistics.pc': pc }) + this.addVehicleModuleEffects(mod) } else { // Now deactivated pc.actnrg -= Number(mod.system.nrg) pc.maxnrg += Number(mod.system.nrg) this.update({ 'system.statistics.pc': pc }) await this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }]) + this.removeVehicleModuleEffects(mod) } } else { + if ( mod.system.activated) { + this.removeVehicleModuleEffects(mod) + } else { + this.addVehicleModuleEffects(mod) + } await this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }]) } } diff --git a/modules/pegasus-vehicle-sheet.js b/modules/pegasus-vehicle-sheet.js index ef20762..45f4be2 100644 --- a/modules/pegasus-vehicle-sheet.js +++ b/modules/pegasus-vehicle-sheet.js @@ -134,19 +134,7 @@ export class PegasusVehicleSheet extends ActorSheet { let itemId = li.data("item-id") this.actor.activateVehicleModule( itemId) }); - - html.find('.equip-activate').click(ev => { - const li = $(ev.currentTarget).parents(".item") - let itemId = li.data("item-id") - this.actor.equipActivate( itemId) - }); - html.find('.equip-deactivate').click(ev => { - const li = $(ev.currentTarget).parents(".item") - let itemId = li.data("item-id") - this.actor.equipDeactivate( itemId) - }); - - html.find('.effect-used').click(ev => { + html.find('.effect-used').click(ev => { const li = $(ev.currentTarget).parents(".item"); let itemId = li.data("item-id"); this.actor.perkEffectUsed( itemId)