BlueGit

timfa questward

Files

questward / shared / items / stackRules.js

stackRules.js

stackRules.js 1.1 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 && !inVault)
21 {
22 return { stackable: false, maxStackSize: 1, uniqueInstance: false };
23 }
24 if (definition.equipment && inVault)
25 {
26 return {
27 stackable: true,
28 maxStackSize: Number.POSITIVE_INFINITY,
29 uniqueInstance: false
30 };
31 }
32 if (inVault)
33 {
34 return {
35 stackable: definition.stackable !== false,
36 maxStackSize: Number.POSITIVE_INFINITY,
37 uniqueInstance: false
38 };
39 }
40 return {
41 stackable: definition.stackable !== false,
42 maxStackSize: definition.maxStackSize ?? DEFAULT_MAX_STACK,
43 uniqueInstance: false
44 };
45}