diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 6c8ab36..44b1663 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -9,8 +9,21 @@ const __subkey2title = { "melee-dmg": "Melee Damage", "melee-atk": "Melee Attack", "ranged-atk": "Ranged Attack", "ranged-dmg": "Ranged Damage", "dmg-res": "Damare Resistance" } +const __statBuild = [ + { modules: ["vehiclehull"], field: "hr", itemfield: "hr" }, + { 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" }, + { modules: ["powercoremodule"], field: "pc", itemfield: "pc", }, + { modules: ["mobilitymodule"], field: "mr", itemfield: "mr", }, + { modules: ["propulsionmodule"], field: "ad", itemfield: "ad", }, + { modules: ["combatmodule"], field: "fc", itemfield: "fc", }, +] +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"] -/* -------------------------------------------- */ /* -------------------------------------------- */ /** * Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system. @@ -71,7 +84,9 @@ export class PegasusActor extends Actor { this.system.encCapacity = this.getEncumbranceCapacity() this.buildContainerTree() } - + if (this.type == 'vehicle') { + this.computeVehicleStats(); + } super.prepareDerivedData(); } @@ -613,6 +628,7 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ async preprocessItem(event, item, onDrop = false) { + // Pre-filter effects if (item.type == 'effect') { if (this.checkMentalDisruption() && item.system.type == "mental" && item.system.genre == "positive") { @@ -897,10 +913,18 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ incDecNRG(value) { - let nrg = duplicate(this.system.nrg) - nrg.value += value - if (nrg.value >= 0 && nrg.value <= nrg.max) { - this.update({ 'data.nrg': nrg }) + if (this.type == "character") { + let nrg = duplicate(this.system.nrg) + nrg.value += value + if (nrg.value >= 0 && nrg.value <= nrg.max) { + this.update({ 'data.nrg': nrg }) + } + } else { + let pc = duplicate(this.system.statistics.pc) + pc.curnrg += value + if (pc.curnrg >= 0) { + this.update({ 'system.statistics.pc': pc }) + } } } @@ -1135,11 +1159,10 @@ export class PegasusActor extends Actor { } } + /* -------------------------------------------- */ async computeNRGHealth() { - if (this.type == "vehicle") { - return - } + if (this.isOwner || game.user.isGM) { let updates = {} let phyDiceValue = PegasusUtility.getDiceValue(this.system.statistics.phy.value) + this.system.secondary.health.bonus + this.system.statistics.phy.mod; @@ -1760,4 +1783,111 @@ export class PegasusActor extends Actor { this.update({ 'stun.value': stun }) } + /* -------------------------------------------- */ + addTopSpeedBonus( topspeed, bonus) { + let num = __speed2Num[topspeed] + Number(bonus) + num = Math.max(0, num) + num = Math.min(num, __num2speed.length-1) + return __num2speed[num] + } + + /* -------------------------------------------- */ + async computeVehicleStats() { + + if (this.type == "vehicle") { + + for (let statDef of __statBuild) { + let sum = 0 + let list = [] + for (let moduleType of statDef.modules) { + list = list.concat(this.items.filter(item => item.type == moduleType)) + } + if (list && list.length > 0) { + sum = list.reduce((value, item2) => value + Number(item2.system[statDef.itemfield]), 0) + } + //console.log("Processing", statDef.field, this.system.statistics[statDef.field].level, list, sum) + if (statDef.subfield){ + if (sum != Number(this.system.statistics[statDef.field][statDef.subfield])) { + //console.log("Update", statDef.field, statDef.subfield, sum, this.system.statistics[statDef.field][statDef.subfield]) + this.update({ [`system.statistics.${statDef.field}.${statDef.subfield}`]: sum } ) + } + } else { + if (sum != Number(this.system.statistics[statDef.field].level)) { + this.update({ [`system.statistics.${statDef.field}.level`]: sum, [`system.statistics.${statDef.field}.currentlevel`]: sum }) + } + } + } + + // Top speed management + let mobility = this.items.find( item => item.type == "mobilitymodule") + let arcs = duplicate(this.system.arcs) + if (mobility) { + let propulsion = this.items.find( item => item.type == "propulsionmodule") + let bonus = (propulsion) ? propulsion.system.topspeed : 0 + arcs.frontarc.topspeed = this.addTopSpeedBonus(mobility.system.ts_f, bonus) + arcs.rightarc.topspeed = mobility.system.ts_s + arcs.leftarc.topspeed = mobility.system.ts_s + arcs.toparc.topspeed = mobility.system.ts_s + arcs.bottomarc.topspeed = mobility.system.ts_s + arcs.reararc.topspeed = mobility.system.ts_r + } else { + arcs.frontarc.topspeed = "fullstop" + arcs.rightarc.topspeed = "fullstop" + arcs.leftarc.topspeed = "fullstop" + arcs.toparc.topspeed = "fullstop" + arcs.bottomarc.topspeed = "fullstop" + arcs.reararc.topspeed = "fullstop" + } + for (let key in this.system.arcs) { + if (this.system.arcs[key].topspeed != arcs[key].topspeed) { + this.update( { 'system.arcs': arcs}) + } + } + + // VMS management + let hull = this.items.find( item => item.type == "vehiclehull") + let modules = duplicate(this.system.modules) + if (hull ) { + modules.totalvms = Number(hull.system.vms) + } else { + modules.totalvms = 0 + } + let spaceList = this.items.filter(item => item.type == "vehiclemodule") || [] + spaceList = spaceList.concat(this.items.filter(item => item.type == "vehicleweaponmodule") || []) + let space = 0 + if (spaceList && spaceList.length> 0) { + space = spaceList.reduce((value, item2) => value + Number(item2.system.space), 0) + } + modules.usedvms = space + if ( modules.totalvms != this.system.modules.totalvms || modules.usedvms != this.system.modules.usedvms) { + this.update( {'system.modules': modules}) + } + if (modules.usedvms > modules.totalvms ) { + ui.notifications.warn("Warning! No more space available in cargo !!") + } + + } + + // Manage top speed + } + + /* -------------------------------------------- */ + async preprocessItemVehicle(event, item, onDrop = false) { + //console.log(">>>>> item", item.type, __isVehicleUnique[item.type]) + if ( __isVehicleUnique[item.type] ) { + let toDelList = [] + for (let toDel of this.items) { + if ( toDel.type == item.type) { + toDelList.push( toDel.id ) + } + } + //console.log("TODEL : ", toDelList) + if ( toDelList.length > 0 ) { + await this.deleteEmbeddedDocuments('Item', toDelList) + } + } + + return true + } + } diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 00bc077..3049e2e 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -399,7 +399,7 @@ export class PegasusUtility { this.rollPegasus(rollData) character.modifyHeroLevelRemaining(-1) } else { - ui.notifications.warn(`No more Hero Level for ${actor.name} ! Unable to reroll.`) + ui.notifications.warn(`No more Hero Level for ${character.name} ! Unable to reroll.`) } } } diff --git a/modules/pegasus-vehicle-sheet.js b/modules/pegasus-vehicle-sheet.js index 786f490..f4f2ff1 100644 --- a/modules/pegasus-vehicle-sheet.js +++ b/modules/pegasus-vehicle-sheet.js @@ -156,10 +156,10 @@ export class PegasusVehicleSheet extends ActorSheet { const li = $(event.currentTarget).parents(".item"); this.actor.incDecQuantity( li.data("item-id"), +1 ); } ) - html.find('.current-nrg-minus').click(event => { + html.find('.vehicle-current-nrg-minus').click(event => { this.actor.incDecNRG( -1 ); } ) - html.find('.current-nrg-plus').click(event => { + html.find('.vehicle-current-nrg-plus').click(event => { this.actor.incDecNRG( 1 ); } ) @@ -286,7 +286,7 @@ export class PegasusVehicleSheet extends ActorSheet { if (item == undefined) { item = this.actor.items.get( dragData.uuid ) } - let ret = await this.actor.preprocessItem( event, item, true ) + let ret = await this.actor.preprocessItemVehicle( event, item, true ) if ( ret ) { super._onDropItem(event, dragData) } diff --git a/system.json b/system.json index b326e5c..440ab05 100644 --- a/system.json +++ b/system.json @@ -1,6 +1,6 @@ { "description": "Pegasus RPG system for FoundryVTT", - "download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v10.0.6.zip", + "download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v10.0.8.zip", "esmodules": [ "modules/pegasus-main.js" ], @@ -254,6 +254,6 @@ ], "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "10.0.6", + "version": "10.0.8", "background": "systems/fvtt-pegasus-rpg/images/ui/pegasus_welcome_page.webp" } \ No newline at end of file diff --git a/template.json b/template.json index d04529f..5bd0305 100644 --- a/template.json +++ b/template.json @@ -10,6 +10,7 @@ "name": "", "age": 0, "size": "", + "sizenum": 0, "weight": "", "hair": "", "sex": "", @@ -265,7 +266,7 @@ "activatedmoduleenergy": 0, "vdp": 0, "vehiculevalue": 0, - "availablevms": 0, + "totalvms": 0, "vmsused": 0, "totalcost": 0 }, @@ -675,6 +676,7 @@ "range": "", "idr": "", "cost": 0, + "size": 0, "space": 0 }, "vehicleweaponmodule": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 1c092b5..2a66b6d 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -848,8 +848,8 @@
  • - - + +
  • @@ -864,9 +864,9 @@

    Catchphrase :

    @@ -1026,14 +1034,6 @@
  • -
  • - - -
  • -
  • - - -
  • -
  • +
  • diff --git a/templates/item-propulsionmodule-sheet.html b/templates/item-propulsionmodule-sheet.html index 1f34c5a..6a4f5c6 100644 --- a/templates/item-propulsionmodule-sheet.html +++ b/templates/item-propulsionmodule-sheet.html @@ -29,7 +29,7 @@ -
  • +
  • diff --git a/templates/item-vehiclemodule-sheet.html b/templates/item-vehiclemodule-sheet.html index 2414462..013b5f3 100644 --- a/templates/item-vehiclemodule-sheet.html +++ b/templates/item-vehiclemodule-sheet.html @@ -50,7 +50,7 @@ -
  • +
  • diff --git a/templates/partial-vehicle-arc.html b/templates/partial-vehicle-arc.html index 9647868..937bf3d 100644 --- a/templates/partial-vehicle-arc.html +++ b/templates/partial-vehicle-arc.html @@ -19,7 +19,7 @@   - {{#select arc.topspeed}} {{> systems/fvtt-pegasus-rpg/templates/partial-options-vehicle-speed.html}} {{/select}} diff --git a/templates/partial-vehicle-stat-block.html b/templates/partial-vehicle-stat-block.html index 8736122..1712089 100644 --- a/templates/partial-vehicle-stat-block.html +++ b/templates/partial-vehicle-stat-block.html @@ -9,7 +9,7 @@ data-stat-key="{{key}}">{{upper stat.abbrev}} {{#select stat.currentlevel}} - {{{@root.optionsLevel}}} + {{{@root.optionsDiceList}}} {{/select}} @@ -30,7 +30,7 @@ @@ -49,6 +49,10 @@ Cur NRG + + + +  - + {{/if}} diff --git a/templates/vehicle-sheet.html b/templates/vehicle-sheet.html index 8ecb91d..81a609e 100644 --- a/templates/vehicle-sheet.html +++ b/templates/vehicle-sheet.html @@ -139,6 +139,7 @@ +
    @@ -248,9 +249,25 @@
    - {{!-- Other Tab --}} + {{!-- Modules Tab --}}
    +
    + +

    VMS

    +
    + +
    +