BlueGit

timfa questward

Files

questward / shared / definitions / items.js

items.js

items.js 20.2 KiB Download Raw
1import { equipImageName, spriteImageName } from "./tileSprites.js";
2import { SkillId } from "./skills.js";
3import { MaterialTier, WoodTier } from "./materialTiers.js";
4import { AttackType } from "./attackTypes.js";
5import { EquipmentKind } from "./equipmentKinds.js";
6import { formatQuantity } from "../items/formatQuantity.js";
7import { formatOriginBreakdown } from "../items/origin.js";
8import { CraftingItemId, CRAFTING_ITEM_STUBS } from "./craftingItems.js";
9import { MetalItemId, METAL_ITEM_DEFINITIONS } from "./metalItems.js";
10import { WoodItemId, WOOD_ITEM_DEFINITIONS, isLogDebarked } from "./woodItems.js";
11import { ItemFamilyId } from "./tierFamilies.js";
12import { ArmourItemId, ARMOUR_ITEM_DEFINITIONS } from "./armourItems.js";
13import { ClothItemId, CLOTH_ITEM_DEFINITIONS } from "./clothItems.js";
14import { LeatherItemId, LEATHER_ITEM_DEFINITIONS } from "./leatherItems.js";
15import { LeatherArmourItemId, LEATHER_ARMOUR_ITEM_DEFINITIONS } from "./leatherArmourItems.js";
16import { WizardItemId, WIZARD_ITEM_DEFINITIONS } from "./wizardItems.js";
17import { DyeItemId, FLOWER_ITEM_DEFINITION, DYE_ITEM_DEFINITION, FLOWER_COLOR_DISPLAY } from "./dyes.js";
18import { HERB_ITEM_DEFINITIONS, HerbItemId } from "./herbs.js";
19import { RANGED_ITEM_DEFINITIONS, RangedItemId } from "./rangedItems.js";
20import { POTION_MAX_STACK, alchemyPotionDefinition } from "./alchemy.js";
21import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
22import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
23import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
24import { JewelryItemId, JEWELRY_ITEM_DEFINITIONS } from "./jewelryItems.js";
25import { SwordItemId, SWORD_ITEM_DEFINITIONS } from "./swordItems.js";
26import { WarAxeItemId, WAR_AXE_ITEM_DEFINITIONS } from "./warAxeItems.js";
27import { EssenceItemId, ESSENCE_ITEM_DEFINITIONS } from "./essenceItems.js";
28import {
29 chequeReservedGoodsStack,
30 chequeExpiryTooltipLine
31} from "../items/cheque.js";
32
33export const ItemId = Object.freeze({
34 paper: 1,
35 apple: 2,
36 stick: 3,
37 blankCheque: 4,
38 /** Cotton shirt (ClothItemId.cottonShirt). */
39 clothShirt: 5,
40 letter: 6,
41 filledCheque: 7,
42 /** Written cheque past its 30-day life — no longer redeemable. */
43 expiredCheque: 590,
44 coins: 8,
45 ...CraftingItemId,
46 lantern: 26,
47 bones: 27,
48 skull: 28,
49 glassBottle: 29,
50 potion: 32,
51 recipePaper: 33,
52 egg: 275,
53 cookedEgg: 504,
54 burntEgg: 505,
55 ...SpellbookItemId,
56 ...MetalItemId,
57 ...WoodItemId,
58 ...FishingToolItemId,
59 ...ArmourItemId,
60 ...ClothItemId,
61 ...LeatherItemId,
62 ...LeatherArmourItemId,
63 ...WizardItemId,
64 ...DyeItemId,
65 ...HerbItemId,
66 ...RangedItemId,
67 ...GemItemId,
68 ...JewelryItemId,
69 ...SwordItemId,
70 ...WarAxeItemId
71});
72
73export const EQUIPMENT_SLOT = Object.freeze({
74 head: "head",
75 chest: "chest",
76 legs: "legs",
77 boots: "boots",
78 weapon: "weapon",
79 offhand: "offhand",
80 ring: "ring",
81 bracelet: "bracelet",
82 amulet: "amulet"
83});
84
85/**
86 * Back → front.
87 * Ring / bracelet sit under clothing; amulet draws over clothing / offhand.
88 */
89export const EQUIPMENT_DRAW_ORDER = Object.freeze([
90 EQUIPMENT_SLOT.boots,
91 EQUIPMENT_SLOT.ring,
92 EQUIPMENT_SLOT.bracelet,
93 EQUIPMENT_SLOT.chest,
94 EQUIPMENT_SLOT.weapon,
95 EQUIPMENT_SLOT.legs,
96 EQUIPMENT_SLOT.head,
97 EQUIPMENT_SLOT.offhand,
98 EQUIPMENT_SLOT.amulet
99]);
100
101export const DEFAULT_MAX_STACK = 99;
102export const BLANK_CHEQUE_CARRY_CAP = 99;
103export const COIN_MAX_STACK = 999_000_000_000;
104
105/** Coin sprite tiers (coins-<n>.png); pick the largest n where stack quantity >= n. */
106export const COIN_SPRITE_TIERS = Object.freeze([
107 1, 5, 15, 50, 150, 500, 1000, 1500, 2000, 5000, 10000, 20000, 50000,
108 1_000_000, 10_000_000, 50_000_000, 100_000_000, 500_000_000,
109 1_000_000_000, 10_000_000_000, 100_000_000_000, 1_000_000_000_000,
110 10_000_000_000_000, 100_000_000_000_000, 500_000_000_000_000,
111 999_999_999_999_999
112]);
113
114export const ITEM_DEFINITIONS = Object.freeze({
115 [ItemId.paper]: Object.freeze({
116 itemId: ItemId.paper,
117 key: "paper",
118 displayName: "Paper",
119 description: "Blank sheet of paper.",
120 seedValue: 2,
121 stackable: true,
122 maxStackSize: DEFAULT_MAX_STACK,
123 uniqueInstance: false,
124 category: "document"
125 }),
126 [ItemId.letter]: Object.freeze({
127 itemId: ItemId.letter,
128 key: "letter",
129 displayName: "Letter",
130 description: "A written letter.",
131 seedValue: 2,
132 stackable: false,
133 maxStackSize: 1,
134 uniqueInstance: true,
135 category: "document",
136 defaultState: "letter-opened",
137 marketplaceSellable: false,
138 marketplaceSellBlockedReason: "Letters cannot be sold on the marketplace."
139 // Letters are not `untradeable`: P2P trade uses authorship rules in shared/items/trade.js
140 // (same spirit as private ground letters). Use `untradeable: true` for future bound/quest items.
141 }),
142 [ItemId.apple]: Object.freeze({
143 itemId: ItemId.apple,
144 key: "apple",
145 displayName: "Apple",
146 description: "Round and juicy!",
147 seedValue: 1,
148 stackable: true,
149 maxStackSize: DEFAULT_MAX_STACK,
150 uniqueInstance: false,
151 category: "food",
152 healing: 4
153 }),
154 [ItemId.egg]: Object.freeze({
155 itemId: ItemId.egg,
156 key: "egg",
157 displayName: "Egg",
158 description: "A fresh egg, still warm from the nest. Bake it in an oven before eating.",
159 seedValue: 1,
160 stackable: true,
161 maxStackSize: DEFAULT_MAX_STACK,
162 uniqueInstance: false,
163 category: "ingredient",
164 iconKey: "egg",
165 defaultState: "egg"
166 }),
167 [ItemId.cookedEgg]: Object.freeze({
168 itemId: ItemId.cookedEgg,
169 key: "cooked-egg",
170 displayName: "Cooked egg",
171 description: "An egg baked until firm, ready to eat.",
172 seedValue: 2,
173 stackable: true,
174 maxStackSize: DEFAULT_MAX_STACK,
175 uniqueInstance: false,
176 category: "food",
177 iconKey: "egg",
178 defaultState: "egg",
179 healing: 3
180 }),
181 [ItemId.burntEgg]: Object.freeze({
182 itemId: ItemId.burntEgg,
183 key: "burnt-egg",
184 displayName: "Burnt egg",
185 description: "An egg left too long in the oven — dry and inedible.",
186 seedValue: 1,
187 stackable: true,
188 maxStackSize: DEFAULT_MAX_STACK,
189 uniqueInstance: false,
190 category: "food",
191 iconKey: "egg",
192 defaultState: "egg"
193 }),
194 [ItemId.stick]: Object.freeze({
195 itemId: ItemId.stick,
196 key: "stick",
197 displayName: "Stick",
198 description: "A wooden stick. Simple and sturdy.",
199 seedValue: 3,
200 stackable: false,
201 maxStackSize: 1,
202 uniqueInstance: false,
203 category: "finished",
204 equipment: Object.freeze({
205 slot: EQUIPMENT_SLOT.weapon,
206 tier: WoodTier.pine,
207 kind: EquipmentKind.clubWeapon,
208 attack: Object.freeze({
209 mode: "melee",
210 rangeTiles: 1,
211 hitSkillId: SkillId.clubfighting,
212 damageSkillId: SkillId.strength,
213 attackType: AttackType.blunt,
214 cooldownMs: 700
215 })
216 })
217 }),
218 [ItemId.blankCheque]: Object.freeze({
219 itemId: ItemId.blankCheque,
220 key: "blank-cheque",
221 displayName: "Blank cheque",
222 description: "Bank stationery for writing cheques against deposited goods.",
223 seedValue: 5,
224 stackable: true,
225 maxStackSize: DEFAULT_MAX_STACK,
226 uniqueInstance: false,
227 category: "document",
228 marketplaceSellable: false,
229 marketplaceSellBlockedReason: "Blank cheques cannot be sold on the marketplace."
230 }),
231 [ItemId.filledCheque]: Object.freeze({
232 itemId: ItemId.filledCheque,
233 key: "filled-cheque",
234 displayName: "Cheque",
235 description: "A bearer cheque linked to reserved goods in the issuer's bank.",
236 seedValue: 5,
237 stackable: false,
238 maxStackSize: 1,
239 uniqueInstance: true,
240 category: "document",
241 defaultState: "filled-cheque",
242 marketplaceSellable: true
243 }),
244 [ItemId.expiredCheque]: Object.freeze({
245 itemId: ItemId.expiredCheque,
246 key: "expired-cheque",
247 displayName: "Expired cheque",
248 description: "A cheque whose claim has lapsed. The reserved goods were returned to the issuer.",
249 seedValue: 1,
250 stackable: true,
251 maxStackSize: DEFAULT_MAX_STACK,
252 uniqueInstance: false,
253 category: "document",
254 /** Reuse blank stationery art — visually distinct from a live written cheque. */
255 iconKey: "blank-cheque",
256 defaultState: "blank-cheque",
257 marketplaceSellable: false,
258 marketplaceSellBlockedReason: "Expired cheques cannot be sold on the marketplace."
259 }),
260 [ItemId.coins]: Object.freeze({
261 itemId: ItemId.coins,
262 key: "coins",
263 displayName: "Coin",
264 displayNamePlural: "Coins",
265 description: "Hard currency of the realm.",
266 seedValue: 1,
267 stackable: true,
268 maxStackSize: COIN_MAX_STACK,
269 uniqueInstance: false,
270 category: "currency"
271 }),
272 [ItemId.lantern]: Object.freeze({
273 itemId: ItemId.lantern,
274 key: "lantern",
275 displayName: "Lantern",
276 description: "A handheld lamp that pushes back the night.",
277 seedValue: 12,
278 stackable: false,
279 maxStackSize: 1,
280 uniqueInstance: false,
281 category: "tool",
282 equipment: Object.freeze({
283 slot: EQUIPMENT_SLOT.offhand,
284 lightRadiusTiles: 6
285 })
286 }),
287 [ItemId.bones]: Object.freeze({
288 itemId: ItemId.bones,
289 key: "bones",
290 displayName: "Bones",
291 description: "Bones of a dead creature.",
292 seedValue: 1,
293 stackable: true,
294 maxStackSize: DEFAULT_MAX_STACK,
295 uniqueInstance: false,
296 category: "ingredient"
297 }),
298 [ItemId.skull]: Object.freeze({
299 itemId: ItemId.skull,
300 key: "skull",
301 displayName: "Skull",
302 description: "Unlucky.",
303 seedValue: 1,
304 stackable: true,
305 maxStackSize: DEFAULT_MAX_STACK,
306 uniqueInstance: false,
307 category: "misc"
308 }),
309 [ItemId.glassBottle]: Object.freeze({
310 itemId: ItemId.glassBottle,
311 key: "glass-bottle",
312 displayName: "Glass bottle",
313 description: "A clear bottle, ready to hold a brew or dye.",
314 seedValue: 2,
315 stackable: true,
316 maxStackSize: DEFAULT_MAX_STACK,
317 uniqueInstance: false,
318 category: "tool",
319 iconKey: "potion",
320 defaultState: "potion-0",
321 npcShopAllowed: true
322 }),
323 [ItemId.potion]: Object.freeze({
324 itemId: ItemId.potion,
325 key: "potion",
326 displayName: "Potion",
327 description: "A bottled brew. Sip with care.",
328 seedValue: 8,
329 stackable: true,
330 maxStackSize: POTION_MAX_STACK,
331 uniqueInstance: false,
332 category: "potion",
333 potion: true,
334 iconKey: "potion"
335 }),
336 [ItemId.recipePaper]: Object.freeze({
337 itemId: ItemId.recipePaper,
338 key: "recipe-paper",
339 displayName: "Recipe paper",
340 description: "An alchemy recipe written for a cauldron.",
341 seedValue: 2,
342 stackable: false,
343 maxStackSize: 1,
344 uniqueInstance: true,
345 category: "document",
346 defaultState: "recipe-paper",
347 iconKey: "paper"
348 }),
349 ...CRAFTING_ITEM_STUBS,
350 ...LEATHER_ITEM_DEFINITIONS,
351 ...LEATHER_ARMOUR_ITEM_DEFINITIONS,
352 ...WIZARD_ITEM_DEFINITIONS,
353 ...METAL_ITEM_DEFINITIONS,
354 ...WOOD_ITEM_DEFINITIONS,
355 ...ARMOUR_ITEM_DEFINITIONS,
356 ...CLOTH_ITEM_DEFINITIONS,
357 ...HERB_ITEM_DEFINITIONS,
358 ...RANGED_ITEM_DEFINITIONS,
359 ...SPELLBOOK_ITEM_DEFINITIONS,
360 ...FISH_ITEM_DEFINITIONS,
361 ...GEM_ITEM_DEFINITIONS,
362 ...JEWELRY_ITEM_DEFINITIONS,
363 ...SWORD_ITEM_DEFINITIONS,
364 ...WAR_AXE_ITEM_DEFINITIONS,
365 ...ESSENCE_ITEM_DEFINITIONS,
366 [DyeItemId.flower]: FLOWER_ITEM_DEFINITION,
367 [DyeItemId.dye]: DYE_ITEM_DEFINITION
368});
369
370export function itemDefinition (itemId)
371{
372 return ITEM_DEFINITIONS[itemId] ?? null;
373}
374
375/** Every defined item for editor pickers (shop stock, dev tools, …). */
376export function listAllItemPickerEntries ()
377{
378 return Object.values(ITEM_DEFINITIONS)
379 .filter((def) => def?.itemId != null)
380 .map((def) => ({
381 itemId: def.itemId,
382 displayName: def.displayName ?? String(def.itemId),
383 key: def.key ?? String(def.itemId)
384 }))
385 .sort((a, b) => a.displayName.localeCompare(b.displayName) || (a.itemId - b.itemId));
386}
387
388/** Garments that accept optional `instance.dyeColor` (tailor / cloth clothing). */
389export function isDyeableClothing (itemIdOrDef)
390{
391 const def = typeof itemIdOrDef === "number"
392 ? itemDefinition(itemIdOrDef)
393 : itemIdOrDef;
394 return !!def?.dyeable;
395}
396
397export { formatQuantity };
398
399export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
400{
401 if (!def)
402 { return "Item"; }
403 const qty = stack?.quantity ?? 1;
404 if (stack?.itemId === ItemId.coins)
405 { return qty === 1 ? (def.displayName ?? "Coin") : (def.displayNamePlural ?? "Coins"); }
406 if (stack?.itemId === ItemId.potion && stack.instance?.displayName)
407 { return stack.instance.displayName; }
408 if (stack?.itemId === ItemId.dye && stack.instance?.kind === "dye")
409 {
410 if (stack.instance.colorId && FLOWER_COLOR_DISPLAY[stack.instance.colorId])
411 { return `${FLOWER_COLOR_DISPLAY[stack.instance.colorId]} dye`; }
412 return "Dye";
413 }
414 if (stack?.itemId === ItemId.flower && stack.instance?.colorId)
415 {
416 return `${FLOWER_COLOR_DISPLAY[stack.instance.colorId] ?? "Flower"} flower`;
417 }
418 if (stack?.itemId === ItemId.recipePaper && stack.instance?.displayName)
419 {
420 return String(stack.instance.displayName).replace(/\s+Recipe$/u, " recipe");
421 }
422 if (stack?.itemId === CraftingItemId.tinderbox && stack.instance?.kind === "tinderbox")
423 {
424 const charges = Math.max(0, stack.instance.charges | 0);
425 return `${def.displayName} (${charges})`;
426 }
427 if (def.familyId === ItemFamilyId.log && isLogDebarked(stack))
428 { return `Debarked ${def.displayName}`; }
429 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
430 {
431 const el = String(stack.instance.element);
432 const label = el.charAt(0).toUpperCase() + el.slice(1);
433 return `${label} ${def.displayName ?? "arrow"}`;
434 }
435 return def.displayName ?? "Item";
436}
437
438export function stackDisplayLabel (stack)
439{
440 const name = itemDisplayName(stack);
441 const qty = stack?.quantity ?? 1;
442 if (qty <= 1)
443 { return name; }
444 return `${name} (${formatQuantity(qty)})`;
445}
446
447export function coinSpriteTierForQuantity (quantity)
448{
449 const qty = Math.max(0, Math.floor(Number(quantity) || 0));
450 let tier = COIN_SPRITE_TIERS[0];
451 for (const candidate of COIN_SPRITE_TIERS)
452 {
453 if (qty >= candidate)
454 { tier = candidate; }
455 else
456 { break; }
457 }
458 return tier;
459}
460
461/** Stack-aware description (letters include open state and author). */
462export function itemDescription (stack, { localCharacterId } = {})
463{
464 const def = itemDefinition(stack?.itemId);
465 if (!def)
466 { return ""; }
467 if (stack.itemId === ItemId.letter && stack.instance?.kind === "letter")
468 {
469 const state = stack.instance.opened === false ? "unopened" : "opened";
470 const authorId = stack.instance.authorCharacterId;
471 const byYou = authorId != null && Number(authorId) === Number(localCharacterId);
472 const author = byYou
473 ? "you"
474 : (stack.instance.authorDisplayName?.trim() || "someone");
475 return `An ${state} letter, written by ${author}.`;
476 }
477 if (stack.itemId === ItemId.filledCheque && stack.instance?.kind === "filled-cheque")
478 {
479 const goods = chequeReservedGoodsStack(stack);
480 const qty = stack.instance.quantity | 0;
481 const name = goods
482 ? itemDisplayName(goods)
483 : (itemDefinition(stack.instance.itemId)?.displayName ?? "goods");
484 return `Bearer cheque for ${qty}× ${name}.`;
485 }
486 if (stack.itemId === ItemId.expiredCheque)
487 { return def.description ?? ""; }
488 if (stack.itemId === ItemId.potion && stack.instance?.kind === "potion")
489 {
490 if (stack.instance.unstable)
491 { return "The brew smells wrong — best sipped with caution."; }
492 const potion = alchemyPotionDefinition(stack.instance.potionKey);
493 return potion?.description
494 ?? def.description
495 ?? "A carefully bottled draught.";
496 }
497 if (stack.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
498 {
499 const authorId = stack.instance.authorCharacterId;
500 const byYou = authorId != null && Number(authorId) === Number(localCharacterId);
501 const author = byYou
502 ? "you"
503 : (stack.instance.authorDisplayName?.trim() || "someone");
504 return `Written by ${author}.`;
505 }
506 return def.description ?? "";
507}
508
509export function itemOriginSummary (stack)
510{
511 // Recipe papers already say "Written by …" in the description — avoid a duplicate origin line.
512 if (stack?.itemId === ItemId.recipePaper && stack.instance?.kind === "recipe-paper")
513 { return ""; }
514 return formatOriginBreakdown(stack);
515}
516
517/** Extra tooltip lines after the description (e.g. cheque expiry). */
518export function itemExtraTooltipLines (stack, { now = Date.now() } = {})
519{
520 const line = chequeExpiryTooltipLine(stack, now);
521 return line ? [line] : [];
522}
523
524export function itemDefaultState (def, instance = null)
525{
526 if (def?.familyId === ItemFamilyId.log && isLogDebarked({ instance }))
527 { return "log-debarked"; }
528 return def?.defaultState ?? def?.key ?? "paper";
529}
530
531export function itemSpriteName (itemId, instance = null, quantity = null)
532{
533 const def = itemDefinition(itemId);
534 if (!def)
535 { return spriteImageName("item", "paper", "paper"); }
536 if (itemId === ItemId.coins)
537 {
538 const tier = coinSpriteTierForQuantity(quantity ?? 1);
539 return spriteImageName("item", "coins", `coins-${tier}`);
540 }
541 if (itemId === ItemId.letter)
542 { return spriteImageName("item", "letter", letterVisualState(instance)); }
543 if (instance?.kind === "tipped-arrow")
544 { return spriteImageName("item", "arrow", "tipped-arrow"); }
545 const folderKey = def.iconKey ?? def.key;
546 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def, instance));
547}
548
549/** Stack-aware sprite key (coins use quantity tiers like inventory icons). */
550export function itemSpriteNameForStack (stack)
551{
552 if (!stack?.itemId)
553 { return itemSpriteName(null); }
554 return itemSpriteName(stack.itemId, stack.instance ?? null, stack.quantity);
555}
556
557export function itemEquipSprite (itemId)
558{
559 const def = itemDefinition(itemId);
560 if (!def)
561 { return null; }
562 const folderKey = def.iconKey ?? def.key;
563 const equipment = def.equipment;
564 if (equipment)
565 {
566 if (equipment.hideEquipSprite)
567 { return null; }
568 return equipment.equipSprite
569 ?? equipment.overlaySpriteId
570 ?? equipImageName("item", folderKey, itemDefaultState(def));
571 }
572 /** Inventory tools (e.g. tinderbox) may still show equip art during gather/firestarting. */
573 if (def.gatherEquipSprite)
574 { return equipImageName("item", folderKey, itemDefaultState(def)); }
575 return null;
576}
577
578/** Largest equipped light radius (e.g. lantern in offhand). Includes opal bracelet night vision. */
579export function equippedLightRadiusTiles (equipment)
580{
581 let best = 0;
582 for (const stack of Object.values(equipment?.slots ?? {}))
583 {
584 if (!stack)
585 { continue; }
586 const radius = itemDefinition(stack.itemId)?.equipment?.lightRadiusTiles ?? 0;
587 if (radius > best)
588 { best = radius; }
589 // Opal bracelet: same range as a torch (see OPAL_NIGHT_VISION_RANGE_TILES).
590 if ((stack.itemId | 0) === JewelryItemId.opalBracelet)
591 { best = Math.max(best, 8); }
592 }
593 return best;
594}
595
596/**
597 * Intensity for the entity light from equipment.
598 * Opal bracelet is half-bright when it is the sole (or stronger) light source.
599 */
600export function equippedLightIntensity (equipment)
601{
602 let itemLight = 0;
603 let hasOpal = false;
604 for (const stack of Object.values(equipment?.slots ?? {}))
605 {
606 if (!stack)
607 { continue; }
608 const radius = itemDefinition(stack.itemId)?.equipment?.lightRadiusTiles ?? 0;
609 if (radius > itemLight)
610 { itemLight = radius; }
611 if ((stack.itemId | 0) === JewelryItemId.opalBracelet)
612 { hasOpal = true; }
613 }
614 if (hasOpal && itemLight < 8)
615 { return 0.5; }
616 return 1;
617}
618
619export function letterVisualState (instance)
620{
621 return instance?.opened === false ? "letter-closed" : "letter-opened";
622}
623
624export function itemAssetPath (itemId, companion = null, instance = null)
625{
626 const def = itemDefinition(itemId);
627 if (def?.herb)
628 {
629 const suffix = companion ? `-${companion}` : "";
630 return `/assets/herbs/${def.key}${suffix}.png`;
631 }
632 const key = def?.iconKey ?? def?.key ?? "paper";
633 const state = itemId === ItemId.letter
634 ? letterVisualState(instance)
635 : itemDefaultState(def ?? { key }, instance);
636 const suffix = companion ? `-${companion}` : "";
637 return `/assets/items/${key}/${state}${suffix}.png`;
638}
639
640export function itemAssetPathForStack (stack)
641{
642 if (!stack)
643 { return itemAssetPath(null); }
644 if (stack.itemId === ItemId.coins)
645 {
646 const tier = coinSpriteTierForQuantity(stack.quantity);
647 return `/assets/items/coins/coins-${tier}.png`;
648 }
649 if (stack.itemId === ItemId.potion)
650 {
651 const fill = Math.max(1, Math.min(5, stack.instance?.fillLevel | 0 || 4));
652 return `/assets/items/potion/potion-${fill}.png`;
653 }
654 if (stack.itemId === ItemId.dye)
655 {
656 const fill = Math.max(1, Math.min(5, stack.instance?.fillLevel | 0 || 4));
657 return `/assets/items/potion/potion-${fill}.png`;
658 }
659 if (stack.itemId === ItemId.glassBottle)
660 { return `/assets/items/potion/potion-0.png`; }
661 if (stack.itemId === ItemId.flower)
662 { return `/assets/items/flower/flower.png`; }
663 if (stack.instance?.kind === "tipped-arrow")
664 { return `/assets/items/arrow/tipped-arrow.png`; }
665 return itemAssetPath(stack.itemId, null, stack.instance);
666}
667
668export const LETTER_MAX_BODY_CHARS = 2000;
669
670export const STARTER_ITEMS = Object.freeze([
671 Object.freeze({ itemId: ItemId.paper, quantity: 5 }),
672 Object.freeze({ itemId: ItemId.apple, quantity: 3 }),
673 Object.freeze({ itemId: ItemId.stick, quantity: 1 }),
674 Object.freeze({ itemId: ItemId.coins, quantity: 25 })
675]);