From 64aee25caee4d16a472469cc04fd437c60cd6449 Mon Sep 17 00:00:00 2001 From: arcos Date: Thu, 13 Jun 2024 08:36:00 +0200 Subject: [PATCH 1/4] Str mod for item-based encumbrance. --- src/module/polyfill.ts | 11 +++++++++++ src/ose.js | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/module/polyfill.ts diff --git a/src/module/polyfill.ts b/src/module/polyfill.ts new file mode 100644 index 00000000..cda6213b --- /dev/null +++ b/src/module/polyfill.ts @@ -0,0 +1,11 @@ +/** + * @file Polyfills for the system + */ + +export default () => { + // @ts-ignore - Math.clamp is not a standard JS function + if (typeof Math.clamp !== "function") { + // @ts-ignore - Math.clamp is not a standard JS function + Math.clamp = Math.clamped; + } +}; diff --git a/src/ose.js b/src/ose.js index daaa4a3d..0d0148da 100644 --- a/src/ose.js +++ b/src/ose.js @@ -31,10 +31,10 @@ import registerSettings from "./module/settings"; import * as treasure from "./module/helpers-treasure"; import "./e2e"; +import polyfill from "./module/polyfill"; -if(typeof Math.clamp !== "function") { - Math.clamp = Math.clamped; -} + +polyfill(); /* -------------------------------------------- */ /* Foundry VTT Initialization */ From f272f598ca62a18f33e1ba1f29e40c195a5d412d Mon Sep 17 00:00:00 2001 From: arcos Date: Thu, 27 Jun 2024 20:01:32 +0200 Subject: [PATCH 2/4] Switched to TypeDataModel --- src/module/actor/data-model-character.js | 2 +- src/module/actor/data-model-monster.js | 2 +- src/module/actor/entity.js | 3 +-- src/module/item/data-model-ability.js | 3 ++- src/module/item/data-model-armor.js | 2 +- src/module/item/data-model-container.js | 3 ++- src/module/item/data-model-item.js | 2 +- src/module/item/data-model-spell.js | 2 +- src/module/item/data-model-weapon.js | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/module/actor/data-model-character.js b/src/module/actor/data-model-character.js index b27088d6..544b94e3 100644 --- a/src/module/actor/data-model-character.js +++ b/src/module/actor/data-model-character.js @@ -11,7 +11,7 @@ const getItemsOfActorOfType = (actor, filterType, filterFn = null) => .filter(({ type }) => type === filterType) .filter(filterFn || (() => true)); -export default class OseDataModelCharacter extends foundry.abstract.DataModel { +export default class OseDataModelCharacter extends foundry.abstract.TypeDataModel { prepareDerivedData() { this.scores = new OseDataModelCharacterScores(this.scores); diff --git a/src/module/actor/data-model-monster.js b/src/module/actor/data-model-monster.js index bb577c2e..44aa741a 100644 --- a/src/module/actor/data-model-monster.js +++ b/src/module/actor/data-model-monster.js @@ -11,7 +11,7 @@ const getItemsOfActorOfType = (actor, filterType, filterFn = null) => .filter(({ type }) => type === filterType) .filter(filterFn || (() => true)); -export default class OseDataModelMonster extends foundry.abstract.DataModel { +export default class OseDataModelMonster extends foundry.abstract.TypeDataModel { prepareDerivedData() { this.encumbrance = new OseDataModelCharacterEncumbranceDisabled(); this.spells = new OseDataModelCharacterSpells(this.spells, this.#spellList); diff --git a/src/module/actor/entity.js b/src/module/actor/entity.js index 3d49778c..29c64973 100644 --- a/src/module/actor/entity.js +++ b/src/module/actor/entity.js @@ -14,8 +14,7 @@ const removeFalsyElements = (arr) => export default class OseActor extends Actor { prepareDerivedData() { - //if (game.version.startsWith("10")) this.system.prepareDerivedData?.(); - this.system.prepareDerivedData?.(); + if (game.version.startsWith("10")) this.system.prepareDerivedData?.(); } static migrateData(source) { diff --git a/src/module/item/data-model-ability.js b/src/module/item/data-model-ability.js index a0d17d43..d5a5ea35 100644 --- a/src/module/item/data-model-ability.js +++ b/src/module/item/data-model-ability.js @@ -3,7 +3,8 @@ */ import OseTags from "../helpers-tags"; -export default class OseDataModelAbility extends foundry.abstract.DataModel { +export default class OseDataModelAbility extends foundry.abstract + .TypeDataModel { static defineSchema() { const { StringField, NumberField, BooleanField, ArrayField, ObjectField } = foundry.data.fields; diff --git a/src/module/item/data-model-armor.js b/src/module/item/data-model-armor.js index 55f6f8f4..555f7380 100644 --- a/src/module/item/data-model-armor.js +++ b/src/module/item/data-model-armor.js @@ -1,7 +1,7 @@ /** * @file The data model for Items of type Armor */ -export default class OseDataModelArmor extends foundry.abstract.DataModel { +export default class OseDataModelArmor extends foundry.abstract.TypeDataModel { static ArmorTypes = { unarmored: "OSE.armor.unarmored", light: "OSE.armor.light", diff --git a/src/module/item/data-model-container.js b/src/module/item/data-model-container.js index 15d33e35..d37da596 100644 --- a/src/module/item/data-model-container.js +++ b/src/module/item/data-model-container.js @@ -1,7 +1,8 @@ /** * @file The data model for Items of type Container */ -export default class OseDataModelContainer extends foundry.abstract.DataModel { +export default class OseDataModelContainer extends foundry.abstract + .TypeDataModel { static defineSchema() { const { SchemaField, diff --git a/src/module/item/data-model-item.js b/src/module/item/data-model-item.js index 205ba43f..6cbb6b5c 100644 --- a/src/module/item/data-model-item.js +++ b/src/module/item/data-model-item.js @@ -1,7 +1,7 @@ /** * @file The data model for Items of type Ability */ -export default class OseDataModelItem extends foundry.abstract.DataModel { +export default class OseDataModelItem extends foundry.abstract.TypeDataModel { static defineSchema() { const { SchemaField, diff --git a/src/module/item/data-model-spell.js b/src/module/item/data-model-spell.js index b1d0d892..2ccb4282 100644 --- a/src/module/item/data-model-spell.js +++ b/src/module/item/data-model-spell.js @@ -3,7 +3,7 @@ */ import OseTags from "../helpers-tags"; -export default class OseDataModelSpell extends foundry.abstract.DataModel { +export default class OseDataModelSpell extends foundry.abstract.TypeDataModel { static defineSchema() { const { StringField, NumberField, ArrayField, ObjectField } = foundry.data.fields; diff --git a/src/module/item/data-model-weapon.js b/src/module/item/data-model-weapon.js index 2003092b..99b3cd83 100644 --- a/src/module/item/data-model-weapon.js +++ b/src/module/item/data-model-weapon.js @@ -1,7 +1,7 @@ /** * @file The data model for Items of type Weapon */ -export default class OseDataModelWeapon extends foundry.abstract.DataModel { +export default class OseDataModelWeapon extends foundry.abstract.TypeDataModel { static defineSchema() { const { SchemaField, From 6e289deade62dcedf77fbe34b60bbdb824ddda5d Mon Sep 17 00:00:00 2001 From: arcos Date: Mon, 1 Jul 2024 20:52:52 +0200 Subject: [PATCH 3/4] Str Mod functionality restored --- src/lang/en.json | 2 + src/module/actor/actor-sheet.js | 3 + src/module/actor/data-model-character.js | 3 +- ...-model-character-encumbrance-item-based.ts | 73 ++++++++++++++++--- .../data-model-character-encumbrance.ts | 4 +- src/module/settings.ts | 9 +++ .../partials/character-inventory-tab.html | 6 ++ 7 files changed, 88 insertions(+), 12 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 4a1ed8da..d8195ebd 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -206,6 +206,8 @@ "OSE.Setting.damageOriginalTarget": "Original Target", "OSE.Setting.InvertedCtrlBehavior": "Invert Roll Ctrl/Meta-key", "OSE.Setting.InvertedCtrlBehaviorHint": "Reverses behavior for holding Ctrl/Meta when clicking on a roll.", + "OSE.Setting.EncumbranceItemStrengthMod": "Enable Strength Modifier for Item-based Encumbrance", + "OSE.Setting.EncumbranceItemStrengthModHint": "Strength modifier is applied to the item-based encumbrance calculation.", "OSE.items.Equip": "Equip", "OSE.items.Unequip": "Unequip", diff --git a/src/module/actor/actor-sheet.js b/src/module/actor/actor-sheet.js index 5d84c48a..ed1298d6 100644 --- a/src/module/actor/actor-sheet.js +++ b/src/module/actor/actor-sheet.js @@ -16,6 +16,9 @@ export default class OseActorSheet extends ActorSheet { ascendingAC: game.settings.get(game.system.id, "ascendingAC"), initiative: game.settings.get(game.system.id, "initiative") !== "group", encumbrance: game.settings.get(game.system.id, "encumbranceOption"), + encumbranceStrengthMod: + game.settings.get(game.system.id, "encumbranceItemStrengthMod") && + game.settings.get(game.system.id, "encumbranceOption") === "itembased", }; data.isNew = this.actor.isNew(); diff --git a/src/module/actor/data-model-character.js b/src/module/actor/data-model-character.js index f37ec757..544b94e3 100644 --- a/src/module/actor/data-model-character.js +++ b/src/module/actor/data-model-character.js @@ -25,7 +25,8 @@ export default class OseDataModelCharacter extends foundry.abstract.TypeDataMode "significantTreasure" ), scores: this.scores, - } + }, + this.scores.str.mod ); this.movement = new OseDataModelCharacterMove( diff --git a/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts b/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts index 5e13dbdd..7ee0d5ad 100644 --- a/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts +++ b/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts @@ -61,10 +61,16 @@ export default class OseDataModelCharacterEncumbranceItemBased #packedWeight; + #weightMod; + // eslint-disable-next-line sonarjs/cognitive-complexity, @typescript-eslint/no-unused-vars - constructor(max = 16, items: Item[] = []) { + constructor(max = 16, items: Item[] = [], _ = "", strMod = 0) { super(OseDataModelCharacterEncumbranceItemBased.type, max); - + if (game.settings.get(game.system.id, "encumbranceItemStrengthMod")) { + this.#weightMod = strMod > 0 ? strMod : 0; + } else { + this.#weightMod = 0; + } this.#packedMax = 16; this.#equippedMax = 9; this.#packedWeight = Math.ceil( @@ -91,13 +97,51 @@ export default class OseDataModelCharacterEncumbranceItemBased 0 ) ); - this.#atFiveEighths = this.#weight > this.#max * (OseDataModelCharacterEncumbranceItemBased.packedEncumbranceSteps.fiveEighths / 100); - this.#atThreeQuarters = this.#weight > this.#max * (OseDataModelCharacterEncumbranceItemBased.packedEncumbranceSteps.threeQuarters / 100); - this.#atSevenEights = this.#weight > this.#max * (OseDataModelCharacterEncumbranceItemBased.packedEncumbranceSteps.sevenEighths / 100); - - this.#atOneThird = this.#weight > this.#max * (OseDataModelCharacterEncumbranceItemBased.equippedEncumbranceSteps.oneThird / 100); - this.#atFiveNinths = this.#weight > this.#max * (OseDataModelCharacterEncumbranceItemBased.equippedEncumbranceSteps.fiveNinths / 100); - this.#atSevenNinths = this.#weight > this.#max * (OseDataModelCharacterEncumbranceItemBased.equippedEncumbranceSteps.sevenNinths / 100); + this.#weight = this.usingEquippedEncumbrance + ? this.#equippedWeight + : this.#packedWeight; + + this.#max = this.usingEquippedEncumbrance + ? this.#equippedMax + : this.#packedMax; + + this.#atFiveEighths = + this.#weight - this.#weightMod > + this.#max * + (OseDataModelCharacterEncumbranceItemBased.packedEncumbranceSteps + .fiveEighths / + 100); + this.#atThreeQuarters = + this.#weight - this.#weightMod > + this.#max * + (OseDataModelCharacterEncumbranceItemBased.packedEncumbranceSteps + .threeQuarters / + 100); + this.#atSevenEights = + this.#weight - this.#weightMod > + this.#max * + (OseDataModelCharacterEncumbranceItemBased.packedEncumbranceSteps + .sevenEighths / + 100); + + this.#atOneThird = + this.#weight > + this.#max * + (OseDataModelCharacterEncumbranceItemBased.equippedEncumbranceSteps + .oneThird / + 100); + this.#atFiveNinths = + this.#weight > + this.#max * + (OseDataModelCharacterEncumbranceItemBased.equippedEncumbranceSteps + .fiveNinths / + 100); + this.#atSevenNinths = + this.#weight > + this.#max * + (OseDataModelCharacterEncumbranceItemBased.equippedEncumbranceSteps + .sevenNinths / + 100); } // eslint-disable-next-line class-methods-use-this @@ -124,7 +168,12 @@ export default class OseDataModelCharacterEncumbranceItemBased equippedIndex = equippedIndex === -1 ? 4 : equippedIndex; let packedIndex = packedValues.findIndex( - (step) => step > (this.#packedWeight / this.#packedMax) * 100); + (step) => + step > + ((this.#packedWeight - this.#weightMod) / + (this.#packedMax + this.#weightMod)) * + 100 + ); packedIndex = packedIndex === -1 ? 4 : packedIndex; return !!(equippedIndex >= packedIndex); } @@ -154,4 +203,8 @@ export default class OseDataModelCharacterEncumbranceItemBased ? this.#atSevenNinths : this.#atSevenEights; } + + get encumbered() { + return this.value > this.max + this.#weightMod; + } } diff --git a/src/module/actor/data-model-classes/data-model-character-encumbrance.ts b/src/module/actor/data-model-classes/data-model-character-encumbrance.ts index 31f65af8..25bd4f21 100644 --- a/src/module/actor/data-model-classes/data-model-character-encumbrance.ts +++ b/src/module/actor/data-model-classes/data-model-character-encumbrance.ts @@ -40,11 +40,13 @@ export default class OseDataModelCharacterEncumbrance * @param {string} variant - The name of this encumbrance variant. * @param {number} max - The max weight this character can carry * @param {Item[]} items - The items this character is carrying. Note: we're not using this in the base class. + * @param {number} strMod - The strength modifier for this character. */ constructor( variant = "disabled", max = OseDataModelCharacterEncumbrance.baseEncumbranceCap, - items = [] // eslint-disable-line @typescript-eslint/no-unused-vars + items = [], // eslint-disable-line @typescript-eslint/no-unused-vars + strMod = 0 ) { this.#encumbranceVariant = variant; this.#max = max; diff --git a/src/module/settings.ts b/src/module/settings.ts index 8ff8a884..7c48b8d8 100644 --- a/src/module/settings.ts +++ b/src/module/settings.ts @@ -67,6 +67,15 @@ const registerSettings = () => { }, {}) as SettingConfig["choices"], }); + game.settings.register(game.system.id, "encumbranceItemStrengthMod", { + name: game.i18n.localize("OSE.Setting.EncumbranceItemStrengthMod"), + hint: game.i18n.localize("OSE.Setting.EncumbranceItemStrengthModHint"), + default: false, + scope: "world", + type: Boolean, + config: true, + }); + game.settings.register(game.system.id, "significantTreasure", { name: game.i18n.localize("OSE.Setting.SignificantTreasure"), hint: game.i18n.localize("OSE.Setting.SignificantTreasureHint"), diff --git a/src/templates/actors/partials/character-inventory-tab.html b/src/templates/actors/partials/character-inventory-tab.html index b9c8ec4b..3e097bb3 100644 --- a/src/templates/actors/partials/character-inventory-tab.html +++ b/src/templates/actors/partials/character-inventory-tab.html @@ -407,10 +407,16 @@

{{item.name~}}

{{#unless (eq @root.system.encumbrance.variant 'disabled')}}
+ {{#with @root.system.encumbrance}}
+ + {{#if @root.config.encumbranceStrengthMod}} + {{value}} / {{#if usingEquippedEncumbrance}}{{max}}{{else}}{{add max @root.system.scores.str.mod}}{{/if}} + {{else}} {{value}} / {{max}} + {{/if}} {{#each steps as |s|}} From d0b1b97f7b9e2cf837af421a174bcc5d4e916696 Mon Sep 17 00:00:00 2001 From: arcos Date: Tue, 31 Dec 2024 14:30:43 +0100 Subject: [PATCH 4/4] Removed unneeded strMod parameter and switched to options.scores.str.mod --- .gitignore | 1 + .../data-model-character-encumbrance-item-based.ts | 4 ++-- .../data-model-classes/data-model-character-encumbrance.ts | 3 --- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 83a8091e..50810e14 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ ose-dev.lock dist .DS_Store .env +.vscode \ No newline at end of file diff --git a/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts b/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts index 7ee0d5ad..78594e9f 100644 --- a/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts +++ b/src/module/actor/data-model-classes/data-model-character-encumbrance-item-based.ts @@ -64,10 +64,10 @@ export default class OseDataModelCharacterEncumbranceItemBased #weightMod; // eslint-disable-next-line sonarjs/cognitive-complexity, @typescript-eslint/no-unused-vars - constructor(max = 16, items: Item[] = [], _ = "", strMod = 0) { + constructor(max = 16, items: Item[] = [], options = {}) { super(OseDataModelCharacterEncumbranceItemBased.type, max); if (game.settings.get(game.system.id, "encumbranceItemStrengthMod")) { - this.#weightMod = strMod > 0 ? strMod : 0; + this.#weightMod = options.scores.str.mod > 0 ? options.scores.str.mod : 0; } else { this.#weightMod = 0; } diff --git a/src/module/actor/data-model-classes/data-model-character-encumbrance.ts b/src/module/actor/data-model-classes/data-model-character-encumbrance.ts index 25bd4f21..f46f02d2 100644 --- a/src/module/actor/data-model-classes/data-model-character-encumbrance.ts +++ b/src/module/actor/data-model-classes/data-model-character-encumbrance.ts @@ -40,13 +40,10 @@ export default class OseDataModelCharacterEncumbrance * @param {string} variant - The name of this encumbrance variant. * @param {number} max - The max weight this character can carry * @param {Item[]} items - The items this character is carrying. Note: we're not using this in the base class. - * @param {number} strMod - The strength modifier for this character. */ constructor( variant = "disabled", max = OseDataModelCharacterEncumbrance.baseEncumbranceCap, - items = [], // eslint-disable-line @typescript-eslint/no-unused-vars - strMod = 0 ) { this.#encumbranceVariant = variant; this.#max = max;