| 1 | import { CraftingStationId } from "../definitions/craftingStations.js"; |
| 2 | import { ItemId } from "../definitions/items.js"; |
| 3 | |
| 4 | /** |
| 5 | * Craft recipe schema (shared client + server): |
| 6 | * |
| 7 | * - recipeId: stable string id |
| 8 | * - stationId | stationIds: where the recipe appears (use stationIds for oven + campfire) |
| 9 | * - output: { itemId, quantity } |
| 10 | * - inputs: [{ itemId, quantity }, ...] |
| 11 | * - minSkillLevel: minimum linked station skill (default 1) |
| 12 | * - burnChanceOven / burnChanceFireplace: cooking-only, 0–1 when skill is below min (TBD) |
| 13 | */ |
| 14 | |
| 15 | /** @type {ReadonlyArray<object>} */ |
| 16 | export const CRAFT_RECIPES = Object.freeze([ |
| 17 | // UI/dev placeholder — replace with real bench recipes. |
| 18 | Object.freeze({ |
| 19 | recipeId: "dev-stick-from-paper", |
| 20 | stationId: CraftingStationId.craftingBench, |
| 21 | output: { itemId: ItemId.stick, quantity: 1 }, |
| 22 | inputs: [{ itemId: ItemId.paper, quantity: 2 }], |
| 23 | minSkillLevel: 1 |
| 24 | }), |
| 25 | |
| 26 | // --- Furnace (smelt ore → bars) --- |
| 27 | // { recipeId: "smelt-bronze", stationId: CraftingStationId.furnace, ... }, |
| 28 | |
| 29 | // --- Spinning wheel (wool → thread) --- |
| 30 | // { recipeId: "spin-thread", stationId: CraftingStationId.spinningWheel, ... }, |
| 31 | |
| 32 | // --- Loom (cloth garments) --- |
| 33 | // { recipeId: "weave-cloth-shirt", stationId: CraftingStationId.loom, ... }, |
| 34 | |
| 35 | // --- Anvil (bars → metal items) --- |
| 36 | // { recipeId: "smith-bronze-sword", stationId: CraftingStationId.anvil, ... }, |
| 37 | |
| 38 | // --- Leatherworking station --- |
| 39 | // { recipeId: "craft-leather-body", stationId: CraftingStationId.leatherworkingStation, ... }, |
| 40 | |
| 41 | // --- Crafting bench (arrows, etc.) --- |
| 42 | // { recipeId: "fletch-arrow", stationId: CraftingStationId.craftingBench, |
| 43 | // output: { itemId: CraftingItemId.arrow, quantity: 1 }, |
| 44 | // inputs: [{ itemId: CraftingItemId.arrowTip, quantity: 1 }, ...] }, |
| 45 | |
| 46 | // --- Cooking (oven + campfire share recipes via stationIds) --- |
| 47 | // { recipeId: "cook-meat", stationIds: [CraftingStationId.oven, CraftingStationId.fireplace], |
| 48 | // output: { itemId: CraftingItemId.cookedMeat, quantity: 1 }, |
| 49 | // inputs: [{ itemId: CraftingItemId.rawMeat, quantity: 1 }], |
| 50 | // minSkillLevel: 1, burnChanceOven: 0.1, burnChanceFireplace: 0.25 } |
| 51 | ]); |
| 52 | |
| 53 | const RECIPE_BY_ID = new Map(CRAFT_RECIPES.map((recipe) => [recipe.recipeId, recipe])); |
| 54 | |
| 55 | export function recipeDefinition (recipeId) |
| 56 | { |
| 57 | return RECIPE_BY_ID.get(recipeId) ?? null; |
| 58 | } |
| 59 | |
| 60 | export function recipeStationIds (recipe) |
| 61 | { |
| 62 | if (!recipe) |
| 63 | { return []; } |
| 64 | if (Array.isArray(recipe.stationIds)) |
| 65 | { return recipe.stationIds; } |
| 66 | if (recipe.stationId) |
| 67 | { return [recipe.stationId]; } |
| 68 | return []; |
| 69 | } |
| 70 | |
| 71 | export function recipesForStation (stationId) |
| 72 | { |
| 73 | return CRAFT_RECIPES.filter((recipe) => recipeStationIds(recipe).includes(stationId)); |
| 74 | } |