BlueGit

timfa questward

Files

questward / shared / items / inventory.js

inventory.js

inventory.js 20.8 KiB Download Raw
1export const INVENTORY_SLOTS = 32;
2export const EQUIPMENT_SLOTS = Object.freeze([
3 "head",
4 "chest",
5 "legs",
6 "boots",
7 "weapon",
8 "offhand",
9 "ring",
10 "bracelet",
11 "amulet"
12]);
13
14import { attachOrigins, mergeOriginLists, normalizeOrigins, splitOrigins } from "./origin.js";
15import { stackRulesFor } from "./stackRules.js";
16import { BLANK_CHEQUE_CARRY_CAP, ItemId, itemDefinition } from "../definitions/items.js";
17import { normalizeChargeStack } from "./charges.js";
18
19/** Stack counts can exceed 32-bit range (coin stacks up to 999B). */
20export function stackQuantity (value)
21{
22 const n = Number(value);
23 if (!Number.isFinite(n) || n <= 0)
24 { return 0; }
25 const q = Math.floor(n);
26 return Number.isSafeInteger(q) ? q : 0;
27}
28
29export function emptySlots (count = INVENTORY_SLOTS)
30{
31 return Array.from({ length: count }, () => null);
32}
33
34export function emptyEquipment ()
35{
36 const slots = {};
37 for (const slot of EQUIPMENT_SLOTS)
38 { slots[slot] = null; }
39 return { slots };
40}
41
42export function cloneStack (stack)
43{
44 return stack ? structuredClone(stack) : null;
45}
46
47/** One item from a stack, preserving a single origin slice (for equip). */
48export function singleItemFromStack (stack)
49{
50 if (!stack)
51 { return null; }
52 const split = splitOrigins(normalizeOrigins(stack), 1);
53 return {
54 itemId: stack.itemId,
55 quantity: 1,
56 instance: stack.instance ? cloneStack(stack.instance) : null,
57 origins: split.taken
58 };
59}
60
61export function potionStackIdentity (instance)
62{
63 if (!instance || instance.kind !== "potion")
64 { return null; }
65 const effectKey = instance.effectKey
66 ?? (instance.effect ? JSON.stringify(instance.effect) : "");
67 const fill = Math.max(1, Math.min(5, instance.fillLevel | 0 || 4));
68 return `${instance.potionKey ?? ""}|${effectKey}|${fill}`;
69}
70
71/** Dye stacks merge when RGB and remaining uses match exactly. */
72export function dyeStackIdentity (instance)
73{
74 if (!instance || instance.kind !== "dye" || !instance.color)
75 { return null; }
76 const fill = Math.max(1, Math.min(5, instance.fillLevel | 0 || 4));
77 return [
78 Math.round((instance.color.r ?? 0) * 1000),
79 Math.round((instance.color.g ?? 0) * 1000),
80 Math.round((instance.color.b ?? 0) * 1000),
81 fill
82 ].join(",");
83}
84
85export function stacksMatch (left, right, definition, { inVault = false } = {})
86{
87 if (!left || !right || left.itemId !== right.itemId)
88 { return false; }
89 const rules = stackRulesFor(definition, { inVault });
90 if (rules.uniqueInstance)
91 {
92 return JSON.stringify(left.instance ?? null) === JSON.stringify(right.instance ?? null);
93 }
94 if (definition?.potion)
95 {
96 const a = potionStackIdentity(left.instance);
97 const b = potionStackIdentity(right.instance);
98 return a != null && a === b;
99 }
100 if (definition?.dye)
101 {
102 const a = dyeStackIdentity(left.instance);
103 const b = dyeStackIdentity(right.instance);
104 return a != null && a === b;
105 }
106 if (left.instance != null || right.instance != null)
107 { return JSON.stringify(left.instance ?? null) === JSON.stringify(right.instance ?? null); }
108 return rules.stackable;
109}
110
111function stackPayload (stack, quantity, origins)
112{
113 return {
114 itemId: stack.itemId,
115 quantity,
116 instance: stack.instance ?? null,
117 origins: origins.map((entry) => ({
118 origin: entry.origin ?? null,
119 quantity: stackQuantity(entry.quantity)
120 })).filter((entry) => entry.quantity > 0)
121 };
122}
123
124export function insertStack (slots, stack, definition, options = {})
125{
126 if (!stack || stack.quantity <= 0)
127 { return { ok: true, slots: slots.map(cloneStack), remainder: 0 }; }
128 const rules = stackRulesFor(definition, options);
129 const next = slots.map(cloneStack);
130 let remaining = stackQuantity(stack.quantity);
131 let pendingOrigins = normalizeOrigins(stack);
132
133 if (rules.stackable && !rules.uniqueInstance)
134 {
135 for (const slot of next)
136 {
137 if (!slot || !stacksMatch(slot, stack, definition, options))
138 { continue; }
139 const space = rules.maxStackSize - stackQuantity(slot.quantity);
140 if (space <= 0)
141 { continue; }
142 const add = Math.min(space, remaining);
143 const split = splitOrigins(pendingOrigins, add);
144 slot.origins = mergeOriginLists(normalizeOrigins(slot), split.taken);
145 slot.quantity = stackQuantity(slot.quantity) + add;
146 if (stack.instance != null && slot.instance == null)
147 { slot.instance = cloneStack(stack.instance); }
148 delete slot.origin;
149 pendingOrigins = split.remain;
150 remaining -= add;
151 if (remaining === 0)
152 { return { ok: true, slots: next, remainder: 0 }; }
153 }
154 }
155
156 for (let i = 0; i < next.length; i++)
157 {
158 if (next[i])
159 { continue; }
160 const cap = rules.maxStackSize === Number.POSITIVE_INFINITY ? remaining : rules.maxStackSize;
161 const amount = rules.stackable && !rules.uniqueInstance
162 ? Math.min(remaining, cap)
163 : 1;
164 const split = splitOrigins(pendingOrigins, amount);
165 next[i] = stackPayload(stack, amount, split.taken);
166 pendingOrigins = split.remain;
167 remaining -= amount;
168 if (remaining === 0)
169 { return { ok: true, slots: next, remainder: 0 }; }
170 if (!rules.stackable || rules.uniqueInstance)
171 { break; }
172 }
173 return { ok: false, slots, remainder: remaining };
174}
175
176/** How many of `stack` can fit into `slots` under bag/vault stack rules. */
177export function fitStackQuantity (slots, stack, definition, options = {})
178{
179 if (!stack)
180 { return 0; }
181 const want = stackQuantity(stack.quantity);
182 if (want <= 0)
183 { return 0; }
184 const rules = stackRulesFor(definition, options);
185 let space = 0;
186
187 if (rules.stackable && !rules.uniqueInstance)
188 {
189 for (const slot of slots ?? [])
190 {
191 if (!slot || !stacksMatch(slot, stack, definition, options))
192 { continue; }
193 space += Math.max(0, rules.maxStackSize - stackQuantity(slot.quantity));
194 if (space >= want)
195 { return want; }
196 }
197 }
198
199 for (const slot of slots ?? [])
200 {
201 if (slot)
202 { continue; }
203 if (rules.stackable && !rules.uniqueInstance)
204 {
205 const cap = rules.maxStackSize === Number.POSITIVE_INFINITY
206 ? want - space
207 : rules.maxStackSize;
208 space += Math.max(0, cap);
209 }
210 else
211 { space += 1; }
212 if (space >= want)
213 { return want; }
214 if (!rules.stackable || rules.uniqueInstance)
215 { break; }
216 }
217 return Math.min(want, space);
218}
219
220export function takeFromSlot (slots, slotIndex, quantity = null)
221{
222 const next = slots.map(cloneStack);
223 const slot = next[slotIndex];
224 if (!slot)
225 { return { ok: false, slots, taken: null }; }
226 const maxQty = stackQuantity(slot.quantity);
227 const amount = quantity == null
228 ? maxQty
229 : Math.min(maxQty, Math.max(1, stackQuantity(quantity)));
230 if (amount <= 0)
231 { return { ok: false, slots, taken: null }; }
232 const split = splitOrigins(normalizeOrigins(slot), amount);
233 const taken = stackPayload(slot, amount, split.taken);
234 if (amount >= maxQty)
235 { next[slotIndex] = null; }
236 else
237 {
238 slot.quantity = maxQty - amount;
239 slot.origins = split.remain;
240 delete slot.origin;
241 }
242 return { ok: true, slots: next, taken };
243}
244
245/**
246 * Move or merge a bag stack from one slot into another (same bag).
247 * Empty target → move. Matching stackable → merge into target. Else → swap.
248 */
249export function moveInventorySlot (slots, fromIndex, toIndex)
250{
251 const next = (slots ?? emptySlots()).map(cloneStack);
252 const from = fromIndex | 0;
253 const to = toIndex | 0;
254 if (from === to)
255 { return { ok: true, slots: next, changed: false }; }
256 if (from < 0 || to < 0 || from >= next.length || to >= next.length)
257 { return { ok: false, slots, reason: "Invalid slot." }; }
258 const source = next[from];
259 if (!source || stackQuantity(source.quantity) <= 0)
260 { return { ok: false, slots, reason: "That inventory slot is empty." }; }
261
262 const dest = next[to];
263 if (!dest)
264 {
265 next[to] = source;
266 next[from] = null;
267 return { ok: true, slots: next, changed: true };
268 }
269
270 const def = itemDefinition(source.itemId);
271 if (stacksMatch(source, dest, def))
272 {
273 const rules = stackRulesFor(def);
274 if (rules.stackable && !rules.uniqueInstance)
275 {
276 const space = rules.maxStackSize === Number.POSITIVE_INFINITY
277 ? stackQuantity(source.quantity)
278 : Math.max(0, rules.maxStackSize - stackQuantity(dest.quantity));
279 if (space > 0)
280 {
281 const add = Math.min(space, stackQuantity(source.quantity));
282 const split = splitOrigins(normalizeOrigins(source), add);
283 dest.origins = mergeOriginLists(normalizeOrigins(dest), split.taken);
284 dest.quantity = stackQuantity(dest.quantity) + add;
285 if (source.instance != null && dest.instance == null)
286 { dest.instance = cloneStack(source.instance); }
287 delete dest.origin;
288 const remainQty = stackQuantity(source.quantity) - add;
289 if (remainQty <= 0)
290 { next[from] = null; }
291 else
292 {
293 source.quantity = remainQty;
294 source.origins = split.remain;
295 delete source.origin;
296 }
297 return { ok: true, slots: next, changed: true };
298 }
299 }
300 }
301
302 next[from] = dest;
303 next[to] = source;
304 return { ok: true, slots: next, changed: true };
305}
306
307/**
308 * Spend one fill charge from a potion/dye slot without losing the leftover bottle.
309 * Single bottles always mutate in place (or become an empty bottle). Multi-stacks
310 * peel one bottle and re-insert the reduced fill; tries both split orderings so a
311 * matching stack can absorb either side. Never mutates the input slots array.
312 *
313 * @returns {{ ok: true, slots, exhausted: boolean, instance: object } | { ok: false, reason: string }}
314 */
315export function consumeFillCharge (slots, slotIndex, {
316 kind = null,
317 itemId = null,
318 definition = null,
319 returnEmptyItemId = null
320} = {})
321{
322 const index = slotIndex | 0;
323 const source = slots?.[index];
324 if (!source || stackQuantity(source.quantity) <= 0)
325 { return { ok: false, reason: "empty" }; }
326 if (itemId != null && source.itemId !== itemId)
327 { return { ok: false, reason: "wrong-item" }; }
328 if (kind != null && source.instance?.kind !== kind)
329 { return { ok: false, reason: "wrong-item" }; }
330 const def = definition ?? itemDefinition(source.itemId);
331 if (!def)
332 { return { ok: false, reason: "unknown" }; }
333
334 const fill = Math.max(1, Math.min(5, source.instance?.fillLevel | 0 || 4));
335 const qty = stackQuantity(source.quantity);
336 const usedInstance = cloneStack(source.instance) ?? { kind, fillLevel: fill };
337
338 if (qty === 1)
339 {
340 const next = slots.map(cloneStack);
341 if (fill <= 1)
342 {
343 next[index] = null;
344 if (returnEmptyItemId)
345 {
346 const emptyDef = itemDefinition(returnEmptyItemId);
347 const emptyStack = attachOrigins({
348 itemId: returnEmptyItemId,
349 quantity: 1,
350 origins: normalizeOrigins(source)
351 });
352 const inserted = insertStack(next, emptyStack, emptyDef);
353 if (!inserted.ok || inserted.remainder > 0)
354 { return { ok: false, reason: "space" }; }
355 return { ok: true, slots: inserted.slots, exhausted: true, instance: usedInstance };
356 }
357 return { ok: true, slots: next, exhausted: true, instance: usedInstance };
358 }
359 next[index].instance = { ...next[index].instance, fillLevel: fill - 1 };
360 return { ok: true, slots: next, exhausted: false, instance: usedInstance };
361 }
362
363 // Multi-stack: try leaving the remainder in place, then the reduced bottle in place.
364 const reducedFirst = tryPeelFillCharge(slots, index, fill, def, returnEmptyItemId, false);
365 if (reducedFirst.ok)
366 { return { ...reducedFirst, instance: usedInstance }; }
367 const remainderFirst = tryPeelFillCharge(slots, index, fill, def, returnEmptyItemId, true);
368 if (remainderFirst.ok)
369 { return { ...remainderFirst, instance: usedInstance }; }
370 return { ok: false, reason: "space" };
371}
372
373function tryPeelFillCharge (slots, index, fill, def, returnEmptyItemId, remainderStaysInSlot)
374{
375 const peeled = takeFromSlot(slots, index, 1);
376 if (!peeled.ok || !peeled.taken)
377 { return { ok: false }; }
378
379 if (fill <= 1)
380 {
381 if (!returnEmptyItemId)
382 { return { ok: true, slots: peeled.slots, exhausted: true }; }
383 const emptyDef = itemDefinition(returnEmptyItemId);
384 const emptyStack = attachOrigins({
385 itemId: returnEmptyItemId,
386 quantity: 1,
387 origins: normalizeOrigins(peeled.taken)
388 });
389 const inserted = insertStack(peeled.slots, emptyStack, emptyDef);
390 if (!inserted.ok || inserted.remainder > 0)
391 { return { ok: false }; }
392 return { ok: true, slots: inserted.slots, exhausted: true };
393 }
394
395 const reduced = {
396 itemId: peeled.taken.itemId,
397 quantity: 1,
398 instance: { ...cloneStack(peeled.taken.instance), fillLevel: fill - 1 },
399 origins: peeled.taken.origins
400 };
401 const remainder = peeled.slots[index]
402 ? cloneStack(peeled.slots[index])
403 : null;
404
405 if (!remainderStaysInSlot)
406 {
407 const inserted = insertStack(peeled.slots, reduced, def);
408 if (!inserted.ok || inserted.remainder > 0)
409 { return { ok: false }; }
410 return { ok: true, slots: inserted.slots, exhausted: false };
411 }
412
413 // Put reduced bottle back in the original slot; re-home the untouched remainder.
414 const next = peeled.slots.map(cloneStack);
415 next[index] = stackPayload(reduced, 1, normalizeOrigins(reduced));
416 if (!remainder)
417 { return { ok: true, slots: next, exhausted: false }; }
418 const inserted = insertStack(next, remainder, def);
419 if (!inserted.ok || inserted.remainder > 0)
420 { return { ok: false }; }
421 return { ok: true, slots: inserted.slots, exhausted: false };
422}
423
424/** Like insertStack, but grows the slot array when capacity runs out (vault). */
425export function insertStackGrowable (slots, stack, definition)
426{
427 if (!stack || stack.quantity <= 0)
428 { return { ok: true, slots: (slots ?? []).map(cloneStack), remainder: 0 }; }
429 let next = (slots ?? []).map(cloneStack);
430 let remaining = stackQuantity(stack.quantity);
431 let pendingOrigins = normalizeOrigins(stack);
432 const rules = stackRulesFor(definition, { inVault: true });
433
434 if (rules.stackable && !rules.uniqueInstance)
435 {
436 for (const slot of next)
437 {
438 if (!slot || !stacksMatch(slot, stack, definition, { inVault: true }))
439 { continue; }
440 const space = rules.maxStackSize - stackQuantity(slot.quantity);
441 if (space <= 0)
442 { continue; }
443 const add = Math.min(space, remaining);
444 const split = splitOrigins(pendingOrigins, add);
445 slot.origins = mergeOriginLists(normalizeOrigins(slot), split.taken);
446 slot.quantity = stackQuantity(slot.quantity) + add;
447 if (stack.instance != null && slot.instance == null)
448 { slot.instance = cloneStack(stack.instance); }
449 delete slot.origin;
450 pendingOrigins = split.remain;
451 remaining -= add;
452 if (remaining === 0)
453 { return { ok: true, slots: next, remainder: 0 }; }
454 }
455 }
456
457 while (remaining > 0)
458 {
459 const cap = rules.maxStackSize === Number.POSITIVE_INFINITY ? remaining : rules.maxStackSize;
460 const amount = rules.stackable && !rules.uniqueInstance
461 ? Math.min(remaining, cap)
462 : 1;
463 const split = splitOrigins(pendingOrigins, amount);
464 next.push(stackPayload(stack, amount, split.taken));
465 pendingOrigins = split.remain;
466 remaining -= amount;
467 if (!rules.stackable || rules.uniqueInstance)
468 { break; }
469 }
470 return { ok: remaining === 0, slots: next, remainder: remaining };
471}
472
473/** Take `quantity` of matching goods from slots (any slots). Vault may compact; inventory should pass `{ compact: false }`. */
474export function takeMatchingFromSlots (slots, { itemId, quantity, instance = null, compact = true })
475{
476 let remaining = Math.max(0, stackQuantity(quantity));
477 if (!remaining)
478 { return { ok: false, slots, taken: null }; }
479 const next = (slots ?? []).map(cloneStack);
480 const takenOrigins = [];
481 for (let i = 0; i < next.length && remaining > 0; i++)
482 {
483 const slot = next[i];
484 if (!slot || slot.itemId !== itemId)
485 { continue; }
486 if (instance != null)
487 {
488 if (JSON.stringify(slot.instance ?? null) !== JSON.stringify(instance))
489 { continue; }
490 }
491 const amount = Math.min(stackQuantity(slot.quantity), remaining);
492 const split = splitOrigins(normalizeOrigins(slot), amount);
493 takenOrigins.push(...split.taken);
494 if (amount >= stackQuantity(slot.quantity))
495 { next[i] = null; }
496 else
497 {
498 slot.quantity = stackQuantity(slot.quantity) - amount;
499 slot.origins = split.remain;
500 delete slot.origin;
501 }
502 remaining -= amount;
503 }
504 if (remaining > 0)
505 { return { ok: false, slots, taken: null }; }
506 return {
507 ok: true,
508 slots: compact ? next.filter((slot) => slot) : next,
509 taken: attachOrigins({
510 itemId,
511 quantity: stackQuantity(quantity),
512 instance: instance ?? null,
513 origins: mergeOriginLists([], takenOrigins)
514 })
515 };
516}
517
518export function countItemInSlots (slots, itemId)
519{
520 let total = 0;
521 for (const slot of slots ?? [])
522 {
523 if (slot?.itemId === itemId)
524 { total += stackQuantity(slot.quantity); }
525 }
526 return total;
527}
528
529export function countCoinsInSlots (slots)
530{
531 return countItemInSlots(slots, ItemId.coins);
532}
533
534/** Remove coin quantity from bag slots (FIFO across coin stacks). */
535export function takeCoinsFromSlots (slots, amount)
536{
537 let remaining = stackQuantity(amount);
538 if (!remaining)
539 { return { ok: true, slots: (slots ?? []).map(cloneStack) }; }
540 if (countCoinsInSlots(slots) < remaining)
541 { return { ok: false, slots: (slots ?? []).map(cloneStack) }; }
542 let next = (slots ?? []).map(cloneStack);
543 for (let i = 0; i < next.length && remaining > 0; i++)
544 {
545 if (!next[i] || next[i].itemId !== ItemId.coins)
546 { continue; }
547 const taken = takeFromSlot(next, i, remaining);
548 if (!taken.ok)
549 { continue; }
550 next = taken.slots;
551 remaining -= stackQuantity(taken.taken?.quantity);
552 }
553 return { ok: remaining === 0, slots: next };
554}
555
556/** Add coin stacks, splitting at max stack size (999B). */
557export function addCoinsToSlots (slots, amount, { growable = false } = {})
558{
559 const def = itemDefinition(ItemId.coins);
560 if (!def || amount <= 0)
561 { return { ok: true, slots: (slots ?? []).map(cloneStack), remainder: 0 }; }
562 let next = (slots ?? []).map(cloneStack);
563 if (!growable && next.length < INVENTORY_SLOTS)
564 {
565 const padded = emptySlots();
566 for (let i = 0; i < next.length; i++)
567 { padded[i] = next[i]; }
568 next = padded;
569 }
570 let remaining = stackQuantity(amount);
571 const insert = growable ? insertStackGrowable : insertStack;
572 while (remaining > 0)
573 {
574 const chunk = Math.min(remaining, def.maxStackSize ?? 99);
575 const result = insert(next, attachOrigins({ itemId: ItemId.coins, quantity: chunk }), def);
576 next = result.slots;
577 const placed = chunk - (result.remainder ?? 0);
578 remaining -= placed;
579 if (!result.ok || result.remainder > 0)
580 { return { ok: false, slots: next, remainder: remaining }; }
581 }
582 return { ok: true, slots: next, remainder: 0 };
583}
584
585/** Convert legacy currency counters into coin stacks. */
586export function migrateBagCoins (bag)
587{
588 let inventory = bag.inventory ?? emptySlots();
589 let vault = bag.vault ?? [];
590 if (bag.currency > 0)
591 {
592 const added = addCoinsToSlots(inventory, stackQuantity(bag.currency), { growable: false });
593 inventory = added.slots;
594 }
595 if (bag.vaultCurrency > 0)
596 {
597 const added = addCoinsToSlots(vault, stackQuantity(bag.vaultCurrency), { growable: true });
598 vault = added.slots;
599 }
600 return {
601 ...bag,
602 inventory,
603 vault,
604 currency: 0,
605 vaultCurrency: 0
606 };
607}
608
609export function migrateInheritanceCoins (inheritance)
610{
611 if (!inheritance?.currency)
612 { return inheritance; }
613 const added = addCoinsToSlots(inheritance.slots ?? emptySlots(), stackQuantity(inheritance.currency), { growable: true });
614 return {
615 ...inheritance,
616 slots: added.slots,
617 currency: 0
618 };
619}
620
621/** Trim excess blank cheques in inventory (e.g. after legacy saves or bugs). */
622export function normalizeInventorySlots (slots)
623{
624 const capped = capItemTotalInSlots(slots ?? emptySlots(), ItemId.blankCheque, BLANK_CHEQUE_CARRY_CAP);
625 return capped.map((slot) => normalizeChargeStack(slot));
626}
627
628export function capItemTotalInSlots (slots, itemId, cap)
629{
630 const next = (slots ?? []).map(cloneStack);
631 let total = countItemInSlots(next, itemId);
632 if (total <= cap)
633 { return next; }
634 let toRemove = total - cap;
635 for (let i = next.length - 1; i >= 0 && toRemove > 0; i--)
636 {
637 const slot = next[i];
638 if (!slot || slot.itemId !== itemId)
639 { continue; }
640 const beforeQty = stackQuantity(slot.quantity);
641 const drop = Math.min(beforeQty, toRemove);
642 const { remain } = splitOrigins(normalizeOrigins({ ...slot, quantity: beforeQty }), drop);
643 slot.quantity = beforeQty - drop;
644 slot.origins = remain;
645 delete slot.origin;
646 toRemove -= drop;
647 if (slot.quantity <= 0)
648 { next[i] = null; }
649 }
650 return next;
651}
652
653export function normalizeVault (raw)
654{
655 if (Array.isArray(raw))
656 {
657 return {
658 slots: raw.map((slot) => normalizeChargeStack(cloneStack(slot))),
659 reserved: []
660 };
661 }
662 return {
663 slots: (raw?.slots ?? []).map((slot) => normalizeChargeStack(cloneStack(slot))),
664 reserved: (raw?.reserved ?? []).map((slot) => normalizeChargeStack(cloneStack(slot)))
665 };
666}
667
668export function serializeVault (vault)
669{
670 const normalized = normalizeVault(vault);
671 return {
672 slots: publicSlots(normalized.slots),
673 reserved: publicSlots(normalized.reserved)
674 };
675}
676
677export function publicSlots (slots)
678{
679 return (slots ?? emptySlots()).map((slot) =>
680 {
681 if (!slot)
682 { return null; }
683 const payload = attachOrigins(cloneStack(slot));
684 const next = {
685 itemId: payload.itemId,
686 quantity: payload.quantity,
687 origins: payload.origins,
688 instance: payload.instance ?? null
689 };
690 // Cheque reservations keep chequeId so redeem can match the paper to vault goods.
691 if (payload.chequeId != null)
692 { next.chequeId = payload.chequeId; }
693 return next;
694 });
695}
696
697export function publicEquipment (equipment)
698{
699 const slots = {};
700 for (const slot of EQUIPMENT_SLOTS)
701 { slots[slot] = equipment?.slots?.[slot] ? cloneStack(equipment.slots[slot]) : null; }
702 return { slots };
703}