From 65d0b181916419e9c33f472b6f5c65956c2b21ad Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 28 Sep 2022 13:48:50 +0200 Subject: [PATCH] Fix #53 --- modules/pegasus-actor.js | 43 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 51e5c29..878aa16 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -2032,7 +2032,7 @@ export class PegasusActor extends Actor { if (this.system.statistics.hr.currentlevel == 0) { ChatMessage.create({ content: `The vehicle ${this.name} has been destroyed !` }) } - + this.processVehicleArmorShields() } } @@ -2094,24 +2094,6 @@ export class PegasusActor extends Actor { } } - // Armour management - if (item.type == "vehiclemodule" && item.system.category == "armor") { - let armorsList = this.items.filter(item => item.type == "vehiclemodule" && item.system.category == "armor") || [] - armorsList.push(item) - let arcKey = item.system.location + "arc" - let arc = duplicate(this.system.arcs[arcKey]) - let level = 0 - for (let armour of armorsList) { - if (armour.system.armourdicevalue > 0) { - level += Number(armour.system.armourdicevalue) - } - } - if (level != Number(arc.armourlevel)) { - arc.armourlevel = level - setTimeout(500, this.update({ [`system.arcs.${arcKey}`]: arc })) - } - } - return true } @@ -2249,6 +2231,12 @@ export class PegasusActor extends Actor { await this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }]) } } + + this.processVehicleArmorShields() + } + + /* -------------------------------------------- */ + processVehicleArmorShields() { // Shield management let shieldsList = this.items.filter(item => item.type == "vehiclemodule" && item.system.category == "shield" && item.system.activated) || [] let level = 0 @@ -2267,6 +2255,23 @@ export class PegasusActor extends Actor { shift += 200 } } + + // Armour management + let armorsList = this.items.filter(item => item.type == "vehiclemodule" && item.system.category == "armor" && item.system.activated) || [] + for (let loc of __LocationsArmour) { + let arcKey = loc + "arc" + let arc = duplicate(this.system.arcs[arcKey]) + let level = 0 + for (let armour of armorsList) { + if (armour.system.location == loc && armour.system.armourdicevalue > 0) { + level += Number(armour.system.armourdicevalue) + } + } + if (level != Number(arc.armourlevel)) { + arc.armourlevel = level + setTimeout(500, this.update({ [`system.arcs.${arcKey}`]: arc })) + } + } } /* -------------------------------------------- */