| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { BlockType, blockDefinition } from "../../shared/definitions/tiles.js"; |
| 4 | import { CraftingStationId, CRAFT_DURATION_MS } from "../../shared/definitions/craftingStations.js"; |
| 5 | import { ItemId } from "../../shared/definitions/items.js"; |
| 6 | import { ArmourItemId } from "../../shared/definitions/armourItems.js"; |
| 7 | import { LeatherItemId } from "../../shared/definitions/leatherItems.js"; |
| 8 | import { LeatherArmourItemId } from "../../shared/definitions/leatherArmourItems.js"; |
| 9 | import { WizardItemId } from "../../shared/definitions/wizardItems.js"; |
| 10 | import { ClothItemId } from "../../shared/definitions/clothItems.js"; |
| 11 | import { resolveTailorCraft } from "../../shared/crafting/tailor.js"; |
| 12 | import { SkillId } from "../../shared/definitions/skills.js"; |
| 13 | import |
| 14 | { |
| 15 | MaterialTier, |
| 16 | GatherMaterialId, |
| 17 | tierSmeltSkillLevel, |
| 18 | smeltingDurationMs, |
| 19 | associatedBarTier |
| 20 | } from "../../shared/definitions/materialTiers.js"; |
| 21 | import { craftDurationMs } from "../../shared/definitions/gathering.js"; |
| 22 | import { recipesForStation, recipeDefinition } from "../../shared/crafting/stationRecipes.js"; |
| 23 | import { emptyEquipment, emptySlots } from "../../shared/items/inventory.js"; |
| 24 | import { totalXpForLevel } from "../../shared/skills/progression.js"; |
| 25 | import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js"; |
| 26 | import { Component } from "../src/ecs/components.js"; |
| 27 | |
| 28 | function countItem (slots, itemId) |
| 29 | { |
| 30 | return (slots ?? []).reduce((sum, slot) => |
| 31 | { |
| 32 | if (slot?.itemId === itemId) |
| 33 | { return sum + (slot.quantity | 0); } |
| 34 | return sum; |
| 35 | }, 0); |
| 36 | } |
| 37 | |
| 38 | function placeFurnace (worker, tileX, tileY) |
| 39 | { |
| 40 | const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16)); |
| 41 | const localX = tileX % 16; |
| 42 | const localY = tileY % 16; |
| 43 | data.blocks[localY * 16 + localX] = { |
| 44 | typeId: BlockType.furnace, |
| 45 | state: "furnace", |
| 46 | config: null |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | function setSkillLevel (worker, playerId, skillId, level) |
| 51 | { |
| 52 | const handle = worker.world.ecs.handleOf(playerId); |
| 53 | const skills = worker.world.ecs.get(handle, Component.skills); |
| 54 | skills.xp[skillId] = totalXpForLevel(level); |
| 55 | } |
| 56 | |
| 57 | function giveInventory (harness, playerId, items) |
| 58 | { |
| 59 | const inventory = emptySlots(); |
| 60 | items.forEach((stack, index) => |
| 61 | { |
| 62 | inventory[index] = { itemId: stack.itemId, quantity: stack.quantity }; |
| 63 | }); |
| 64 | harness.simulation.applyBag(playerId, { |
| 65 | inventory, |
| 66 | equipment: emptyEquipment(), |
| 67 | vault: [], |
| 68 | vaultReserved: [] |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | function advanceMs (harness, ms) |
| 73 | { |
| 74 | const ticks = Math.ceil(ms / 50) + 3; |
| 75 | for (let i = 0; i < ticks; i++) |
| 76 | { |
| 77 | harness.advance(50); |
| 78 | harness.simulation.step(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | test("furnace recipes: bronze is tin+copper; steel is iron+coal; high tiers need coal", () => |
| 83 | { |
| 84 | assert.equal(blockDefinition(BlockType.furnace)?.key, "furnace"); |
| 85 | const bronze = recipeDefinition("smelt-bronze"); |
| 86 | assert.deepEqual(bronze.inputs.map((row) => row.itemId).sort(), [ |
| 87 | ItemId.copperOre, |
| 88 | ItemId.tinOre |
| 89 | ].sort()); |
| 90 | assert.equal(bronze.output.itemId, ItemId.bronzeBar); |
| 91 | assert.equal(bronze.minSkillLevel, tierSmeltSkillLevel(MaterialTier.bronze)); |
| 92 | |
| 93 | const steel = recipesForStation(CraftingStationId.furnace) |
| 94 | .find((recipe) => recipe.recipeId === "smelt-steel"); |
| 95 | assert.ok(steel); |
| 96 | assert.deepEqual(steel.inputs.map((row) => row.itemId).sort(), [ |
| 97 | ItemId.coal, |
| 98 | ItemId.ironOre |
| 99 | ].sort()); |
| 100 | assert.equal(steel.output.itemId, ItemId.steelBar); |
| 101 | |
| 102 | const silver = recipesForStation(CraftingStationId.furnace) |
| 103 | .find((recipe) => recipe.recipeId === "smelt-silver"); |
| 104 | assert.ok(silver); |
| 105 | assert.deepEqual(silver.inputs.map((row) => row.itemId), [ItemId.silverOre]); |
| 106 | assert.equal(silver.output.itemId, ItemId.silverBar); |
| 107 | assert.equal(silver.minSkillLevel, tierSmeltSkillLevel(GatherMaterialId.silver)); |
| 108 | |
| 109 | const gold = recipesForStation(CraftingStationId.furnace) |
| 110 | .find((recipe) => recipe.recipeId === "smelt-gold"); |
| 111 | assert.ok(gold); |
| 112 | assert.deepEqual(gold.inputs.map((row) => row.itemId), [ItemId.goldOre]); |
| 113 | assert.equal(gold.output.itemId, ItemId.goldBar); |
| 114 | assert.equal(gold.minSkillLevel, tierSmeltSkillLevel(GatherMaterialId.gold)); |
| 115 | |
| 116 | const electrum = recipesForStation(CraftingStationId.furnace) |
| 117 | .find((recipe) => recipe.recipeId === "smelt-electrum"); |
| 118 | assert.ok(electrum); |
| 119 | assert.deepEqual(electrum.inputs.map((row) => row.itemId).sort(), [ |
| 120 | ItemId.coal, |
| 121 | ItemId.goldOre, |
| 122 | ItemId.silverOre |
| 123 | ].sort()); |
| 124 | assert.equal(electrum.output.itemId, ItemId.electrumBar); |
| 125 | assert.equal(electrum.minSkillLevel, tierSmeltSkillLevel(GatherMaterialId.electrum)); |
| 126 | |
| 127 | const adamantium = recipeDefinition("smelt-adamantium"); |
| 128 | assert.deepEqual(adamantium.inputs, [ |
| 129 | { itemId: ItemId.adamantiumOre, quantity: 1 }, |
| 130 | { itemId: ItemId.coal, quantity: 1 } |
| 131 | ]); |
| 132 | const orichalcum = recipeDefinition("smelt-orichalcum"); |
| 133 | assert.deepEqual(orichalcum.inputs, [ |
| 134 | { itemId: ItemId.orichalcumOre, quantity: 1 }, |
| 135 | { itemId: ItemId.coal, quantity: 3 } |
| 136 | ]); |
| 137 | const dragon = recipeDefinition("smelt-dragon"); |
| 138 | assert.deepEqual(dragon.inputs, [ |
| 139 | { itemId: ItemId.dragonOre, quantity: 1 }, |
| 140 | { itemId: ItemId.coal, quantity: 5 } |
| 141 | ]); |
| 142 | }); |
| 143 | |
| 144 | test("tin copper coal map to associated bar tiers for smelt duration", () => |
| 145 | { |
| 146 | assert.equal(associatedBarTier(GatherMaterialId.tin), MaterialTier.bronze); |
| 147 | assert.equal(associatedBarTier(GatherMaterialId.copper), MaterialTier.bronze); |
| 148 | assert.equal(associatedBarTier(GatherMaterialId.coal), MaterialTier.steel); |
| 149 | assert.equal(associatedBarTier(GatherMaterialId.silver), GatherMaterialId.silver); |
| 150 | assert.equal(associatedBarTier(GatherMaterialId.gold), GatherMaterialId.gold); |
| 151 | assert.equal(smeltingDurationMs(MaterialTier.bronze), 2000); |
| 152 | assert.equal(smeltingDurationMs(GatherMaterialId.tin), 2000); |
| 153 | assert.equal(smeltingDurationMs(MaterialTier.steel), 6000); |
| 154 | assert.equal(smeltingDurationMs(GatherMaterialId.coal), 6000); |
| 155 | assert.equal(smeltingDurationMs(GatherMaterialId.silver), 4000); |
| 156 | assert.equal(smeltingDurationMs(GatherMaterialId.gold), 6000); |
| 157 | assert.equal(craftDurationMs(recipeDefinition("smelt-bronze"), CRAFT_DURATION_MS), 2000); |
| 158 | assert.equal(craftDurationMs(recipeDefinition("smelt-steel"), CRAFT_DURATION_MS), 6000); |
| 159 | assert.equal(craftDurationMs(recipeDefinition("smelt-silver"), CRAFT_DURATION_MS), 4000); |
| 160 | assert.equal(craftDurationMs(recipeDefinition("smelt-gold"), CRAFT_DURATION_MS), 6000); |
| 161 | }); |
| 162 | |
| 163 | test("open furnace near station emits shove and station-open", () => |
| 164 | { |
| 165 | const harness = makeSimulation({ workerCount: 1 }); |
| 166 | try |
| 167 | { |
| 168 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 169 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 170 | const record = harness.simulation.entityRecord(playerId); |
| 171 | const worker = harness.simulation.workers[record.workerId]; |
| 172 | placeFurnace(worker, 9, 8); |
| 173 | |
| 174 | harness.simulation.enqueue(1, { |
| 175 | type: "open-station", |
| 176 | characterId: character.character_id, |
| 177 | stationId: CraftingStationId.furnace |
| 178 | }); |
| 179 | const result = harness.simulation.step(); |
| 180 | assert.ok(result.events.some((event) => event.type === "tile-shove")); |
| 181 | assert.ok(result.events.some((event) => |
| 182 | event.type === "station-open" && event.stationId === CraftingStationId.furnace)); |
| 183 | } |
| 184 | finally |
| 185 | { harness.close(); } |
| 186 | }); |
| 187 | |
| 188 | test("open leatherworking table near station emits station-open", () => |
| 189 | { |
| 190 | const harness = makeSimulation({ workerCount: 1 }); |
| 191 | try |
| 192 | { |
| 193 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 194 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 195 | const record = harness.simulation.entityRecord(playerId); |
| 196 | const worker = harness.simulation.workers[record.workerId]; |
| 197 | const data = worker.world.chunkData(Math.floor(9 / 16), Math.floor(8 / 16)); |
| 198 | data.blocks[8 * 16 + 9] = { |
| 199 | typeId: BlockType.leatherworkingTable, |
| 200 | state: "leatherworking-table", |
| 201 | config: null |
| 202 | }; |
| 203 | |
| 204 | harness.simulation.enqueue(1, { |
| 205 | type: "open-station", |
| 206 | characterId: character.character_id, |
| 207 | stationId: CraftingStationId.leatherworkingStation |
| 208 | }); |
| 209 | const result = harness.simulation.step(); |
| 210 | assert.ok(result.events.some((event) => |
| 211 | event.type === "station-open" && event.stationId === CraftingStationId.leatherworkingStation)); |
| 212 | } |
| 213 | finally |
| 214 | { harness.close(); } |
| 215 | }); |
| 216 | |
| 217 | test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () => |
| 218 | { |
| 219 | const harness = makeSimulation({ workerCount: 1 }); |
| 220 | try |
| 221 | { |
| 222 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 223 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 224 | const record = harness.simulation.entityRecord(playerId); |
| 225 | const worker = harness.simulation.workers[record.workerId]; |
| 226 | placeFurnace(worker, 9, 8); |
| 227 | giveInventory(harness, playerId, [ |
| 228 | { itemId: ItemId.tinOre, quantity: 1 }, |
| 229 | { itemId: ItemId.copperOre, quantity: 1 } |
| 230 | ]); |
| 231 | |
| 232 | harness.simulation.enqueue(1, { |
| 233 | type: "start-craft", |
| 234 | characterId: character.character_id, |
| 235 | stationId: CraftingStationId.furnace, |
| 236 | recipeId: "smelt-bronze" |
| 237 | }); |
| 238 | const start = harness.simulation.step(); |
| 239 | assert.ok(start.events.some((event) => event.type === "tile-shove")); |
| 240 | assert.ok(start.events.some((event) => |
| 241 | event.type === "item-bubble" && event.itemId === ItemId.bronzeBar)); |
| 242 | |
| 243 | const smithingBefore = harness.stateDb.getSkills(character.character_id).xp.smithing ?? 0; |
| 244 | advanceMs(harness, craftDurationMs(recipeDefinition("smelt-bronze"), CRAFT_DURATION_MS)); |
| 245 | |
| 246 | const bag = harness.simulation.bagOf(playerId); |
| 247 | assert.equal(countItem(bag.inventory, ItemId.tinOre), 0); |
| 248 | assert.equal(countItem(bag.inventory, ItemId.copperOre), 0); |
| 249 | assert.equal(countItem(bag.inventory, ItemId.bronzeBar), 1); |
| 250 | const bar = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.bronzeBar); |
| 251 | assert.equal(bar?.origins?.[0]?.origin?.verb, "Forged"); |
| 252 | assert.match(bar?.origins?.[0]?.origin?.displayName ?? "", /^Ada/); |
| 253 | const smithingAfter = harness.stateDb.getSkills(character.character_id).xp.smithing ?? 0; |
| 254 | assert.equal(smithingAfter - smithingBefore, 6); |
| 255 | } |
| 256 | finally |
| 257 | { harness.close(); } |
| 258 | }); |
| 259 | |
| 260 | test("smelting steel requires iron ore and coal", () => |
| 261 | { |
| 262 | const harness = makeSimulation({ workerCount: 1 }); |
| 263 | try |
| 264 | { |
| 265 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 266 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 267 | const record = harness.simulation.entityRecord(playerId); |
| 268 | const worker = harness.simulation.workers[record.workerId]; |
| 269 | placeFurnace(worker, 9, 8); |
| 270 | setSkillLevel(worker, playerId, SkillId.smithing, tierSmeltSkillLevel(MaterialTier.steel)); |
| 271 | giveInventory(harness, playerId, [ |
| 272 | { itemId: ItemId.ironOre, quantity: 1 }, |
| 273 | { itemId: ItemId.coal, quantity: 1 } |
| 274 | ]); |
| 275 | |
| 276 | harness.simulation.enqueue(1, { |
| 277 | type: "start-craft", |
| 278 | characterId: character.character_id, |
| 279 | stationId: CraftingStationId.furnace, |
| 280 | recipeId: "smelt-steel" |
| 281 | }); |
| 282 | harness.simulation.step(); |
| 283 | advanceMs(harness, craftDurationMs(recipeDefinition("smelt-steel"), CRAFT_DURATION_MS)); |
| 284 | |
| 285 | const bag = harness.simulation.bagOf(playerId); |
| 286 | assert.equal(countItem(bag.inventory, ItemId.ironOre), 0); |
| 287 | assert.equal(countItem(bag.inventory, ItemId.coal), 0); |
| 288 | assert.equal(countItem(bag.inventory, ItemId.steelBar), 1); |
| 289 | } |
| 290 | finally |
| 291 | { harness.close(); } |
| 292 | }); |
| 293 | |
| 294 | test("craft rejects missing materials", () => |
| 295 | { |
| 296 | const harness = makeSimulation({ workerCount: 1 }); |
| 297 | try |
| 298 | { |
| 299 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 300 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 301 | const record = harness.simulation.entityRecord(playerId); |
| 302 | const worker = harness.simulation.workers[record.workerId]; |
| 303 | placeFurnace(worker, 9, 8); |
| 304 | giveInventory(harness, playerId, [{ itemId: ItemId.copperOre, quantity: 1 }]); |
| 305 | |
| 306 | harness.simulation.enqueue(1, { |
| 307 | type: "start-craft", |
| 308 | characterId: character.character_id, |
| 309 | stationId: CraftingStationId.furnace, |
| 310 | recipeId: "smelt-bronze" |
| 311 | }); |
| 312 | const result = harness.simulation.step(); |
| 313 | assert.ok(result.events.some((event) => |
| 314 | event.type === "command-error" && /missing|materials/i.test(event.message ?? ""))); |
| 315 | } |
| 316 | finally |
| 317 | { harness.close(); } |
| 318 | }); |
| 319 | |
| 320 | test("craft rejects low Smithing for iron bars", () => |
| 321 | { |
| 322 | const harness = makeSimulation({ workerCount: 1 }); |
| 323 | try |
| 324 | { |
| 325 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 326 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 327 | const record = harness.simulation.entityRecord(playerId); |
| 328 | const worker = harness.simulation.workers[record.workerId]; |
| 329 | placeFurnace(worker, 9, 8); |
| 330 | giveInventory(harness, playerId, [{ itemId: ItemId.ironOre, quantity: 1 }]); |
| 331 | |
| 332 | harness.simulation.enqueue(1, { |
| 333 | type: "start-craft", |
| 334 | characterId: character.character_id, |
| 335 | stationId: CraftingStationId.furnace, |
| 336 | recipeId: "smelt-iron" |
| 337 | }); |
| 338 | const result = harness.simulation.step(); |
| 339 | assert.ok(result.events.some((event) => |
| 340 | event.type === "command-error" && /smithing|requires/i.test(event.message ?? ""))); |
| 341 | } |
| 342 | finally |
| 343 | { harness.close(); } |
| 344 | }); |
| 345 | |
| 346 | test("craft rejects furnace recipes when not next to a furnace", () => |
| 347 | { |
| 348 | const harness = makeSimulation({ workerCount: 1 }); |
| 349 | try |
| 350 | { |
| 351 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 352 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 353 | giveInventory(harness, playerId, [ |
| 354 | { itemId: ItemId.tinOre, quantity: 1 }, |
| 355 | { itemId: ItemId.copperOre, quantity: 1 } |
| 356 | ]); |
| 357 | |
| 358 | harness.simulation.enqueue(1, { |
| 359 | type: "start-craft", |
| 360 | characterId: character.character_id, |
| 361 | stationId: CraftingStationId.furnace, |
| 362 | recipeId: "smelt-bronze" |
| 363 | }); |
| 364 | const result = harness.simulation.step(); |
| 365 | assert.ok(result.events.some((event) => |
| 366 | event.type === "command-error" && /station|next to/i.test(event.message ?? ""))); |
| 367 | } |
| 368 | finally |
| 369 | { harness.close(); } |
| 370 | }); |
| 371 | |
| 372 | function placeStation (worker, tileX, tileY, typeId, state) |
| 373 | { |
| 374 | const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16)); |
| 375 | const localX = tileX % 16; |
| 376 | const localY = tileY % 16; |
| 377 | data.blocks[localY * 16 + localX] = { |
| 378 | typeId, |
| 379 | state, |
| 380 | config: null |
| 381 | }; |
| 382 | } |
| 383 | |
| 384 | test("bronze pickaxe chain: pine log → handle, bar → head, assemble pickaxe", () => |
| 385 | { |
| 386 | const harness = makeSimulation({ workerCount: 1 }); |
| 387 | try |
| 388 | { |
| 389 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 390 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 391 | const record = harness.simulation.entityRecord(playerId); |
| 392 | const worker = harness.simulation.workers[record.workerId]; |
| 393 | placeStation(worker, 9, 8, BlockType.woodworkingBench, "woodworking-bench"); |
| 394 | placeStation(worker, 9, 9, BlockType.anvil, "anvil"); |
| 395 | placeStation(worker, 8, 9, BlockType.craftingBench, "crafting-bench"); |
| 396 | giveInventory(harness, playerId, [ |
| 397 | { itemId: ItemId.pineLog, quantity: 1 }, |
| 398 | { itemId: ItemId.bronzeBar, quantity: 1 } |
| 399 | ]); |
| 400 | |
| 401 | harness.simulation.enqueue(1, { |
| 402 | type: "start-craft", |
| 403 | characterId: character.character_id, |
| 404 | stationId: CraftingStationId.woodworkingBench, |
| 405 | recipeId: "handle-pine" |
| 406 | }); |
| 407 | advanceMs(harness, craftDurationMs(recipeDefinition("handle-pine"), CRAFT_DURATION_MS)); |
| 408 | let bag = harness.simulation.bagOf(playerId); |
| 409 | assert.equal(countItem(bag.inventory, ItemId.pineHandle), 1); |
| 410 | assert.equal(countItem(bag.inventory, ItemId.pineLog), 0); |
| 411 | const handle = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.pineHandle); |
| 412 | assert.equal(handle?.origins?.[0]?.origin?.verb, "Carved"); |
| 413 | |
| 414 | harness.simulation.enqueue(1, { |
| 415 | type: "start-craft", |
| 416 | characterId: character.character_id, |
| 417 | stationId: CraftingStationId.anvil, |
| 418 | recipeId: "pickaxe-head-bronze" |
| 419 | }); |
| 420 | advanceMs(harness, craftDurationMs(recipeDefinition("pickaxe-head-bronze"), CRAFT_DURATION_MS)); |
| 421 | bag = harness.simulation.bagOf(playerId); |
| 422 | assert.equal(countItem(bag.inventory, ItemId.bronzePickaxeHead), 1); |
| 423 | assert.equal(countItem(bag.inventory, ItemId.bronzeBar), 0); |
| 424 | const head = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.bronzePickaxeHead); |
| 425 | assert.equal(head?.origins?.[0]?.origin?.verb, "Smithed"); |
| 426 | |
| 427 | harness.simulation.enqueue(1, { |
| 428 | type: "start-craft", |
| 429 | characterId: character.character_id, |
| 430 | stationId: CraftingStationId.craftingBench, |
| 431 | recipeId: "pickaxe-bronze" |
| 432 | }); |
| 433 | advanceMs(harness, craftDurationMs(recipeDefinition("pickaxe-bronze"), CRAFT_DURATION_MS)); |
| 434 | bag = harness.simulation.bagOf(playerId); |
| 435 | assert.equal(countItem(bag.inventory, ItemId.bronzePickaxe), 1); |
| 436 | assert.equal(countItem(bag.inventory, ItemId.pineHandle), 0); |
| 437 | assert.equal(countItem(bag.inventory, ItemId.bronzePickaxeHead), 0); |
| 438 | const pickaxe = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.bronzePickaxe); |
| 439 | assert.equal(pickaxe?.origins?.[0]?.origin?.verb, "Assembled"); |
| 440 | assert.match(pickaxe?.origins?.[0]?.origin?.displayName ?? "", /^Ada/); |
| 441 | } |
| 442 | finally |
| 443 | { harness.close(); } |
| 444 | }); |
| 445 | |
| 446 | test("anvil accepts Craft x batchCount like the crafting bench", () => |
| 447 | { |
| 448 | const harness = makeSimulation({ workerCount: 1 }); |
| 449 | try |
| 450 | { |
| 451 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 452 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 453 | const record = harness.simulation.entityRecord(playerId); |
| 454 | const worker = harness.simulation.workers[record.workerId]; |
| 455 | placeStation(worker, 9, 9, BlockType.anvil, "anvil"); |
| 456 | giveInventory(harness, playerId, [{ itemId: ItemId.bronzeBar, quantity: 3 }]); |
| 457 | |
| 458 | harness.simulation.enqueue(1, { |
| 459 | type: "start-craft", |
| 460 | characterId: character.character_id, |
| 461 | stationId: CraftingStationId.anvil, |
| 462 | recipeId: "pickaxe-head-bronze", |
| 463 | batchCount: 3 |
| 464 | }); |
| 465 | const one = craftDurationMs(recipeDefinition("pickaxe-head-bronze"), CRAFT_DURATION_MS); |
| 466 | advanceMs(harness, one * 3 + 200); |
| 467 | const bag = harness.simulation.bagOf(playerId); |
| 468 | assert.equal(countItem(bag.inventory, ItemId.bronzePickaxeHead), 3); |
| 469 | assert.equal(countItem(bag.inventory, ItemId.bronzeBar), 0); |
| 470 | } |
| 471 | finally |
| 472 | { harness.close(); } |
| 473 | }); |
| 474 | |
| 475 | test("anvil armour recipes use bar counts per piece", () => |
| 476 | { |
| 477 | const chest = recipeDefinition("armour-chestplate-bronze"); |
| 478 | assert.ok(chest); |
| 479 | assert.equal(chest.stationId, CraftingStationId.anvil); |
| 480 | assert.equal(chest.output.itemId, ArmourItemId.bronzeChestplate); |
| 481 | assert.deepEqual(chest.inputs, [{ itemId: ItemId.bronzeBar, quantity: 6 }]); |
| 482 | |
| 483 | const greaves = recipeDefinition("armour-greaves-iron"); |
| 484 | assert.deepEqual(greaves.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]); |
| 485 | |
| 486 | const skirt = recipeDefinition("armour-skirt-iron"); |
| 487 | assert.ok(skirt); |
| 488 | assert.equal(skirt.output.itemId, ArmourItemId.ironSkirt); |
| 489 | assert.deepEqual(skirt.inputs, [{ itemId: ItemId.ironBar, quantity: 4 }]); |
| 490 | |
| 491 | const boots = recipeDefinition("armour-boots-steel"); |
| 492 | assert.deepEqual(boots.inputs, [{ itemId: ItemId.steelBar, quantity: 2 }]); |
| 493 | |
| 494 | const helmet = recipeDefinition("armour-helmet-mithril"); |
| 495 | assert.deepEqual(helmet.inputs, [{ itemId: ItemId.mithrilBar, quantity: 2 }]); |
| 496 | |
| 497 | const fullHelm = recipeDefinition("armour-full-helm-adamantium"); |
| 498 | assert.deepEqual(fullHelm.inputs, [{ itemId: ItemId.adamantiumBar, quantity: 3 }]); |
| 499 | |
| 500 | const horned = recipeDefinition("armour-horned-helm-orichalcum"); |
| 501 | assert.deepEqual(horned.inputs, [ |
| 502 | { itemId: ItemId.orichalcumBar, quantity: 2 }, |
| 503 | { itemId: ItemId.bones, quantity: 1 } |
| 504 | ]); |
| 505 | |
| 506 | const shield = recipeDefinition("armour-shield-iron"); |
| 507 | assert.ok(shield); |
| 508 | assert.equal(shield.output.itemId, ArmourItemId.ironShield); |
| 509 | assert.deepEqual(shield.inputs, [ |
| 510 | { itemId: ItemId.ironBar, quantity: 4 }, |
| 511 | { itemId: ItemId.hardLeather, quantity: 1 } |
| 512 | ]); |
| 513 | |
| 514 | const anvilArmour = recipesForStation(CraftingStationId.anvil) |
| 515 | .filter((recipe) => recipe.recipeId.startsWith("armour-")); |
| 516 | assert.equal(anvilArmour.length, 7 * 8); |
| 517 | }); |
| 518 | |
| 519 | test("leatherworking shoes recipes use 2 leather per tier", () => |
| 520 | { |
| 521 | const shoes = recipesForStation(CraftingStationId.leatherworkingStation) |
| 522 | .filter((recipe) => recipe.craftGroup === "leather-shoes"); |
| 523 | assert.equal(shoes.length, 7); |
| 524 | for (const recipe of shoes) |
| 525 | { |
| 526 | assert.equal(recipe.inputs.length, 1); |
| 527 | assert.equal(recipe.inputs[0].quantity, 2); |
| 528 | assert.equal(recipe.skillId, "leatherworking"); |
| 529 | assert.ok(recipe.xpMaterial); |
| 530 | assert.equal(recipe.craftGroupLabel, "Shoes"); |
| 531 | } |
| 532 | const soft = recipeDefinition("leather-shoes-softLeather"); |
| 533 | assert.ok(soft); |
| 534 | assert.equal(soft.output.itemId, LeatherItemId.leatherShoes); |
| 535 | assert.deepEqual(soft.inputs, [{ itemId: ItemId.leather, quantity: 2 }]); |
| 536 | const hide = recipeDefinition("leather-shoes-dragonhide"); |
| 537 | assert.ok(hide); |
| 538 | assert.equal(hide.output.itemId, LeatherItemId.dragonhideShoes); |
| 539 | assert.deepEqual(hide.inputs, [{ itemId: LeatherItemId.dragonhide, quantity: 2 }]); |
| 540 | }); |
| 541 | |
| 542 | test("leatherworking armour recipes use leather and cloth per tier", () => |
| 543 | { |
| 544 | const chest = recipeDefinition("leather-chestguard-softLeather"); |
| 545 | assert.ok(chest); |
| 546 | assert.equal(chest.output.itemId, LeatherArmourItemId.softLeatherChestguard); |
| 547 | assert.deepEqual(chest.inputs, [ |
| 548 | { itemId: ItemId.leather, quantity: 4 }, |
| 549 | { itemId: ClothItemId.cottonCloth, quantity: 2 } |
| 550 | ]); |
| 551 | const chausses = recipeDefinition("leather-chausses-studdedLeather"); |
| 552 | assert.ok(chausses); |
| 553 | assert.equal(chausses.inputs[0].quantity, 3); |
| 554 | assert.equal(chausses.inputs[1].quantity, 1); |
| 555 | const helmet = recipeDefinition("leather-helmet-dragonhide"); |
| 556 | assert.ok(helmet); |
| 557 | assert.equal(helmet.inputs.length, 1); |
| 558 | assert.equal(helmet.inputs[0].quantity, 2); |
| 559 | }); |
| 560 | |
| 561 | test("tailor wizard robe recipes resolve cloth and leather inputs", () => |
| 562 | { |
| 563 | const hat = resolveTailorCraft({ templateId: "wizard-hat", clothTier: "wool" }); |
| 564 | assert.equal(hat.ok, true); |
| 565 | assert.equal(hat.recipe.output.itemId, WizardItemId.woolHat); |
| 566 | assert.deepEqual(hat.recipe.inputs, [ |
| 567 | { itemId: ClothItemId.woolCloth, quantity: 2 }, |
| 568 | { itemId: LeatherItemId.hardLeather, quantity: 1 } |
| 569 | ]); |
| 570 | const bottoms = resolveTailorCraft({ templateId: "wizard-robebottoms", clothTier: "cotton" }); |
| 571 | assert.equal(bottoms.ok, true); |
| 572 | assert.equal(bottoms.recipe.output.itemId, WizardItemId.cottonRobeBottoms); |
| 573 | assert.deepEqual(bottoms.recipe.inputs, [{ itemId: ClothItemId.cottonCloth, quantity: 4 }]); |
| 574 | const dyed = resolveTailorCraft({ |
| 575 | templateId: "wizard-hat", |
| 576 | clothTier: "cotton", |
| 577 | dyeStack: { |
| 578 | itemId: ItemId.dye, |
| 579 | instance: { kind: "dye", color: { r: 0.2, g: 0.5, b: 0.9 }, fillLevel: 5 } |
| 580 | } |
| 581 | }); |
| 582 | assert.equal(dyed.ok, true); |
| 583 | assert.equal(dyed.recipe.consumeDye, true); |
| 584 | assert.deepEqual(dyed.recipe.dyeColor, { r: 0.2, g: 0.5, b: 0.9 }); |
| 585 | assert.equal(dyed.recipe.output.itemId, WizardItemId.cottonHat); |
| 586 | }); |