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