import { ItemCategory } from "./itemCategories.js"; import { ClothTier, CLOTH_TIER_ORDER, CLOTH_DISPLAY_NAME, WoodTier, WOOD_TIER_ORDER, MATERIAL_DISPLAY_NAME, tierRank, tierMinSkillLevel, clothTierForWood } from "./materialTiers.js"; import { EquipmentKind } from "./equipmentKinds.js"; import { SkillId } from "./skills.js"; import { CraftingStationId } from "./craftingStations.js"; import { yarnItemId } from "./clothItems.js"; import { logItemIdForWood } from "./woodItems.js"; const DEFAULT_STACK = 99; /** * Fish species keyed by stable id. `tier` is cloth/wood rank 1–7. * Item IDs: raw / cooked / burnt are allocated in {@link FISH_ITEM_IDS}. */ export const FISH_SPECIES = Object.freeze({ minnow: Object.freeze({ key: "minnow", displayName: "Minnow", tier: 1 }), guppy: Object.freeze({ key: "guppy", displayName: "Guppy", tier: 1 }), shrimp: Object.freeze({ key: "shrimp", displayName: "Shrimp", tier: 1 }), anchovies: Object.freeze({ key: "anchovies", displayName: "Anchovies", tier: 1 }), sardine: Object.freeze({ key: "sardine", displayName: "Sardine", tier: 1 }), perch: Object.freeze({ key: "perch", displayName: "Perch", tier: 2 }), herring: Object.freeze({ key: "herring", displayName: "Herring", tier: 2 }), crab: Object.freeze({ key: "crab", displayName: "Crab", tier: 2 }), trout: Object.freeze({ key: "trout", displayName: "Trout", tier: 3 }), cod: Object.freeze({ key: "cod", displayName: "Cod", tier: 3 }), bass: Object.freeze({ key: "bass", displayName: "Bass", tier: 3 }), pike: Object.freeze({ key: "pike", displayName: "Pike", tier: 4 }), squid: Object.freeze({ key: "squid", displayName: "Squid", tier: 4 }), salmon: Object.freeze({ key: "salmon", displayName: "Salmon", tier: 5 }), tuna: Object.freeze({ key: "tuna", displayName: "Tuna", tier: 5 }), lobster: Object.freeze({ key: "lobster", displayName: "Lobster", tier: 5 }), sturgeon: Object.freeze({ key: "sturgeon", displayName: "Sturgeon", tier: 6 }), swordfish: Object.freeze({ key: "swordfish", displayName: "Swordfish", tier: 6 }), giantKrill: Object.freeze({ key: "giant-krill", displayName: "Giant Krill", tier: 6 }), marlin: Object.freeze({ key: "marlin", displayName: "Marlin", tier: 7 }), shark: Object.freeze({ key: "shark", displayName: "Shark", tier: 7 }) }); export const FISH_SPECIES_ORDER = Object.freeze(Object.keys(FISH_SPECIES)); /** Magenta cook tints vary slightly per species (hue shift from tier). */ function fishCookColors (tier) { const t = (tier - 1) / 6; return Object.freeze({ raw: Object.freeze({ r: 0.45 + t * 0.2, g: 0.55 + t * 0.1, b: 0.72 - t * 0.15 }), cooked: Object.freeze({ r: 0.55 + t * 0.15, g: 0.38 + t * 0.05, b: 0.22 }), burnt: Object.freeze({ r: 0.16, g: 0.13, b: 0.11 }) }); } /** Allocated from 288 upward: each species gets raw, cooked, burnt. */ const FISH_ITEM_IDS = (() => { const out = {}; let next = 288; for (const speciesId of FISH_SPECIES_ORDER) { out[speciesId] = Object.freeze({ raw: next++, cooked: next++, burnt: next++ }); } return Object.freeze(out); })(); export function fishSpeciesDefinition (speciesId) { return FISH_SPECIES[speciesId] ?? null; } export function fishItemIdsForSpecies (speciesId) { return FISH_ITEM_IDS[speciesId] ?? null; } export function rawFishItemId (speciesId) { return FISH_ITEM_IDS[speciesId]?.raw ?? null; } export function cookedFishItemId (speciesId) { return FISH_ITEM_IDS[speciesId]?.cooked ?? null; } export function burntFishItemId (speciesId) { return FISH_ITEM_IDS[speciesId]?.burnt ?? null; } /** Resolve species id from any cook-state item id. */ export function fishSpeciesIdFromItemId (itemId) { const id = itemId | 0; for (const speciesId of FISH_SPECIES_ORDER) { const ids = FISH_ITEM_IDS[speciesId]; if (ids.raw === id || ids.cooked === id || ids.burnt === id) { return speciesId; } } return null; } export function fishTierRankFromItemId (itemId) { const speciesId = fishSpeciesIdFromItemId(itemId); if (!speciesId) { return 0; } return FISH_SPECIES[speciesId].tier | 0; } function buildFishItemDefinitions () { const out = {}; for (const speciesId of FISH_SPECIES_ORDER) { const species = FISH_SPECIES[speciesId]; const ids = FISH_ITEM_IDS[speciesId]; const colors = fishCookColors(species.tier); const heal = species.tier * 5; const clothTier = CLOTH_TIER_ORDER[species.tier - 1] ?? ClothTier.cotton; out[ids.raw] = Object.freeze({ itemId: ids.raw, key: `uncooked-${species.key}`, displayName: `Uncooked ${species.displayName}`, description: `Fresh ${species.displayName.toLowerCase()}. Cook at an oven or campfire.`, seedValue: species.tier, stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.ingredient, iconKey: "meat", defaultState: "raw", cookable: true, cookState: "raw", fishSpeciesId: speciesId, fishTier: species.tier, tier: clothTier, burntItemId: ids.burnt, tint: colors.raw, npcShopAllowed: true }); out[ids.cooked] = Object.freeze({ itemId: ids.cooked, key: `cooked-${species.key}`, displayName: `Cooked ${species.displayName}`, description: `Roasted ${species.displayName.toLowerCase()}, ready to eat.`, seedValue: species.tier + 1, stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.food, iconKey: "meat", defaultState: "cooked", cookable: true, cookState: "cooked", fishSpeciesId: speciesId, fishTier: species.tier, tier: clothTier, tint: colors.cooked, healing: heal, npcShopAllowed: true }); out[ids.burnt] = Object.freeze({ itemId: ids.burnt, key: `burnt-${species.key}`, displayName: `Burnt ${species.displayName}`, description: `Charred ${species.displayName.toLowerCase()} — inedible.`, seedValue: 1, stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.food, iconKey: "meat", defaultState: "burnt", cookable: true, cookState: "burnt", fishSpeciesId: speciesId, fishTier: species.tier, tier: clothTier, tint: colors.burnt }); } return out; } /** Bait display names by cloth tier (rank 1–7). */ const BAIT_NAMES = Object.freeze({ [ClothTier.cotton]: "Worms", [ClothTier.wool]: "Maggots", [ClothTier.linen]: "Crickets", [ClothTier.cashmere]: "Leeches", [ClothTier.silk]: "Roe", [ClothTier.fairySilk]: "Glowworms", [ClothTier.dragonweave]: "Fairy flies" }); /** Bait item IDs by cloth tier (358+). */ export const BaitItemId = Object.freeze({ [ClothTier.cotton]: 358, [ClothTier.wool]: 359, [ClothTier.linen]: 360, [ClothTier.cashmere]: 361, [ClothTier.silk]: 362, [ClothTier.fairySilk]: 363, [ClothTier.dragonweave]: 364 }); export function baitItemIdForCloth (clothTier) { return BaitItemId[clothTier] ?? null; } export function baitItemIdForRank (rank) { const cloth = CLOTH_TIER_ORDER[(rank | 0) - 1]; return cloth ? BaitItemId[cloth] : null; } function buildBaitDefinitions () { const out = {}; for (const clothTier of CLOTH_TIER_ORDER) { const itemId = BaitItemId[clothTier]; const name = BAIT_NAMES[clothTier] ?? `${CLOTH_DISPLAY_NAME[clothTier]} bait`; out[itemId] = Object.freeze({ itemId, key: `${clothTier}-bait`, displayName: name, description: `Bait for a fishing rod. Attracts fish up to this grade.`, seedValue: tierRank(clothTier), stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.ingredient, iconKey: "bait", defaultState: "bait", tier: clothTier, tintFromTier: true, bait: true, npcShopAllowed: true }); } return out; } /** * Fishing tools. * Net = tier 1 (id 23). Poles + rods from birch…elder (tier 2–7). * Pole = unstrung; rod = pole + line (usable). */ export const FishingToolItemId = Object.freeze({ net: 23, birchRod: 365, oakRod: 366, ebonyRod: 367, lignumRod: 368, heartwoodRod: 369, elderRod: 370, birchPole: 371, oakPole: 372, ebonyPole: 373, lignumPole: 374, heartwoodPole: 375, elderPole: 376 }); const ROD_BY_WOOD = Object.freeze({ [WoodTier.birch]: FishingToolItemId.birchRod, [WoodTier.oak]: FishingToolItemId.oakRod, [WoodTier.ebony]: FishingToolItemId.ebonyRod, [WoodTier.lignum]: FishingToolItemId.lignumRod, [WoodTier.heartwood]: FishingToolItemId.heartwoodRod, [WoodTier.elder]: FishingToolItemId.elderRod }); const POLE_BY_WOOD = Object.freeze({ [WoodTier.birch]: FishingToolItemId.birchPole, [WoodTier.oak]: FishingToolItemId.oakPole, [WoodTier.ebony]: FishingToolItemId.ebonyPole, [WoodTier.lignum]: FishingToolItemId.lignumPole, [WoodTier.heartwood]: FishingToolItemId.heartwoodPole, [WoodTier.elder]: FishingToolItemId.elderPole }); export function fishingRodItemIdForWood (woodTier) { return ROD_BY_WOOD[woodTier] ?? null; } export function fishingPoleItemIdForWood (woodTier) { return POLE_BY_WOOD[woodTier] ?? null; } export function woodTierFromFishingRodItemId (itemId) { for (const [woodTier, id] of Object.entries(ROD_BY_WOOD)) { if (id === (itemId | 0)) { return woodTier; } } return null; } function buildToolDefinitions () { const out = {}; out[FishingToolItemId.net] = Object.freeze({ itemId: FishingToolItemId.net, key: "fishing-net", displayName: "Fishing net", description: "A cotton mesh for scooping small fish from the shallows. Needs no bait.", seedValue: 6, stackable: false, maxStackSize: 1, uniqueInstance: false, category: ItemCategory.tool, iconKey: "fishing-net", defaultState: "fishing-net", tier: ClothTier.cotton, tintFromTier: true, equipment: Object.freeze({ slot: "weapon", tier: ClothTier.cotton, kind: EquipmentKind.fishingNet, tintFromTier: true }), npcShopAllowed: true }); for (const woodTier of WOOD_TIER_ORDER) { const poleId = POLE_BY_WOOD[woodTier]; const rodId = ROD_BY_WOOD[woodTier]; if (!poleId || !rodId) { continue; } const woodName = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier; const clothTier = clothTierForWood(woodTier); out[poleId] = Object.freeze({ itemId: poleId, key: `${woodTier}-fishing-pole`, displayName: `${woodName} fishing pole`, description: `A shaped ${woodName.toLowerCase()} pole, waiting for a fishing line.`, seedValue: tierRank(woodTier), stackable: false, maxStackSize: 1, uniqueInstance: false, category: ItemCategory.intermediate, iconKey: "fishing-pole", defaultState: "fishing-pole", tier: woodTier, clothTier, tintFromTier: true, fishingPole: true, npcShopAllowed: true }); out[rodId] = Object.freeze({ itemId: rodId, key: `${woodTier}-fishing-rod`, displayName: `${woodName} fishing rod`, description: `A ${woodName.toLowerCase()} rod strung for deeper water.`, seedValue: tierRank(woodTier) * 2, stackable: false, maxStackSize: 1, uniqueInstance: false, category: ItemCategory.tool, iconKey: "fishing-rod", defaultState: "fishing-rod", tier: woodTier, clothTier, tintFromTier: true, fishingRod: true, poleItemId: poleId, equipment: Object.freeze({ slot: "weapon", tier: woodTier, kind: EquipmentKind.fishingRod, tintFromTier: true }), npcShopAllowed: true }); } return out; } export const FISH_ITEM_DEFINITIONS = Object.freeze({ ...buildFishItemDefinitions(), ...buildBaitDefinitions(), ...buildToolDefinitions() }); /** All raw fish item ids (for editor picker). */ export function listRawFishPickerEntries () { return FISH_SPECIES_ORDER.map((speciesId) => { const species = FISH_SPECIES[speciesId]; const itemId = FISH_ITEM_IDS[speciesId].raw; return { itemId, speciesId, displayName: `Uncooked ${species.displayName}`, tier: species.tier, key: `uncooked-${species.key}` }; }); } /** Normalize fishing-spot config to unique raw fish item ids. */ export function normalizeFishingSpotConfig (config) { const fishes = []; const seen = new Set(); for (const entry of config?.fishes ?? []) { const itemId = typeof entry === "number" ? entry | 0 : entry?.itemId | 0; if (!itemId || seen.has(itemId)) { continue; } const speciesId = fishSpeciesIdFromItemId(itemId); if (!speciesId) { continue; } const ids = FISH_ITEM_IDS[speciesId]; const rawId = ids?.raw ?? itemId; if (seen.has(rawId)) { continue; } seen.add(rawId); fishes.push(rawId); } return { fishes }; } /** Craft recipes for fishing tools. */ export function fishingToolRecipes () { const recipes = [ Object.freeze({ recipeId: "fishing-net", craftGroup: "fishing-net", craftGroupLabel: "Fishing net", stationId: CraftingStationId.craftingBench, output: { itemId: FishingToolItemId.net, quantity: 1 }, inputs: [{ itemId: yarnItemId(ClothTier.cotton), quantity: 3 }], minSkillLevel: 1, skillId: "crafting", xpMaterial: ClothTier.cotton }) ]; for (const woodTier of WOOD_TIER_ORDER) { const poleId = POLE_BY_WOOD[woodTier]; const rodId = ROD_BY_WOOD[woodTier]; if (!poleId || !rodId) { continue; } const clothTier = clothTierForWood(woodTier); recipes.push(Object.freeze({ recipeId: `fishing-pole-${woodTier}`, craftGroup: "fishing-pole", craftGroupLabel: "Fishing pole", stationId: CraftingStationId.woodworkingBench, output: { itemId: poleId, quantity: 1 }, inputs: [{ itemId: logItemIdForWood(woodTier), quantity: 1 }], minSkillLevel: tierMinSkillLevel(woodTier), skillId: "crafting", xpMaterial: woodTier })); recipes.push(Object.freeze({ recipeId: `fishing-rod-${woodTier}`, craftGroup: "fishing-rod", craftGroupLabel: "Fishing rod", stationId: CraftingStationId.craftingBench, output: { itemId: rodId, quantity: 1 }, inputs: [ { itemId: poleId, quantity: 1 }, { itemId: yarnItemId(clothTier), quantity: 2 } ], minSkillLevel: tierMinSkillLevel(woodTier), skillId: "crafting", xpMaterial: woodTier })); } return recipes; } /** Cook recipes for every fish species (oven + fireplace). */ export function fishingCookRecipes () { return FISH_SPECIES_ORDER.map((speciesId) => { const ids = FISH_ITEM_IDS[speciesId]; const species = FISH_SPECIES[speciesId]; return Object.freeze({ recipeId: `cook-${species.key}`, craftGroup: "cook-fish", craftGroupLabel: "Fish", stationIds: [CraftingStationId.oven, CraftingStationId.fireplace], output: { itemId: ids.cooked, quantity: 1 }, inputs: [{ itemId: ids.raw, quantity: 1 }], minSkillLevel: 1, skillId: "cooking", xpMaterial: CLOTH_TIER_ORDER[species.tier - 1] ?? ClothTier.cotton, burntOutput: { itemId: ids.burnt, quantity: 1 } }); }); } /** Fishing roll difficulty from bait tier rank. */ export function fishingDifficulty (baitTierRank) { const rank = Math.max(1, baitTierRank | 0); return Math.max((rank - 1) * 10, 1); } export function fishingExhaustDurationMs (fishTierRank) { return Math.max(1, fishTierRank | 0) * 10_000; }