BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

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