From e8e32d6f4e42a38eb6664f7211377a834e683c71 Mon Sep 17 00:00:00 2001 From: Peter Hunnisett <29824554+phBalance@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:45:04 -0700 Subject: [PATCH 1/6] refactor(strength): turn into if else if chain --- module/actor/actor.mjs | 243 +++++++++++++++++------------------------ 1 file changed, 102 insertions(+), 141 deletions(-) diff --git a/module/actor/actor.mjs b/module/actor/actor.mjs index 163ccb27..11047354 100644 --- a/module/actor/actor.mjs +++ b/module/actor/actor.mjs @@ -659,178 +659,139 @@ export class HeroSystem6eActor extends Actor { strDetails(str) { let strLiftText = "0"; let strRunningThrow = 0; - let value = str || this.system.characteristics.str?.value; - if (value >= 1) { - strLiftText = "8kg"; - strRunningThrow = 2; - } - if (value >= 2) { - strLiftText = "16kg"; - strRunningThrow = 3; - } - if (value >= 3) { - strLiftText = "25kg"; - strRunningThrow = 4; - } - if (value >= 4) { - strLiftText = "38kg"; - strRunningThrow = 6; - } - if (value >= 5) { - strLiftText = "50kg"; - strRunningThrow = 8; - } - if (value >= 8) { - strLiftText = "75kg"; - strRunningThrow = 12; - } - if (value >= 10) { - strLiftText = "100kg"; - strRunningThrow = 16; - } - if (value >= 13) { - strLiftText = "150kg"; - strRunningThrow = 20; - } - if (value >= 15) { - strLiftText = "200kg"; - strRunningThrow = 24; - } - if (value >= 18) { - strLiftText = "300kg"; - strRunningThrow = 28; - } - if (value >= 20) { - strLiftText = "400kg"; - strRunningThrow = 32; - } - if (value >= 23) { - strLiftText = "600kg"; - strRunningThrow = 36; - } - if (value >= 25) { - strLiftText = "800kg"; - strRunningThrow = 40; - } - if (value >= 28) { - strLiftText = "1,200kg"; - strRunningThrow = 44; - } - if (value >= 30) { - strLiftText = "1,600kg"; - strRunningThrow = 48; - } - if (value >= 35) { - strLiftText = "3,200kg"; - strRunningThrow = 56; - } - if (value >= 40) { - strLiftText = "6,400kg"; - strRunningThrow = 64; - } - if (value >= 45) { - strLiftText = "12.5 tons"; - strRunningThrow = 72; - } - if (value >= 50) { - strLiftText = "25 tons"; - strRunningThrow = 80; - } - if (value >= 55) { - strLiftText = "50 tons"; - strRunningThrow = 88; - } - if (value >= 60) { - strLiftText = "100 tons"; - strRunningThrow = 96; - } - if (value >= 65) { - strLiftText = "200 tons"; - strRunningThrow = 104; - } - if (value >= 70) { - strLiftText = "400 tons"; - strRunningThrow = 112; - } - if (value >= 75) { - strLiftText = "800 tons"; - strRunningThrow = 120; - } - if (value >= 80) { - strLiftText = "1.6 ktons"; - strRunningThrow = 128; - } - if (value >= 85) { - strLiftText = "3.2 ktons"; - strRunningThrow = 136; - } - if (value >= 90) { - strLiftText = "6.4 ktons"; - strRunningThrow = 144; - } - if (value >= 95) { - strLiftText = "12.5 ktons"; - strRunningThrow = 152; - } - if (value >= 100) { - strLiftText = "25 ktons"; - strRunningThrow = 160; - } + const value = str || this.system.characteristics.str?.value; + if (value >= 105) { strLiftText = `${50 + Math.floor((value - 105) / 5) * 25} ktons`; strRunningThrow = 168 + Math.floor((value - 105) / 5) * 8; + } else if (value >= 100) { + strLiftText = "25 ktons"; + strRunningThrow = 160; + } else if (value >= 95) { + strLiftText = "12.5 ktons"; + strRunningThrow = 152; + } else if (value >= 90) { + strLiftText = "6.4 ktons"; + strRunningThrow = 144; + } else if (value >= 85) { + strLiftText = "3.2 ktons"; + strRunningThrow = 136; + } else if (value >= 80) { + strLiftText = "1.6 ktons"; + strRunningThrow = 128; + } else if (value >= 75) { + strLiftText = "800 tons"; + strRunningThrow = 120; + } else if (value >= 70) { + strLiftText = "400 tons"; + strRunningThrow = 112; + } else if (value >= 65) { + strLiftText = "200 tons"; + strRunningThrow = 104; + } else if (value >= 60) { + strLiftText = "100 tons"; + strRunningThrow = 96; + } else if (value >= 55) { + strLiftText = "50 tons"; + strRunningThrow = 88; + } else if (value >= 50) { + strLiftText = "25 tons"; + strRunningThrow = 80; + } else if (value >= 45) { + strLiftText = "12.5 tons"; + strRunningThrow = 72; + } else if (value >= 40) { + strLiftText = "6,400kg"; + strRunningThrow = 64; + } else if (value >= 35) { + strLiftText = "3,200kg"; + strRunningThrow = 56; + } else if (value >= 30) { + strLiftText = "1,600kg"; + strRunningThrow = 48; + } else if (value >= 28) { + strLiftText = "1,200kg"; + strRunningThrow = 44; + } else if (value >= 25) { + strLiftText = "800kg"; + strRunningThrow = 40; + } else if (value >= 23) { + strLiftText = "600kg"; + strRunningThrow = 36; + } else if (value >= 20) { + strLiftText = "400kg"; + strRunningThrow = 32; + } else if (value >= 18) { + strLiftText = "300kg"; + strRunningThrow = 28; + } else if (value >= 15) { + strLiftText = "200kg"; + strRunningThrow = 24; + } else if (value >= 13) { + strLiftText = "150kg"; + strRunningThrow = 20; + } else if (value >= 10) { + strLiftText = "100kg"; + strRunningThrow = 16; + } else if (value >= 8) { + strLiftText = "75kg"; + strRunningThrow = 12; + } else if (value >= 5) { + strLiftText = "50kg"; + strRunningThrow = 8; + } else if (value >= 4) { + strLiftText = "38kg"; + strRunningThrow = 6; + } else if (value >= 3) { + strLiftText = "25kg"; + strRunningThrow = 4; + } else if (value >= 2) { + strLiftText = "16kg"; + strRunningThrow = 3; + } else if (value >= 1) { + strLiftText = "8kg"; + strRunningThrow = 2; } + // 5e allows negative strength if (this.system.is5e) { if (value < -25) { strLiftText = "0"; strRunningThrow = 0; - } - if (value >= -25 && value < -23) { + } else if (value < -23) { strLiftText = "0.8kg"; strRunningThrow = 1; - } - if (value >= -23 && value < -20) { + } else if (value < -20) { strLiftText = "1kg"; strRunningThrow = 1; - } - if (value >= -20 && value < -18) { + } else if (value < -18) { strLiftText = "1.6kg"; strRunningThrow = 1; - } - if (value >= -18 && value < -15) { + } else if (value < -15) { strLiftText = "2kg"; strRunningThrow = 1; - } - if (value >= -15 && value < -13) { + } else if (value < -13) { strLiftText = "3.2kg"; strRunningThrow = 1; - } - if (value >= -13 && value < -10) { + } else if (value < -10) { strLiftText = "4kg"; strRunningThrow = 1; - } - if (value >= -10 && value < -8) { + } else if (value < -8) { strLiftText = "6.4kg"; strRunningThrow = 1; - } - if (value >= -8 && value < -5) { + } else if (value < -5) { strLiftText = "8kg"; strRunningThrow = 2; - } - if (value >= -5 && value < -3) { + } else if (value < -3) { strLiftText = "12.5kg"; strRunningThrow = 2; - } - if (value >= -3 && value < 0) { + } else if (value < 0) { strLiftText = "16kg"; strRunningThrow = 3; - } - if (value >= 0 && value < 3) { + } else if (value < 3) { strLiftText = "25kg"; strRunningThrow = 4; - } - if (value >= 3 && value < 5) { + } else if (value < 5) { strLiftText = "37kg"; strRunningThrow = 6; } From 29d749779c2c287dd68ac53b79507a92ed054897 Mon Sep 17 00:00:00 2001 From: Peter Hunnisett <29824554+phBalance@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:45:45 -0700 Subject: [PATCH 2/6] refactor(item): remove dead stuff and let -> const --- module/item/item.mjs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/module/item/item.mjs b/module/item/item.mjs index a7e5b56e..bb122b05 100644 --- a/module/item/item.mjs +++ b/module/item/item.mjs @@ -3955,21 +3955,11 @@ export class HeroSystem6eItem extends Item { } // MULTIPOWER slots typically include limitations - let modifiers = this.modifiers + const modifiers = this.modifiers .filter((o) => o.BASECOST_total < 0) .sort((a, b) => { return a.BASECOST_total - b.BASECOST_total; }); - // Looks like atting parentItem mods is handed in the calc functions - // if (this.parentItem) { - // modifiers.push( - // ...(this.parentItem.system.MODIFIER || []) - // .filter((o) => o.BASECOST < 0) - // .sort((a, b) => { - // return a.BASECOST_total - b.BASECOST_total; - // }), - // ); - // } // Disadvantages sorted low to high for (const modifier of modifiers) { From ac1230b9766f5670a1ee6135d44c0b9ea81e0184 Mon Sep 17 00:00:00 2001 From: Peter Hunnisett <29824554+phBalance@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:46:50 -0700 Subject: [PATCH 3/6] refactor(encumbrance): cleanup method --- module/actor/actor.mjs | 73 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/module/actor/actor.mjs b/module/actor/actor.mjs index 11047354..f2524fd7 100644 --- a/module/actor/actor.mjs +++ b/module/actor/actor.mjs @@ -5,7 +5,7 @@ import { getPowerInfo, getCharacteristicInfoArrayForActor, whisperUserTargetsFor import { HeroProgressBar } from "../utility/progress-bar.mjs"; import { clamp } from "../utility/compatibility.mjs"; import { overrideCanAct } from "../settings/settings-helpers.mjs"; -import { RoundFavorPlayerUp } from "../utility/round.mjs"; +import { RoundFavorPlayerDown, RoundFavorPlayerUp } from "../utility/round.mjs"; /** * Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system. @@ -816,43 +816,38 @@ export class HeroSystem6eActor extends Actor { if (!game.users.activeGM?.isSelf) return; const { strLiftKg } = this.strDetails(); - let encumbrance = this.encumbrance; + const encumbrance = this.encumbrance; // Is actor encumbered? let dcvDex = 0; - let move = 0; - if (encumbrance / strLiftKg >= 0.1) { - dcvDex = -1; - } - if (encumbrance / strLiftKg >= 0.25) { - dcvDex = -2; - //move = -2; - } - if (encumbrance / strLiftKg >= 0.5) { - dcvDex = -3; - //move = -4; - } - if (encumbrance / strLiftKg >= 0.75) { - dcvDex = -4; - //move = -8; - } - if (encumbrance / strLiftKg >= 0.9) { + const maxStrengthPct = RoundFavorPlayerDown((100 * encumbrance) / strLiftKg); + if (maxStrengthPct >= 90) { dcvDex = -5; - //move = -16; + } else if (maxStrengthPct >= 75) { + dcvDex = -4; + } else if (maxStrengthPct >= 50) { + dcvDex = -3; + } else if (maxStrengthPct >= 25) { + dcvDex = -2; + } else if (maxStrengthPct >= 10) { + dcvDex = -1; } // Penalty Skill Levels for encumbrance for (const pslEncumbrance of this.items.filter( - (o) => - o.system.XMLID === "PENALTY_SKILL_LEVELS" && - o.system.penalty === "encumbrance" && - (o.type === "skill" || o.isActive), + (item) => + item.system.XMLID === "PENALTY_SKILL_LEVELS" && + item.system.penalty === "encumbrance" && + (item.type === "skill" || item.isActive), )) { dcvDex = Math.min(0, dcvDex + parseInt(pslEncumbrance.system.LEVELS)); } // Movement + let move = 0; switch (dcvDex) { + case 0: + // intentional fallthrough case -1: move = 0; break; @@ -868,9 +863,12 @@ export class HeroSystem6eActor extends Actor { case -5: move = -16; break; + default: + console.error(`${this.name} has an unexpected dcvDex of ${dcvDex}`); + break; } - const name = `Encumbered ${Math.floor((encumbrance / strLiftKg) * 100)}%`; + const name = `Encumbered ${maxStrengthPct}%`; const prevActiveEffects = this.effects.filter((o) => o.flags?.encumbrance); // There should only be 1 encumbered effect, but with async loading we may have more @@ -880,7 +878,7 @@ export class HeroSystem6eActor extends Actor { } const prevActiveEffect = prevActiveEffects?.[0]; if (dcvDex < 0 && prevActiveEffect?.flags?.dcvDex != dcvDex) { - let activeEffect = { + const activeEffect = { name: name, id: "encumbered", img: `systems/${HEROSYS.module}/icons/encumbered.svg`, @@ -951,16 +949,19 @@ export class HeroSystem6eActor extends Actor { } // If we have control of this token, re-acquire to update movement types - const myToken = this.getActiveTokens()?.[0]; - if (canvas.tokens.controlled.find((t) => t.id == myToken.id)) { + const myToken = this.getActiveTokens()?.[0] || {}; + if (canvas.tokens.controlled.find((token) => token.id === myToken.id)) { myToken.release(); myToken.control(); } + return; } if (dcvDex === 0 && prevActiveEffect) { await prevActiveEffect.delete(); + } else if (prevActiveEffect && prevActiveEffect.name !== name) { + await prevActiveEffect.update({ name: name }); } // else if (prevActiveEffect && prevActiveEffect.name != name) { // await prevActiveEffect.update({ name: name }); @@ -978,8 +979,8 @@ export class HeroSystem6eActor extends Actor { // 0 on movement and DCV occur 5 points of STR // sooner. const massMultiplier = this.items - .filter((o) => o.system.XMLID === "DENSITYINCREASE" && o.isActive) - .reduce((p, a) => p + parseInt(a.system.LEVELS), 0); + .filter((item) => item.system.XMLID === "DENSITYINCREASE" && item.isActive) + .reduce((accum, currItem) => accum + parseInt(currItem.system.LEVELS), 0); const minStr = massMultiplier * 5; const prevStr0ActiveEffect = this.effects.find((o) => o.flags?.str0); @@ -1028,8 +1029,8 @@ export class HeroSystem6eActor extends Actor { await this.createEmbeddedDocuments("ActiveEffect", [str0ActiveEffect]); // If we have control of this token, re-acquire to update movement types - const myToken = this.getActiveTokens()?.[0]; - if (canvas.tokens.controlled.find((t) => t.id == myToken.id)) { + const myToken = this.getActiveTokens()?.[0] || {}; + if (canvas.tokens.controlled.find((token) => token.id === myToken.id)) { myToken.release(); myToken.control(); } @@ -1037,8 +1038,8 @@ export class HeroSystem6eActor extends Actor { if (prevStr0ActiveEffect && this.system.characteristics.str.value > minStr) { await prevStr0ActiveEffect.delete(); // If we have control of this token, re-acquire to update movement types - const myToken = this.getActiveTokens()?.[0]; - if (canvas.tokens.controlled.find((t) => t.id == myToken.id)) { + const myToken = this.getActiveTokens()?.[0] || {}; + if (canvas.tokens.controlled.find((token) => token.id === myToken.id)) { myToken.release(); myToken.control(); } @@ -1048,8 +1049,8 @@ export class HeroSystem6eActor extends Actor { async FullHealth() { // Remove all status effects - for (let status of this.statuses) { - let ae = Array.from(this.effects).find((effect) => effect.statuses.has(status)); + for (const status of this.statuses) { + const ae = Array.from(this.effects).find((effect) => effect.statuses.has(status)); await ae.delete(); } From a719506937d5ce03894cdc41645615980a8edc9d Mon Sep 17 00:00:00 2001 From: Peter Hunnisett <29824554+phBalance@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:51:41 -0700 Subject: [PATCH 4/6] fix(strength): make 0kg lift consistent --- module/actor/actor.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/actor/actor.mjs b/module/actor/actor.mjs index f2524fd7..41b666b1 100644 --- a/module/actor/actor.mjs +++ b/module/actor/actor.mjs @@ -657,7 +657,7 @@ export class HeroSystem6eActor extends Actor { } strDetails(str) { - let strLiftText = "0"; + let strLiftText = "0kg"; let strRunningThrow = 0; const value = str || this.system.characteristics.str?.value; @@ -756,7 +756,7 @@ export class HeroSystem6eActor extends Actor { // 5e allows negative strength if (this.system.is5e) { if (value < -25) { - strLiftText = "0"; + strLiftText = "0kg"; strRunningThrow = 0; } else if (value < -23) { strLiftText = "0.8kg"; From 094913306e8c53c3118a296f4422a8e00104ec2e Mon Sep 17 00:00:00 2001 From: Peter Hunnisett <29824554+phBalance@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:09:37 -0700 Subject: [PATCH 5/6] refactor(effect): make find argument clearer --- module/actor/actor.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/actor/actor.mjs b/module/actor/actor.mjs index 41b666b1..e9f95dfb 100644 --- a/module/actor/actor.mjs +++ b/module/actor/actor.mjs @@ -983,7 +983,7 @@ export class HeroSystem6eActor extends Actor { .reduce((accum, currItem) => accum + parseInt(currItem.system.LEVELS), 0); const minStr = massMultiplier * 5; - const prevStr0ActiveEffect = this.effects.find((o) => o.flags?.str0); + const prevStr0ActiveEffect = this.effects.find((effect) => effect.flags?.str0); if (this.system.characteristics.str?.value <= minStr && !prevStr0ActiveEffect) { const str0ActiveEffect = { name: "STR0", From 5e28306f5add1f4d9377bf8c8c605af655f08565 Mon Sep 17 00:00:00 2001 From: Peter Hunnisett <29824554+phBalance@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:13:03 -0700 Subject: [PATCH 6/6] refactor(dead): remove dead code --- module/item/item-attack-application.mjs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/module/item/item-attack-application.mjs b/module/item/item-attack-application.mjs index 6768e4e6..9154de87 100644 --- a/module/item/item-attack-application.mjs +++ b/module/item/item-attack-application.mjs @@ -21,23 +21,6 @@ export class ItemAttackFormApplication extends FormApplication { this.data = data; this.options.title = `${this.data?.item?.actor?.name} roll to hit`; - // const _updateItem = async function (item, changes, options, userId) { - // if (!this.rendered) return; - - // if (item.id === this.data.item.id) { - // this.updateItem(item, changes, options, userId); - // } - - // const cslSkill = CombatSkillLevelsForAttack(this.data.item).skill; - // if (cslSkill && item.id === cslSkill.id) { - // this.updateItem(item, changes, options, userId); - // } - // if (!cslSkill && data.cslSkill) { - // this.updateItem(item, changes, options, userId); - // } - // }; - // Hooks.on("updateItem", _updateItem.bind(this)); - const _targetToken = async function () { // Necessary for situations where it is not possible // to properly wait for promises to resolve before refreshing the UI. @@ -62,13 +45,6 @@ export class ItemAttackFormApplication extends FormApplication { Hooks.on("updateItem", _updateItem.bind(this)); } - // async close(options = {}) { - // Hooks.off("targetToken", this._targetToken); - // Hooks.off("controlToken", this._controlToken); - // Hooks.off("updateItem", this._updateItem); - // return super.close(options); - // } - refresh() { foundry.utils.debounce(this.render(), 100); }