BlueGit

timfa questward

Files

questward / shared / crafting / stationRecipes.js

stationRecipes.js

lots of things
timfa Tim Falken · pushed by timfa · 2 months ago
07a95f71 History
stationRecipes.js 6.4 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 craftGroup: "yarn",
48 craftGroupLabel: "Yarn",
49 stationId: CraftingStationId.spinningWheel,
50 output: { itemId: yarnItemId(clothTier), quantity: 1 },
51 inputs: [{ itemId: rawClothItemId(clothTier), quantity: 1 }],
52 minSkillLevel: tierCraftSkillLevel(clothTier),
53 skillId: "tailoring",
54 xpMaterial: clothTier
55 });
56}
57
58function clothWeaveRecipe (clothTier)
59{
60 return Object.freeze({
61 recipeId: `cloth-${clothTier}`,
62 craftGroup: "cloth",
63 craftGroupLabel: "Cloth",
64 stationId: CraftingStationId.loom,
65 output: { itemId: wovenClothItemId(clothTier), quantity: 1 },
66 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
67 minSkillLevel: tierCraftSkillLevel(clothTier),
68 skillId: "tailoring",
69 xpMaterial: clothTier
70 });
71}
72
73const YARN_SPIN_RECIPES = CLOTH_TIER_ORDER.map((tier) => yarnSpinRecipe(tier));
74const CLOTH_WEAVE_RECIPES = CLOTH_TIER_ORDER.map((tier) => clothWeaveRecipe(tier));
75
76/** Tailor templates — client picks material; server resolves inputs/output. */
77const TAILOR_TEMPLATE_RECIPES = Object.values(CLOTHING_TEMPLATES).map((template) => Object.freeze({
78 recipeId: `tailor-${template.templateId}`,
79 stationId: CraftingStationId.tailorBench,
80 tailorTemplate: template.templateId,
81 output: { itemId: template.outputItemIdForTier(CLOTH_TIER_ORDER[0]), quantity: 1 },
82 inputs: [],
83 minSkillLevel: template.minSkillLevel ?? 1,
84 skillId: "tailoring"
85}));
86
87/** @type {ReadonlyArray<object>} */
88export const CRAFT_RECIPES = Object.freeze([
89 smelt(MaterialTier.bronze, "smelt-bronze", [
90 { itemId: CraftingItemId.tinOre, quantity: 1 },
91 { itemId: CraftingItemId.copperOre, quantity: 1 }
92 ], CraftingItemId.bronzeBar),
93
94 smelt(MaterialTier.iron, "smelt-iron", [
95 { itemId: MetalItemId.ironOre, quantity: 1 }
96 ], MetalItemId.ironBar),
97
98 smelt(MaterialTier.steel, "smelt-steel", [
99 { itemId: MetalItemId.ironOre, quantity: 1 },
100 { itemId: MetalItemId.coal, quantity: 1 }
101 ], MetalItemId.steelBar),
102
103 smelt(GatherMaterialId.silver, "smelt-silver", [
104 { itemId: MetalItemId.silverOre, quantity: 1 }
105 ], MetalItemId.silverBar),
106
107 smelt(GatherMaterialId.gold, "smelt-gold", [
108 { itemId: MetalItemId.goldOre, quantity: 1 }
109 ], MetalItemId.goldBar),
110
111 smelt(MaterialTier.mithril, "smelt-mithril", [
112 { itemId: MetalItemId.mithrilOre, quantity: 1 }
113 ], MetalItemId.mithrilBar),
114
115 smelt(MaterialTier.adamantium, "smelt-adamantium", [
116 { itemId: MetalItemId.adamantiumOre, quantity: 1 },
117 { itemId: MetalItemId.coal, quantity: 1 }
118 ], MetalItemId.adamantiumBar),
119
120 smelt(MaterialTier.orichalcum, "smelt-orichalcum", [
121 { itemId: MetalItemId.orichalcumOre, quantity: 1 },
122 { itemId: MetalItemId.coal, quantity: 3 }
123 ], MetalItemId.orichalcumBar),
124
125 smelt(MaterialTier.dragon, "smelt-dragon", [
126 { itemId: MetalItemId.dragonOre, quantity: 1 },
127 { itemId: MetalItemId.coal, quantity: 5 }
128 ], MetalItemId.dragonBar),
129
130 ...TIER_FAMILY_RECIPES,
131 ...YARN_SPIN_RECIPES,
132 ...CLOTH_WEAVE_RECIPES,
133 ...TAILOR_TEMPLATE_RECIPES,
134
135 Object.freeze({
136 recipeId: "smith-steel-stud",
137 stationId: CraftingStationId.anvil,
138 output: { itemId: LeatherItemId.steelStud, quantity: 6 },
139 inputs: [{ itemId: MetalItemId.steelBar, quantity: 1 }],
140 minSkillLevel: tierCraftSkillLevel(MaterialTier.steel),
141 skillId: "smithing",
142 xpMaterial: MaterialTier.steel
143 }),
144
145 Object.freeze({
146 recipeId: "leather-hard",
147 stationId: CraftingStationId.leatherworkingStation,
148 output: { itemId: LeatherItemId.hardLeather, quantity: 1 },
149 inputs: [
150 { itemId: LeatherItemId.softLeather, quantity: 1 },
151 { itemId: LeatherItemId.tanningBrew, quantity: 1 }
152 ],
153 minSkillLevel: tierCraftSkillLevel(LeatherTier.hardLeather),
154 skillId: "leatherworking",
155 xpMaterial: LeatherTier.hardLeather
156 }),
157
158 Object.freeze({
159 recipeId: "leather-studded",
160 stationId: CraftingStationId.leatherworkingStation,
161 output: { itemId: LeatherItemId.studdedLeather, quantity: 1 },
162 inputs: [
163 { itemId: LeatherItemId.hardLeather, quantity: 1 },
164 { itemId: LeatherItemId.steelStud, quantity: 2 }
165 ],
166 minSkillLevel: tierCraftSkillLevel(LeatherTier.studdedLeather),
167 skillId: "leatherworking",
168 xpMaterial: LeatherTier.studdedLeather
169 }),
170
171 Object.freeze({
172 recipeId: "leather-reinforced",
173 stationId: CraftingStationId.leatherworkingStation,
174 output: { itemId: LeatherItemId.reinforcedLeather, quantity: 1 },
175 inputs: [
176 { itemId: LeatherItemId.studdedLeather, quantity: 1 },
177 { itemId: wovenClothItemId(ClothTier.cashmere), quantity: 1 }
178 ],
179 minSkillLevel: tierCraftSkillLevel(LeatherTier.reinforcedLeather),
180 skillId: "leatherworking",
181 xpMaterial: LeatherTier.reinforcedLeather
182 })
183]);
184
185const RECIPE_BY_ID = new Map(CRAFT_RECIPES.map((recipe) => [recipe.recipeId, recipe]));
186
187export function recipeDefinition (recipeId)
188{
189 return RECIPE_BY_ID.get(recipeId) ?? null;
190}
191
192export function recipeStationIds (recipe)
193{
194 if (!recipe)
195 { return []; }
196 if (Array.isArray(recipe.stationIds))
197 { return recipe.stationIds; }
198 if (recipe.stationId)
199 { return [recipe.stationId]; }
200 return [];
201}
202
203export function recipesForStation (stationId)
204{
205 return CRAFT_RECIPES.filter((recipe) => recipeStationIds(recipe).includes(stationId));
206}