| 1 | import { CraftingStationId } from "../definitions/craftingStations.js"; |
| 2 | import { ItemId } from "../definitions/items.js"; |
| 3 | import { CraftingItemId } from "../definitions/craftingItems.js"; |
| 4 | import { |
| 5 | MetalItemId, |
| 6 | PICKAXE_HEAD_ITEM_BY_METAL, |
| 7 | PICKAXE_ITEM_BY_METAL, |
| 8 | AXE_HEAD_ITEM_BY_METAL, |
| 9 | AXE_ITEM_BY_METAL, |
| 10 | PLANT_CLIPPERS_ITEM_BY_METAL |
| 11 | } from "../definitions/metalItems.js"; |
| 12 | import { |
| 13 | WOOD_TIER_ORDER, |
| 14 | MaterialTier, |
| 15 | GatherMaterialId, |
| 16 | MATERIAL_TIER_ORDER, |
| 17 | CLOTH_TIER_ORDER, |
| 18 | woodTierForMetal, |
| 19 | tierSmeltSkillLevel, |
| 20 | tierCraftSkillLevel |
| 21 | } from "../definitions/materialTiers.js"; |
| 22 | import { |
| 23 | logItemIdForWood, |
| 24 | handleItemIdForWood |
| 25 | } from "../definitions/woodItems.js"; |
| 26 | import { |
| 27 | ARMOUR_CRAFT_PIECES, |
| 28 | armourItemIdForTier |
| 29 | } from "../definitions/armourItems.js"; |
| 30 | import { |
| 31 | rawClothItemId, |
| 32 | yarnItemId, |
| 33 | wovenClothItemId, |
| 34 | CLOTHING_TEMPLATES |
| 35 | } from "../definitions/clothItems.js"; |
| 36 | import { |
| 37 | arrowShaftRecipe, |
| 38 | arrowTipRecipe, |
| 39 | arrowAssembleRecipe, |
| 40 | unstrungBowRecipe, |
| 41 | bowstringRecipe, |
| 42 | bowAssembleRecipe |
| 43 | } from "../definitions/rangedItems.js"; |
| 44 | |
| 45 | /** |
| 46 | * Craft recipe schema (shared client + server): |
| 47 | * |
| 48 | * - recipeId: stable string id |
| 49 | * - stationId | stationIds: where the recipe appears |
| 50 | * - output: { itemId, quantity } |
| 51 | * - inputs: [{ itemId, quantity }, ...] |
| 52 | * - minSkillLevel: minimum linked station skill (default 1) |
| 53 | * - xpMaterial: tier id for duration + XP scaling |
| 54 | * - craftGroup / craftGroupLabel: UI groups tier variants behind one material dropdown |
| 55 | */ |
| 56 | |
| 57 | function smelt (tier, recipeId, inputs, outputItemId) |
| 58 | { |
| 59 | return Object.freeze({ |
| 60 | recipeId, |
| 61 | stationId: CraftingStationId.furnace, |
| 62 | output: { itemId: outputItemId, quantity: 1 }, |
| 63 | inputs, |
| 64 | minSkillLevel: tierSmeltSkillLevel(tier), |
| 65 | skillId: "smithing", |
| 66 | xpMaterial: tier |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | function handleRecipe (woodTier) |
| 71 | { |
| 72 | const logId = logItemIdForWood(woodTier); |
| 73 | const handleId = handleItemIdForWood(woodTier); |
| 74 | return Object.freeze({ |
| 75 | recipeId: `handle-${woodTier}`, |
| 76 | craftGroup: "tool-handle", |
| 77 | craftGroupLabel: "Tool handle", |
| 78 | stationId: CraftingStationId.woodworkingBench, |
| 79 | output: { itemId: handleId, quantity: 1 }, |
| 80 | inputs: [{ itemId: logId, quantity: 1 }], |
| 81 | minSkillLevel: tierCraftSkillLevel(woodTier), |
| 82 | skillId: "crafting", |
| 83 | xpMaterial: woodTier |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | function pickaxeHeadRecipe (metalTier, barItemId, headItemId) |
| 88 | { |
| 89 | return Object.freeze({ |
| 90 | recipeId: `pickaxe-head-${metalTier}`, |
| 91 | craftGroup: "pickaxe-head", |
| 92 | craftGroupLabel: "Pickaxe head", |
| 93 | stationId: CraftingStationId.anvil, |
| 94 | output: { itemId: headItemId, quantity: 1 }, |
| 95 | inputs: [{ itemId: barItemId, quantity: 1 }], |
| 96 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 97 | skillId: "smithing", |
| 98 | xpMaterial: metalTier |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | function pickaxeAssembleRecipe (metalTier, handleItemId, headItemId, pickaxeItemId) |
| 103 | { |
| 104 | return Object.freeze({ |
| 105 | recipeId: `pickaxe-${metalTier}`, |
| 106 | stationId: CraftingStationId.craftingBench, |
| 107 | output: { itemId: pickaxeItemId, quantity: 1 }, |
| 108 | inputs: [ |
| 109 | { itemId: handleItemId, quantity: 1 }, |
| 110 | { itemId: headItemId, quantity: 1 } |
| 111 | ], |
| 112 | minSkillLevel: tierCraftSkillLevel(metalTier), |
| 113 | skillId: "crafting", |
| 114 | xpMaterial: metalTier |
| 115 | }); |
| 116 | } |
| 117 | |
| 118 | function axeHeadRecipe (metalTier, barItemId, headItemId) |
| 119 | { |
| 120 | return Object.freeze({ |
| 121 | recipeId: `axe-head-${metalTier}`, |
| 122 | craftGroup: "axe-head", |
| 123 | craftGroupLabel: "Axe head", |
| 124 | stationId: CraftingStationId.anvil, |
| 125 | output: { itemId: headItemId, quantity: 1 }, |
| 126 | inputs: [{ itemId: barItemId, quantity: 1 }], |
| 127 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 128 | skillId: "smithing", |
| 129 | xpMaterial: metalTier |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | function axeAssembleRecipe (metalTier, handleItemId, headItemId, axeItemId) |
| 134 | { |
| 135 | return Object.freeze({ |
| 136 | recipeId: `axe-${metalTier}`, |
| 137 | stationId: CraftingStationId.craftingBench, |
| 138 | output: { itemId: axeItemId, quantity: 1 }, |
| 139 | inputs: [ |
| 140 | { itemId: handleItemId, quantity: 1 }, |
| 141 | { itemId: headItemId, quantity: 1 } |
| 142 | ], |
| 143 | minSkillLevel: tierCraftSkillLevel(metalTier), |
| 144 | skillId: "crafting", |
| 145 | xpMaterial: metalTier |
| 146 | }); |
| 147 | } |
| 148 | |
| 149 | function armourRecipe (metalTier, piece) |
| 150 | { |
| 151 | const outputItemId = armourItemIdForTier(metalTier, piece.idKey); |
| 152 | const inputs = [{ itemId: BAR_BY_METAL[metalTier], quantity: piece.ingots }]; |
| 153 | if (piece.needsBone) |
| 154 | { inputs.push({ itemId: ItemId.bones, quantity: 1 }); } |
| 155 | const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1); |
| 156 | return Object.freeze({ |
| 157 | recipeId: `armour-${piece.suffix}-${metalTier}`, |
| 158 | craftGroup: `armour-${piece.suffix}`, |
| 159 | craftGroupLabel: label, |
| 160 | stationId: CraftingStationId.anvil, |
| 161 | output: { itemId: outputItemId, quantity: 1 }, |
| 162 | inputs, |
| 163 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 164 | skillId: "smithing", |
| 165 | xpMaterial: metalTier |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | function plantClippersRecipe (metalTier, barItemId, clippersItemId) |
| 170 | { |
| 171 | return Object.freeze({ |
| 172 | recipeId: `plant-clippers-${metalTier}`, |
| 173 | craftGroup: "plant-clippers", |
| 174 | craftGroupLabel: "Plant clippers", |
| 175 | stationId: CraftingStationId.anvil, |
| 176 | output: { itemId: clippersItemId, quantity: 1 }, |
| 177 | inputs: [{ itemId: barItemId, quantity: 1 }], |
| 178 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 179 | skillId: "smithing", |
| 180 | xpMaterial: metalTier |
| 181 | }); |
| 182 | } |
| 183 | |
| 184 | const BAR_BY_METAL = Object.freeze({ |
| 185 | [MaterialTier.bronze]: CraftingItemId.bronzeBar, |
| 186 | [MaterialTier.iron]: MetalItemId.ironBar, |
| 187 | [MaterialTier.steel]: MetalItemId.steelBar, |
| 188 | [MaterialTier.mithril]: MetalItemId.mithrilBar, |
| 189 | [MaterialTier.adamantium]: MetalItemId.adamantiumBar, |
| 190 | [MaterialTier.orichalcum]: MetalItemId.orichalcumBar, |
| 191 | [MaterialTier.dragon]: MetalItemId.dragonBar |
| 192 | }); |
| 193 | |
| 194 | const PICKAXE_BY_METAL = Object.freeze({ |
| 195 | [MaterialTier.bronze]: CraftingItemId.bronzePickaxe, |
| 196 | ...PICKAXE_ITEM_BY_METAL |
| 197 | }); |
| 198 | |
| 199 | const AXE_BY_METAL = Object.freeze({ |
| 200 | [MaterialTier.bronze]: CraftingItemId.bronzeAxe, |
| 201 | ...AXE_ITEM_BY_METAL |
| 202 | }); |
| 203 | |
| 204 | const WOOD_HANDLE_RECIPES = WOOD_TIER_ORDER.map((tier) => handleRecipe(tier)); |
| 205 | |
| 206 | const PICKAXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) => |
| 207 | pickaxeHeadRecipe(tier, BAR_BY_METAL[tier], PICKAXE_HEAD_ITEM_BY_METAL[tier])); |
| 208 | |
| 209 | const PICKAXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) => |
| 210 | { |
| 211 | const wood = woodTierForMetal(tier); |
| 212 | return pickaxeAssembleRecipe( |
| 213 | tier, |
| 214 | handleItemIdForWood(wood), |
| 215 | PICKAXE_HEAD_ITEM_BY_METAL[tier], |
| 216 | PICKAXE_BY_METAL[tier] |
| 217 | ); |
| 218 | }); |
| 219 | |
| 220 | const AXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) => |
| 221 | axeHeadRecipe(tier, BAR_BY_METAL[tier], AXE_HEAD_ITEM_BY_METAL[tier])); |
| 222 | |
| 223 | const AXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) => |
| 224 | { |
| 225 | const wood = woodTierForMetal(tier); |
| 226 | return axeAssembleRecipe( |
| 227 | tier, |
| 228 | handleItemIdForWood(wood), |
| 229 | AXE_HEAD_ITEM_BY_METAL[tier], |
| 230 | AXE_BY_METAL[tier] |
| 231 | ); |
| 232 | }); |
| 233 | |
| 234 | const ARMOUR_RECIPES = MATERIAL_TIER_ORDER.flatMap((tier) => |
| 235 | ARMOUR_CRAFT_PIECES.map((piece) => armourRecipe(tier, piece))); |
| 236 | |
| 237 | const PLANT_CLIPPERS_RECIPES = MATERIAL_TIER_ORDER.map((tier) => |
| 238 | plantClippersRecipe(tier, BAR_BY_METAL[tier], PLANT_CLIPPERS_ITEM_BY_METAL[tier])); |
| 239 | |
| 240 | const ARROW_SHAFT_RECIPES = WOOD_TIER_ORDER.map((tier) => arrowShaftRecipe(tier)); |
| 241 | const ARROW_TIP_RECIPES = MATERIAL_TIER_ORDER.map((tier) => |
| 242 | arrowTipRecipe(tier, BAR_BY_METAL[tier])); |
| 243 | const ARROW_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) => arrowAssembleRecipe(tier)); |
| 244 | const UNSTRUNG_BOW_RECIPES = WOOD_TIER_ORDER.map((tier) => unstrungBowRecipe(tier)); |
| 245 | const BOWSTRING_RECIPES = CLOTH_TIER_ORDER.map((tier) => bowstringRecipe(tier)); |
| 246 | const BOW_ASSEMBLE_RECIPES = WOOD_TIER_ORDER.map((tier) => bowAssembleRecipe(tier)); |
| 247 | |
| 248 | function yarnSpinRecipe (clothTier) |
| 249 | { |
| 250 | return Object.freeze({ |
| 251 | recipeId: `yarn-${clothTier}`, |
| 252 | stationId: CraftingStationId.spinningWheel, |
| 253 | output: { itemId: yarnItemId(clothTier), quantity: 1 }, |
| 254 | inputs: [{ itemId: rawClothItemId(clothTier), quantity: 1 }], |
| 255 | minSkillLevel: tierCraftSkillLevel(clothTier), |
| 256 | skillId: "tailoring", |
| 257 | xpMaterial: clothTier |
| 258 | }); |
| 259 | } |
| 260 | |
| 261 | function clothWeaveRecipe (clothTier) |
| 262 | { |
| 263 | return Object.freeze({ |
| 264 | recipeId: `cloth-${clothTier}`, |
| 265 | stationId: CraftingStationId.loom, |
| 266 | output: { itemId: wovenClothItemId(clothTier), quantity: 1 }, |
| 267 | inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }], |
| 268 | minSkillLevel: tierCraftSkillLevel(clothTier), |
| 269 | skillId: "tailoring", |
| 270 | xpMaterial: clothTier |
| 271 | }); |
| 272 | } |
| 273 | |
| 274 | const YARN_SPIN_RECIPES = CLOTH_TIER_ORDER.map((tier) => yarnSpinRecipe(tier)); |
| 275 | const CLOTH_WEAVE_RECIPES = CLOTH_TIER_ORDER.map((tier) => clothWeaveRecipe(tier)); |
| 276 | |
| 277 | /** Tailor templates — client picks material; server resolves inputs/output. */ |
| 278 | const TAILOR_TEMPLATE_RECIPES = Object.values(CLOTHING_TEMPLATES).map((template) => Object.freeze({ |
| 279 | recipeId: `tailor-${template.templateId}`, |
| 280 | stationId: CraftingStationId.tailorBench, |
| 281 | tailorTemplate: template.templateId, |
| 282 | output: { itemId: template.outputItemIdForTier(CLOTH_TIER_ORDER[0]), quantity: 1 }, |
| 283 | inputs: [], |
| 284 | minSkillLevel: template.minSkillLevel ?? 1, |
| 285 | skillId: "tailoring" |
| 286 | })); |
| 287 | |
| 288 | /** @type {ReadonlyArray<object>} */ |
| 289 | export const CRAFT_RECIPES = Object.freeze([ |
| 290 | Object.freeze({ |
| 291 | recipeId: "dev-stick-from-paper", |
| 292 | stationId: CraftingStationId.craftingBench, |
| 293 | output: { itemId: ItemId.stick, quantity: 1 }, |
| 294 | inputs: [{ itemId: ItemId.paper, quantity: 2 }], |
| 295 | minSkillLevel: 1 |
| 296 | }), |
| 297 | |
| 298 | smelt(MaterialTier.bronze, "smelt-bronze", [ |
| 299 | { itemId: CraftingItemId.tinOre, quantity: 1 }, |
| 300 | { itemId: CraftingItemId.copperOre, quantity: 1 } |
| 301 | ], CraftingItemId.bronzeBar), |
| 302 | |
| 303 | smelt(MaterialTier.iron, "smelt-iron", [ |
| 304 | { itemId: MetalItemId.ironOre, quantity: 1 } |
| 305 | ], MetalItemId.ironBar), |
| 306 | |
| 307 | smelt(MaterialTier.steel, "smelt-steel", [ |
| 308 | { itemId: MetalItemId.ironOre, quantity: 1 }, |
| 309 | { itemId: MetalItemId.coal, quantity: 1 } |
| 310 | ], MetalItemId.steelBar), |
| 311 | |
| 312 | smelt(GatherMaterialId.silver, "smelt-silver", [ |
| 313 | { itemId: MetalItemId.silverOre, quantity: 1 } |
| 314 | ], MetalItemId.silverBar), |
| 315 | |
| 316 | smelt(GatherMaterialId.gold, "smelt-gold", [ |
| 317 | { itemId: MetalItemId.goldOre, quantity: 1 } |
| 318 | ], MetalItemId.goldBar), |
| 319 | |
| 320 | smelt(MaterialTier.mithril, "smelt-mithril", [ |
| 321 | { itemId: MetalItemId.mithrilOre, quantity: 1 } |
| 322 | ], MetalItemId.mithrilBar), |
| 323 | |
| 324 | smelt(MaterialTier.adamantium, "smelt-adamantium", [ |
| 325 | { itemId: MetalItemId.adamantiumOre, quantity: 1 }, |
| 326 | { itemId: MetalItemId.coal, quantity: 1 } |
| 327 | ], MetalItemId.adamantiumBar), |
| 328 | |
| 329 | smelt(MaterialTier.orichalcum, "smelt-orichalcum", [ |
| 330 | { itemId: MetalItemId.orichalcumOre, quantity: 1 }, |
| 331 | { itemId: MetalItemId.coal, quantity: 3 } |
| 332 | ], MetalItemId.orichalcumBar), |
| 333 | |
| 334 | smelt(MaterialTier.dragon, "smelt-dragon", [ |
| 335 | { itemId: MetalItemId.dragonOre, quantity: 1 }, |
| 336 | { itemId: MetalItemId.coal, quantity: 5 } |
| 337 | ], MetalItemId.dragonBar), |
| 338 | |
| 339 | ...WOOD_HANDLE_RECIPES, |
| 340 | ...PICKAXE_HEAD_RECIPES, |
| 341 | ...PICKAXE_ASSEMBLE_RECIPES, |
| 342 | ...AXE_HEAD_RECIPES, |
| 343 | ...AXE_ASSEMBLE_RECIPES, |
| 344 | ...ARMOUR_RECIPES, |
| 345 | ...PLANT_CLIPPERS_RECIPES, |
| 346 | ...ARROW_SHAFT_RECIPES, |
| 347 | ...UNSTRUNG_BOW_RECIPES, |
| 348 | ...ARROW_TIP_RECIPES, |
| 349 | ...BOWSTRING_RECIPES, |
| 350 | ...ARROW_ASSEMBLE_RECIPES, |
| 351 | ...BOW_ASSEMBLE_RECIPES, |
| 352 | ...YARN_SPIN_RECIPES, |
| 353 | ...CLOTH_WEAVE_RECIPES, |
| 354 | ...TAILOR_TEMPLATE_RECIPES |
| 355 | ]); |
| 356 | |
| 357 | const RECIPE_BY_ID = new Map(CRAFT_RECIPES.map((recipe) => [recipe.recipeId, recipe])); |
| 358 | |
| 359 | export function recipeDefinition (recipeId) |
| 360 | { |
| 361 | return RECIPE_BY_ID.get(recipeId) ?? null; |
| 362 | } |
| 363 | |
| 364 | export function recipeStationIds (recipe) |
| 365 | { |
| 366 | if (!recipe) |
| 367 | { return []; } |
| 368 | if (Array.isArray(recipe.stationIds)) |
| 369 | { return recipe.stationIds; } |
| 370 | if (recipe.stationId) |
| 371 | { return [recipe.stationId]; } |
| 372 | return []; |
| 373 | } |
| 374 | |
| 375 | export function recipesForStation (stationId) |
| 376 | { |
| 377 | return CRAFT_RECIPES.filter((recipe) => recipeStationIds(recipe).includes(stationId)); |
| 378 | } |