BlueGit

timfa questward

Files

questward / shared / definitions / fishItems.js

fishItems.js

fishItems.js 14.6 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import {
3 ClothTier,
4 CLOTH_TIER_ORDER,
5 CLOTH_DISPLAY_NAME,
6 WoodTier,
7 WOOD_TIER_ORDER,
8 MATERIAL_DISPLAY_NAME,
9 tierRank,
10 tierMinSkillLevel,
11 clothTierForWood
12} from "./materialTiers.js";
13import { EquipmentKind } from "./equipmentKinds.js";
14import { SkillId } from "./skills.js";
15import { CraftingStationId } from "./craftingStations.js";
16import { yarnItemId } from "./clothItems.js";
17import { logItemIdForWood } from "./woodItems.js";
18
19const DEFAULT_STACK = 99;
20
21/**
22 * Fish species keyed by stable id. `tier` is cloth/wood rank 1–7.
23 * Item IDs: raw / cooked / burnt are allocated in {@link FISH_ITEM_IDS}.
24 */
25export const FISH_SPECIES = Object.freeze({
26 minnow: Object.freeze({ key: "minnow", displayName: "Minnow", tier: 1 }),
27 guppy: Object.freeze({ key: "guppy", displayName: "Guppy", tier: 1 }),
28 shrimp: Object.freeze({ key: "shrimp", displayName: "Shrimp", tier: 1 }),
29 anchovies: Object.freeze({ key: "anchovies", displayName: "Anchovies", tier: 1 }),
30 sardine: Object.freeze({ key: "sardine", displayName: "Sardine", tier: 1 }),
31 perch: Object.freeze({ key: "perch", displayName: "Perch", tier: 2 }),
32 herring: Object.freeze({ key: "herring", displayName: "Herring", tier: 2 }),
33 crab: Object.freeze({ key: "crab", displayName: "Crab", tier: 2 }),
34 trout: Object.freeze({ key: "trout", displayName: "Trout", tier: 3 }),
35 cod: Object.freeze({ key: "cod", displayName: "Cod", tier: 3 }),
36 bass: Object.freeze({ key: "bass", displayName: "Bass", tier: 3 }),
37 pike: Object.freeze({ key: "pike", displayName: "Pike", tier: 4 }),
38 squid: Object.freeze({ key: "squid", displayName: "Squid", tier: 4 }),
39 salmon: Object.freeze({ key: "salmon", displayName: "Salmon", tier: 5 }),
40 tuna: Object.freeze({ key: "tuna", displayName: "Tuna", tier: 5 }),
41 lobster: Object.freeze({ key: "lobster", displayName: "Lobster", tier: 5 }),
42 sturgeon: Object.freeze({ key: "sturgeon", displayName: "Sturgeon", tier: 6 }),
43 swordfish: Object.freeze({ key: "swordfish", displayName: "Swordfish", tier: 6 }),
44 giantKrill: Object.freeze({ key: "giant-krill", displayName: "Giant Krill", tier: 6 }),
45 marlin: Object.freeze({ key: "marlin", displayName: "Marlin", tier: 7 }),
46 shark: Object.freeze({ key: "shark", displayName: "Shark", tier: 7 })
47});
48
49export const FISH_SPECIES_ORDER = Object.freeze(Object.keys(FISH_SPECIES));
50
51/** Magenta cook tints vary slightly per species (hue shift from tier). */
52function fishCookColors (tier)
53{
54 const t = (tier - 1) / 6;
55 return Object.freeze({
56 raw: Object.freeze({ r: 0.45 + t * 0.2, g: 0.55 + t * 0.1, b: 0.72 - t * 0.15 }),
57 cooked: Object.freeze({ r: 0.55 + t * 0.15, g: 0.38 + t * 0.05, b: 0.22 }),
58 burnt: Object.freeze({ r: 0.16, g: 0.13, b: 0.11 })
59 });
60}
61
62/** Allocated from 288 upward: each species gets raw, cooked, burnt. */
63const FISH_ITEM_IDS = (() =>
64{
65 const out = {};
66 let next = 288;
67 for (const speciesId of FISH_SPECIES_ORDER)
68 {
69 out[speciesId] = Object.freeze({
70 raw: next++,
71 cooked: next++,
72 burnt: next++
73 });
74 }
75 return Object.freeze(out);
76})();
77
78export function fishSpeciesDefinition (speciesId)
79{
80 return FISH_SPECIES[speciesId] ?? null;
81}
82
83export function fishItemIdsForSpecies (speciesId)
84{
85 return FISH_ITEM_IDS[speciesId] ?? null;
86}
87
88export function rawFishItemId (speciesId)
89{
90 return FISH_ITEM_IDS[speciesId]?.raw ?? null;
91}
92
93export function cookedFishItemId (speciesId)
94{
95 return FISH_ITEM_IDS[speciesId]?.cooked ?? null;
96}
97
98export function burntFishItemId (speciesId)
99{
100 return FISH_ITEM_IDS[speciesId]?.burnt ?? null;
101}
102
103/** Resolve species id from any cook-state item id. */
104export function fishSpeciesIdFromItemId (itemId)
105{
106 const id = itemId | 0;
107 for (const speciesId of FISH_SPECIES_ORDER)
108 {
109 const ids = FISH_ITEM_IDS[speciesId];
110 if (ids.raw === id || ids.cooked === id || ids.burnt === id)
111 { return speciesId; }
112 }
113 return null;
114}
115
116export function fishTierRankFromItemId (itemId)
117{
118 const speciesId = fishSpeciesIdFromItemId(itemId);
119 if (!speciesId)
120 { return 0; }
121 return FISH_SPECIES[speciesId].tier | 0;
122}
123
124function buildFishItemDefinitions ()
125{
126 const out = {};
127 for (const speciesId of FISH_SPECIES_ORDER)
128 {
129 const species = FISH_SPECIES[speciesId];
130 const ids = FISH_ITEM_IDS[speciesId];
131 const colors = fishCookColors(species.tier);
132 const heal = species.tier * 5;
133 const clothTier = CLOTH_TIER_ORDER[species.tier - 1] ?? ClothTier.cotton;
134
135 out[ids.raw] = Object.freeze({
136 itemId: ids.raw,
137 key: `uncooked-${species.key}`,
138 displayName: `Uncooked ${species.displayName}`,
139 description: `Fresh ${species.displayName.toLowerCase()}. Cook at an oven or campfire.`,
140 seedValue: species.tier,
141 stackable: true,
142 maxStackSize: DEFAULT_STACK,
143 uniqueInstance: false,
144 category: ItemCategory.ingredient,
145 iconKey: "meat",
146 defaultState: "raw",
147 cookable: true,
148 cookState: "raw",
149 fishSpeciesId: speciesId,
150 fishTier: species.tier,
151 tier: clothTier,
152 burntItemId: ids.burnt,
153 tint: colors.raw,
154 npcShopAllowed: true
155 });
156 out[ids.cooked] = Object.freeze({
157 itemId: ids.cooked,
158 key: `cooked-${species.key}`,
159 displayName: `Cooked ${species.displayName}`,
160 description: `Roasted ${species.displayName.toLowerCase()}, ready to eat.`,
161 seedValue: species.tier + 1,
162 stackable: true,
163 maxStackSize: DEFAULT_STACK,
164 uniqueInstance: false,
165 category: ItemCategory.food,
166 iconKey: "meat",
167 defaultState: "cooked",
168 cookable: true,
169 cookState: "cooked",
170 fishSpeciesId: speciesId,
171 fishTier: species.tier,
172 tier: clothTier,
173 tint: colors.cooked,
174 healing: heal,
175 npcShopAllowed: true
176 });
177 out[ids.burnt] = Object.freeze({
178 itemId: ids.burnt,
179 key: `burnt-${species.key}`,
180 displayName: `Burnt ${species.displayName}`,
181 description: `Charred ${species.displayName.toLowerCase()} — inedible.`,
182 seedValue: 1,
183 stackable: true,
184 maxStackSize: DEFAULT_STACK,
185 uniqueInstance: false,
186 category: ItemCategory.food,
187 iconKey: "meat",
188 defaultState: "burnt",
189 cookable: true,
190 cookState: "burnt",
191 fishSpeciesId: speciesId,
192 fishTier: species.tier,
193 tier: clothTier,
194 tint: colors.burnt
195 });
196 }
197 return out;
198}
199
200/** Bait display names by cloth tier (rank 1–7). */
201const BAIT_NAMES = Object.freeze({
202 [ClothTier.cotton]: "Worms",
203 [ClothTier.wool]: "Maggots",
204 [ClothTier.linen]: "Crickets",
205 [ClothTier.cashmere]: "Leeches",
206 [ClothTier.silk]: "Roe",
207 [ClothTier.fairySilk]: "Glowworms",
208 [ClothTier.dragonweave]: "Fairy flies"
209});
210
211/** Bait item IDs by cloth tier (358+). */
212export const BaitItemId = Object.freeze({
213 [ClothTier.cotton]: 358,
214 [ClothTier.wool]: 359,
215 [ClothTier.linen]: 360,
216 [ClothTier.cashmere]: 361,
217 [ClothTier.silk]: 362,
218 [ClothTier.fairySilk]: 363,
219 [ClothTier.dragonweave]: 364
220});
221
222export function baitItemIdForCloth (clothTier)
223{
224 return BaitItemId[clothTier] ?? null;
225}
226
227export function baitItemIdForRank (rank)
228{
229 const cloth = CLOTH_TIER_ORDER[(rank | 0) - 1];
230 return cloth ? BaitItemId[cloth] : null;
231}
232
233function buildBaitDefinitions ()
234{
235 const out = {};
236 for (const clothTier of CLOTH_TIER_ORDER)
237 {
238 const itemId = BaitItemId[clothTier];
239 const name = BAIT_NAMES[clothTier] ?? `${CLOTH_DISPLAY_NAME[clothTier]} bait`;
240 out[itemId] = Object.freeze({
241 itemId,
242 key: `${clothTier}-bait`,
243 displayName: name,
244 description: `Bait for a fishing rod. Attracts fish up to this grade.`,
245 seedValue: tierRank(clothTier),
246 stackable: true,
247 maxStackSize: DEFAULT_STACK,
248 uniqueInstance: false,
249 category: ItemCategory.ingredient,
250 iconKey: "bait",
251 defaultState: "bait",
252 tier: clothTier,
253 tintFromTier: true,
254 bait: true,
255 npcShopAllowed: true
256 });
257 }
258 return out;
259}
260
261/**
262 * Fishing tools.
263 * Net = tier 1 (id 23). Poles + rods from birch…elder (tier 2–7).
264 * Pole = unstrung; rod = pole + line (usable).
265 */
266export const FishingToolItemId = Object.freeze({
267 net: 23,
268 birchRod: 365,
269 oakRod: 366,
270 ebonyRod: 367,
271 lignumRod: 368,
272 heartwoodRod: 369,
273 elderRod: 370,
274 birchPole: 371,
275 oakPole: 372,
276 ebonyPole: 373,
277 lignumPole: 374,
278 heartwoodPole: 375,
279 elderPole: 376
280});
281
282const ROD_BY_WOOD = Object.freeze({
283 [WoodTier.birch]: FishingToolItemId.birchRod,
284 [WoodTier.oak]: FishingToolItemId.oakRod,
285 [WoodTier.ebony]: FishingToolItemId.ebonyRod,
286 [WoodTier.lignum]: FishingToolItemId.lignumRod,
287 [WoodTier.heartwood]: FishingToolItemId.heartwoodRod,
288 [WoodTier.elder]: FishingToolItemId.elderRod
289});
290
291const POLE_BY_WOOD = Object.freeze({
292 [WoodTier.birch]: FishingToolItemId.birchPole,
293 [WoodTier.oak]: FishingToolItemId.oakPole,
294 [WoodTier.ebony]: FishingToolItemId.ebonyPole,
295 [WoodTier.lignum]: FishingToolItemId.lignumPole,
296 [WoodTier.heartwood]: FishingToolItemId.heartwoodPole,
297 [WoodTier.elder]: FishingToolItemId.elderPole
298});
299
300export function fishingRodItemIdForWood (woodTier)
301{
302 return ROD_BY_WOOD[woodTier] ?? null;
303}
304
305export function fishingPoleItemIdForWood (woodTier)
306{
307 return POLE_BY_WOOD[woodTier] ?? null;
308}
309
310export function woodTierFromFishingRodItemId (itemId)
311{
312 for (const [woodTier, id] of Object.entries(ROD_BY_WOOD))
313 {
314 if (id === (itemId | 0))
315 { return woodTier; }
316 }
317 return null;
318}
319
320function buildToolDefinitions ()
321{
322 const out = {};
323 out[FishingToolItemId.net] = Object.freeze({
324 itemId: FishingToolItemId.net,
325 key: "fishing-net",
326 displayName: "Fishing net",
327 description: "A cotton mesh for scooping small fish from the shallows. Needs no bait.",
328 seedValue: 6,
329 stackable: false,
330 maxStackSize: 1,
331 uniqueInstance: false,
332 category: ItemCategory.tool,
333 iconKey: "fishing-net",
334 defaultState: "fishing-net",
335 tier: ClothTier.cotton,
336 tintFromTier: true,
337 equipment: Object.freeze({
338 slot: "weapon",
339 tier: ClothTier.cotton,
340 kind: EquipmentKind.fishingNet,
341 tintFromTier: true
342 }),
343 npcShopAllowed: true
344 });
345
346 for (const woodTier of WOOD_TIER_ORDER)
347 {
348 const poleId = POLE_BY_WOOD[woodTier];
349 const rodId = ROD_BY_WOOD[woodTier];
350 if (!poleId || !rodId)
351 { continue; }
352 const woodName = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
353 const clothTier = clothTierForWood(woodTier);
354 out[poleId] = Object.freeze({
355 itemId: poleId,
356 key: `${woodTier}-fishing-pole`,
357 displayName: `${woodName} fishing pole`,
358 description: `A shaped ${woodName.toLowerCase()} pole, waiting for a fishing line.`,
359 seedValue: tierRank(woodTier),
360 stackable: false,
361 maxStackSize: 1,
362 uniqueInstance: false,
363 category: ItemCategory.intermediate,
364 iconKey: "fishing-pole",
365 defaultState: "fishing-pole",
366 tier: woodTier,
367 clothTier,
368 tintFromTier: true,
369 fishingPole: true,
370 npcShopAllowed: true
371 });
372 out[rodId] = Object.freeze({
373 itemId: rodId,
374 key: `${woodTier}-fishing-rod`,
375 displayName: `${woodName} fishing rod`,
376 description: `A ${woodName.toLowerCase()} rod strung for deeper water.`,
377 seedValue: tierRank(woodTier) * 2,
378 stackable: false,
379 maxStackSize: 1,
380 uniqueInstance: false,
381 category: ItemCategory.tool,
382 iconKey: "fishing-rod",
383 defaultState: "fishing-rod",
384 tier: woodTier,
385 clothTier,
386 tintFromTier: true,
387 fishingRod: true,
388 poleItemId: poleId,
389 equipment: Object.freeze({
390 slot: "weapon",
391 tier: woodTier,
392 kind: EquipmentKind.fishingRod,
393 tintFromTier: true
394 }),
395 npcShopAllowed: true
396 });
397 }
398 return out;
399}
400
401export const FISH_ITEM_DEFINITIONS = Object.freeze({
402 ...buildFishItemDefinitions(),
403 ...buildBaitDefinitions(),
404 ...buildToolDefinitions()
405});
406
407/** All raw fish item ids (for editor picker). */
408export function listRawFishPickerEntries ()
409{
410 return FISH_SPECIES_ORDER.map((speciesId) =>
411 {
412 const species = FISH_SPECIES[speciesId];
413 const itemId = FISH_ITEM_IDS[speciesId].raw;
414 return {
415 itemId,
416 speciesId,
417 displayName: `Uncooked ${species.displayName}`,
418 tier: species.tier,
419 key: `uncooked-${species.key}`
420 };
421 });
422}
423
424/** Normalize fishing-spot config to unique raw fish item ids. */
425export function normalizeFishingSpotConfig (config)
426{
427 const fishes = [];
428 const seen = new Set();
429 for (const entry of config?.fishes ?? [])
430 {
431 const itemId = typeof entry === "number" ? entry | 0 : entry?.itemId | 0;
432 if (!itemId || seen.has(itemId))
433 { continue; }
434 const speciesId = fishSpeciesIdFromItemId(itemId);
435 if (!speciesId)
436 { continue; }
437 const ids = FISH_ITEM_IDS[speciesId];
438 const rawId = ids?.raw ?? itemId;
439 if (seen.has(rawId))
440 { continue; }
441 seen.add(rawId);
442 fishes.push(rawId);
443 }
444 return { fishes };
445}
446
447/** Craft recipes for fishing tools. */
448export function fishingToolRecipes ()
449{
450 const recipes = [
451 Object.freeze({
452 recipeId: "fishing-net",
453 stationId: CraftingStationId.craftingBench,
454 output: { itemId: FishingToolItemId.net, quantity: 1 },
455 inputs: [{ itemId: yarnItemId(ClothTier.cotton), quantity: 3 }],
456 minSkillLevel: 1,
457 skillId: "crafting",
458 xpMaterial: ClothTier.cotton
459 })
460 ];
461 for (const woodTier of WOOD_TIER_ORDER)
462 {
463 const poleId = POLE_BY_WOOD[woodTier];
464 const rodId = ROD_BY_WOOD[woodTier];
465 if (!poleId || !rodId)
466 { continue; }
467 const clothTier = clothTierForWood(woodTier);
468 recipes.push(Object.freeze({
469 recipeId: `fishing-pole-${woodTier}`,
470 craftGroup: "fishing-pole",
471 craftGroupLabel: "Fishing pole",
472 stationId: CraftingStationId.woodworkingBench,
473 output: { itemId: poleId, quantity: 1 },
474 inputs: [{ itemId: logItemIdForWood(woodTier), quantity: 1 }],
475 minSkillLevel: tierMinSkillLevel(woodTier),
476 skillId: "crafting",
477 xpMaterial: woodTier
478 }));
479 recipes.push(Object.freeze({
480 recipeId: `fishing-rod-${woodTier}`,
481 craftGroup: "fishing-rod",
482 craftGroupLabel: "Fishing rod",
483 stationId: CraftingStationId.craftingBench,
484 output: { itemId: rodId, quantity: 1 },
485 inputs: [
486 { itemId: poleId, quantity: 1 },
487 { itemId: yarnItemId(clothTier), quantity: 2 }
488 ],
489 minSkillLevel: tierMinSkillLevel(woodTier),
490 skillId: "crafting",
491 xpMaterial: woodTier
492 }));
493 }
494 return recipes;
495}
496
497/** Cook recipes for every fish species (oven + fireplace). */
498export function fishingCookRecipes ()
499{
500 return FISH_SPECIES_ORDER.map((speciesId) =>
501 {
502 const ids = FISH_ITEM_IDS[speciesId];
503 const species = FISH_SPECIES[speciesId];
504 return Object.freeze({
505 recipeId: `cook-${species.key}`,
506 craftGroup: "cook-fish",
507 craftGroupLabel: "Fish",
508 stationIds: [CraftingStationId.oven, CraftingStationId.fireplace],
509 output: { itemId: ids.cooked, quantity: 1 },
510 inputs: [{ itemId: ids.raw, quantity: 1 }],
511 minSkillLevel: 1,
512 skillId: "cooking",
513 xpMaterial: CLOTH_TIER_ORDER[species.tier - 1] ?? ClothTier.cotton,
514 burntOutput: { itemId: ids.burnt, quantity: 1 }
515 });
516 });
517}
518
519/** Fishing roll difficulty from bait tier rank. */
520export function fishingDifficulty (baitTierRank)
521{
522 const rank = Math.max(1, baitTierRank | 0);
523 return Math.max((rank - 1) * 10, 1);
524}
525
526export function fishingExhaustDurationMs (fishTierRank)
527{
528 return Math.max(1, fishTierRank | 0) * 10_000;
529}