| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { |
| 4 | shopUnitPrice, |
| 5 | undiscountedMarketValue, |
| 6 | undiscountedMarketCoins, |
| 7 | marketValueAsCoins, |
| 8 | canSellInNpcShop, |
| 9 | canPlayerSellToNpc, |
| 10 | shopBuyFromPlayerPrice, |
| 11 | shopBoughtResalePrice, |
| 12 | shopChequeAdminFee, |
| 13 | resolveShopSellQuote, |
| 14 | shopRestockDayKey, |
| 15 | lerp |
| 16 | } from "../../shared/shop/pricing.js"; |
| 17 | import { ItemId } from "../../shared/definitions/items.js"; |
| 18 | import { MobId, normalizeSpawnerConfig, isHumanoidMob } from "../../shared/definitions/mobs.js"; |
| 19 | import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js"; |
| 20 | import { Component } from "../src/ecs/components.js"; |
| 21 | import { emptyEquipment, emptySlots, addCoinsToSlots, countCoinsInSlots, INVENTORY_SLOTS } from "../../shared/items/inventory.js"; |
| 22 | import { ItemOriginKind } from "../../shared/items/origin.js"; |
| 23 | import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js"; |
| 24 | import { ensureShopRestocked } from "../src/shop/service.js"; |
| 25 | import { BlockType } from "../../shared/definitions/tiles.js"; |
| 26 | import { GatherOriginVerb, gatherOrigin } from "../../shared/items/origin.js"; |
| 27 | |
| 28 | function boughtQty (shop, itemId) |
| 29 | { |
| 30 | const raw = shop?.boughtStock?.[itemId]; |
| 31 | if (raw == null) |
| 32 | { return 0; } |
| 33 | if (typeof raw === "number") |
| 34 | { return raw | 0; } |
| 35 | return raw.quantity | 0 || 0; |
| 36 | } |
| 37 | |
| 38 | test("shop prices fall back to seedValue and apply hidden discount", () => |
| 39 | { |
| 40 | assert.equal(undiscountedMarketValue(ItemId.copperOre), 5); |
| 41 | assert.equal(undiscountedMarketValue(ItemId.tinOre), 5); |
| 42 | assert.equal(undiscountedMarketValue(ItemId.pineLog), 5); |
| 43 | assert.equal(shopUnitPrice(ItemId.copperOre, { hiddenDiscount: 0.9 }), 5); |
| 44 | assert.equal(shopUnitPrice(ItemId.copperOre, { hiddenDiscount: 0.5 }), 3); |
| 45 | assert.equal(shopBuyFromPlayerPrice(ItemId.copperOre), 4); |
| 46 | assert.equal(shopBoughtResalePrice(ItemId.copperOre), 6); |
| 47 | assert.equal(lerp(10, 20, 0.5), 15); |
| 48 | assert.equal(canSellInNpcShop(ItemId.copperOre), true); |
| 49 | assert.equal(canSellInNpcShop(ItemId.tinOre), true); |
| 50 | assert.equal(canSellInNpcShop(ItemId.stick), false); |
| 51 | assert.equal(canPlayerSellToNpc({ itemId: ItemId.copperOre, quantity: 1 }), true); |
| 52 | assert.equal(canPlayerSellToNpc({ itemId: ItemId.stick, quantity: 1 }), true); |
| 53 | assert.equal(canPlayerSellToNpc({ itemId: ItemId.blankCheque, quantity: 1 }), false); |
| 54 | assert.equal(canPlayerSellToNpc({ itemId: ItemId.coins, quantity: 10 }), false); |
| 55 | assert.equal(canPlayerSellToNpc({ |
| 56 | itemId: ItemId.recipePaper, |
| 57 | quantity: 1, |
| 58 | instance: { kind: "recipe-paper", recipeId: "lesser-health-tonic" } |
| 59 | }), false); |
| 60 | assert.equal(canPlayerSellToNpc({ |
| 61 | itemId: ItemId.filledCheque, |
| 62 | quantity: 1, |
| 63 | instance: { kind: "filled-cheque", itemId: ItemId.copperOre, quantity: 3 } |
| 64 | }), true); |
| 65 | assert.equal(shopChequeAdminFee(100), 5); |
| 66 | assert.equal(shopChequeAdminFee(10), 1); |
| 67 | assert.equal(shopChequeAdminFee(1), 1); |
| 68 | const chequeQuote = resolveShopSellQuote({ |
| 69 | itemId: ItemId.filledCheque, |
| 70 | quantity: 1, |
| 71 | instance: { kind: "filled-cheque", itemId: ItemId.copperOre, quantity: 2 } |
| 72 | }); |
| 73 | assert.equal(chequeQuote.baseTotal, shopBuyFromPlayerPrice(ItemId.copperOre) * 2); |
| 74 | assert.equal(chequeQuote.adminFee, shopChequeAdminFee(chequeQuote.baseTotal)); |
| 75 | assert.equal(chequeQuote.payout, chequeQuote.baseTotal - chequeQuote.adminFee); |
| 76 | }); |
| 77 | |
| 78 | test("market value display and shop use ceil fractional lerps", () => |
| 79 | { |
| 80 | const now = 1_000_000; |
| 81 | const lastSale = { |
| 82 | lastTradePrice: 10, |
| 83 | lastTradeAt: now - 500, |
| 84 | priceFrom: 5 |
| 85 | }; |
| 86 | // Halfway from 5 → 10 over 1000ms → 7.5 internally. |
| 87 | const raw = undiscountedMarketValue(ItemId.copperOre, lastSale, now, 1000); |
| 88 | assert.equal(raw, 7.5); |
| 89 | assert.equal(marketValueAsCoins(raw), 8); |
| 90 | assert.equal(undiscountedMarketCoins(ItemId.copperOre, lastSale, now, 1000), 8); |
| 91 | assert.equal(shopBuyFromPlayerPrice(ItemId.copperOre, { lastSale, now, lerpDurationMs: 1000 }), 6); |
| 92 | assert.equal(shopBoughtResalePrice(ItemId.copperOre, { lastSale, now, lerpDurationMs: 1000 }), 9); |
| 93 | assert.equal(shopUnitPrice(ItemId.copperOre, { |
| 94 | lastSale, |
| 95 | now, |
| 96 | lerpDurationMs: 1000, |
| 97 | hiddenDiscount: 1 |
| 98 | }), 8); |
| 99 | }); |
| 100 | |
| 101 | test("humanoid spawner config keeps sex equipment sells quantities and buysItems", () => |
| 102 | { |
| 103 | assert.equal(isHumanoidMob(MobId.humanoid), true); |
| 104 | const config = normalizeSpawnerConfig({ |
| 105 | mobTypeId: MobId.humanoid, |
| 106 | sex: "female", |
| 107 | displayName: "Ore trader", |
| 108 | equipment: { chest: ItemId.clothShirt, weapon: ItemId.stick }, |
| 109 | sells: [ |
| 110 | { itemId: ItemId.copperOre, quantity: 10 }, |
| 111 | { itemId: ItemId.tinOre, quantity: 0 }, |
| 112 | ItemId.copperOre |
| 113 | ], |
| 114 | buysItems: true, |
| 115 | hiddenDiscount: 0.85 |
| 116 | }, "shop-1"); |
| 117 | assert.equal(config.sex, "female"); |
| 118 | assert.equal(config.displayName, "Ore trader"); |
| 119 | assert.equal(config.equipment.chest, ItemId.clothShirt); |
| 120 | assert.deepEqual(config.sells, [ |
| 121 | { itemId: ItemId.copperOre, quantity: 10 }, |
| 122 | { itemId: ItemId.tinOre, quantity: 0 } |
| 123 | ]); |
| 124 | assert.equal(config.buysItems, true); |
| 125 | assert.equal(config.hiddenDiscount, 0.85); |
| 126 | assert.equal(config.maxAlive, 1); |
| 127 | }); |
| 128 | |
| 129 | test("humanoid spawner equipment can store clothing dye color", () => |
| 130 | { |
| 131 | const dyeColor = { r: 0.2, g: 0.4, b: 0.8 }; |
| 132 | const config = normalizeSpawnerConfig({ |
| 133 | mobTypeId: MobId.humanoid, |
| 134 | equipment: { |
| 135 | chest: { itemId: ItemId.clothShirt, dyeColor }, |
| 136 | weapon: ItemId.stick |
| 137 | } |
| 138 | }, "shop-dye"); |
| 139 | assert.deepEqual(config.equipment.chest, { |
| 140 | itemId: ItemId.clothShirt, |
| 141 | dyeColor |
| 142 | }); |
| 143 | assert.equal(config.equipment.weapon, ItemId.stick); |
| 144 | }); |
| 145 | |
| 146 | test("buy copper ore from a spawned shopkeeper", () => |
| 147 | { |
| 148 | const harness = makeSimulation({ workerCount: 1 }); |
| 149 | try |
| 150 | { |
| 151 | const data = createEmptyChunkData(); |
| 152 | data.open = true; |
| 153 | data.spawners = [{ |
| 154 | localX: 9, |
| 155 | localY: 8, |
| 156 | config: { |
| 157 | mobTypeId: MobId.humanoid, |
| 158 | maxAlive: 1, |
| 159 | spawnRangeTiles: 1, |
| 160 | maxWanderRangeTiles: 1, |
| 161 | sex: "male", |
| 162 | displayName: "Ore trader", |
| 163 | sells: [ |
| 164 | { itemId: ItemId.copperOre, quantity: 0 }, |
| 165 | { itemId: ItemId.tinOre, quantity: 0 } |
| 166 | ], |
| 167 | hiddenDiscount: 1, |
| 168 | equipment: { chest: ItemId.clothShirt } |
| 169 | } |
| 170 | }]; |
| 171 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 172 | harness.simulation.reloadWorld(); |
| 173 | |
| 174 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 175 | const funded = addCoinsToSlots(emptySlots(), 50); |
| 176 | assert.equal(funded.ok, true); |
| 177 | harness.stateDb.saveBag(character.character_id, { |
| 178 | inventory: funded.slots, |
| 179 | equipment: emptyEquipment(), |
| 180 | vault: [], |
| 181 | vaultReserved: [] |
| 182 | }); |
| 183 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 184 | harness.simulation.step(); |
| 185 | harness.advance(50); |
| 186 | harness.simulation.step(); |
| 187 | |
| 188 | const record = harness.simulation.entityRecord(playerId); |
| 189 | const worker = harness.simulation.workers[record.workerId]; |
| 190 | let npcId = null; |
| 191 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 192 | { |
| 193 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 194 | { |
| 195 | npcId = entity.entityId; |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | assert.ok(npcId, "expected a humanoid shopkeeper"); |
| 200 | |
| 201 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 202 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 203 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 204 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 205 | playerPos.tileX = npcPos.tileX; |
| 206 | playerPos.tileY = npcPos.tileY; |
| 207 | |
| 208 | harness.simulation.enqueue(1, { |
| 209 | type: "interact", |
| 210 | characterId: character.character_id, |
| 211 | targetEntityId: npcId |
| 212 | }); |
| 213 | const open = harness.simulation.step(); |
| 214 | const shopOpen = open.events.find((event) => event.type === "shop-open"); |
| 215 | assert.ok(shopOpen, JSON.stringify(open.events)); |
| 216 | assert.ok(shopOpen.stock.some((row) => row.itemId === ItemId.copperOre)); |
| 217 | |
| 218 | harness.simulation.enqueue(1, { |
| 219 | type: "buy-from-shop", |
| 220 | characterId: character.character_id, |
| 221 | npcEntityId: npcId, |
| 222 | itemId: ItemId.copperOre, |
| 223 | quantity: 1, |
| 224 | listingId: `stock:${ItemId.copperOre}` |
| 225 | }); |
| 226 | const buy = harness.simulation.step(); |
| 227 | assert.equal(buy.events.some((event) => event.type === "command-error"), false, JSON.stringify(buy.events)); |
| 228 | const bag = harness.simulation.bagOf(playerId); |
| 229 | const ore = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.copperOre); |
| 230 | assert.ok(ore, JSON.stringify(bag.inventory)); |
| 231 | assert.equal(ore.origins?.[0]?.origin?.kind, ItemOriginKind.shop); |
| 232 | assert.equal(ore.origins?.[0]?.origin?.displayName, "Ore trader"); |
| 233 | } |
| 234 | finally |
| 235 | { harness.close(); } |
| 236 | }); |
| 237 | |
| 238 | test("limited shop stock depletes and restocks on a new day", () => |
| 239 | { |
| 240 | const shop = { |
| 241 | catalog: [{ itemId: ItemId.copperOre, quantity: 2 }], |
| 242 | buysItems: false, |
| 243 | hiddenDiscount: 1, |
| 244 | remaining: Object.create(null), |
| 245 | boughtStock: Object.create(null), |
| 246 | restockDay: null |
| 247 | }; |
| 248 | const dayA = new Date(2026, 7, 25, 12, 0, 0, 0).getTime(); |
| 249 | ensureShopRestocked(shop, dayA); |
| 250 | assert.equal(shop.restockDay, shopRestockDayKey(dayA)); |
| 251 | assert.equal(shop.remaining[ItemId.copperOre], 2); |
| 252 | shop.remaining[ItemId.copperOre] = 0; |
| 253 | shop.boughtStock[ItemId.tinOre] = 3; |
| 254 | ensureShopRestocked(shop, dayA); |
| 255 | assert.equal(shop.remaining[ItemId.copperOre], 0); |
| 256 | assert.equal(shop.boughtStock[ItemId.tinOre], 3); |
| 257 | const dayB = new Date(2026, 7, 26, 0, 0, 1, 0).getTime(); |
| 258 | ensureShopRestocked(shop, dayB); |
| 259 | assert.equal(shop.remaining[ItemId.copperOre], 2); |
| 260 | assert.equal(shop.boughtStock[ItemId.tinOre], undefined); |
| 261 | }); |
| 262 | |
| 263 | test("shop overflow goes to bank vault when inventory is full", () => |
| 264 | { |
| 265 | const harness = makeSimulation({ workerCount: 1 }); |
| 266 | try |
| 267 | { |
| 268 | const data = createEmptyChunkData(); |
| 269 | data.open = true; |
| 270 | data.spawners = [{ |
| 271 | localX: 9, |
| 272 | localY: 8, |
| 273 | config: { |
| 274 | mobTypeId: MobId.humanoid, |
| 275 | maxAlive: 1, |
| 276 | spawnRangeTiles: 0, |
| 277 | maxWanderRangeTiles: 0, |
| 278 | displayName: "Ore trader", |
| 279 | sells: [{ itemId: ItemId.copperOre, quantity: 0 }], |
| 280 | hiddenDiscount: 1 |
| 281 | } |
| 282 | }]; |
| 283 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 284 | harness.simulation.reloadWorld(); |
| 285 | |
| 286 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 287 | const slots = emptySlots(); |
| 288 | const funded = addCoinsToSlots(slots, 50); |
| 289 | assert.equal(funded.ok, true); |
| 290 | for (let i = 0; i < funded.slots.length; i++) |
| 291 | { |
| 292 | if (!funded.slots[i]) |
| 293 | { funded.slots[i] = { itemId: ItemId.stick, quantity: 1 }; } |
| 294 | } |
| 295 | harness.stateDb.saveBag(character.character_id, { |
| 296 | inventory: funded.slots, |
| 297 | equipment: emptyEquipment(), |
| 298 | vault: [], |
| 299 | vaultReserved: [] |
| 300 | }); |
| 301 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 302 | harness.simulation.step(); |
| 303 | harness.advance(50); |
| 304 | harness.simulation.step(); |
| 305 | |
| 306 | const record = harness.simulation.entityRecord(playerId); |
| 307 | const worker = harness.simulation.workers[record.workerId]; |
| 308 | let npcId = null; |
| 309 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 310 | { |
| 311 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 312 | { |
| 313 | npcId = entity.entityId; |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | assert.ok(npcId); |
| 318 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 319 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 320 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 321 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 322 | playerPos.tileX = npcPos.tileX; |
| 323 | playerPos.tileY = npcPos.tileY; |
| 324 | |
| 325 | harness.simulation.enqueue(1, { |
| 326 | type: "buy-from-shop", |
| 327 | characterId: character.character_id, |
| 328 | npcEntityId: npcId, |
| 329 | itemId: ItemId.copperOre, |
| 330 | quantity: 1, |
| 331 | listingId: `stock:${ItemId.copperOre}` |
| 332 | }); |
| 333 | const buy = harness.simulation.step(); |
| 334 | assert.equal(buy.events.some((event) => event.type === "command-error"), false, JSON.stringify(buy.events)); |
| 335 | const bag = harness.simulation.bagOf(playerId); |
| 336 | assert.equal((bag.inventory ?? []).some((slot) => slot?.itemId === ItemId.copperOre), false); |
| 337 | assert.ok((bag.vault ?? []).some((slot) => slot?.itemId === ItemId.copperOre)); |
| 338 | } |
| 339 | finally |
| 340 | { harness.close(); } |
| 341 | }); |
| 342 | |
| 343 | test("buysItems refills limited catalog then stores extras for 120% resale", () => |
| 344 | { |
| 345 | const harness = makeSimulation({ workerCount: 1 }); |
| 346 | try |
| 347 | { |
| 348 | const data = createEmptyChunkData(); |
| 349 | data.open = true; |
| 350 | data.spawners = [{ |
| 351 | localX: 9, |
| 352 | localY: 8, |
| 353 | config: { |
| 354 | mobTypeId: MobId.humanoid, |
| 355 | maxAlive: 1, |
| 356 | spawnRangeTiles: 0, |
| 357 | maxWanderRangeTiles: 0, |
| 358 | displayName: "Buyer", |
| 359 | sells: [{ itemId: ItemId.copperOre, quantity: 2 }], |
| 360 | buysItems: true, |
| 361 | hiddenDiscount: 1 |
| 362 | } |
| 363 | }]; |
| 364 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 365 | harness.simulation.reloadWorld(); |
| 366 | |
| 367 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 368 | harness.stateDb.saveBag(character.character_id, { |
| 369 | inventory: emptySlots(INVENTORY_SLOTS), |
| 370 | equipment: emptyEquipment(), |
| 371 | vault: [], |
| 372 | vaultReserved: [] |
| 373 | }); |
| 374 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 375 | harness.simulation.step(); |
| 376 | harness.advance(50); |
| 377 | harness.simulation.step(); |
| 378 | |
| 379 | const record = harness.simulation.entityRecord(playerId); |
| 380 | const worker = harness.simulation.workers[record.workerId]; |
| 381 | let npcId = null; |
| 382 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 383 | { |
| 384 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 385 | { |
| 386 | npcId = entity.entityId; |
| 387 | break; |
| 388 | } |
| 389 | } |
| 390 | assert.ok(npcId); |
| 391 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 392 | const shop = worker.world.ecs.get(npcHandle, Component.shop); |
| 393 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 394 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 395 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 396 | playerPos.tileX = npcPos.tileX; |
| 397 | playerPos.tileY = npcPos.tileY; |
| 398 | |
| 399 | // Fund coins and buy out limited stock first. |
| 400 | const inv = worker.world.ecs.get(playerHandle, Component.inventory); |
| 401 | const funded = addCoinsToSlots(inv.slots, 50); |
| 402 | assert.equal(funded.ok, true); |
| 403 | inv.slots = funded.slots; |
| 404 | inv.slots[1] = { itemId: ItemId.copperOre, quantity: 5 }; |
| 405 | |
| 406 | harness.simulation.enqueue(1, { |
| 407 | type: "buy-from-shop", |
| 408 | characterId: character.character_id, |
| 409 | npcEntityId: npcId, |
| 410 | itemId: ItemId.copperOre, |
| 411 | quantity: 2, |
| 412 | listingId: `stock:${ItemId.copperOre}` |
| 413 | }); |
| 414 | const boughtOut = harness.simulation.step(); |
| 415 | assert.equal(boughtOut.events.some((event) => event.type === "command-error"), false, JSON.stringify(boughtOut.events)); |
| 416 | assert.equal(shop.remaining[ItemId.copperOre], 0); |
| 417 | |
| 418 | const oreSlot = inv.slots.findIndex((slot) => slot?.itemId === ItemId.copperOre && (slot.quantity | 0) >= 5); |
| 419 | assert.ok(oreSlot >= 0); |
| 420 | |
| 421 | harness.simulation.enqueue(1, { |
| 422 | type: "sell-to-shop", |
| 423 | characterId: character.character_id, |
| 424 | npcEntityId: npcId, |
| 425 | slotIndex: oreSlot, |
| 426 | quantity: 5 |
| 427 | }); |
| 428 | const sold = harness.simulation.step(); |
| 429 | assert.equal(sold.events.some((event) => event.type === "command-error"), false, JSON.stringify(sold.events)); |
| 430 | assert.equal(shop.remaining[ItemId.copperOre], 2); |
| 431 | assert.equal(boughtQty(shop, ItemId.copperOre), 3); |
| 432 | |
| 433 | const open = sold.events.find((event) => event.type === "shop-open"); |
| 434 | assert.ok(open.stock.some((row) => row.source === "stock" && row.available === 2)); |
| 435 | assert.ok(open.stock.some((row) => row.source === "bought" && row.available === 3)); |
| 436 | } |
| 437 | finally |
| 438 | { harness.close(); } |
| 439 | }); |
| 440 | |
| 441 | test("shop adjacency errors use gendered pronouns", () => |
| 442 | { |
| 443 | const harness = makeSimulation({ workerCount: 1 }); |
| 444 | try |
| 445 | { |
| 446 | const data = createEmptyChunkData(); |
| 447 | data.open = true; |
| 448 | data.spawners = [{ |
| 449 | localX: 9, |
| 450 | localY: 8, |
| 451 | config: { |
| 452 | mobTypeId: MobId.humanoid, |
| 453 | maxAlive: 1, |
| 454 | spawnRangeTiles: 0, |
| 455 | maxWanderRangeTiles: 0, |
| 456 | sex: "female", |
| 457 | displayName: "Trader", |
| 458 | sells: [{ itemId: ItemId.copperOre, quantity: 0 }], |
| 459 | hiddenDiscount: 1 |
| 460 | } |
| 461 | }]; |
| 462 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 463 | harness.simulation.reloadWorld(); |
| 464 | |
| 465 | const character = makeCharacter(harness.stateDb, { tileX: 2, tileY: 2 }); |
| 466 | harness.stateDb.saveBag(character.character_id, { |
| 467 | inventory: emptySlots(INVENTORY_SLOTS), |
| 468 | equipment: emptyEquipment(), |
| 469 | vault: [], |
| 470 | vaultReserved: [] |
| 471 | }); |
| 472 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 473 | harness.simulation.step(); |
| 474 | harness.advance(50); |
| 475 | harness.simulation.step(); |
| 476 | |
| 477 | const record = harness.simulation.entityRecord(playerId); |
| 478 | const worker = harness.simulation.workers[record.workerId]; |
| 479 | let npcId = null; |
| 480 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 481 | { |
| 482 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 483 | { |
| 484 | npcId = entity.entityId; |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | assert.ok(npcId); |
| 489 | |
| 490 | harness.simulation.enqueue(1, { |
| 491 | type: "interact", |
| 492 | characterId: character.character_id, |
| 493 | targetEntityId: npcId |
| 494 | }); |
| 495 | const open = harness.simulation.step(); |
| 496 | const err = open.events.find((event) => event.type === "command-error"); |
| 497 | assert.ok(err, JSON.stringify(open.events)); |
| 498 | assert.match(err.message, /stand next to her/i); |
| 499 | assert.doesNotMatch(err.message, /\bthem\b/i); |
| 500 | } |
| 501 | finally |
| 502 | { harness.close(); } |
| 503 | }); |
| 504 | |
| 505 | test("shopkeeper stops wandering while a player has the shop open", () => |
| 506 | { |
| 507 | const harness = makeSimulation({ workerCount: 1 }); |
| 508 | try |
| 509 | { |
| 510 | const data = createEmptyChunkData(); |
| 511 | data.open = true; |
| 512 | data.spawners = [{ |
| 513 | localX: 8, |
| 514 | localY: 8, |
| 515 | config: { |
| 516 | mobTypeId: MobId.humanoid, |
| 517 | maxAlive: 1, |
| 518 | spawnRangeTiles: 4, |
| 519 | maxWanderRangeTiles: 8, |
| 520 | sex: "male", |
| 521 | displayName: "Stay put", |
| 522 | sells: [{ itemId: ItemId.copperOre, quantity: 0 }], |
| 523 | hiddenDiscount: 1 |
| 524 | } |
| 525 | }]; |
| 526 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 527 | harness.simulation.reloadWorld(); |
| 528 | |
| 529 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 530 | harness.stateDb.saveBag(character.character_id, { |
| 531 | inventory: emptySlots(INVENTORY_SLOTS), |
| 532 | equipment: emptyEquipment(), |
| 533 | vault: [], |
| 534 | vaultReserved: [] |
| 535 | }); |
| 536 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 537 | harness.simulation.step(); |
| 538 | harness.advance(50); |
| 539 | harness.simulation.step(); |
| 540 | |
| 541 | const record = harness.simulation.entityRecord(playerId); |
| 542 | const worker = harness.simulation.workers[record.workerId]; |
| 543 | let npc = null; |
| 544 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature, Component.position, Component.path)) |
| 545 | { |
| 546 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 547 | { |
| 548 | npc = entity; |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | assert.ok(npc); |
| 553 | |
| 554 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 555 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 556 | playerPos.tileX = npc.position.tileX; |
| 557 | playerPos.tileY = npc.position.tileY; |
| 558 | |
| 559 | harness.simulation.enqueue(1, { |
| 560 | type: "interact", |
| 561 | characterId: character.character_id, |
| 562 | targetEntityId: npc.entityId |
| 563 | }); |
| 564 | const open = harness.simulation.step(); |
| 565 | assert.ok(open.events.some((event) => event.type === "shop-open")); |
| 566 | assert.equal(!!npc.shop.browsers?.[character.character_id], true); |
| 567 | |
| 568 | npc.path.tiles = [{ x: npc.position.tileX + 1, y: npc.position.tileY }]; |
| 569 | for (let i = 0; i < 20; i++) |
| 570 | { harness.simulation.step(); } |
| 571 | assert.equal(npc.path.tiles.length, 0); |
| 572 | assert.equal(npc.position.tileX, playerPos.tileX); |
| 573 | assert.equal(npc.position.tileY, playerPos.tileY); |
| 574 | |
| 575 | harness.simulation.enqueue(1, { |
| 576 | type: "close-shop", |
| 577 | characterId: character.character_id, |
| 578 | npcEntityId: npc.entityId |
| 579 | }); |
| 580 | harness.simulation.step(); |
| 581 | assert.equal(!!npc.shop.browsers?.[character.character_id], false); |
| 582 | } |
| 583 | finally |
| 584 | { harness.close(); } |
| 585 | }); |
| 586 | |
| 587 | test("buysItems accepts non-ingredient tools like sticks", () => |
| 588 | { |
| 589 | const harness = makeSimulation({ workerCount: 1 }); |
| 590 | try |
| 591 | { |
| 592 | const data = createEmptyChunkData(); |
| 593 | data.open = true; |
| 594 | data.spawners = [{ |
| 595 | localX: 9, |
| 596 | localY: 8, |
| 597 | config: { |
| 598 | mobTypeId: MobId.humanoid, |
| 599 | maxAlive: 1, |
| 600 | spawnRangeTiles: 0, |
| 601 | maxWanderRangeTiles: 0, |
| 602 | displayName: "Buyer", |
| 603 | buysItems: true, |
| 604 | hiddenDiscount: 1 |
| 605 | } |
| 606 | }]; |
| 607 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 608 | harness.simulation.reloadWorld(); |
| 609 | |
| 610 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 611 | const slots = emptySlots(INVENTORY_SLOTS); |
| 612 | slots[0] = { itemId: ItemId.stick, quantity: 1 }; |
| 613 | harness.stateDb.saveBag(character.character_id, { |
| 614 | inventory: slots, |
| 615 | equipment: emptyEquipment(), |
| 616 | vault: [], |
| 617 | vaultReserved: [] |
| 618 | }); |
| 619 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 620 | harness.simulation.step(); |
| 621 | harness.advance(50); |
| 622 | harness.simulation.step(); |
| 623 | |
| 624 | const record = harness.simulation.entityRecord(playerId); |
| 625 | const worker = harness.simulation.workers[record.workerId]; |
| 626 | let npcId = null; |
| 627 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 628 | { |
| 629 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 630 | { |
| 631 | npcId = entity.entityId; |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | assert.ok(npcId); |
| 636 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 637 | const shop = worker.world.ecs.get(npcHandle, Component.shop); |
| 638 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 639 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 640 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 641 | playerPos.tileX = npcPos.tileX; |
| 642 | playerPos.tileY = npcPos.tileY; |
| 643 | |
| 644 | const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots); |
| 645 | harness.simulation.enqueue(1, { |
| 646 | type: "sell-to-shop", |
| 647 | characterId: character.character_id, |
| 648 | npcEntityId: npcId, |
| 649 | slotIndex: 0, |
| 650 | quantity: 1 |
| 651 | }); |
| 652 | const sold = harness.simulation.step(); |
| 653 | assert.equal(sold.events.some((event) => event.type === "command-error"), false, JSON.stringify(sold.events)); |
| 654 | const inv = worker.world.ecs.get(playerHandle, Component.inventory); |
| 655 | assert.equal(inv.slots[0]?.itemId === ItemId.stick, false); |
| 656 | assert.ok(countCoinsInSlots(inv.slots) >= beforeCoins + shopBuyFromPlayerPrice(ItemId.stick)); |
| 657 | assert.equal(boughtQty(shop, ItemId.stick), 1); |
| 658 | } |
| 659 | finally |
| 660 | { harness.close(); } |
| 661 | }); |
| 662 | |
| 663 | test("selling a filled cheque pays reserved-goods price minus 5% admin fee", () => |
| 664 | { |
| 665 | const harness = makeSimulation({ workerCount: 1 }); |
| 666 | try |
| 667 | { |
| 668 | const data = createEmptyChunkData(); |
| 669 | data.open = true; |
| 670 | data.blocks[8 * 16 + 8] = { typeId: BlockType.bank, state: 0 }; |
| 671 | data.spawners = [{ |
| 672 | localX: 9, |
| 673 | localY: 8, |
| 674 | config: { |
| 675 | mobTypeId: MobId.humanoid, |
| 676 | maxAlive: 1, |
| 677 | spawnRangeTiles: 0, |
| 678 | maxWanderRangeTiles: 0, |
| 679 | displayName: "Buyer", |
| 680 | sells: [{ itemId: ItemId.copperOre, quantity: 0 }], |
| 681 | buysItems: true, |
| 682 | hiddenDiscount: 1 |
| 683 | } |
| 684 | }]; |
| 685 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 686 | harness.simulation.reloadWorld(); |
| 687 | |
| 688 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 9 }); |
| 689 | const slots = emptySlots(INVENTORY_SLOTS); |
| 690 | slots[0] = { itemId: ItemId.copperOre, quantity: 2 }; |
| 691 | harness.stateDb.saveBag(character.character_id, { |
| 692 | inventory: slots, |
| 693 | equipment: emptyEquipment(), |
| 694 | vault: [], |
| 695 | vaultReserved: [] |
| 696 | }); |
| 697 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 698 | harness.simulation.step(); |
| 699 | |
| 700 | harness.simulation.enqueue(1, { |
| 701 | type: "get-blank-cheques", |
| 702 | characterId: character.character_id |
| 703 | }); |
| 704 | harness.simulation.step(); |
| 705 | harness.simulation.enqueue(1, { |
| 706 | type: "bank-deposit", |
| 707 | characterId: character.character_id, |
| 708 | slotIndex: 0, |
| 709 | quantity: null |
| 710 | }); |
| 711 | harness.simulation.step(); |
| 712 | let bag = harness.simulation.bagOf(playerId); |
| 713 | const blankIndex = bag.inventory.findIndex((slot) => slot?.itemId === ItemId.blankCheque); |
| 714 | const vaultIndex = bag.vault.findIndex((slot) => slot?.itemId === ItemId.copperOre); |
| 715 | harness.simulation.enqueue(1, { |
| 716 | type: "write-cheque", |
| 717 | characterId: character.character_id, |
| 718 | slotIndex: blankIndex, |
| 719 | vaultSlotIndex: vaultIndex, |
| 720 | quantity: 2 |
| 721 | }); |
| 722 | harness.simulation.step(); |
| 723 | bag = harness.simulation.bagOf(playerId); |
| 724 | const chequeIndex = bag.inventory.findIndex((slot) => slot?.itemId === ItemId.filledCheque); |
| 725 | assert.ok(chequeIndex >= 0); |
| 726 | |
| 727 | const record = harness.simulation.entityRecord(playerId); |
| 728 | const worker = harness.simulation.workers[record.workerId]; |
| 729 | let npcId = null; |
| 730 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 731 | { |
| 732 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 733 | { |
| 734 | npcId = entity.entityId; |
| 735 | break; |
| 736 | } |
| 737 | } |
| 738 | assert.ok(npcId); |
| 739 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 740 | const shop = worker.world.ecs.get(npcHandle, Component.shop); |
| 741 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 742 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 743 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 744 | playerPos.tileX = npcPos.tileX; |
| 745 | playerPos.tileY = npcPos.tileY; |
| 746 | |
| 747 | const quote = resolveShopSellQuote(bag.inventory[chequeIndex]); |
| 748 | assert.ok(quote?.isCheque); |
| 749 | const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots); |
| 750 | harness.simulation.enqueue(1, { |
| 751 | type: "sell-to-shop", |
| 752 | characterId: character.character_id, |
| 753 | npcEntityId: npcId, |
| 754 | slotIndex: chequeIndex, |
| 755 | quantity: 1 |
| 756 | }); |
| 757 | const sold = harness.simulation.step(); |
| 758 | assert.equal(sold.events.some((event) => event.type === "command-error"), false, JSON.stringify(sold.events)); |
| 759 | bag = harness.simulation.bagOf(playerId); |
| 760 | assert.equal(bag.inventory.findIndex((slot) => slot?.itemId === ItemId.filledCheque), -1); |
| 761 | assert.equal((bag.vaultReserved ?? []).length, 0); |
| 762 | const afterCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots); |
| 763 | assert.equal(afterCoins - beforeCoins, quote.payout); |
| 764 | // Infinite catalog absorbs goods without bought-from-player resale stock. |
| 765 | assert.equal(boughtQty(shop, ItemId.copperOre), 0); |
| 766 | } |
| 767 | finally |
| 768 | { harness.close(); } |
| 769 | }); |
| 770 | |
| 771 | test("resale stock keeps the seller origin instead of Bought from NPC", () => |
| 772 | { |
| 773 | const harness = makeSimulation({ workerCount: 1 }); |
| 774 | try |
| 775 | { |
| 776 | const data = createEmptyChunkData(); |
| 777 | data.open = true; |
| 778 | data.spawners = [{ |
| 779 | localX: 9, |
| 780 | localY: 8, |
| 781 | config: { |
| 782 | mobTypeId: MobId.humanoid, |
| 783 | maxAlive: 1, |
| 784 | spawnRangeTiles: 0, |
| 785 | maxWanderRangeTiles: 0, |
| 786 | displayName: "Fence", |
| 787 | sells: [], |
| 788 | buysItems: true, |
| 789 | hiddenDiscount: 1 |
| 790 | } |
| 791 | }]; |
| 792 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 793 | harness.simulation.reloadWorld(); |
| 794 | |
| 795 | const minerOrigin = gatherOrigin(GatherOriginVerb.mined, "Ada Miner"); |
| 796 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 797 | const funded = addCoinsToSlots(emptySlots(), 50); |
| 798 | assert.equal(funded.ok, true); |
| 799 | funded.slots[1] = { |
| 800 | itemId: ItemId.copperOre, |
| 801 | quantity: 2, |
| 802 | origins: [{ origin: minerOrigin, quantity: 2 }] |
| 803 | }; |
| 804 | harness.stateDb.saveBag(character.character_id, { |
| 805 | inventory: funded.slots, |
| 806 | equipment: emptyEquipment(), |
| 807 | vault: [], |
| 808 | vaultReserved: [] |
| 809 | }); |
| 810 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 811 | harness.simulation.step(); |
| 812 | harness.advance(50); |
| 813 | harness.simulation.step(); |
| 814 | |
| 815 | const record = harness.simulation.entityRecord(playerId); |
| 816 | const worker = harness.simulation.workers[record.workerId]; |
| 817 | let npcId = null; |
| 818 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 819 | { |
| 820 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 821 | { |
| 822 | npcId = entity.entityId; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | assert.ok(npcId); |
| 827 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 828 | const shop = worker.world.ecs.get(npcHandle, Component.shop); |
| 829 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 830 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 831 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 832 | playerPos.tileX = npcPos.tileX; |
| 833 | playerPos.tileY = npcPos.tileY; |
| 834 | |
| 835 | harness.simulation.enqueue(1, { |
| 836 | type: "sell-to-shop", |
| 837 | characterId: character.character_id, |
| 838 | npcEntityId: npcId, |
| 839 | slotIndex: 1, |
| 840 | quantity: 2 |
| 841 | }); |
| 842 | const sold = harness.simulation.step(); |
| 843 | assert.equal(sold.events.some((event) => event.type === "command-error"), false, JSON.stringify(sold.events)); |
| 844 | assert.equal(boughtQty(shop, ItemId.copperOre), 2); |
| 845 | assert.deepEqual(shop.boughtStock[ItemId.copperOre].origins, [ |
| 846 | { origin: minerOrigin, quantity: 2 } |
| 847 | ]); |
| 848 | |
| 849 | harness.simulation.enqueue(1, { |
| 850 | type: "buy-from-shop", |
| 851 | characterId: character.character_id, |
| 852 | npcEntityId: npcId, |
| 853 | itemId: ItemId.copperOre, |
| 854 | quantity: 2, |
| 855 | listingId: `bought:${ItemId.copperOre}`, |
| 856 | source: "bought" |
| 857 | }); |
| 858 | const buy = harness.simulation.step(); |
| 859 | assert.equal(buy.events.some((event) => event.type === "command-error"), false, JSON.stringify(buy.events)); |
| 860 | const bag = harness.simulation.bagOf(playerId); |
| 861 | const ore = (bag.inventory ?? []).find((slot) => slot?.itemId === ItemId.copperOre); |
| 862 | assert.ok(ore); |
| 863 | assert.equal(ore.origins?.[0]?.origin?.kind, ItemOriginKind.gathered); |
| 864 | assert.equal(ore.origins?.[0]?.origin?.displayName, "Ada Miner"); |
| 865 | assert.equal(ore.origins?.[0]?.origin?.kind === ItemOriginKind.shop, false); |
| 866 | } |
| 867 | finally |
| 868 | { harness.close(); } |
| 869 | }); |
| 870 | |
| 871 | test("NPC letter sales pay out and destroy the letter without stock", () => |
| 872 | { |
| 873 | const harness = makeSimulation({ workerCount: 1 }); |
| 874 | try |
| 875 | { |
| 876 | const data = createEmptyChunkData(); |
| 877 | data.open = true; |
| 878 | data.spawners = [{ |
| 879 | localX: 9, |
| 880 | localY: 8, |
| 881 | config: { |
| 882 | mobTypeId: MobId.humanoid, |
| 883 | maxAlive: 1, |
| 884 | spawnRangeTiles: 0, |
| 885 | maxWanderRangeTiles: 0, |
| 886 | displayName: "Fence", |
| 887 | sells: [], |
| 888 | buysItems: true, |
| 889 | hiddenDiscount: 1 |
| 890 | } |
| 891 | }]; |
| 892 | harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data)); |
| 893 | harness.simulation.reloadWorld(); |
| 894 | |
| 895 | const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); |
| 896 | const funded = addCoinsToSlots(emptySlots(), 10); |
| 897 | assert.equal(funded.ok, true); |
| 898 | funded.slots[1] = { |
| 899 | itemId: ItemId.letter, |
| 900 | quantity: 1, |
| 901 | instance: { |
| 902 | kind: "letter", |
| 903 | letterId: "sell-me", |
| 904 | authorCharacterId: character.character_id, |
| 905 | authorDisplayName: "Ada", |
| 906 | body: "For sale", |
| 907 | opened: true, |
| 908 | writtenAt: Date.now() |
| 909 | } |
| 910 | }; |
| 911 | harness.stateDb.saveBag(character.character_id, { |
| 912 | inventory: funded.slots, |
| 913 | equipment: emptyEquipment(), |
| 914 | vault: [], |
| 915 | vaultReserved: [] |
| 916 | }); |
| 917 | const playerId = harness.simulation.spawnCharacter(1, character); |
| 918 | harness.simulation.step(); |
| 919 | harness.advance(50); |
| 920 | harness.simulation.step(); |
| 921 | |
| 922 | const record = harness.simulation.entityRecord(playerId); |
| 923 | const worker = harness.simulation.workers[record.workerId]; |
| 924 | let npcId = null; |
| 925 | for (const entity of worker.world.ecs.query(Component.shop, Component.creature)) |
| 926 | { |
| 927 | if (entity.creature.mobTypeId === MobId.humanoid) |
| 928 | { |
| 929 | npcId = entity.entityId; |
| 930 | break; |
| 931 | } |
| 932 | } |
| 933 | assert.ok(npcId); |
| 934 | const npcHandle = worker.world.ecs.handleOf(npcId); |
| 935 | const shop = worker.world.ecs.get(npcHandle, Component.shop); |
| 936 | const npcPos = worker.world.ecs.get(npcHandle, Component.position); |
| 937 | const playerHandle = worker.world.ecs.handleOf(playerId); |
| 938 | const playerPos = worker.world.ecs.get(playerHandle, Component.position); |
| 939 | playerPos.tileX = npcPos.tileX; |
| 940 | playerPos.tileY = npcPos.tileY; |
| 941 | |
| 942 | const letterSlot = harness.simulation.bagOf(playerId).inventory |
| 943 | .findIndex((slot) => slot?.itemId === ItemId.letter); |
| 944 | assert.ok(letterSlot >= 0); |
| 945 | const quote = resolveShopSellQuote(harness.simulation.bagOf(playerId).inventory[letterSlot]); |
| 946 | assert.ok(quote); |
| 947 | const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots); |
| 948 | |
| 949 | harness.simulation.enqueue(1, { |
| 950 | type: "sell-to-shop", |
| 951 | characterId: character.character_id, |
| 952 | npcEntityId: npcId, |
| 953 | slotIndex: letterSlot, |
| 954 | quantity: 1 |
| 955 | }); |
| 956 | const sold = harness.simulation.step(); |
| 957 | assert.equal(sold.events.some((event) => event.type === "command-error"), false, JSON.stringify(sold.events)); |
| 958 | const bag = harness.simulation.bagOf(playerId); |
| 959 | assert.equal(bag.inventory.some((slot) => slot?.itemId === ItemId.letter), false); |
| 960 | assert.equal(boughtQty(shop, ItemId.letter), 0); |
| 961 | assert.equal(shop.boughtStock?.[ItemId.letter], undefined); |
| 962 | const afterCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots); |
| 963 | assert.equal(afterCoins - beforeCoins, quote.payout); |
| 964 | } |
| 965 | finally |
| 966 | { harness.close(); } |
| 967 | }); |