From c0c6231b4c99e358ccf304ff7369bb72dcab6c4c Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 27 Sep 2022 16:45:07 +0200 Subject: [PATCH] Fix #51 --- modules/pegasus-actor.js | 76 +++++++++++++++++++++++++------------- modules/pegasus-utility.js | 2 +- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 7a134bd..741776e 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -14,18 +14,21 @@ const __statBuild = [ { modules: ["vehiclehull", "vehiclemodule"], field: "hr", itemfield: "size", subfield: "size" }, //{ modules: ["vehiclehull"], field: "pc", itemfield: "vms", subfield: "avgnrg" }, //{ modules: ["powercoremodule"], field: "pc", itemfield: "nrg", subfield: "avgnrg" }, - { modules: ["vehiclehull", "mobilitymodule"], itemfield: "man", field: "man", additionnal1: "turningarc45"}, + { modules: ["vehiclehull", "mobilitymodule"], itemfield: "man", field: "man", additionnal1: "turningarc45" }, { modules: ["powercoremodule"], field: "pc", itemfield: "pc", additionnal1: "curnrg", additionnal2: "maxnrg" }, { modules: ["mobilitymodule"], field: "mr", itemfield: "mr" }, { modules: ["propulsionmodule"], field: "ad", itemfield: "ad" }, { modules: ["combatmodule"], field: "fc", itemfield: "fc" }, ] +const __LocationsArmour = ["front", "rear", "bottom", "left", "right", "bottom"] const __isVehicleUnique = { vehiclehull: 1, powercoremodule: 1, mobilitymodule: 1, propulsionmodule: 1, combatmodule: 1 } const __speed2Num = { fullstop: 0, crawling: 1, slow: 2, average: 3, fast: 4, extfast: 5 } const __num2speed = ["fullstop", "crawling", "slow", "average", "fast", "extfast"] -const __isVehicle = { vehiclehull: 1, powercoremodule: 1, mobilitymodule: 1, combatmodule: 1, - propulsionmodule: 1, vehiclemodule: 1, vehicleweaponmodule: 1, effect: 1, cargo: 1 } -const __isVehicleCargo = {cargo: 1} +const __isVehicle = { + vehiclehull: 1, powercoremodule: 1, mobilitymodule: 1, combatmodule: 1, + propulsionmodule: 1, vehiclemodule: 1, vehicleweaponmodule: 1, effect: 1, cargo: 1 +} +const __isVehicleCargo = { cargo: 1 } const __bonusEffect = { name: "Crawling MAN Bonus", type: "effect", img: "systems/fvtt-pegasus-rpg/images/icons/icon_effect.webp", system: { @@ -2006,9 +2009,10 @@ export class PegasusActor extends Actor { } // Destroyed - if ( this.system.statistics.hr.currentlevel == 0) { - ChatMessage.create({ content: `The vehicle ${this.name} has been destroyed !`} ) + if (this.system.statistics.hr.currentlevel == 0) { + ChatMessage.create({ content: `The vehicle ${this.name} has been destroyed !` }) } + } } @@ -2054,20 +2058,42 @@ export class PegasusActor extends Actor { return false } } - if( __isVehicleCargo[item.type]) { + // Cargo management + if (__isVehicleCargo[item.type]) { let capacity = this.getCurrentCargoCapacity() - if ( item.type == "cargo") { + if (item.type == "cargo") { capacity += Number(item.system.capacity) } else { - let q = item.system.quantity || 1 + let q = item.system.quantity || 1 capacity += Number(q) * Number(item.system.weight) } console.log("capa", capacity, this.system.cargo.cargocapacity) - if ( capacity > this.system.cargo.cargocapacity) { + if (capacity > this.system.cargo.cargocapacity) { ui.notifications.warn("Your cargo capacity is already full, unable to add this content : " + item.name) return false } } + + // 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) + } + } + //console.log(">>>> AMROR, ", level, arc.armourlevel) + if (level != Number(arc.armourlevel)) { + arc.armourlevel = level + setTimeout(500, this.update({ [`system.arcs.${arcKey}`]: arc })) + } + } + + return true } @@ -2163,7 +2189,7 @@ export class PegasusActor extends Actor { this.addVehicleShields(rollData) this.startRoll(rollData) - this.modifyVehicleStun( 1 ) + this.modifyVehicleStun(1) } } @@ -2171,22 +2197,22 @@ export class PegasusActor extends Actor { activateVehicleModule(itemId) { let mod = this.items.get(itemId) if (mod) { - if ( mod.system.nrg && mod.system.nrg > 0) { - let pc = duplicate( this.system.statistics.pc) - if ( !mod.system.activated ) { // Previous state was non activated -> activated now - if ( mod.system.nrg > pc.curnrg) { - ChatMessage.create( { content: `The Vehicle ${this.name} does not have enough Energy to Activate this module at this time.`}) + if (mod.system.nrg && mod.system.nrg > 0) { + let pc = duplicate(this.system.statistics.pc) + if (!mod.system.activated) { // Previous state was non activated -> activated now + if (mod.system.nrg > pc.curnrg) { + ChatMessage.create({ content: `The Vehicle ${this.name} does not have enough Energy to Activate this module at this time.` }) return } this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }]) pc.actnrg += Number(mod.system.nrg) pc.maxnrg -= Number(mod.system.nrg) pc.curnrg -= Number(mod.system.nrg) - this.update({'system.statistics.pc': pc}) - } else { // Now deactivated + this.update({ 'system.statistics.pc': pc }) + } else { // Now deactivated pc.actnrg -= Number(mod.system.nrg) pc.maxnrg += Number(mod.system.nrg) - this.update({'system.statistics.pc': pc}) + this.update({ 'system.statistics.pc': pc }) this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }]) } } else { @@ -2196,23 +2222,23 @@ export class PegasusActor extends Actor { } /* -------------------------------------------- */ - setTurningArc( currentLevel) { - this.update( { 'system.statistics.man.turningarc45': currentLevel }) + setTurningArc(currentLevel) { + this.update({ 'system.statistics.man.turningarc45': currentLevel }) } /* -------------------------------------------- */ - getCurrentCargoCapacity( ) { + getCurrentCargoCapacity() { let capacity = 0 for (let cargo of this.items) { - if (cargo.type == "equipment" || cargo.type == "weapon" || cargo.type == "armor" || cargo.type == "money" || cargo.type == "shield" ) { + if (cargo.type == "equipment" || cargo.type == "weapon" || cargo.type == "armor" || cargo.type == "money" || cargo.type == "shield") { let q = cargo.system.quantity || 1 capacity += Number(q) * Number(cargo.system.weight) } - if (cargo.type == "cargo" ) { + if (cargo.type == "cargo") { capacity += Number(cargo.system.capacity) } } return capacity } - + } diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index c840ddb..1183eb6 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -995,7 +995,7 @@ export class PegasusUtility { icon: '', label: "Yes, remove it", callback: () => { - actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]); + actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]) li.slideUp(200, () => actorSheet.render(false)); } },