BlueGit

timfa questward

Files

questward / shared / items / stackRules.js

stackRules.js

stackRules.js 1.3 KiB Download Raw
1import { ItemId, COIN_MAX_STACK, DEFAULT_MAX_STACK } from "../definitions/items.js";
2
3/** Effective stack behaviour for inventory vs bank vault. */
4export function stackRulesFor (definition, { inVault = false } = {})
5{
6 if (!definition)
7 { return { stackable: false, maxStackSize: 1, uniqueInstance: true }; }
8 if (definition.itemId === ItemId.coins)
9 {
10 return {
11 stackable: true,
12 maxStackSize: COIN_MAX_STACK,
13 uniqueInstance: false
14 };
15 }
16 if (definition.uniqueInstance)
17 {
18 return { stackable: false, maxStackSize: 1, uniqueInstance: true };
19 }
20 if (definition.equipment?.kind === "arrowAmmo" && !inVault)
21 {
22 return {
23 stackable: true,
24 maxStackSize: definition.maxStackSize ?? 999,
25 uniqueInstance: false
26 };
27 }
28 if (definition.equipment && !inVault)
29 {
30 return { stackable: false, maxStackSize: 1, uniqueInstance: false };
31 }
32 if (definition.equipment && inVault)
33 {
34 return {
35 stackable: true,
36 maxStackSize: Number.POSITIVE_INFINITY,
37 uniqueInstance: false
38 };
39 }
40 if (inVault)
41 {
42 return {
43 stackable: definition.stackable !== false,
44 maxStackSize: Number.POSITIVE_INFINITY,
45 uniqueInstance: false
46 };
47 }
48 return {
49 stackable: definition.stackable !== false,
50 maxStackSize: definition.maxStackSize ?? DEFAULT_MAX_STACK,
51 uniqueInstance: false
52 };
53}