| 1 | import { CraftingStationId } from "../definitions/craftingStations.js"; |
| 2 | import { ItemId } from "../definitions/items.js"; |
| 3 | import { CraftingItemId } from "../definitions/craftingItems.js"; |
| 4 | import { MetalItemId } from "../definitions/metalItems.js"; |
| 5 | import { LeatherItemId } from "../definitions/leatherItems.js"; |
| 6 | import { ClothItemId, wovenClothItemId, rawClothItemId, yarnItemId, CLOTHING_TEMPLATES } from "../definitions/clothItems.js"; |
| 7 | import { |
| 8 | MaterialTier, |
| 9 | GatherMaterialId, |
| 10 | CLOTH_TIER_ORDER, |
| 11 | ClothTier, |
| 12 | LeatherTier, |
| 13 | tierSmeltSkillLevel, |
| 14 | tierCraftSkillLevel |
| 15 | } from "../definitions/materialTiers.js"; |
| 16 | import { TIER_FAMILY_RECIPES } from "./tierRecipes.js"; |
| 17 | import { fishingToolRecipes, fishingCookRecipes } from "../definitions/fishItems.js"; |
| 18 | import { staffCraftRecipes } from "../definitions/gemItems.js"; |
| 19 | |
| 20 | /** |
| 21 | * Craft recipe schema (shared client + server): |
| 22 | * |
| 23 | * - recipeId: stable string id |
| 24 | * - stationId | stationIds: where the recipe appears |
| 25 | * - output: { itemId, quantity } |
| 26 | * - inputs: [{ itemId, quantity }, ...] |
| 27 | * - minSkillLevel: minimum linked station skill (default 1) |
| 28 | * - xpMaterial: tier id for duration + XP scaling |
| 29 | * - craftGroup / craftGroupLabel: UI groups tier variants behind one material dropdown |
| 30 | */ |
| 31 | |
| 32 | function smelt (tier, recipeId, inputs, outputItemId) |
| 33 | { |
| 34 | return Object.freeze({ |
| 35 | recipeId, |
| 36 | stationId: CraftingStationId.furnace, |
| 37 | output: { itemId: outputItemId, quantity: 1 }, |
| 38 | inputs, |
| 39 | minSkillLevel: tierSmeltSkillLevel(tier), |
| 40 | skillId: "smithing", |
| 41 | xpMaterial: tier |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | function yarnSpinRecipe (clothTier) |
| 46 | { |
| 47 | return Object.freeze({ |
| 48 | recipeId: `yarn-${clothTier}`, |
| 49 | craftGroup: "yarn", |
| 50 | craftGroupLabel: "Yarn", |
| 51 | stationId: CraftingStationId.spinningWheel, |
| 52 | output: { itemId: yarnItemId(clothTier), quantity: 1 }, |
| 53 | inputs: [{ itemId: rawClothItemId(clothTier), quantity: 1 }], |
| 54 | minSkillLevel: tierCraftSkillLevel(clothTier), |
| 55 | skillId: "tailoring", |
| 56 | xpMaterial: clothTier |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | function clothWeaveRecipe (clothTier) |
| 61 | { |
| 62 | return Object.freeze({ |
| 63 | recipeId: `cloth-${clothTier}`, |
| 64 | craftGroup: "cloth", |
| 65 | craftGroupLabel: "Cloth", |
| 66 | stationId: CraftingStationId.loom, |
| 67 | output: { itemId: wovenClothItemId(clothTier), quantity: 1 }, |
| 68 | inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }], |
| 69 | minSkillLevel: tierCraftSkillLevel(clothTier), |
| 70 | skillId: "tailoring", |
| 71 | xpMaterial: clothTier |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | const YARN_SPIN_RECIPES = CLOTH_TIER_ORDER.map((tier) => yarnSpinRecipe(tier)); |
| 76 | const CLOTH_WEAVE_RECIPES = CLOTH_TIER_ORDER.map((tier) => clothWeaveRecipe(tier)); |
| 77 | |
| 78 | /** Tailor templates — client picks material; server resolves inputs/output. */ |
| 79 | const TAILOR_TEMPLATE_RECIPES = Object.values(CLOTHING_TEMPLATES).map((template) => Object.freeze({ |
| 80 | recipeId: `tailor-${template.templateId}`, |
| 81 | stationId: CraftingStationId.tailorBench, |
| 82 | tailorTemplate: template.templateId, |
| 83 | output: { itemId: template.outputItemIdForTier(CLOTH_TIER_ORDER[0]), quantity: 1 }, |
| 84 | inputs: [], |
| 85 | minSkillLevel: template.minSkillLevel ?? 1, |
| 86 | skillId: "tailoring" |
| 87 | })); |
| 88 | |
| 89 | /** @type {ReadonlyArray<object>} */ |
| 90 | export const CRAFT_RECIPES = Object.freeze([ |
| 91 | smelt(MaterialTier.bronze, "smelt-bronze", [ |
| 92 | { itemId: CraftingItemId.tinOre, quantity: 1 }, |
| 93 | { itemId: CraftingItemId.copperOre, quantity: 1 } |
| 94 | ], CraftingItemId.bronzeBar), |
| 95 | |
| 96 | smelt(MaterialTier.iron, "smelt-iron", [ |
| 97 | { itemId: MetalItemId.ironOre, quantity: 1 } |
| 98 | ], MetalItemId.ironBar), |
| 99 | |
| 100 | smelt(MaterialTier.steel, "smelt-steel", [ |
| 101 | { itemId: MetalItemId.ironOre, quantity: 1 }, |
| 102 | { itemId: MetalItemId.coal, quantity: 1 } |
| 103 | ], MetalItemId.steelBar), |
| 104 | |
| 105 | smelt(GatherMaterialId.silver, "smelt-silver", [ |
| 106 | { itemId: MetalItemId.silverOre, quantity: 1 } |
| 107 | ], MetalItemId.silverBar), |
| 108 | |
| 109 | smelt(GatherMaterialId.gold, "smelt-gold", [ |
| 110 | { itemId: MetalItemId.goldOre, quantity: 1 } |
| 111 | ], MetalItemId.goldBar), |
| 112 | |
| 113 | smelt(MaterialTier.mithril, "smelt-mithril", [ |
| 114 | { itemId: MetalItemId.mithrilOre, quantity: 1 } |
| 115 | ], MetalItemId.mithrilBar), |
| 116 | |
| 117 | smelt(MaterialTier.adamantium, "smelt-adamantium", [ |
| 118 | { itemId: MetalItemId.adamantiumOre, quantity: 1 }, |
| 119 | { itemId: MetalItemId.coal, quantity: 1 } |
| 120 | ], MetalItemId.adamantiumBar), |
| 121 | |
| 122 | smelt(MaterialTier.orichalcum, "smelt-orichalcum", [ |
| 123 | { itemId: MetalItemId.orichalcumOre, quantity: 1 }, |
| 124 | { itemId: MetalItemId.coal, quantity: 3 } |
| 125 | ], MetalItemId.orichalcumBar), |
| 126 | |
| 127 | smelt(MaterialTier.dragon, "smelt-dragon", [ |
| 128 | { itemId: MetalItemId.dragonOre, quantity: 1 }, |
| 129 | { itemId: MetalItemId.coal, quantity: 5 } |
| 130 | ], MetalItemId.dragonBar), |
| 131 | |
| 132 | ...TIER_FAMILY_RECIPES, |
| 133 | ...YARN_SPIN_RECIPES, |
| 134 | ...CLOTH_WEAVE_RECIPES, |
| 135 | ...TAILOR_TEMPLATE_RECIPES, |
| 136 | |
| 137 | Object.freeze({ |
| 138 | recipeId: "smith-steel-stud", |
| 139 | stationId: CraftingStationId.anvil, |
| 140 | output: { itemId: LeatherItemId.steelStud, quantity: 6 }, |
| 141 | inputs: [{ itemId: MetalItemId.steelBar, quantity: 1 }], |
| 142 | minSkillLevel: tierCraftSkillLevel(MaterialTier.steel), |
| 143 | skillId: "smithing", |
| 144 | xpMaterial: MaterialTier.steel |
| 145 | }), |
| 146 | |
| 147 | Object.freeze({ |
| 148 | recipeId: "leather-hard", |
| 149 | stationId: CraftingStationId.leatherworkingStation, |
| 150 | output: { itemId: LeatherItemId.hardLeather, quantity: 1 }, |
| 151 | inputs: [ |
| 152 | { itemId: LeatherItemId.softLeather, quantity: 1 }, |
| 153 | { itemId: LeatherItemId.tanningBrew, quantity: 1 } |
| 154 | ], |
| 155 | minSkillLevel: tierCraftSkillLevel(LeatherTier.hardLeather), |
| 156 | skillId: "leatherworking", |
| 157 | xpMaterial: LeatherTier.hardLeather |
| 158 | }), |
| 159 | |
| 160 | Object.freeze({ |
| 161 | recipeId: "leather-studded", |
| 162 | stationId: CraftingStationId.leatherworkingStation, |
| 163 | output: { itemId: LeatherItemId.studdedLeather, quantity: 1 }, |
| 164 | inputs: [ |
| 165 | { itemId: LeatherItemId.hardLeather, quantity: 1 }, |
| 166 | { itemId: LeatherItemId.steelStud, quantity: 2 } |
| 167 | ], |
| 168 | minSkillLevel: tierCraftSkillLevel(LeatherTier.studdedLeather), |
| 169 | skillId: "leatherworking", |
| 170 | xpMaterial: LeatherTier.studdedLeather |
| 171 | }), |
| 172 | |
| 173 | Object.freeze({ |
| 174 | recipeId: "leather-reinforced", |
| 175 | stationId: CraftingStationId.leatherworkingStation, |
| 176 | output: { itemId: LeatherItemId.reinforcedLeather, quantity: 1 }, |
| 177 | inputs: [ |
| 178 | { itemId: LeatherItemId.studdedLeather, quantity: 1 }, |
| 179 | { itemId: wovenClothItemId(ClothTier.cashmere), quantity: 1 } |
| 180 | ], |
| 181 | minSkillLevel: tierCraftSkillLevel(LeatherTier.reinforcedLeather), |
| 182 | skillId: "leatherworking", |
| 183 | xpMaterial: LeatherTier.reinforcedLeather |
| 184 | }), |
| 185 | |
| 186 | Object.freeze({ |
| 187 | recipeId: "cook-venison", |
| 188 | stationIds: [CraftingStationId.oven, CraftingStationId.fireplace], |
| 189 | output: { itemId: CraftingItemId.cookedMeat, quantity: 1 }, |
| 190 | inputs: [{ itemId: CraftingItemId.rawMeat, quantity: 1 }], |
| 191 | minSkillLevel: 1, |
| 192 | skillId: "cooking", |
| 193 | burntOutput: { itemId: CraftingItemId.burntMeat, quantity: 1 } |
| 194 | }), |
| 195 | |
| 196 | ...fishingToolRecipes(), |
| 197 | ...fishingCookRecipes(), |
| 198 | ...staffCraftRecipes() |
| 199 | ]); |
| 200 | |
| 201 | const RECIPE_BY_ID = new Map(CRAFT_RECIPES.map((recipe) => [recipe.recipeId, recipe])); |
| 202 | |
| 203 | export function recipeDefinition (recipeId) |
| 204 | { |
| 205 | return RECIPE_BY_ID.get(recipeId) ?? null; |
| 206 | } |
| 207 | |
| 208 | export function recipeStationIds (recipe) |
| 209 | { |
| 210 | if (!recipe) |
| 211 | { return []; } |
| 212 | if (Array.isArray(recipe.stationIds)) |
| 213 | { return recipe.stationIds; } |
| 214 | if (recipe.stationId) |
| 215 | { return [recipe.stationId]; } |
| 216 | return []; |
| 217 | } |
| 218 | |
| 219 | export function recipesForStation (stationId) |
| 220 | { |
| 221 | return CRAFT_RECIPES.filter((recipe) => recipeStationIds(recipe).includes(stationId)); |
| 222 | } |