From 7977233d9340b6b8b941c9d590831108e98d833c Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 28 Sep 2022 16:27:16 +0200 Subject: [PATCH] #68 : Process stat effects automatically --- modules/pegasus-actor.js | 26 +++++++++++++++++++++++-- modules/pegasus-utility.js | 7 +++++++ template.json | 16 +++++++++++++++ templates/partial-actor-stat-block.html | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index c9e7bd5..9fe29e1 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -1330,6 +1330,25 @@ export class PegasusActor extends Actor { this.system.combat.hindrancedice = hindrance this.getTraumaState() this.cleanupPerksIfTrauma() + this.parseStatEffects() + } + } + + /* -------------------------------------------- */ + parseStatEffects() { + let effects = this.items.filter(effect => effect.type == "effect" && effect.system.genre == "positive" && effect.system.statdice ) + for (let statKey in this.system.statistics) { + let stat = duplicate(this.system.statistics[statKey]) + let bonus = 0 + for (let effect of effects) { + if (effect.system.stataffected == statKey) { + bonus += Number(effect.system.effectlevel) + } + } + if ( bonus != stat.bonuseffect) { + stat.bonuseffect = bonus + this.update( { [`system.statistics.${statKey}`]: stat} ) + } } } @@ -1568,7 +1587,7 @@ export class PegasusActor extends Actor { let effects = this.items.filter(item => item.type == 'effect') for (let effect of effects) { effect = duplicate(effect) - if (!effect.system.hindrance + if (!effect.system.hindrance && !effect.system.statdice && (effect.system.stataffected != "notapplicable" || effect.system.specaffected.length > 0) && effect.system.stataffected != "special" && effect.system.stataffected != "powerroll" @@ -1660,7 +1679,10 @@ export class PegasusActor extends Actor { if (statKey) { rollData.statKey = statKey rollData.stat = this.getStat(statKey) - rollData.statDicesLevel = rollData.stat.value || rollData.stat.level + if ( rollData.stat.value != undefined ) { + rollData.stat.level = rollData.stat.value // Normalize + } + rollData.statDicesLevel = rollData.stat.level + rollData.stat.bonuseffect rollData.statMod = rollData.stat.mod if (vehicle) { rollData.vehicle = duplicate(vehicle) diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 8e31c5e..2393be0 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -59,6 +59,13 @@ export class PegasusUtility { Handlebars.registerHelper('mul', function (a, b) { return parseInt(a) * parseInt(b); }) + Handlebars.registerHelper('add', function (a, b) { + return parseInt(a) + parseInt(b); + }); + Handlebars.registerHelper('sub', function (a, b) { + return parseInt(a) - parseInt(b); + }) + } /* -------------------------------------------- */ diff --git a/template.json b/template.json index 48ad441..82effbc 100644 --- a/template.json +++ b/template.json @@ -49,6 +49,7 @@ "abbrev": "AGI", "level": 1, "value": 1, + "bonuseffect": 0, "mod": 0, "col": 1 }, @@ -57,6 +58,7 @@ "abbrev": "MND", "level": 1, "value": 1, + "bonuseffect": 0, "col": 1, "mod": 0 }, @@ -65,6 +67,7 @@ "abbrev": "SOC", "level": 1, "value": 1, + "bonuseffect": 0, "col": 1, "mod": 0 }, @@ -73,6 +76,7 @@ "abbrev": "STR", "level": 1, "value": 1, + "bonuseffect": 0, "col": 1, "mod": 0 }, @@ -81,6 +85,7 @@ "abbrev": "PHY", "level": 1, "value": 1, + "bonuseffect": 0, "col": 1, "mod": 0 }, @@ -89,6 +94,7 @@ "abbrev": "COM", "level": 1, "value": 1, + "bonuseffect": 0, "col": 2, "mod": 0 }, @@ -97,6 +103,7 @@ "abbrev": "DEF", "level": 1, "value": 1, + "bonuseffect": 0, "col": 2, "mod": 0 }, @@ -105,6 +112,7 @@ "abbrev": "STL", "level": 1, "value": 1, + "bonuseffect": 0, "col": 2, "mod": 0 }, @@ -113,6 +121,7 @@ "abbrev": "PER", "level": 1, "value": 1, + "bonuseffect": 0, "col": 2, "mod": 0 }, @@ -121,6 +130,7 @@ "abbrev": "FOC", "level": 1, "value": 1, + "bonuseffect": 0, "col": 2, "mod": 0 } @@ -208,6 +218,7 @@ "label": "FC", "abbrev": "fc", "level": 0, + "bonuseffect": 0, "currentlevel": 0, "col": 1 }, @@ -216,6 +227,7 @@ "abbrev": "man", "dicevalue": "", "level": 0, + "bonuseffect": 0, "currentlevel": 0, "turningarc45": 0, "col": 1 @@ -224,6 +236,7 @@ "label": "HR", "abbrev": "hr", "level": 0, + "bonuseffect": 0, "currentlevel": 0, "size": 0, "col": 2 @@ -232,6 +245,7 @@ "label": "PC", "abbrev": "pc", "level": 0, + "bonuseffect": 0, "currentlevel": 0, "actnrg": 0, "curnrg": 0, @@ -242,6 +256,7 @@ "label": "MR", "abbrev": "mr", "level": 0, + "bonuseffect": 0, "currentlevel": 0, "col": 3 }, @@ -249,6 +264,7 @@ "label": "A/D", "abbrev": "ad", "level": 0, + "bonuseffect": 0, "currentlevel": 0, "accmode": "", "currentspeed": "", diff --git a/templates/partial-actor-stat-block.html b/templates/partial-actor-stat-block.html index dd47241..5763401 100644 --- a/templates/partial-actor-stat-block.html +++ b/templates/partial-actor-stat-block.html @@ -7,7 +7,7 @@