Fix encumbrance calculations
parent
7a548e55b5
commit
2606d577aa
|
@ -900,15 +900,6 @@
|
|||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
.acks.sheet.actor.character .encumbrance .encumbrance-breakpoint.encumbrance-25 {
|
||||
left: 24.4%;
|
||||
}
|
||||
.acks.sheet.actor.character .encumbrance .encumbrance-breakpoint.encumbrance-35 {
|
||||
left: 34.4%;
|
||||
}
|
||||
.acks.sheet.actor.character .encumbrance .encumbrance-breakpoint.encumbrance-50 {
|
||||
left: 49.4%;
|
||||
}
|
||||
.acks.sheet.actor.character .encumbrance .arrow-up {
|
||||
bottom: 0;
|
||||
width: 0;
|
||||
|
|
|
@ -50,7 +50,6 @@ export class AcksActorSheetCharacter extends AcksActorSheet {
|
|||
|
||||
data.config.ascendingAC = game.settings.get("acks", "ascendingAC");
|
||||
data.config.initiative = game.settings.get("acks", "initiative") != "group";
|
||||
data.config.encumbrance = game.settings.get("acks", "encumbranceOption");
|
||||
data.config.BHR = game.settings.get("acks", "bhr");
|
||||
data.config.removeMagicBonus = game.settings.get("acks", "removeMagicBonus");
|
||||
|
||||
|
|
|
@ -608,92 +608,67 @@ export class AcksActor extends Actor {
|
|||
}
|
||||
|
||||
computeEncumbrance() {
|
||||
if (this.data.type != "character") {
|
||||
if (this.data.type !== "character") {
|
||||
return;
|
||||
}
|
||||
const data = this.data.data;
|
||||
let option = game.settings.get("acks", "encumbranceOption");
|
||||
|
||||
// Compute encumbrance
|
||||
let totalWeight = 0;
|
||||
let hasItems = false;
|
||||
Object.values(this.data.items).forEach((item) => {
|
||||
if (item.type == "item" && !item.data.treasure) {
|
||||
if (option === "detailed") totalWeight += 166.6;
|
||||
const option = game.settings.get("acks", "encumbranceOption");
|
||||
|
||||
// hasItems = true;
|
||||
}
|
||||
if (
|
||||
item.type == "item" &&
|
||||
(["complete", "disabled"].includes(option) || item.data.treasure)
|
||||
) {
|
||||
totalWeight += item.data.quantity.value * item.data.weight;
|
||||
} else if (option != "basic" && ["weapon", "armor"].includes(item.type)) {
|
||||
totalWeight += item.data.weight;
|
||||
let totalEncumbrance = 0;
|
||||
|
||||
this.data.items.forEach((item) => {
|
||||
if (item.type === "item") {
|
||||
if (option === "detailed") {
|
||||
if (item.data.data.treasure) {
|
||||
totalEncumbrance += item.data.data.weight * item.data.data.quantity.value;
|
||||
} else {
|
||||
totalEncumbrance += item.data.data.weight;
|
||||
}
|
||||
} else {
|
||||
if (item.data.data.treasure) {
|
||||
totalEncumbrance += 1000 * item.data.data.quantity.value;
|
||||
} else {
|
||||
totalEncumbrance += 1000;
|
||||
}
|
||||
}
|
||||
} else if (["weapon", "armor"].includes(item.type)) {
|
||||
if (option === "detailed") {
|
||||
totalEncumbrance += item.data.data.weight;
|
||||
} else {
|
||||
totalEncumbrance += 1000;
|
||||
}
|
||||
}
|
||||
});
|
||||
// if (option === "detailed" && hasItems) totalWeight += 166.6;
|
||||
|
||||
data.encumbrance = {
|
||||
const maxEncumbrance = 20000 + (this.data.data.scores.str.mod * 1000);
|
||||
|
||||
this.data.data.encumbrance = {
|
||||
pct: Math.clamped(
|
||||
// To correct for percentage bar not lining up with movement rates.
|
||||
// (100 * parseFloat(totalWeight)) / data.encumbrance.max,
|
||||
(100 * parseFloat(totalWeight)) / 20000,
|
||||
(totalEncumbrance / maxEncumbrance) * 100,
|
||||
0,
|
||||
100
|
||||
),
|
||||
max: data.encumbrance.max,
|
||||
encumbered: totalWeight > data.encumbrance.max,
|
||||
value: Math.round(totalWeight),
|
||||
max: maxEncumbrance,
|
||||
encumbered: totalEncumbrance > maxEncumbrance,
|
||||
value: Math.round(totalEncumbrance),
|
||||
};
|
||||
|
||||
if (data.config.movementAuto && option != "disabled") {
|
||||
if (this.data.data.config.movementAuto) {
|
||||
this._calculateMovement();
|
||||
}
|
||||
}
|
||||
|
||||
_calculateMovement() {
|
||||
const data = this.data.data;
|
||||
let option = game.settings.get("acks", "encumbranceOption");
|
||||
let weight = data.encumbrance.value;
|
||||
if (["detailed", "complete"].includes(option)) {
|
||||
if (weight > data.encumbrance.max) {
|
||||
data.movement.base = 0;
|
||||
} else if (weight > 10000) {
|
||||
data.movement.base = 30;
|
||||
} else if (weight > 7000) {
|
||||
data.movement.base = 60;
|
||||
} else if (weight > 5000) {
|
||||
data.movement.base = 90;
|
||||
} else {
|
||||
data.movement.base = 120;
|
||||
}
|
||||
} else if (option == "basic") {
|
||||
const armors = this.data.items.filter((i) => i.type == "armor");
|
||||
let heaviest = 0;
|
||||
armors.forEach((a) => {
|
||||
if (a.data.equipped) {
|
||||
if (a.data.type == "light" && heaviest == 0) {
|
||||
heaviest = 1;
|
||||
} else if (a.data.type == "heavy") {
|
||||
heaviest = 2;
|
||||
}
|
||||
}
|
||||
});
|
||||
switch (heaviest) {
|
||||
case 0:
|
||||
data.movement.base = 120;
|
||||
break;
|
||||
case 1:
|
||||
data.movement.base = 90;
|
||||
break;
|
||||
case 2:
|
||||
data.movement.base = 60;
|
||||
break;
|
||||
}
|
||||
if (weight > game.settings.get("acks", "significantTreasure")) {
|
||||
data.movement.base -= 30;
|
||||
}
|
||||
if (this.data.data.encumbrance.value > this.data.data.encumbrance.max) {
|
||||
this.data.data.movement.base = 0;
|
||||
} else if (this.data.data.encumbrance.value > 10000) {
|
||||
this.data.data.movement.base = 30;
|
||||
} else if (this.data.data.encumbrance.value > 7000) {
|
||||
this.data.data.movement.base = 60;
|
||||
} else if (this.data.data.encumbrance.value > 5000) {
|
||||
this.data.data.movement.base = 90;
|
||||
} else {
|
||||
this.data.data.movement.base = 120;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,13 +23,21 @@ export const registerHelpers = async function () {
|
|||
});
|
||||
|
||||
Handlebars.registerHelper("subtract", function (lh, rh) {
|
||||
return parseInt(rh) - parseInt(lh);
|
||||
return parseInt(lh) - parseInt(rh);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("fsubtract", (lh, rh) => {
|
||||
return parseFloat(lh) - parseFloat(rh);
|
||||
})
|
||||
|
||||
Handlebars.registerHelper("divide", function (lh, rh) {
|
||||
return Math.floor(parseFloat(lh) / parseFloat(rh));
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("fdivide", (lh, rh) => {
|
||||
return parseFloat(lh) / parseFloat(rh);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper("mult", function (lh, rh) {
|
||||
return parseFloat(lh) * parseFloat(rh);
|
||||
});
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
{{/each}}
|
||||
</div>
|
||||
<div class="field-short">
|
||||
{{#if (eq @root.config.encumbrance "basic")}}_{{else}}{{item.data.weight}}{{/if}}
|
||||
{{#if (eq @root.config.encumbrance "detailed")}}{{item.data.weight}}{{else}}_{{/if}}
|
||||
</div>
|
||||
<div class="item-controls">
|
||||
{{#if ../owner}}
|
||||
|
@ -87,7 +87,7 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
<div class="field-short">
|
||||
{{#if (eq @root.config.encumbrance "basic")}}_{{else}}{{item.data.weight}}{{/if}}
|
||||
{{#if (eq @root.config.encumbrance "detailed")}}{{item.data.weight}}{{else}}_{{/if}}
|
||||
</div>
|
||||
<div class="item-controls">
|
||||
{{#if ../owner}}
|
||||
|
@ -134,7 +134,7 @@
|
|||
placeholder="0" />{{#if item.data.quantity.max}}<span>/{{item.data.quantity.max}}</span>{{/if}}
|
||||
</div>
|
||||
<div class="field-short">
|
||||
{{#if (eq @root.config.encumbrance "basic")}}_{{else if (eq @root.config.encumbrance "detailed")}}_{{else}}{{item.data.weight}}{{/if}}
|
||||
{{#if (eq @root.config.encumbrance "detailed")}}{{item.data.weight}}{{else}}_{{/if}}
|
||||
</div>
|
||||
<div class="item-controls">
|
||||
{{#if ../owner}}
|
||||
|
@ -157,7 +157,7 @@
|
|||
<div class="field-short"><i class="fas fa-hashtag"></i></div>
|
||||
<div class="field-short"><i class="fas fa-weight-hanging"></i></div>
|
||||
<div class="item-controls">
|
||||
<a class="item-control item-create" data-type="item" data-treasure="true" title="{{localize 'ACKS.Add'}}"><i
|
||||
<a class="item-control item-create" data-type="item" data-treasure="true" data-weight=1000 title="{{localize 'ACKS.Add'}}"><i
|
||||
class="fa fa-plus"></i></a>
|
||||
</div>
|
||||
</li>
|
||||
|
@ -180,7 +180,7 @@
|
|||
placeholder="0" />{{#if item.data.quantity.max}}<span>/{{item.data.quantity.max}}</span>{{/if}}
|
||||
</div>
|
||||
<div class="field-short">
|
||||
{{mult item.data.quantity.value item.data.weight}}
|
||||
{{#if (eq @root.config.encumbrance "detailed")}}{{mult item.data.quantity.value item.data.weight}}{{else}}_{{/if}}
|
||||
</div>
|
||||
<div class="item-controls">
|
||||
{{#if ../owner}}
|
||||
|
@ -200,12 +200,12 @@
|
|||
<div class="encumbrance {{#if encumbered}}encumbered{{/if}}">
|
||||
<span class="encumbrance-bar" style="width:{{pct}}%"></span>
|
||||
<span class="encumbrance-label">{{value}} / {{max}}</span>
|
||||
<i class="encumbrance-breakpoint encumbrance-25 arrow-up"></i>
|
||||
<i class="encumbrance-breakpoint encumbrance-25 arrow-down"></i>
|
||||
<i class="encumbrance-breakpoint encumbrance-35 arrow-up"></i>
|
||||
<i class="encumbrance-breakpoint encumbrance-35 arrow-down"></i>
|
||||
<i class="encumbrance-breakpoint encumbrance-50 arrow-up"></i>
|
||||
<i class="encumbrance-breakpoint encumbrance-50 arrow-down"></i>
|
||||
<i class="encumbrance-breakpoint arrow-up" style="left: {{fsubtract (mult (fdivide 5000 max) 100) 1}}%"></i>
|
||||
<i class="encumbrance-breakpoint arrow-down" style="left: {{fsubtract (mult (fdivide 5000 max) 100) 1}}%"></i>
|
||||
<i class="encumbrance-breakpoint arrow-up" style="left: {{fsubtract (mult (fdivide 7000 max) 100) 1}}%"></i>
|
||||
<i class="encumbrance-breakpoint arrow-down" style="left: {{fsubtract (mult (fdivide 7000 max) 100) 1}}%"></i>
|
||||
<i class="encumbrance-breakpoint arrow-up" style="left: {{fsubtract (mult (fdivide 10000 max) 100) 1}}%"></i>
|
||||
<i class="encumbrance-breakpoint arrow-down" style="left: {{fsubtract (mult (fdivide 10000 max) 100) 1}}%"></i>
|
||||
{{/with}}
|
||||
</div>
|
||||
</section>
|
Loading…
Reference in New Issue