BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

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