BlueGit

timfa questward

Files

questward / shared / definitions / fishItems.js

fishItems.js

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