Skip to content
Snippets Groups Projects
Verified Commit 43a9d3a7 authored by Martin Claesson's avatar Martin Claesson
Browse files

fix(inventory): #82 Fix carrying capacity for strength values > 29

parent 29690c31
Branches
Tags
1 merge request!62fix(inventory): Fix coin conversion
import {calculateWeight, PathfinderCarryingCapacities} from "@alboneon/library/helpers/CharacterHelpers" import {calculateWeight, PathfinderCarryingCapacities} from "@alboneon/library/helpers/CharacterHelpers"
import {Enums} from "@alboneon/library/types/Enums" import {Enums} from "@alboneon/library/types/Enums"
import GameSystem = Enums.GameSystem; import GameSystem = Enums.GameSystem;
import {describe, it, test} from "@jest/globals"
import {expect} from "expect"
test("Test Pathfinder Weights", () => { test("Test Pathfinder Weights", () => {
[Enums.Size.FINE, [Enums.Size.FINE,
...@@ -25,6 +27,7 @@ test("Test Pathfinder Weights", () => { ...@@ -25,6 +27,7 @@ test("Test Pathfinder Weights", () => {
}) })
PathfinderCarryingCapacities[Enums.CarryLoad.MEDIUM].forEach((expected, str) => { PathfinderCarryingCapacities[Enums.CarryLoad.MEDIUM].forEach((expected, str) => {
try { try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
expect(calculateWeight(str, Enums.GameSystem.Pathfinder, undefined, size)).toEqual(0) expect(calculateWeight(str, Enums.GameSystem.Pathfinder, undefined, size)).toEqual(0)
} catch (e: unknown) { } catch (e: unknown) {
...@@ -34,7 +37,43 @@ test("Test Pathfinder Weights", () => { ...@@ -34,7 +37,43 @@ test("Test Pathfinder Weights", () => {
}) })
}) })
}) })
it("should test pathfinder weights for > 29", async function () {
[Enums.Size.FINE,
Enums.Size.DIMINUTIVE,
Enums.Size.TINY,
Enums.Size.SMALL,
Enums.Size.MEDIUM,
Enums.Size.LARGE,
Enums.Size.HUGE,
Enums.Size.GARGANTUAN,
Enums.Size.COLOSSAL]
.forEach((size) => {
[Enums.CarryLoad.LIGHT, Enums.CarryLoad.MEDIUM, Enums.CarryLoad.HEAVY].forEach((load) => {
expect(calculateWeight(30, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][20] * 4 * size)
expect(calculateWeight(31, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][21] * 4 * size)
expect(calculateWeight(32, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][22] * 4 * size)
expect(calculateWeight(33, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][23] * 4 * size)
expect(calculateWeight(34, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][24] * 4 * size)
expect(calculateWeight(35, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][25] * 4 * size)
expect(calculateWeight(36, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][26] * 4 * size)
expect(calculateWeight(37, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][27] * 4 * size)
expect(calculateWeight(38, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][28] * 4 * size)
expect(calculateWeight(39, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][29] * 4 * size)
expect(calculateWeight(40, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][20] * 16 * size)
expect(calculateWeight(41, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][21] * 16 * size)
expect(calculateWeight(42, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][22] * 16 * size)
expect(calculateWeight(43, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][23] * 16 * size)
expect(calculateWeight(44, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][24] * 16 * size)
expect(calculateWeight(45, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][25] * 16 * size)
expect(calculateWeight(46, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][26] * 16 * size)
expect(calculateWeight(47, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][27] * 16 * size)
expect(calculateWeight(48, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][28] * 16 * size)
expect(calculateWeight(49, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][29] * 16 * size)
expect(calculateWeight(50, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][20] * 64 * size)
expect(calculateWeight(60, Enums.GameSystem.Pathfinder, load, size)).toEqual(PathfinderCarryingCapacities[load][20] * 256 * size)
})
})
})
test("Test DND5E Weights", () => { test("Test DND5E Weights", () => {
[Enums.Size.FINE, [Enums.Size.FINE,
Enums.Size.DIMINUTIVE, Enums.Size.DIMINUTIVE,
......
...@@ -113,7 +113,17 @@ export function calculateWeight(str: number, system: Enums.GameSystem, acceptedL ...@@ -113,7 +113,17 @@ export function calculateWeight(str: number, system: Enums.GameSystem, acceptedL
return 0 return 0
} }
if (system === Enums.GameSystem.Pathfinder) { if (system === Enums.GameSystem.Pathfinder) {
if (str < PathfinderCarryingCapacities[acceptedLoad].length) {
return PathfinderCarryingCapacities[acceptedLoad][str] * size return PathfinderCarryingCapacities[acceptedLoad][str] * size
}
let localStr = str - 20
let modifier = 1
while (localStr >= 10) {
modifier *= 4
localStr -= 10
}
const baseValue = (str%10 + 20)
return PathfinderCarryingCapacities[acceptedLoad][baseValue] * modifier * size
} else { } else {
let multiplier = 0 let multiplier = 0
switch (acceptedLoad) { switch (acceptedLoad) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment