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