BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

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