BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

stationRecipes.js 10.3 KiB Download Raw
1import { CraftingStationId } from "../definitions/craftingStations.js";
2import { ItemId } from "../definitions/items.js";
3import { CraftingItemId } from "../definitions/craftingItems.js";
4import {
5 MetalItemId,
6 PICKAXE_HEAD_ITEM_BY_METAL,
7 PICKAXE_ITEM_BY_METAL,
8 AXE_HEAD_ITEM_BY_METAL,
9 AXE_ITEM_BY_METAL,
10 PLANT_CLIPPERS_ITEM_BY_METAL
11} from "../definitions/metalItems.js";
12import {
13 WOOD_TIER_ORDER,
14 MaterialTier,
15 GatherMaterialId,
16 MATERIAL_TIER_ORDER,
17 CLOTH_TIER_ORDER,
18 woodTierForMetal,
19 tierSmeltSkillLevel,
20 tierCraftSkillLevel
21} from "../definitions/materialTiers.js";
22import {
23 logItemIdForWood,
24 handleItemIdForWood
25} from "../definitions/woodItems.js";
26import {
27 ARMOUR_CRAFT_PIECES,
28 armourItemIdForTier
29} from "../definitions/armourItems.js";
30import {
31 rawClothItemId,
32 yarnItemId,
33 wovenClothItemId,
34 CLOTHING_TEMPLATES
35} from "../definitions/clothItems.js";
36
37/**
38 * Craft recipe schema (shared client + server):
39 *
40 * - recipeId: stable string id
41 * - stationId | stationIds: where the recipe appears
42 * - output: { itemId, quantity }
43 * - inputs: [{ itemId, quantity }, ...]
44 * - minSkillLevel: minimum linked station skill (default 1)
45 * - xpMaterial: tier id for duration + XP scaling
46 * - craftGroup / craftGroupLabel: UI groups tier variants behind one material dropdown
47 */
48
49function smelt (tier, recipeId, inputs, outputItemId)
50{
51 return Object.freeze({
52 recipeId,
53 stationId: CraftingStationId.furnace,
54 output: { itemId: outputItemId, quantity: 1 },
55 inputs,
56 minSkillLevel: tierSmeltSkillLevel(tier),
57 skillId: "smithing",
58 xpMaterial: tier
59 });
60}
61
62function handleRecipe (woodTier)
63{
64 const logId = logItemIdForWood(woodTier);
65 const handleId = handleItemIdForWood(woodTier);
66 return Object.freeze({
67 recipeId: `handle-${woodTier}`,
68 craftGroup: "tool-handle",
69 craftGroupLabel: "Tool handle",
70 stationId: CraftingStationId.woodworkingBench,
71 output: { itemId: handleId, quantity: 1 },
72 inputs: [{ itemId: logId, quantity: 1 }],
73 minSkillLevel: tierCraftSkillLevel(woodTier),
74 skillId: "crafting",
75 xpMaterial: woodTier
76 });
77}
78
79function pickaxeHeadRecipe (metalTier, barItemId, headItemId)
80{
81 return Object.freeze({
82 recipeId: `pickaxe-head-${metalTier}`,
83 craftGroup: "pickaxe-head",
84 craftGroupLabel: "Pickaxe head",
85 stationId: CraftingStationId.anvil,
86 output: { itemId: headItemId, quantity: 1 },
87 inputs: [{ itemId: barItemId, quantity: 1 }],
88 minSkillLevel: tierSmeltSkillLevel(metalTier),
89 skillId: "smithing",
90 xpMaterial: metalTier
91 });
92}
93
94function pickaxeAssembleRecipe (metalTier, handleItemId, headItemId, pickaxeItemId)
95{
96 return Object.freeze({
97 recipeId: `pickaxe-${metalTier}`,
98 stationId: CraftingStationId.craftingBench,
99 output: { itemId: pickaxeItemId, quantity: 1 },
100 inputs: [
101 { itemId: handleItemId, quantity: 1 },
102 { itemId: headItemId, quantity: 1 }
103 ],
104 minSkillLevel: tierCraftSkillLevel(metalTier),
105 skillId: "crafting",
106 xpMaterial: metalTier
107 });
108}
109
110function axeHeadRecipe (metalTier, barItemId, headItemId)
111{
112 return Object.freeze({
113 recipeId: `axe-head-${metalTier}`,
114 craftGroup: "axe-head",
115 craftGroupLabel: "Axe head",
116 stationId: CraftingStationId.anvil,
117 output: { itemId: headItemId, quantity: 1 },
118 inputs: [{ itemId: barItemId, quantity: 1 }],
119 minSkillLevel: tierSmeltSkillLevel(metalTier),
120 skillId: "smithing",
121 xpMaterial: metalTier
122 });
123}
124
125function axeAssembleRecipe (metalTier, handleItemId, headItemId, axeItemId)
126{
127 return Object.freeze({
128 recipeId: `axe-${metalTier}`,
129 stationId: CraftingStationId.craftingBench,
130 output: { itemId: axeItemId, quantity: 1 },
131 inputs: [
132 { itemId: handleItemId, quantity: 1 },
133 { itemId: headItemId, quantity: 1 }
134 ],
135 minSkillLevel: tierCraftSkillLevel(metalTier),
136 skillId: "crafting",
137 xpMaterial: metalTier
138 });
139}
140
141function armourRecipe (metalTier, piece)
142{
143 const outputItemId = armourItemIdForTier(metalTier, piece.idKey);
144 const inputs = [{ itemId: BAR_BY_METAL[metalTier], quantity: piece.ingots }];
145 if (piece.needsBone)
146 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
147 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
148 return Object.freeze({
149 recipeId: `armour-${piece.suffix}-${metalTier}`,
150 craftGroup: `armour-${piece.suffix}`,
151 craftGroupLabel: label,
152 stationId: CraftingStationId.anvil,
153 output: { itemId: outputItemId, quantity: 1 },
154 inputs,
155 minSkillLevel: tierSmeltSkillLevel(metalTier),
156 skillId: "smithing",
157 xpMaterial: metalTier
158 });
159}
160
161function plantClippersRecipe (metalTier, barItemId, clippersItemId)
162{
163 return Object.freeze({
164 recipeId: `plant-clippers-${metalTier}`,
165 craftGroup: "plant-clippers",
166 craftGroupLabel: "Plant clippers",
167 stationId: CraftingStationId.anvil,
168 output: { itemId: clippersItemId, quantity: 1 },
169 inputs: [{ itemId: barItemId, quantity: 1 }],
170 minSkillLevel: tierSmeltSkillLevel(metalTier),
171 skillId: "smithing",
172 xpMaterial: metalTier
173 });
174}
175
176const BAR_BY_METAL = Object.freeze({
177 [MaterialTier.bronze]: CraftingItemId.bronzeBar,
178 [MaterialTier.iron]: MetalItemId.ironBar,
179 [MaterialTier.steel]: MetalItemId.steelBar,
180 [MaterialTier.mithril]: MetalItemId.mithrilBar,
181 [MaterialTier.adamantium]: MetalItemId.adamantiumBar,
182 [MaterialTier.orichalcum]: MetalItemId.orichalcumBar,
183 [MaterialTier.dragon]: MetalItemId.dragonBar
184});
185
186const PICKAXE_BY_METAL = Object.freeze({
187 [MaterialTier.bronze]: CraftingItemId.bronzePickaxe,
188 ...PICKAXE_ITEM_BY_METAL
189});
190
191const AXE_BY_METAL = Object.freeze({
192 [MaterialTier.bronze]: CraftingItemId.bronzeAxe,
193 ...AXE_ITEM_BY_METAL
194});
195
196const WOOD_HANDLE_RECIPES = WOOD_TIER_ORDER.map((tier) => handleRecipe(tier));
197
198const PICKAXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
199 pickaxeHeadRecipe(tier, BAR_BY_METAL[tier], PICKAXE_HEAD_ITEM_BY_METAL[tier]));
200
201const PICKAXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
202{
203 const wood = woodTierForMetal(tier);
204 return pickaxeAssembleRecipe(
205 tier,
206 handleItemIdForWood(wood),
207 PICKAXE_HEAD_ITEM_BY_METAL[tier],
208 PICKAXE_BY_METAL[tier]
209 );
210});
211
212const AXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
213 axeHeadRecipe(tier, BAR_BY_METAL[tier], AXE_HEAD_ITEM_BY_METAL[tier]));
214
215const AXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
216{
217 const wood = woodTierForMetal(tier);
218 return axeAssembleRecipe(
219 tier,
220 handleItemIdForWood(wood),
221 AXE_HEAD_ITEM_BY_METAL[tier],
222 AXE_BY_METAL[tier]
223 );
224});
225
226const ARMOUR_RECIPES = MATERIAL_TIER_ORDER.flatMap((tier) =>
227 ARMOUR_CRAFT_PIECES.map((piece) => armourRecipe(tier, piece)));
228
229const PLANT_CLIPPERS_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
230 plantClippersRecipe(tier, BAR_BY_METAL[tier], PLANT_CLIPPERS_ITEM_BY_METAL[tier]));
231
232function yarnSpinRecipe (clothTier)
233{
234 return Object.freeze({
235 recipeId: `yarn-${clothTier}`,
236 stationId: CraftingStationId.spinningWheel,
237 output: { itemId: yarnItemId(clothTier), quantity: 1 },
238 inputs: [{ itemId: rawClothItemId(clothTier), quantity: 1 }],
239 minSkillLevel: tierCraftSkillLevel(clothTier),
240 skillId: "tailoring",
241 xpMaterial: clothTier
242 });
243}
244
245function clothWeaveRecipe (clothTier)
246{
247 return Object.freeze({
248 recipeId: `cloth-${clothTier}`,
249 stationId: CraftingStationId.loom,
250 output: { itemId: wovenClothItemId(clothTier), quantity: 1 },
251 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
252 minSkillLevel: tierCraftSkillLevel(clothTier),
253 skillId: "tailoring",
254 xpMaterial: clothTier
255 });
256}
257
258const YARN_SPIN_RECIPES = CLOTH_TIER_ORDER.map((tier) => yarnSpinRecipe(tier));
259const CLOTH_WEAVE_RECIPES = CLOTH_TIER_ORDER.map((tier) => clothWeaveRecipe(tier));
260
261/** Tailor templates — client picks material; server resolves inputs/output. */
262const TAILOR_TEMPLATE_RECIPES = Object.values(CLOTHING_TEMPLATES).map((template) => Object.freeze({
263 recipeId: `tailor-${template.templateId}`,
264 stationId: CraftingStationId.tailorBench,
265 tailorTemplate: template.templateId,
266 output: { itemId: template.outputItemIdForTier(CLOTH_TIER_ORDER[0]), quantity: 1 },
267 inputs: [],
268 minSkillLevel: template.minSkillLevel ?? 1,
269 skillId: "tailoring"
270}));
271
272/** @type {ReadonlyArray<object>} */
273export const CRAFT_RECIPES = Object.freeze([
274 Object.freeze({
275 recipeId: "dev-stick-from-paper",
276 stationId: CraftingStationId.craftingBench,
277 output: { itemId: ItemId.stick, quantity: 1 },
278 inputs: [{ itemId: ItemId.paper, quantity: 2 }],
279 minSkillLevel: 1
280 }),
281
282 smelt(MaterialTier.bronze, "smelt-bronze", [
283 { itemId: CraftingItemId.tinOre, quantity: 1 },
284 { itemId: CraftingItemId.copperOre, quantity: 1 }
285 ], CraftingItemId.bronzeBar),
286
287 smelt(MaterialTier.iron, "smelt-iron", [
288 { itemId: MetalItemId.ironOre, quantity: 1 }
289 ], MetalItemId.ironBar),
290
291 smelt(MaterialTier.steel, "smelt-steel", [
292 { itemId: MetalItemId.ironOre, quantity: 1 },
293 { itemId: MetalItemId.coal, quantity: 1 }
294 ], MetalItemId.steelBar),
295
296 smelt(GatherMaterialId.silver, "smelt-silver", [
297 { itemId: MetalItemId.silverOre, quantity: 1 }
298 ], MetalItemId.silverBar),
299
300 smelt(GatherMaterialId.gold, "smelt-gold", [
301 { itemId: MetalItemId.goldOre, quantity: 1 }
302 ], MetalItemId.goldBar),
303
304 smelt(MaterialTier.mithril, "smelt-mithril", [
305 { itemId: MetalItemId.mithrilOre, quantity: 1 }
306 ], MetalItemId.mithrilBar),
307
308 smelt(MaterialTier.adamantium, "smelt-adamantium", [
309 { itemId: MetalItemId.adamantiumOre, quantity: 1 },
310 { itemId: MetalItemId.coal, quantity: 1 }
311 ], MetalItemId.adamantiumBar),
312
313 smelt(MaterialTier.orichalcum, "smelt-orichalcum", [
314 { itemId: MetalItemId.orichalcumOre, quantity: 1 },
315 { itemId: MetalItemId.coal, quantity: 3 }
316 ], MetalItemId.orichalcumBar),
317
318 smelt(MaterialTier.dragon, "smelt-dragon", [
319 { itemId: MetalItemId.dragonOre, quantity: 1 },
320 { itemId: MetalItemId.coal, quantity: 5 }
321 ], MetalItemId.dragonBar),
322
323 ...WOOD_HANDLE_RECIPES,
324 ...PICKAXE_HEAD_RECIPES,
325 ...PICKAXE_ASSEMBLE_RECIPES,
326 ...AXE_HEAD_RECIPES,
327 ...AXE_ASSEMBLE_RECIPES,
328 ...ARMOUR_RECIPES,
329 ...PLANT_CLIPPERS_RECIPES,
330 ...YARN_SPIN_RECIPES,
331 ...CLOTH_WEAVE_RECIPES,
332 ...TAILOR_TEMPLATE_RECIPES
333]);
334
335const RECIPE_BY_ID = new Map(CRAFT_RECIPES.map((recipe) => [recipe.recipeId, recipe]));
336
337export function recipeDefinition (recipeId)
338{
339 return RECIPE_BY_ID.get(recipeId) ?? null;
340}
341
342export function recipeStationIds (recipe)
343{
344 if (!recipe)
345 { return []; }
346 if (Array.isArray(recipe.stationIds))
347 { return recipe.stationIds; }
348 if (recipe.stationId)
349 { return [recipe.stationId]; }
350 return [];
351}
352
353export function recipesForStation (stationId)
354{
355 return CRAFT_RECIPES.filter((recipe) => recipeStationIds(recipe).includes(stationId));
356}