| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import |
| 4 | { |
| 5 | CraftingStationId, |
| 6 | FIREPLACE_DURATION_MS, |
| 7 | CRAFT_DURATION_MS, |
| 8 | craftingStationDefinition |
| 9 | } from "../../shared/definitions/craftingStations.js"; |
| 10 | import { SkillId } from "../../shared/definitions/skills.js"; |
| 11 | import { ItemId, itemDefinition } from "../../shared/definitions/items.js"; |
| 12 | import { emptySlots } from "../../shared/items/inventory.js"; |
| 13 | import { canCraftFitInventory, CRAFT_DURATION_MS as RECIPE_CRAFT_MS, canStartCraft } from "../../shared/crafting/recipes.js"; |
| 14 | import { recipesForStation, recipeDefinition } from "../../shared/crafting/stationRecipes.js"; |
| 15 | import { CraftingItemId } from "../../shared/definitions/craftingItems.js"; |
| 16 | import { GemItemId } from "../../shared/definitions/gemItems.js"; |
| 17 | import { JEWELRY_RECIPE_GUIDELINES } from "../../shared/definitions/jewelryItems.js"; |
| 18 | import { GatherMaterialId, GemTier, tierSmeltSkillLevel } from "../../shared/definitions/materialTiers.js"; |
| 19 | import { MetalItemId } from "../../shared/definitions/metalItems.js"; |
| 20 | |
| 21 | test("crafting stations map to the expected skills", () => |
| 22 | { |
| 23 | assert.equal(craftingStationDefinition(CraftingStationId.furnace).skillId, SkillId.smithing); |
| 24 | assert.equal(craftingStationDefinition(CraftingStationId.anvil).skillId, SkillId.smithing); |
| 25 | assert.equal(craftingStationDefinition(CraftingStationId.jeweleringStation).skillId, SkillId.jewelering); |
| 26 | assert.equal(craftingStationDefinition(CraftingStationId.loom).skillId, SkillId.tailoring); |
| 27 | assert.equal(craftingStationDefinition(CraftingStationId.craftingBench).skillId, SkillId.crafting); |
| 28 | assert.equal(craftingStationDefinition(CraftingStationId.woodworkingBench).skillId, SkillId.woodworking); |
| 29 | assert.equal(craftingStationDefinition(CraftingStationId.oven).skillId, SkillId.cooking); |
| 30 | assert.equal(craftingStationDefinition(CraftingStationId.fireplace).skillId, SkillId.cooking); |
| 31 | }); |
| 32 | |
| 33 | test("fireplace is portable with a ten minute lifetime", () => |
| 34 | { |
| 35 | const def = craftingStationDefinition(CraftingStationId.fireplace); |
| 36 | assert.equal(def.portable, true); |
| 37 | assert.equal(def.maxPerTile, 1); |
| 38 | assert.equal(def.durationMs, FIREPLACE_DURATION_MS); |
| 39 | assert.equal(FIREPLACE_DURATION_MS, 10 * 60 * 1000); |
| 40 | }); |
| 41 | |
| 42 | test("every craft takes two seconds", () => |
| 43 | { |
| 44 | assert.equal(CRAFT_DURATION_MS, 2000); |
| 45 | assert.equal(RECIPE_CRAFT_MS, CRAFT_DURATION_MS); |
| 46 | }); |
| 47 | |
| 48 | test("canCraftFitInventory accounts for space freed by consumed materials", () => |
| 49 | { |
| 50 | const recipe = { |
| 51 | output: { itemId: ItemId.stick, quantity: 1 }, |
| 52 | inputs: [{ itemId: ItemId.pineLog, quantity: 1 }] |
| 53 | }; |
| 54 | const slots = emptySlots(); |
| 55 | slots[0] = { itemId: ItemId.pineLog, quantity: 10 }; |
| 56 | for (let i = 1; i < 32; i++) |
| 57 | { slots[i] = { itemId: ItemId.coins, quantity: 1 }; } |
| 58 | assert.equal(canCraftFitInventory(slots, recipe), false); |
| 59 | slots[31] = null; |
| 60 | assert.equal(canCraftFitInventory(slots, recipe), true); |
| 61 | }); |
| 62 | |
| 63 | test("canCraftFitInventory rejects missing inputs", () => |
| 64 | { |
| 65 | const slots = emptySlots(); |
| 66 | slots[0] = { itemId: ItemId.pineLog, quantity: 0 }; |
| 67 | assert.equal(canCraftFitInventory(slots, { |
| 68 | output: { itemId: ItemId.stick, quantity: 1 }, |
| 69 | inputs: [{ itemId: ItemId.pineLog, quantity: 1 }] |
| 70 | }), false); |
| 71 | }); |
| 72 | |
| 73 | test("recipesForStation lists woodworking stick and quarterstaff recipes", () => |
| 74 | { |
| 75 | const bench = recipesForStation(CraftingStationId.woodworkingBench); |
| 76 | assert.ok(bench.some((recipe) => recipe.recipeId === "stick-pine")); |
| 77 | assert.ok(bench.some((recipe) => recipe.recipeId === "quarterstaff-birch")); |
| 78 | assert.ok(bench.some((recipe) => recipe.recipeId === "staff-pine")); |
| 79 | const stick = recipeDefinition("stick-pine"); |
| 80 | assert.equal(stick.output.itemId, ItemId.stick); |
| 81 | assert.deepEqual(stick.inputs, [{ itemId: ItemId.pineLog, quantity: 1 }]); |
| 82 | }); |
| 83 | |
| 84 | test("canStartCraft enforces minimum skill level", () => |
| 85 | { |
| 86 | const slots = emptySlots(); |
| 87 | slots[0] = { itemId: ItemId.pineLog, quantity: 5 }; |
| 88 | const recipe = recipeDefinition("stick-pine"); |
| 89 | assert.equal(canStartCraft(slots, recipe, 1), true); |
| 90 | assert.equal(canStartCraft(slots, recipe, 0), false); |
| 91 | }); |
| 92 | |
| 93 | test("crafting item stubs are registered", () => |
| 94 | { |
| 95 | assert.equal(itemDefinition(ItemId.pineLog)?.key, "pine-log"); |
| 96 | assert.equal(itemDefinition(ItemId.pineHandle)?.defaultState, "handle"); |
| 97 | assert.equal(itemDefinition(CraftingItemId.bronzeBar)?.key, "bronze-bar"); |
| 98 | }); |
| 99 | |
| 100 | test("woodworking, anvil, and crafting bench expose pickaxe and axe chain recipes", () => |
| 101 | { |
| 102 | assert.equal(craftingStationDefinition(CraftingStationId.woodworkingBench).skillId, SkillId.woodworking); |
| 103 | assert.equal(craftingStationDefinition(CraftingStationId.craftingBench).skillId, SkillId.crafting); |
| 104 | const handle = recipeDefinition("handle-pine"); |
| 105 | assert.ok(handle); |
| 106 | assert.equal(handle.stationId, CraftingStationId.woodworkingBench); |
| 107 | assert.equal(handle.output.itemId, ItemId.pineHandle); |
| 108 | const head = recipeDefinition("pickaxe-head-bronze"); |
| 109 | assert.ok(head); |
| 110 | assert.equal(head.stationId, CraftingStationId.anvil); |
| 111 | assert.equal(head.output.itemId, ItemId.bronzePickaxeHead); |
| 112 | const pickaxe = recipeDefinition("pickaxe-bronze"); |
| 113 | assert.ok(pickaxe); |
| 114 | assert.equal(pickaxe.stationId, CraftingStationId.craftingBench); |
| 115 | assert.deepEqual(pickaxe.inputs.map((row) => row.itemId).sort(), [ |
| 116 | ItemId.pineHandle, |
| 117 | ItemId.bronzePickaxeHead |
| 118 | ].sort()); |
| 119 | assert.equal(pickaxe.output.itemId, ItemId.bronzePickaxe); |
| 120 | const axeHead = recipeDefinition("axe-head-bronze"); |
| 121 | assert.ok(axeHead); |
| 122 | assert.equal(axeHead.stationId, CraftingStationId.anvil); |
| 123 | assert.equal(axeHead.output.itemId, ItemId.bronzeAxeHead); |
| 124 | const axe = recipeDefinition("axe-bronze"); |
| 125 | assert.ok(axe); |
| 126 | assert.equal(axe.stationId, CraftingStationId.craftingBench); |
| 127 | assert.deepEqual(axe.inputs.map((row) => row.itemId).sort(), [ |
| 128 | ItemId.pineHandle, |
| 129 | ItemId.bronzeAxeHead |
| 130 | ].sort()); |
| 131 | assert.equal(axe.output.itemId, ItemId.bronzeAxe); |
| 132 | assert.equal(itemDefinition(ItemId.bronzeAxe)?.stub, undefined); |
| 133 | assert.equal(itemDefinition(ItemId.bronzeAxe)?.equipment?.kind, "axeTool"); |
| 134 | }); |
| 135 | |
| 136 | test("jewelering cuts rough gems; staff recipes need cut gems", () => |
| 137 | { |
| 138 | const cut = recipeDefinition("cut-tourmaline"); |
| 139 | assert.ok(cut); |
| 140 | assert.equal(cut.craftGroupLabel, "Cut gem"); |
| 141 | assert.equal(cut.stationId, CraftingStationId.jeweleringStation); |
| 142 | assert.equal(cut.skillId, SkillId.jewelering); |
| 143 | assert.equal(cut.minSkillLevel, tierSmeltSkillLevel(GemTier.tourmaline)); |
| 144 | assert.deepEqual(cut.inputs, [{ itemId: GemItemId.tourmaline, quantity: 1 }]); |
| 145 | assert.equal(cut.output.itemId, GemItemId.tourmalineCut); |
| 146 | assert.equal(itemDefinition(GemItemId.tourmaline)?.gemForm, "rough"); |
| 147 | assert.equal(itemDefinition(GemItemId.tourmalineCut)?.gemForm, "cut"); |
| 148 | assert.equal(itemDefinition(GemItemId.tourmaline)?.defaultState, "rough"); |
| 149 | assert.equal(itemDefinition(GemItemId.tourmalineCut)?.defaultState, "cut"); |
| 150 | |
| 151 | const staff = recipeDefinition("staff-pine"); |
| 152 | assert.ok(staff); |
| 153 | assert.equal(staff.stationId, CraftingStationId.woodworkingBench); |
| 154 | assert.ok(staff.inputs.some((row) => row.itemId === GemItemId.tourmalineCut)); |
| 155 | assert.ok(!staff.inputs.some((row) => row.itemId === GemItemId.tourmaline)); |
| 156 | |
| 157 | assert.equal(recipesForStation(CraftingStationId.jeweleringStation).length, 28); |
| 158 | assert.equal(JEWELRY_RECIPE_GUIDELINES.length, 7); |
| 159 | assert.equal(JEWELRY_RECIPE_GUIDELINES[0].metalId, GatherMaterialId.silver); |
| 160 | assert.equal(JEWELRY_RECIPE_GUIDELINES[0].metalQuantity, 1); |
| 161 | assert.equal(JEWELRY_RECIPE_GUIDELINES[3].metalId, GatherMaterialId.gold); |
| 162 | assert.equal(JEWELRY_RECIPE_GUIDELINES[3].metalQuantity, 1); |
| 163 | assert.equal(JEWELRY_RECIPE_GUIDELINES[6].metalId, GatherMaterialId.electrum); |
| 164 | assert.equal(JEWELRY_RECIPE_GUIDELINES[6].metalBarItemId, MetalItemId.electrumBar); |
| 165 | assert.equal(JEWELRY_RECIPE_GUIDELINES[6].metalQuantity, 1); |
| 166 | assert.ok(recipeDefinition("ring-tourmaline")); |
| 167 | assert.ok(recipeDefinition("bracelet-diamond")); |
| 168 | assert.ok(recipeDefinition("amulet-jadeite")); |
| 169 | }); |