diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 2de2da6..64f3944 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -4,7 +4,7 @@ import { PegasusRollDialog } from "./pegasus-roll-dialog.js"; /* -------------------------------------------- */ const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entrenchedcover": 6 }; - +const statThreatLevel = [ "agi", "str", "phy", "com", "def", "per" ] /* -------------------------------------------- */ /* -------------------------------------------- */ /** @@ -295,6 +295,47 @@ export class PegasusActor extends Actor { return duplicate(this.data.items.filter(item => item.type == "equipment") || []) } + /* ------------------------------------------- */ + computeThreatLevel() { + let tl = 0 + for(let key of statThreatLevel) { // Init with concerned stats + tl += PegasusUtility.getDiceValue( this.data.data.statistics[key].value ) + } + let powers = this.getPowers() + if ( powers && powers.length > 0 ) { // Then add some mental ones of powers + tl += PegasusUtility.getDiceValue( this.data.data.statistics.foc.value ) + tl += PegasusUtility.getDiceValue( this.data.data.statistics.mnd.value ) + } + tl += PegasusUtility.getDiceValue( this.data.data.mr.value ) + let specThreat = this.data.items.filter( it => it.type == "specialisation" && it.data.data.isthreatlevel) || [] + for (let spec of specThreat) { + tl += PegasusUtility.getDiceValue( spec.data.data.level ) + } + tl += this.data.data.nrg.absolutemax + this.data.data.secondary.health.max + this.data.data.secondary.delirium.max + tl += this.getPerks().length * 5 + + let weapons = this.getWeapons() + for(let weapon of weapons) { + tl += PegasusUtility.getDiceValue(weapon.data.damage) + } + let armors = this.getArmors() + for(let armor of armors) { + tl += PegasusUtility.getDiceValue(armor.data.resistance) + } + let shields = this.getShields() + for(let shield of shields) { + tl += PegasusUtility.getDiceValue(shield.data.level) + } + + let equipments = this.getEquipmentsOnly() + for (let equip of equipments) { + tl += equip.data.threatlevel + } + if ( tl != this.data.data.biodata.threatlevel) { + this.update( {'data.biodata.threatlevel': tl} ) + } + } + /* ------------------------------------------- */ async buildContainerTree() { let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || []) @@ -305,7 +346,8 @@ export class PegasusActor extends Actor { for (let equip2 of equipments) { if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) { equip1.data.contents.push(equip2) - equip1.data.contentsEnc += equip2.data.weight + let q = equip2.data.quantity ?? 1 + equip1.data.contentsEnc += q *equip2.data.weight } } } @@ -319,13 +361,15 @@ export class PegasusActor extends Actor { if (item.data.iscontainer) { enc += item.data.contentsEnc } else if (item.data.containerid == "") { - enc += item.data.weight + let q = item.data.quantity ?? 1 + enc += q * item.data.weight } } } for (let item of this.data.items) { // Process items/shields/armors if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.data.data.equipped) { - enc += item.data.data.weight + let q = item.data.data.quantity ?? 1 + enc += q * item.data.data.weight } } @@ -826,6 +870,8 @@ export class PegasusActor extends Actor { } //console.log("UPD", updates, this.data.data.biodata) await this.update(updates) + + this.computeThreatLevel() } if (this.isOwner || game.user.isGM) { @@ -875,8 +921,10 @@ export class PegasusActor extends Actor { async incDecQuantity(objetId, incDec = 0) { let objetQ = this.data.items.get(objetId) if (objetQ) { - let newQ = objetQ.data.data.quantity + incDec; - const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]); // pdates one EmbeddedEntity + let newQ = objetQ.data.data.quantity + incDec + if (newQ >= 0) { + const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]) // pdates one EmbeddedEntity + } } } /* -------------------------------------------- */ diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 75e2191..d0300fd 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -31,24 +31,26 @@ export class PegasusUtility { Handlebars.registerHelper('count', function (list) { return list.length; - }); + }) Handlebars.registerHelper('includes', function (array, val) { return array.includes(val); - }); + }) Handlebars.registerHelper('upper', function (text) { return text.toUpperCase(); - }); + }) Handlebars.registerHelper('lower', function (text) { return text.toLowerCase() - }); + }) Handlebars.registerHelper('upperFirst', function (text) { if (typeof text !== 'string') return text return text.charAt(0).toUpperCase() + text.slice(1) - }); + }) Handlebars.registerHelper('notEmpty', function (list) { return list.length > 0; - }); - + }) + Handlebars.registerHelper('mul', function (a, b) { + return parseInt(a) * parseInt(b); + }) } /* -------------------------------------------- */ diff --git a/system.json b/system.json index 91c9a13..ed5ba5c 100644 --- a/system.json +++ b/system.json @@ -180,9 +180,9 @@ "styles": [ "styles/simple.css" ], - "templateVersion": 87, + "templateVersion": 88, "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "0.5.6", + "version": "0.5.7", "background" : "./images/ui/pegasus_welcome_page.webp" } diff --git a/template.json b/template.json index cbe07e7..d01a0f5 100644 --- a/template.json +++ b/template.json @@ -269,6 +269,7 @@ "powersource": "", "powersactivated": false, "powers": [], + "isthreatlevel": false, "description": "" }, "perk": { @@ -384,6 +385,7 @@ "iscontainer": false, "containercapacity": 0, "containerid": "", + "threatlevel": 0, "description":"" }, "money" : { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index c52cdc7..efa57a7 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -526,7 +526,7 @@ - + @@ -548,11 +548,11 @@ {{#if (gt weapon.data.ammomax 0)}} -