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