| 1 | import { CraftingStationId } from "../definitions/craftingStations.js"; |
| 2 | import { ItemId } from "../definitions/items.js"; |
| 3 | import { ItemFamilyId } from "../definitions/tierFamilies.js"; |
| 4 | import { familyItemId } from "../definitions/familyItemIds.js"; |
| 5 | import { WoodItemId } from "../definitions/woodItems.js"; |
| 6 | import |
| 7 | { |
| 8 | WOOD_TIER_ORDER, |
| 9 | MATERIAL_TIER_ORDER, |
| 10 | CLOTH_TIER_ORDER, |
| 11 | MATERIAL_DISPLAY_NAME, |
| 12 | WoodTier, |
| 13 | woodTierForMetal, |
| 14 | leatherTierForMetal, |
| 15 | clothTierForWood, |
| 16 | tierSmeltSkillLevel, |
| 17 | tierCraftSkillLevel, |
| 18 | tierMinSkillLevel |
| 19 | } from "../definitions/materialTiers.js"; |
| 20 | import |
| 21 | { |
| 22 | ARMOUR_CRAFT_PIECES, |
| 23 | armourItemIdForTier |
| 24 | } from "../definitions/armourItems.js"; |
| 25 | import { RangedItemId } from "../definitions/rangedItems.js"; |
| 26 | import { yarnItemId } from "../definitions/clothItems.js"; |
| 27 | import { leatherMaterialItemId } from "../definitions/leatherItems.js"; |
| 28 | |
| 29 | /** |
| 30 | * Tier-scaled craft recipes generated from {@link ItemFamilyId} templates. |
| 31 | * Adding a tier to materialTiers + item id maps extends every matching recipe chain. |
| 32 | */ |
| 33 | |
| 34 | function tierRecipe ({ |
| 35 | recipeId, |
| 36 | stationId, |
| 37 | outputFamily, |
| 38 | outputTier, |
| 39 | outputQty = 1, |
| 40 | inputs, |
| 41 | minSkillLevel, |
| 42 | skillId, |
| 43 | xpMaterial, |
| 44 | craftGroup, |
| 45 | craftGroupLabel |
| 46 | }) |
| 47 | { |
| 48 | const outputItemId = familyItemId(outputFamily, outputTier); |
| 49 | if (!outputItemId) |
| 50 | { throw new Error(`Missing output item for ${outputFamily}@${outputTier}`); } |
| 51 | return Object.freeze({ |
| 52 | recipeId, |
| 53 | stationId, |
| 54 | output: { itemId: outputItemId, quantity: outputQty }, |
| 55 | inputs, |
| 56 | minSkillLevel, |
| 57 | skillId, |
| 58 | xpMaterial, |
| 59 | ...(craftGroup ? { craftGroup, craftGroupLabel } : {}) |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | function handleRecipes () |
| 64 | { |
| 65 | return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({ |
| 66 | recipeId: `handle-${woodTier}`, |
| 67 | craftGroup: "tool-handle", |
| 68 | craftGroupLabel: "Handle", |
| 69 | stationId: CraftingStationId.woodworkingBench, |
| 70 | outputFamily: ItemFamilyId.handle, |
| 71 | outputTier: woodTier, |
| 72 | inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }], |
| 73 | minSkillLevel: tierCraftSkillLevel(woodTier), |
| 74 | skillId: "crafting", |
| 75 | xpMaterial: woodTier |
| 76 | })); |
| 77 | } |
| 78 | |
| 79 | function stickAndQuarterstaffRecipes () |
| 80 | { |
| 81 | const recipes = [ |
| 82 | Object.freeze({ |
| 83 | recipeId: "stick-pine", |
| 84 | craftGroup: "stick", |
| 85 | craftGroupLabel: "Stick", |
| 86 | stationId: CraftingStationId.woodworkingBench, |
| 87 | output: { itemId: ItemId.stick, quantity: 1 }, |
| 88 | inputs: [{ itemId: WoodItemId.pineLog, quantity: 1 }], |
| 89 | minSkillLevel: 1, |
| 90 | skillId: "crafting", |
| 91 | xpMaterial: WoodTier.pine |
| 92 | }) |
| 93 | ]; |
| 94 | for (const woodTier of WOOD_TIER_ORDER) |
| 95 | { |
| 96 | if (woodTier === WoodTier.pine) |
| 97 | { continue; } |
| 98 | recipes.push(tierRecipe({ |
| 99 | recipeId: `quarterstaff-${woodTier}`, |
| 100 | craftGroup: "quarterstaff", |
| 101 | craftGroupLabel: "Quarterstaff", |
| 102 | stationId: CraftingStationId.woodworkingBench, |
| 103 | outputFamily: ItemFamilyId.quarterstaff, |
| 104 | outputTier: woodTier, |
| 105 | inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }], |
| 106 | minSkillLevel: tierCraftSkillLevel(woodTier), |
| 107 | skillId: "crafting", |
| 108 | xpMaterial: woodTier |
| 109 | })); |
| 110 | } |
| 111 | return recipes; |
| 112 | } |
| 113 | |
| 114 | function pickaxeHeadRecipes () |
| 115 | { |
| 116 | return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({ |
| 117 | recipeId: `pickaxe-head-${metalTier}`, |
| 118 | craftGroup: "pickaxe-head", |
| 119 | craftGroupLabel: "Pickaxe head", |
| 120 | stationId: CraftingStationId.anvil, |
| 121 | outputFamily: ItemFamilyId.pickaxeHead, |
| 122 | outputTier: metalTier, |
| 123 | inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }], |
| 124 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 125 | skillId: "smithing", |
| 126 | xpMaterial: metalTier |
| 127 | })); |
| 128 | } |
| 129 | |
| 130 | function pickaxeAssembleRecipes () |
| 131 | { |
| 132 | return MATERIAL_TIER_ORDER.map((metalTier) => |
| 133 | { |
| 134 | const woodTier = woodTierForMetal(metalTier); |
| 135 | return tierRecipe({ |
| 136 | recipeId: `pickaxe-${metalTier}`, |
| 137 | craftGroup: "pickaxe", |
| 138 | craftGroupLabel: "Pickaxe", |
| 139 | stationId: CraftingStationId.craftingBench, |
| 140 | outputFamily: ItemFamilyId.pickaxe, |
| 141 | outputTier: metalTier, |
| 142 | inputs: [ |
| 143 | { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 }, |
| 144 | { itemId: familyItemId(ItemFamilyId.pickaxeHead, metalTier), quantity: 1 } |
| 145 | ], |
| 146 | minSkillLevel: tierCraftSkillLevel(metalTier), |
| 147 | skillId: "crafting", |
| 148 | xpMaterial: metalTier |
| 149 | }); |
| 150 | }); |
| 151 | } |
| 152 | |
| 153 | function axeHeadRecipes () |
| 154 | { |
| 155 | return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({ |
| 156 | recipeId: `axe-head-${metalTier}`, |
| 157 | craftGroup: "axe-head", |
| 158 | craftGroupLabel: "Axe head", |
| 159 | stationId: CraftingStationId.anvil, |
| 160 | outputFamily: ItemFamilyId.axeHead, |
| 161 | outputTier: metalTier, |
| 162 | inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }], |
| 163 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 164 | skillId: "smithing", |
| 165 | xpMaterial: metalTier |
| 166 | })); |
| 167 | } |
| 168 | |
| 169 | function axeAssembleRecipes () |
| 170 | { |
| 171 | return MATERIAL_TIER_ORDER.map((metalTier) => |
| 172 | { |
| 173 | const woodTier = woodTierForMetal(metalTier); |
| 174 | return tierRecipe({ |
| 175 | recipeId: `axe-${metalTier}`, |
| 176 | craftGroup: "axe", |
| 177 | craftGroupLabel: "Axe", |
| 178 | stationId: CraftingStationId.craftingBench, |
| 179 | outputFamily: ItemFamilyId.axe, |
| 180 | outputTier: metalTier, |
| 181 | inputs: [ |
| 182 | { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 }, |
| 183 | { itemId: familyItemId(ItemFamilyId.axeHead, metalTier), quantity: 1 } |
| 184 | ], |
| 185 | minSkillLevel: tierCraftSkillLevel(metalTier), |
| 186 | skillId: "crafting", |
| 187 | xpMaterial: metalTier |
| 188 | }); |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | function plantClippersRecipes () |
| 193 | { |
| 194 | return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({ |
| 195 | recipeId: `plant-clippers-${metalTier}`, |
| 196 | craftGroup: "plant-clippers", |
| 197 | craftGroupLabel: "Plant clippers", |
| 198 | stationId: CraftingStationId.anvil, |
| 199 | outputFamily: ItemFamilyId.plantClippers, |
| 200 | outputTier: metalTier, |
| 201 | inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }], |
| 202 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 203 | skillId: "smithing", |
| 204 | xpMaterial: metalTier |
| 205 | })); |
| 206 | } |
| 207 | |
| 208 | function swordBladeRecipes () |
| 209 | { |
| 210 | return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({ |
| 211 | recipeId: `sword-blade-${metalTier}`, |
| 212 | craftGroup: "sword-blade", |
| 213 | craftGroupLabel: "Sword blade", |
| 214 | stationId: CraftingStationId.anvil, |
| 215 | outputFamily: ItemFamilyId.swordBlade, |
| 216 | outputTier: metalTier, |
| 217 | inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 2 }], |
| 218 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 219 | skillId: "smithing", |
| 220 | xpMaterial: metalTier |
| 221 | })); |
| 222 | } |
| 223 | |
| 224 | function swordAssembleRecipes () |
| 225 | { |
| 226 | return MATERIAL_TIER_ORDER.map((metalTier) => |
| 227 | { |
| 228 | const woodTier = woodTierForMetal(metalTier); |
| 229 | const leatherTier = leatherTierForMetal(metalTier); |
| 230 | const leatherId = leatherMaterialItemId(leatherTier); |
| 231 | return tierRecipe({ |
| 232 | recipeId: `sword-${metalTier}`, |
| 233 | craftGroup: "sword", |
| 234 | craftGroupLabel: "Sword", |
| 235 | stationId: CraftingStationId.craftingBench, |
| 236 | outputFamily: ItemFamilyId.sword, |
| 237 | outputTier: metalTier, |
| 238 | inputs: [ |
| 239 | { itemId: familyItemId(ItemFamilyId.swordBlade, metalTier), quantity: 1 }, |
| 240 | { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 }, |
| 241 | { itemId: leatherId, quantity: 1 } |
| 242 | ], |
| 243 | minSkillLevel: tierCraftSkillLevel(metalTier), |
| 244 | skillId: "crafting", |
| 245 | xpMaterial: metalTier |
| 246 | }); |
| 247 | }); |
| 248 | } |
| 249 | |
| 250 | function warAxeHeadRecipes () |
| 251 | { |
| 252 | return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({ |
| 253 | recipeId: `war-axe-head-${metalTier}`, |
| 254 | craftGroup: "war-axe-head", |
| 255 | craftGroupLabel: "War axe head", |
| 256 | stationId: CraftingStationId.anvil, |
| 257 | outputFamily: ItemFamilyId.warAxeHead, |
| 258 | outputTier: metalTier, |
| 259 | inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 3 }], |
| 260 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 261 | skillId: "smithing", |
| 262 | xpMaterial: metalTier |
| 263 | })); |
| 264 | } |
| 265 | |
| 266 | function warAxeAssembleRecipes () |
| 267 | { |
| 268 | return MATERIAL_TIER_ORDER.map((metalTier) => |
| 269 | { |
| 270 | const woodTier = woodTierForMetal(metalTier); |
| 271 | return tierRecipe({ |
| 272 | recipeId: `war-axe-${metalTier}`, |
| 273 | craftGroup: "war-axe", |
| 274 | craftGroupLabel: "War axe", |
| 275 | stationId: CraftingStationId.craftingBench, |
| 276 | outputFamily: ItemFamilyId.warAxe, |
| 277 | outputTier: metalTier, |
| 278 | inputs: [ |
| 279 | { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 }, |
| 280 | { itemId: familyItemId(ItemFamilyId.warAxeHead, metalTier), quantity: 1 } |
| 281 | ], |
| 282 | minSkillLevel: tierCraftSkillLevel(metalTier), |
| 283 | skillId: "crafting", |
| 284 | xpMaterial: metalTier |
| 285 | }); |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | function arrowShaftRecipes () |
| 290 | { |
| 291 | return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({ |
| 292 | recipeId: `arrow-shafts-${woodTier}`, |
| 293 | craftGroup: "arrow-shafts", |
| 294 | craftGroupLabel: "Arrow shafts", |
| 295 | stationId: CraftingStationId.woodworkingBench, |
| 296 | outputFamily: ItemFamilyId.arrowShaft, |
| 297 | outputTier: woodTier, |
| 298 | outputQty: 15, |
| 299 | inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }], |
| 300 | minSkillLevel: tierMinSkillLevel(woodTier), |
| 301 | skillId: "crafting", |
| 302 | xpMaterial: woodTier |
| 303 | })); |
| 304 | } |
| 305 | |
| 306 | function arrowTipRecipes () |
| 307 | { |
| 308 | return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({ |
| 309 | recipeId: `arrow-tips-${metalTier}`, |
| 310 | craftGroup: "arrow-tips", |
| 311 | craftGroupLabel: "Arrow tips", |
| 312 | stationId: CraftingStationId.anvil, |
| 313 | outputFamily: ItemFamilyId.arrowTip, |
| 314 | outputTier: metalTier, |
| 315 | outputQty: 15, |
| 316 | inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }], |
| 317 | minSkillLevel: tierMinSkillLevel(metalTier), |
| 318 | skillId: "smithing", |
| 319 | xpMaterial: metalTier |
| 320 | })); |
| 321 | } |
| 322 | |
| 323 | function arrowAssembleRecipes () |
| 324 | { |
| 325 | return MATERIAL_TIER_ORDER.map((metalTier) => |
| 326 | { |
| 327 | const woodTier = woodTierForMetal(metalTier); |
| 328 | return tierRecipe({ |
| 329 | recipeId: `arrow-${metalTier}`, |
| 330 | craftGroup: "arrow", |
| 331 | craftGroupLabel: "Arrow", |
| 332 | stationId: CraftingStationId.craftingBench, |
| 333 | outputFamily: ItemFamilyId.arrow, |
| 334 | outputTier: metalTier, |
| 335 | inputs: [ |
| 336 | { itemId: RangedItemId.feather, quantity: 1 }, |
| 337 | { itemId: familyItemId(ItemFamilyId.arrowShaft, woodTier), quantity: 1 }, |
| 338 | { itemId: familyItemId(ItemFamilyId.arrowTip, metalTier), quantity: 1 } |
| 339 | ], |
| 340 | minSkillLevel: tierMinSkillLevel(metalTier), |
| 341 | skillId: "crafting", |
| 342 | xpMaterial: metalTier |
| 343 | }); |
| 344 | }); |
| 345 | } |
| 346 | |
| 347 | function unstrungBowRecipes () |
| 348 | { |
| 349 | return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({ |
| 350 | recipeId: `unstrung-bow-${woodTier}`, |
| 351 | craftGroup: "unstrung-bow", |
| 352 | craftGroupLabel: "Unstrung bow", |
| 353 | stationId: CraftingStationId.woodworkingBench, |
| 354 | outputFamily: ItemFamilyId.unstrungBow, |
| 355 | outputTier: woodTier, |
| 356 | inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }], |
| 357 | minSkillLevel: tierMinSkillLevel(woodTier), |
| 358 | skillId: "crafting", |
| 359 | xpMaterial: woodTier |
| 360 | })); |
| 361 | } |
| 362 | |
| 363 | function bowstringRecipes () |
| 364 | { |
| 365 | return CLOTH_TIER_ORDER.map((clothTier) => tierRecipe({ |
| 366 | recipeId: `bowstring-${clothTier}`, |
| 367 | craftGroup: "bowstring", |
| 368 | craftGroupLabel: "Bowstring", |
| 369 | stationId: CraftingStationId.spinningWheel, |
| 370 | outputFamily: ItemFamilyId.bowstring, |
| 371 | outputTier: clothTier, |
| 372 | inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }], |
| 373 | minSkillLevel: tierMinSkillLevel(clothTier), |
| 374 | skillId: "tailoring", |
| 375 | xpMaterial: clothTier |
| 376 | })); |
| 377 | } |
| 378 | |
| 379 | function bowAssembleRecipes () |
| 380 | { |
| 381 | return WOOD_TIER_ORDER.map((woodTier) => |
| 382 | { |
| 383 | const clothTier = clothTierForWood(woodTier); |
| 384 | return tierRecipe({ |
| 385 | recipeId: `bow-${woodTier}`, |
| 386 | craftGroup: "bow", |
| 387 | craftGroupLabel: "Bow", |
| 388 | stationId: CraftingStationId.craftingBench, |
| 389 | outputFamily: ItemFamilyId.bow, |
| 390 | outputTier: woodTier, |
| 391 | inputs: [ |
| 392 | { itemId: familyItemId(ItemFamilyId.unstrungBow, woodTier), quantity: 1 }, |
| 393 | { itemId: familyItemId(ItemFamilyId.bowstring, clothTier), quantity: 1 } |
| 394 | ], |
| 395 | minSkillLevel: tierMinSkillLevel(woodTier), |
| 396 | skillId: "crafting", |
| 397 | xpMaterial: woodTier |
| 398 | }); |
| 399 | }); |
| 400 | } |
| 401 | |
| 402 | function armourRecipes () |
| 403 | { |
| 404 | return MATERIAL_TIER_ORDER.flatMap((metalTier) => |
| 405 | ARMOUR_CRAFT_PIECES.map((piece) => |
| 406 | { |
| 407 | const inputs = [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: piece.ingots }]; |
| 408 | if (piece.needsBone) |
| 409 | { inputs.push({ itemId: ItemId.bones, quantity: 1 }); } |
| 410 | if (piece.needsLeather) |
| 411 | { |
| 412 | const leatherId = leatherMaterialItemId(leatherTierForMetal(metalTier)); |
| 413 | if (leatherId != null) |
| 414 | { inputs.push({ itemId: leatherId, quantity: 1 }); } |
| 415 | } |
| 416 | const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1); |
| 417 | return Object.freeze({ |
| 418 | recipeId: `armour-${piece.suffix}-${metalTier}`, |
| 419 | craftGroup: `armour-${piece.suffix}`, |
| 420 | craftGroupLabel: label, |
| 421 | stationId: CraftingStationId.anvil, |
| 422 | output: { itemId: armourItemIdForTier(metalTier, piece.idKey), quantity: 1 }, |
| 423 | inputs, |
| 424 | minSkillLevel: tierSmeltSkillLevel(metalTier), |
| 425 | skillId: "smithing", |
| 426 | xpMaterial: metalTier |
| 427 | }); |
| 428 | })); |
| 429 | } |
| 430 | |
| 431 | /** All recipes driven by tier families (tools, wood/metal intermediates, ranged). */ |
| 432 | export const TIER_FAMILY_RECIPES = Object.freeze([ |
| 433 | ...handleRecipes(), |
| 434 | ...stickAndQuarterstaffRecipes(), |
| 435 | ...pickaxeHeadRecipes(), |
| 436 | ...pickaxeAssembleRecipes(), |
| 437 | ...axeHeadRecipes(), |
| 438 | ...axeAssembleRecipes(), |
| 439 | ...plantClippersRecipes(), |
| 440 | ...swordBladeRecipes(), |
| 441 | ...swordAssembleRecipes(), |
| 442 | ...warAxeHeadRecipes(), |
| 443 | ...warAxeAssembleRecipes(), |
| 444 | ...arrowShaftRecipes(), |
| 445 | ...arrowTipRecipes(), |
| 446 | ...arrowAssembleRecipes(), |
| 447 | ...unstrungBowRecipes(), |
| 448 | ...bowstringRecipes(), |
| 449 | ...bowAssembleRecipes(), |
| 450 | ...armourRecipes() |
| 451 | ]); |