Start vehicle automation

This commit is contained in:
sladecraven 2022-09-16 17:36:58 +02:00
parent ae697b0bb8
commit 9a20a96cec
12 changed files with 190 additions and 37 deletions

View File

@ -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
}
}

View File

@ -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.`)
}
}
}

View File

@ -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)
}

View File

@ -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"
}

View File

@ -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": {

View File

@ -848,8 +848,8 @@
<input type="text" class="" name="system.biodata.age" value="{{data.biodata.age}}" data-dtype="String" />
</li>
<li class="item flexrow">
<label class="generic-label">Height</label>
<input type="text" class="" name="system.biodata.size" value="{{data.biodata.size}}" data-dtype="String" />
<label class="generic-label">Height/Weight</label>
<input type="text" class="" name="system.biodata.weight" value="{{data.biodata.weight}}" data-dtype="String" />
</li>
<li class="item flexrow">
<label class="generic-label">Eyes</label>
@ -864,9 +864,9 @@
<div>
<ul>
<li class="flexrow item">
<label class="generic-label">Weight</label>
<input type="text" class="" name="system.biodata.weight" value="{{data.biodata.weight}}"
data-dtype="String" />
<label class="generic-label">Size</label>
<input type="text" class="" name="system.biodata.sizenum" value="{{data.biodata.sizenum}}"
data-dtype="Number" />
</li>
<li class="flexrow item">
<label class="generic-label">Sex</label>
@ -986,6 +986,14 @@
<label class="attribute-value checkbox"><input type="checkbox" class="change-desires"
name="system.biodata.desiresactive" {{checked data.biodata.desiresactive}} /> Active ?</label>
</li>
<li class="flexrow">
<label class="short-label">Morality : </label>
<input type="text" class="" name="system.biodata.morality" value="{{data.biodata.morality}}" data-dtype="Number" />
</li>
<li class="flexrow">
<label class="short-label">Morality threshold : </label>
<input type="text" class="" name="system.biodata.moralitythreshold" value="{{data.biodata.moralitythreshold}}" disabled data-dtype="Number" />
</li>
</ul>
<h3>Catchphrase : </h3>
@ -1026,14 +1034,6 @@
<label class="short-label">Bonus selection : </label>
<input type="text" class="" name="system.biodata.bonusselection" value="{{data.biodata.bonusselection}}" data-dtype="String" />
</li>
<li class="flexrow">
<label class="short-label">Morality : </label>
<input type="text" class="" name="system.biodata.morality" value="{{data.biodata.morality}}" data-dtype="Number" />
</li>
<li class="flexrow">
<label class="short-label">Morality threshold : </label>
<input type="text" class="" name="system.biodata.moralitythreshold" value="{{data.biodata.moralitythreshold}}" disabled data-dtype="Number" />
</li>
<li class="flexrow">
<label class="short-label">Hero Level (max) : </label>
<select class="status-small-label color-class-common" type="text" name="system.biodata.maxlevelremaining" value="{{data.biodata.maxlevelremaining}}" data-dtype="Number" {{#unless @root.editScore}}disabled{{/unless}}>

View File

@ -124,7 +124,7 @@
<input type="text" class="padd-right" name="system.deactivatedtext" value="{{data.deactivatedtext}}" data-dtype="String"/>
</li>
<li class="flexrow"><label class="generic-label">Power Level Cost</label>
<li class="flexrow"><label class="generic-label">PPP Used to Purchase</label>
<input type="text" class="input-numeric-short padd-right" name="system.powerlevelcost" value="{{data.powerlevelcost}}"
data-dtype="Number" />
</li>

View File

@ -29,7 +29,7 @@
<input type="text" class="" name="system.ad" value="{{data.ad}}" data-dtype="Number"/>
</li>
<li class="flexrow"><label class="generic-label">Top Speed (TS)</label>
<li class="flexrow"><label class="generic-label">Top Speed (TS) bonus</label>
<input type="text" class="" name="system.topspeed" value="{{data.topspeed}}" data-dtype="Number"/>
</li>

View File

@ -50,7 +50,7 @@
<label class="attribute-value checkbox"><input type="checkbox" name="system.activated" {{checked data.activated}}/></label>
</li>
<li class="flexrow"><label class="generic-label">NRG</label>
<li class="flexrow"><label class="generic-label">NRG Cost</label>
<input type="text" class="" name="system.nrg" value="{{data.nrg}}" data-dtype="Number"/>
</li>

View File

@ -19,7 +19,7 @@
<span class="item-name-label-long">&nbsp;</span>
<span class="item-field-label-long">
<select type="text" name="system.arcs.{{idx}}.topspeed" value="{{arc.topspeed}}" data-dtype="String">
<select type="text" name="system.arcs.{{idx}}.topspeed" value="{{arc.topspeed}}" data-dtype="String" disabled>
{{#select arc.topspeed}}
{{> systems/fvtt-pegasus-rpg/templates/partial-options-vehicle-speed.html}}
{{/select}}

View File

@ -9,7 +9,7 @@
data-stat-key="{{key}}">{{upper stat.abbrev}}</a></h4>
</span>
<select class="status-small-label color-class-common" type="text" name="system.statistics.{{key}}.level"
value="{{stat.level}}" data-dtype="Number" {{#unless @root.editScore}}disabled{{/unless}}>
value="{{stat.level}}" data-dtype="Number" disabled>
{{#select stat.level}}
{{{@root.optionsDiceList}}}
{{/select}}
@ -20,7 +20,7 @@
<select class="status-small-label color-class-common" type="text" name="system.statistics.{{key}}.currentlevel"
value="{{stat.currentlevel}}" data-dtype="Number" {{#unless @root.editScore}}disabled{{/unless}}>
{{#select stat.currentlevel}}
{{{@root.optionsLevel}}}
{{{@root.optionsDiceList}}}
{{/select}}
</select>
</div>
@ -30,7 +30,7 @@
<select class="status-small-label color-class-common" type="text" name="system.statistics.{{key}}.turningarc45"
value="{{stat.turningarc45}}" data-dtype="Number" {{#unless @root.editScore}}disabled{{/unless}}>
{{#select stat.turningarc45}}
{{{@root.optionsLevel}}}
{{{@root.optionsDiceList}}}
{{/select}}
</select>
</div>
@ -49,6 +49,10 @@
<input type="text" class="input-numeric-short" name="system.statistics.{{key}}.avgnrg" value="{{stat.avgnrg}}" data-dtype="Number" />
<span class="stat-label stat-margin" name="{{key}}">Cur NRG</span>
<input type="text" class="input-numeric-short" name="system.statistics.{{key}}.curnrg" value="{{stat.curnrg}}" data-dtype="Number" />
<span class="padd-right status-small-label no-grow">
<a class="vehicle-current-nrg-plus plus-minus-button">+</a>
<a class="vehicle-current-nrg-minus plus-minus-button">&nbsp;-</a>
</span>
</div>
{{/if}}

View File

@ -139,6 +139,7 @@
</li>
</ul>
</div>
</div>
<div class="flexrow">
@ -248,9 +249,25 @@
</div>
</div>
{{!-- Other Tab --}}
{{!-- Modules Tab --}}
<div class="tab items" data-group="primary" data-tab="modules">
<div class="stat-item">
<span class="flexrow">
<h3>VMS</h3>
</span>
<ul class="stat-list alternate-list">
<li class="item stat flexrow list-item">
<span class="generic-label small-label">Total</span>
<input type="text" class="" name="system.modules.totalvms" value="{{data.modules.totalvms}}"
data-dtype="Number" disabled />
<span class="generic-label small-label">Used</span>
<input type="text" class="" name="system.modules.vmsused" value="{{data.modules.vmsused}}"
data-dtype="Number" disabled />
</li>
</ul>
</div>
<ul class="stat-list alternate-list">
<li class="item flexrow list-item items-title-bg">
<span class="item-name-label-header-long">