Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Optionally allow Strength modifier for item-based encumbrance #523

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ ose-dev.lock
dist
.DS_Store
.env
.vscode
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,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",
Expand Down
3 changes: 3 additions & 0 deletions src/module/actor/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion src/module/actor/data-model-character.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default class OseDataModelCharacter extends foundry.abstract.TypeDataMode
"significantTreasure"
),
scores: this.scores,
arcos marked this conversation as resolved.
Show resolved Hide resolved
}
},
this.scores.str.mod
);

this.movement = new OseDataModelCharacterMove(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [], options = {}) {
super(OseDataModelCharacterEncumbranceItemBased.type, max);

if (game.settings.get(game.system.id, "encumbranceItemStrengthMod")) {
this.#weightMod = options.scores.str.mod > 0 ? options.scores.str.mod : 0;
} else {
this.#weightMod = 0;
}
this.#packedMax = 16;
this.#equippedMax = 9;
this.#packedWeight = Math.ceil(
Expand All @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -154,4 +203,8 @@ export default class OseDataModelCharacterEncumbranceItemBased
? this.#atSevenNinths
: this.#atSevenEights;
}

get encumbered() {
return this.value > this.max + this.#weightMod;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default class OseDataModelCharacterEncumbrance
constructor(
variant = "disabled",
max = OseDataModelCharacterEncumbrance.baseEncumbranceCap,
items = [] // eslint-disable-line @typescript-eslint/no-unused-vars
) {
this.#encumbranceVariant = variant;
this.#max = max;
Expand Down
3 changes: 2 additions & 1 deletion src/module/item/data-model-ability.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*/
import OseTags from "../helpers-tags";

export default class OseDataModelAbility extends foundry.abstract.TypeDataModel {
export default class OseDataModelAbility extends foundry.abstract
.TypeDataModel {
static defineSchema() {
const { StringField, NumberField, BooleanField, ArrayField, ObjectField } =
foundry.data.fields;
Expand Down
3 changes: 2 additions & 1 deletion src/module/item/data-model-container.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* @file The data model for Items of type Container
*/
export default class OseDataModelContainer extends foundry.abstract.TypeDataModel {
export default class OseDataModelContainer extends foundry.abstract
.TypeDataModel {
static defineSchema() {
const {
SchemaField,
Expand Down
9 changes: 9 additions & 0 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ const registerSettings = () => {
}, {}) as SettingConfig<EncumbranceOption>["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"),
Expand Down
6 changes: 6 additions & 0 deletions src/templates/actors/partials/character-inventory-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,16 @@ <h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
</section>
{{#unless (eq @root.system.encumbrance.variant 'disabled')}}
<section>

{{#with @root.system.encumbrance}}
<div class="encumbrance {{#if encumbered}}encumbered{{/if}}">

<span class="encumbrance-bar" style="width:{{pct}}%"></span>
{{#if @root.config.encumbranceStrengthMod}}
<span class="encumbrance-label">{{value}} / {{#if usingEquippedEncumbrance}}{{max}}{{else}}{{add max @root.system.scores.str.mod}}{{/if}}</span>
{{else}}
<span class="encumbrance-label">{{value}} / {{max}}</span>
{{/if}}
{{#each steps as |s|}}
<i class="encumbrance-breakpoint arrow-up" style="left:{{s}}%"></i>
<i class="encumbrance-breakpoint arrow-down" style="left:{{s}}%"></i>
Expand Down