BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

stationRecipes.js 8.8 KiB Download Raw
1import { CraftingStationId } from "../definitions/craftingStations.js";
2import { ItemId } from "../definitions/items.js";
3import { CraftingItemId } from "../definitions/craftingItems.js";
4import { MetalItemId } from "../definitions/metalItems.js";
5import { LeatherItemId } from "../definitions/leatherItems.js";
6import { ClothItemId, wovenClothItemId, rawClothItemId, yarnItemId, CLOTHING_TEMPLATES } from "../definitions/clothItems.js";
7import { WIZARD_TEMPLATES } from "../definitions/wizardItems.js";
8import
9 {
10 MaterialTier,
11 GatherMaterialId,
12 CLOTH_TIER_ORDER,
13 ClothTier,
14 LeatherTier,
15 tierSmeltSkillLevel,
16 tierCraftSkillLevel
17 } from "../definitions/materialTiers.js";
18import { TIER_FAMILY_RECIPES } from "./tierRecipes.js";
19import { fishingToolRecipes, fishingCookRecipes } from "../definitions/fishItems.js";
20import { staffCraftRecipes, gemCutRecipes } from "../definitions/gemItems.js";
21
22/**
23 * Craft recipe schema (shared client + server):
24 *
25 * - recipeId: stable string id
26 * - stationId | stationIds: where the recipe appears
27 * - output: { itemId, quantity }
28 * - inputs: [{ itemId, quantity }, ...]
29 * - minSkillLevel: minimum linked station skill (default 1)
30 * - xpMaterial: tier id for duration + XP scaling
31 * - craftGroup / craftGroupLabel: UI groups tier variants behind one material dropdown
32 */
33
34function smelt (tier, recipeId, inputs, outputItemId)
35{
36 return Object.freeze({
37 recipeId,
38 stationId: CraftingStationId.furnace,
39 output: { itemId: outputItemId, quantity: 1 },
40 inputs,
41 minSkillLevel: tierSmeltSkillLevel(tier),
42 skillId: "smithing",
43 xpMaterial: tier
44 });
45}
46
47function yarnSpinRecipe (clothTier)
48{
49 return Object.freeze({
50 recipeId: `yarn-${clothTier}`,
51 craftGroup: "yarn",
52 craftGroupLabel: "Yarn",
53 stationId: CraftingStationId.spinningWheel,
54 output: { itemId: yarnItemId(clothTier), quantity: 1 },
55 inputs: [{ itemId: rawClothItemId(clothTier), quantity: 1 }],
56 minSkillLevel: tierCraftSkillLevel(clothTier),
57 skillId: "tailoring",
58 xpMaterial: clothTier
59 });
60}
61
62function clothWeaveRecipe (clothTier)
63{
64 return Object.freeze({
65 recipeId: `cloth-${clothTier}`,
66 craftGroup: "cloth",
67 craftGroupLabel: "Cloth",
68 stationId: CraftingStationId.loom,
69 output: { itemId: wovenClothItemId(clothTier), quantity: 1 },
70 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
71 minSkillLevel: tierCraftSkillLevel(clothTier),
72 skillId: "tailoring",
73 xpMaterial: clothTier
74 });
75}
76
77const YARN_SPIN_RECIPES = CLOTH_TIER_ORDER.map((tier) => yarnSpinRecipe(tier));
78const CLOTH_WEAVE_RECIPES = CLOTH_TIER_ORDER.map((tier) => clothWeaveRecipe(tier));
79
80/** Tailor templates — client picks material; server resolves inputs/output. */
81const TAILOR_TEMPLATE_RECIPES = Object.freeze([
82 ...Object.values(CLOTHING_TEMPLATES).map((template) => Object.freeze({
83 recipeId: `tailor-${template.templateId}`,
84 stationId: CraftingStationId.tailorBench,
85 tailorTemplate: template.templateId,
86 output: { itemId: template.outputItemIdForTier(CLOTH_TIER_ORDER[0]), quantity: 1 },
87 inputs: [],
88 minSkillLevel: template.minSkillLevel ?? 1,
89 skillId: "tailoring"
90 })),
91 ...Object.values(WIZARD_TEMPLATES).map((template) => Object.freeze({
92 recipeId: template.templateId,
93 stationId: CraftingStationId.tailorBench,
94 tailorTemplate: template.templateId,
95 output: { itemId: template.outputItemIdForTier(CLOTH_TIER_ORDER[0]), quantity: 1 },
96 inputs: [],
97 minSkillLevel: template.minSkillLevel ?? 1,
98 skillId: "tailoring"
99 }))
100]);
101
102/** @type {ReadonlyArray<object>} */
103export const CRAFT_RECIPES = Object.freeze([
104 smelt(MaterialTier.bronze, "smelt-bronze", [
105 { itemId: CraftingItemId.tinOre, quantity: 1 },
106 { itemId: CraftingItemId.copperOre, quantity: 1 }
107 ], CraftingItemId.bronzeBar),
108
109 smelt(MaterialTier.iron, "smelt-iron", [
110 { itemId: MetalItemId.ironOre, quantity: 1 }
111 ], MetalItemId.ironBar),
112
113 smelt(MaterialTier.steel, "smelt-steel", [
114 { itemId: MetalItemId.ironOre, quantity: 1 },
115 { itemId: MetalItemId.coal, quantity: 1 }
116 ], MetalItemId.steelBar),
117
118 smelt(GatherMaterialId.silver, "smelt-silver", [
119 { itemId: MetalItemId.silverOre, quantity: 1 }
120 ], MetalItemId.silverBar),
121
122 smelt(GatherMaterialId.gold, "smelt-gold", [
123 { itemId: MetalItemId.goldOre, quantity: 1 }
124 ], MetalItemId.goldBar),
125
126 smelt(GatherMaterialId.electrum, "smelt-electrum", [
127 { itemId: MetalItemId.goldOre, quantity: 1 },
128 { itemId: MetalItemId.silverOre, quantity: 1 },
129 { itemId: MetalItemId.coal, quantity: 3 }
130 ], MetalItemId.electrumBar),
131
132 smelt(MaterialTier.mithril, "smelt-mithril", [
133 { itemId: MetalItemId.mithrilOre, quantity: 1 }
134 ], MetalItemId.mithrilBar),
135
136 smelt(MaterialTier.adamantium, "smelt-adamantium", [
137 { itemId: MetalItemId.adamantiumOre, quantity: 1 },
138 { itemId: MetalItemId.coal, quantity: 1 }
139 ], MetalItemId.adamantiumBar),
140
141 smelt(MaterialTier.orichalcum, "smelt-orichalcum", [
142 { itemId: MetalItemId.orichalcumOre, quantity: 1 },
143 { itemId: MetalItemId.coal, quantity: 3 }
144 ], MetalItemId.orichalcumBar),
145
146 smelt(MaterialTier.dragon, "smelt-dragon", [
147 { itemId: MetalItemId.dragonOre, quantity: 1 },
148 { itemId: MetalItemId.coal, quantity: 5 }
149 ], MetalItemId.dragonBar),
150
151 ...TIER_FAMILY_RECIPES,
152 ...YARN_SPIN_RECIPES,
153 ...CLOTH_WEAVE_RECIPES,
154 ...TAILOR_TEMPLATE_RECIPES,
155
156 Object.freeze({
157 recipeId: "smith-steel-stud",
158 stationId: CraftingStationId.anvil,
159 output: { itemId: LeatherItemId.steelStud, quantity: 6 },
160 inputs: [{ itemId: MetalItemId.steelBar, quantity: 1 }],
161 minSkillLevel: tierCraftSkillLevel(MaterialTier.steel),
162 skillId: "smithing",
163 xpMaterial: MaterialTier.steel
164 }),
165
166 Object.freeze({
167 recipeId: "leather-hard",
168 stationId: CraftingStationId.leatherworkingStation,
169 output: { itemId: LeatherItemId.hardLeather, quantity: 1 },
170 inputs: [
171 { itemId: LeatherItemId.softLeather, quantity: 1 },
172 { itemId: LeatherItemId.tanningBrew, quantity: 1 }
173 ],
174 minSkillLevel: tierCraftSkillLevel(LeatherTier.hardLeather),
175 skillId: "leatherworking",
176 xpMaterial: LeatherTier.hardLeather
177 }),
178
179 Object.freeze({
180 recipeId: "leather-studded",
181 stationId: CraftingStationId.leatherworkingStation,
182 output: { itemId: LeatherItemId.studdedLeather, quantity: 1 },
183 inputs: [
184 { itemId: LeatherItemId.hardLeather, quantity: 1 },
185 { itemId: LeatherItemId.steelStud, quantity: 2 }
186 ],
187 minSkillLevel: tierCraftSkillLevel(LeatherTier.studdedLeather),
188 skillId: "leatherworking",
189 xpMaterial: LeatherTier.studdedLeather
190 }),
191
192 Object.freeze({
193 recipeId: "leather-reinforced",
194 stationId: CraftingStationId.leatherworkingStation,
195 output: { itemId: LeatherItemId.reinforcedLeather, quantity: 1 },
196 inputs: [
197 { itemId: LeatherItemId.studdedLeather, quantity: 1 },
198 { itemId: wovenClothItemId(ClothTier.cashmere), quantity: 1 }
199 ],
200 minSkillLevel: tierCraftSkillLevel(LeatherTier.reinforcedLeather),
201 skillId: "leatherworking",
202 xpMaterial: LeatherTier.reinforcedLeather
203 }),
204
205 Object.freeze({
206 recipeId: "cook-venison",
207 stationIds: [CraftingStationId.oven, CraftingStationId.fireplace],
208 output: { itemId: CraftingItemId.cookedMeat, quantity: 1 },
209 inputs: [{ itemId: CraftingItemId.rawMeat, quantity: 1 }],
210 minSkillLevel: 1,
211 skillId: "cooking",
212 burntOutput: { itemId: CraftingItemId.burntMeat, quantity: 1 }
213 }),
214
215 Object.freeze({
216 recipeId: "cook-mutton",
217 stationIds: [CraftingStationId.oven, CraftingStationId.fireplace],
218 craftGroup: "cook-mutton",
219 craftGroupLabel: "Mutton",
220 output: { itemId: CraftingItemId.cookedMutton, quantity: 1 },
221 inputs: [{ itemId: CraftingItemId.rawMutton, quantity: 1 }],
222 minSkillLevel: 1,
223 skillId: "cooking",
224 burntOutput: { itemId: CraftingItemId.burntMutton, quantity: 1 }
225 }),
226
227 Object.freeze({
228 recipeId: "cook-goat",
229 stationIds: [CraftingStationId.oven, CraftingStationId.fireplace],
230 craftGroup: "cook-goat",
231 craftGroupLabel: "Goat",
232 output: { itemId: CraftingItemId.cookedGoat, quantity: 1 },
233 inputs: [{ itemId: CraftingItemId.rawGoat, quantity: 1 }],
234 minSkillLevel: 1,
235 skillId: "cooking",
236 burntOutput: { itemId: CraftingItemId.burntGoat, quantity: 1 }
237 }),
238
239 Object.freeze({
240 recipeId: "cook-egg",
241 stationIds: [CraftingStationId.oven],
242 craftGroup: "cook-egg",
243 craftGroupLabel: "Egg",
244 output: { itemId: ItemId.cookedEgg, quantity: 1 },
245 inputs: [{ itemId: ItemId.egg, quantity: 1 }],
246 minSkillLevel: 1,
247 skillId: "cooking",
248 burntOutput: { itemId: ItemId.burntEgg, quantity: 1 }
249 }),
250
251 ...fishingToolRecipes(),
252 ...fishingCookRecipes(),
253 ...gemCutRecipes(),
254 ...staffCraftRecipes()
255]);
256
257const RECIPE_BY_ID = new Map(CRAFT_RECIPES.map((recipe) => [recipe.recipeId, recipe]));
258
259export function recipeDefinition (recipeId)
260{
261 return RECIPE_BY_ID.get(recipeId) ?? null;
262}
263
264export function recipeStationIds (recipe)
265{
266 if (!recipe)
267 { return []; }
268 if (Array.isArray(recipe.stationIds))
269 { return recipe.stationIds; }
270 if (recipe.stationId)
271 { return [recipe.stationId]; }
272 return [];
273}
274
275export function recipesForStation (stationId)
276{
277 return CRAFT_RECIPES.filter((recipe) => recipeStationIds(recipe).includes(stationId));
278}