BlueGit

timfa questward

Files

questward / server / tests / crafting.test.js

crafting.test.js

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