BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

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