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