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

Character sheet inventory fixes #500

Merged
merged 10 commits into from
Apr 1, 2024
1 change: 1 addition & 0 deletions src/module/actor/character-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class OseActorSheetCharacter extends OseActorSheet {
treasures: this.actor.system.treasures,
containers: this.actor.system.containers,
};
data.treasure = this.actor.system.carriedTreasure,
data.containers = this.actor.system.containers;
data.abilities = this.actor.system.abilities;
data.spells = this.actor.system.spells.spellList;
Expand Down
5 changes: 1 addition & 4 deletions src/module/actor/data-model-character.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ export default class OseDataModelCharacter extends foundry.abstract.DataModel {
details: new ObjectField(),
ac: new ObjectField(),
aac: new ObjectField(),
encumbrance: new SchemaField({
value: new NumberField({ integer: false }),
max: new NumberField({ integer: false }),
}),
encumbrance: new ObjectField(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind trying something?

Suggested change
encumbrance: new ObjectField(),
encumbrance: new SchemaField({
max: new NumberField({ initial: 1600 }),
}),

See if that fixes it, as well. My guess is that we haven't been setting an initial encumbrance max all this time.

If it doesn't work, eh, heck with it, we'll keep it as you have it. If it does, then maybe we add a system setting for default initial value for max carry weight?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes it worse. If I see things correctly, setting a SchemaField() here makes it impossible to add other variables to it from the data-model-classes, so everything not specified will never be exposed, which is also why #467 looks as is does with this massive schema field.

This is also consistent with prior behavior, because setting the missing max in "Tweaks" did not actually resolve the issue of no bar or breakpoints.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. Fair enough. It was worth a try.

We may want to add a migration to ensure that null/undefined values for encumbrance.max are set to 1600 when this goes out. That default gets pulled from template.json if we're not specifically setting a schema field up for it.

movement: new ObjectField(),
config: new ObjectField(),
initiative: new ObjectField(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ export default class OseDataModelCharacterEncumbranceBasic
return this.value >= this.#treasureEncumbrance;
}

get atHalfEncumbered() {
get atThirdBreakpoint() {
return (
this.#heaviestArmor ===
OseDataModelCharacterEncumbranceBasic.armorWeight.heavy &&
this.value >= this.#treasureEncumbrance
);
}

get atThreeEighthsEncumbered() {
get atSecondBreakpoint() {
const isHeavy =
this.#heaviestArmor ===
OseDataModelCharacterEncumbranceBasic.armorWeight.heavy;
Expand All @@ -126,7 +126,7 @@ export default class OseDataModelCharacterEncumbranceBasic
return isHeavy || isLightWithTreasure;
}

get atQuarterEncumbered() {
get atFirstBreakpoint() {
return (
this.#heaviestArmor ===
OseDataModelCharacterEncumbranceBasic.armorWeight.light ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export default class OseDataModelCharacterEncumbranceItemBased

#max;

#atFiveEighths;
#atThreeQuarters;
#atSevenEights;

#atOneThird;
#atFiveNinths;
#atSevenNinths;

static templateEncumbranceBar = "";

static templateInventoryRow = "";
Expand Down Expand Up @@ -89,6 +97,15 @@ export default class OseDataModelCharacterEncumbranceItemBased
this.#max = this.usingEquippedEncumbrance
? this.#equippedMax
: this.#packedMax;

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);

}

// eslint-disable-next-line class-methods-use-this
Expand Down Expand Up @@ -127,4 +144,22 @@ export default class OseDataModelCharacterEncumbranceItemBased
get max(): number {
return this.#max;
}

get atFirstBreakpoint(): boolean {
return this.usingEquippedEncumbrance
? this.#atOneThird
: this.#atFiveEighths;
}

get atSecondBreakpoint(): boolean {
return this.usingEquippedEncumbrance
? this.#atFiveNinths
: this.#atThreeQuarters;
}

get atThirdBreakpoint(): boolean {
return this.usingEquippedEncumbrance
? this.#atSevenNinths
: this.#atSevenEights;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export interface CharacterEncumbrance {
steps: number[];
value: number;
max: number;
atHalfEncumbered: boolean | null;
atThreeEighthsEncumbered: boolean | null;
atQuarterEncumbered: boolean | null;
atFirstBreakpoint: boolean | null;
atSecondBreakpoint: boolean | null;
atThirdBreakpoint: boolean | null;
}

/**
Expand All @@ -21,17 +21,11 @@ export default class OseDataModelCharacterEncumbrance
implements CharacterEncumbrance
{
static baseEncumbranceCap = 1600;

// Default encumbrance steps used by the 'complete' and 'detailed' encumbrance variants
static encumbranceSteps = {
quarter: 25,
threeEighths: 37.5,
half: 50,
fiveEighths: 62.5,
threeQuarters: 75,
sevenEighths: 87.5,
oneThird: 33.34,
fiveNinths: 55.56,
sevenNinths: 77.78,
half: 50
};

#encumbranceVariant;
Expand Down Expand Up @@ -93,7 +87,7 @@ export default class OseDataModelCharacterEncumbrance
return this.max - OseDataModelCharacterEncumbrance.baseEncumbranceCap;
}

get atHalfEncumbered() {
get atThirdBreakpoint() {
return (
this.value >
this.max *
Expand All @@ -102,7 +96,7 @@ export default class OseDataModelCharacterEncumbrance
);
}

get atThreeEighthsEncumbered() {
get atSecondBreakpoint() {
return (
this.value >
this.max *
Expand All @@ -111,73 +105,12 @@ export default class OseDataModelCharacterEncumbrance
);
}

get atQuarterEncumbered() {
get atFirstBreakpoint() {
return (
this.value >
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.quarter / 100) +
(this.#delta || 0)
);
}

// Item-based encumbrance variant props - packed
get atFiveEighthsEncumbered() {
return (
this.value >
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.fiveEighths / 100)
);
}

get atThreeQuartersEncumbered() {
return (
this.value >
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.threeQuarters / 100)
);
}

get atSevenEighthsEncumbered() {
return (
this.value >
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.sevenEighths / 100)
);
}

// Item-based encumbrance variant props - equipped
// eslint-disable-next-line class-methods-use-this
get usingEquippedEncumbrance() {
return false;
}

get atOneThirdEncumbered() {
return (
this.value >
Math.round(
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.oneThird / 100)
)
);
}

get atFiveNinthsEncumbered() {
return (
this.value >
Math.round(
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.fiveNinths / 100)
)
);
}

get atSevenNinthsEncumbered() {
return (
this.value >
Math.round(
this.max *
(OseDataModelCharacterEncumbrance.encumbranceSteps.sevenNinths / 100)
)
);
}
}
60 changes: 11 additions & 49 deletions src/module/actor/data-model-classes/data-model-character-move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,79 +25,41 @@ export default class OseDataModelCharacterMove implements CharacterMove {

#overEncumbranceLimit;

#halfEncumbered;
#atFirstBreakpoint;

#threeEighthsEncumbered;
#atSecondBreakpoint;

#quarterEncumbered;

#fiveEighthsEncumbered;

#threeQuartersEncumbered;

#sevenEighthsEncumbered;

#usingEquippedEncumbrance;

#oneThirdEncumbered;

#fiveNinthsEncumbered;

#sevenNinthsEncumbered;
#atThirdBreakpoint;

/**
* The constructor
*
* @param {OseDataModelCharacterEncumbrance} encumbrance - An object representing the character's encumbrance values
* @param {boolean} shouldCalculateMovement - Should the class autocalculate movement?
* @param {number} base - The base move rate for the actor
* @param {boolean} usingEquippedEncumbrance - Is the character using equipped encumbrance
*/
constructor(
encumbrance: OseDataModelCharacterEncumbrance = new OseDataModelCharacterEncumbrance(),
shouldCalculateMovement = true,
base = OseDataModelCharacterMove.baseMoveRate,
usingEquippedEncumbrance = encumbrance.usingEquippedEncumbrance
base = OseDataModelCharacterMove.baseMoveRate
) {
// Props necessary for any encumbrance variant
this.#moveBase = base;
this.#autocalculate = shouldCalculateMovement;
this.#encumbranceVariant = encumbrance.variant;
this.#overEncumbranceLimit = encumbrance.encumbered;

// Non-basic encumbrance variant props
this.#halfEncumbered = encumbrance.atHalfEncumbered;
this.#threeEighthsEncumbered = encumbrance.atThreeEighthsEncumbered;
this.#quarterEncumbered = encumbrance.atQuarterEncumbered;

// Item-based encumbrance variant props - packed steps
this.#fiveEighthsEncumbered = encumbrance.atFiveEighthsEncumbered;
this.#threeQuartersEncumbered = encumbrance.atThreeQuartersEncumbered;
this.#sevenEighthsEncumbered = encumbrance.atSevenEighthsEncumbered;
// Item-based encumbrance variant props - equipped steps
this.#usingEquippedEncumbrance = usingEquippedEncumbrance;
this.#oneThirdEncumbered = encumbrance.atOneThirdEncumbered;
this.#fiveNinthsEncumbered = encumbrance.atFiveNinthsEncumbered;
this.#sevenNinthsEncumbered = encumbrance.atSevenNinthsEncumbered;
// Encumbrance Breakpoints
this.#atFirstBreakpoint = encumbrance.atFirstBreakpoint;
this.#atSecondBreakpoint = encumbrance.atSecondBreakpoint;
this.#atThirdBreakpoint = encumbrance.atThirdBreakpoint;
}

#derivedSpeed() {
if (this.#overEncumbranceLimit) return 0;
if (this.#usingEquippedEncumbrance) {
if (this.#sevenNinthsEncumbered) return this.#moveBase * 0.25;
if (this.#fiveNinthsEncumbered) return this.#moveBase * 0.5;
return this.#oneThirdEncumbered ? this.#moveBase * 0.75 : this.#moveBase;
}
if (this.#encumbranceVariant === "itembased") {
if (this.#sevenEighthsEncumbered) return this.#moveBase * 0.25;
if (this.#threeQuartersEncumbered) return this.#moveBase * 0.5;
return this.#fiveEighthsEncumbered
? this.#moveBase * 0.75
: this.#moveBase;
}
if (this.#halfEncumbered) return this.#moveBase * 0.25;
if (this.#threeEighthsEncumbered) return this.#moveBase * 0.5;
return this.#quarterEncumbered ? this.#moveBase * 0.75 : this.#moveBase;
if (this.#atThirdBreakpoint) return this.#moveBase * 0.25;
if (this.#atSecondBreakpoint) return this.#moveBase * 0.5;
return this.#atFirstBreakpoint ? this.#moveBase * 0.75 : this.#moveBase;
}

get base() {
Expand Down
13 changes: 12 additions & 1 deletion src/module/item/data-model-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ export default class OseDataModelItem extends foundry.abstract.DataModel {
cost: new NumberField({ min: 0, initial: 0 }),
containerId: new StringField(),
quantity: new SchemaField({
value: new NumberField({ min: 0, initial: 0 }),
value: new NumberField({ min: 0, initial: 1 }),
max: new NumberField({ min: 0, initial: 0 }),
}),
weight: new NumberField({ min: 0, initial: 0 }),
itemslots: new NumberField({ min: 0, initial: 0 }),
};
}
get cummulativeWeight(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Suggested change
get cummulativeWeight(){
get cumulativeWeight(){

return this.weight * this.quantity.value;
}

get cummulativeCost(){
return this.cost * this.quantity.value;
}

get cummulativeItemslots(){
return Math.ceil(this.itemslots * this.quantity.value);
}

static migrateData(source) {
if (source.details?.description && !source.description)
Expand Down
10 changes: 5 additions & 5 deletions src/templates/actors/partials/character-inventory-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ <h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
{{#if (eq @root.config.encumbrance "basic")}}_{{else if (eq
@root.config.encumbrance
"detailed")}}_{{else if (eq @root.config.encumbrance
"itembased")}}{{item.system.itemslots}}{{else}}{{item.system.weight}}{{/if}}
"itembased")}}{{item.system.cummulativeItemslots}}{{else}}{{item.system.cummulativeWeight}}{{/if}}
</div>
<div class="item-controls">
{{#if @root.owner}}
Expand Down Expand Up @@ -290,7 +290,7 @@ <h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
{{#if (eq @root.config.encumbrance "basic")}}_{{else if (eq
@root.config.encumbrance
"detailed")}}_{{else if (eq @root.config.encumbrance
"itembased")}}{{item.system.itemslots}}{{else}}{{item.system.weight}}{{/if}}
"itembased")}}{{item.system.cummulativeItemslots}}{{else}}{{item.system.cummulativeWeight}}{{/if}}
</div>
<div class="item-controls">
{{#if @root.owner}}
Expand Down Expand Up @@ -336,7 +336,7 @@ <h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
<div class="category-caret"><i class="fas fa-caret-down"></i></div>
<div class="category-name">{{localize "OSE.items.Treasure"}}</div>
<div class="field-long">
{{system.treasure}} <i class="fas fa-circle"></i>
{{treasure}} <i class="fas fa-circle"></i>
</div>
<div class="field-short"><i class="fas fa-hashtag"></i></div>
<div class="field-short"><i class="fas fa-weight-hanging"></i></div>
Expand All @@ -360,7 +360,7 @@ <h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
></div>
<h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
<div class="field-long">
{{mult item.system.quantity.value item.system.cost}}
{{item.system.cummulativeCost}}
</div>
<div class="field-short quantity">
<input
Expand All @@ -375,7 +375,7 @@ <h4 class="item-name" title="{{item.name}}">{{item.name~}}</h4>
</div>
<div class="field-short">
{{#if (eq @root.config.encumbrance
"itembased")}}{{ceil (mult item.system.quantity.value item.system.itemslots)}}{{else}}{{item.system.weight}}{{/if}}{{mult item.system.quantity.value item.system.weight}}
"itembased")}}{{item.system.cummulativeItemslots}}{{else}}{{item.system.cummulativeWeight}}{{/if}}
</div>
<div class="item-controls">
{{#if @root.owner}}
Expand Down