Feature: implement town market functionality with treasure selling and stashing

This commit is contained in:
Keith Solomon
2026-03-15 14:31:53 -05:00
parent 71bdc6d031
commit 8597b4fded
7 changed files with 393 additions and 3 deletions
+74
View File
@@ -0,0 +1,74 @@
import { describe, expect, it } from "vitest";
import { sampleContentPack } from "@/data/sampleContentPack";
import { createStartingAdventurer } from "./character";
import { createRunState } from "./runState";
import { queueTreasureForSale, sellPendingTreasure, sendTreasureToStash } from "./town";
function createAdventurer() {
return createStartingAdventurer(sampleContentPack, {
name: "Aster",
weaponId: "weapon.short-sword",
armourId: "armour.leather-vest",
scrollId: "scroll.lesser-heal",
});
}
describe("town flow", () => {
it("moves treasure from carried inventory into the stash", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.inventory.carried.push({
definitionId: "item.silver-clasp",
quantity: 1,
});
const result = sendTreasureToStash(
sampleContentPack,
run,
"item.silver-clasp",
"2026-03-15T15:00:00.000Z",
);
expect(result.run.townState.stash).toEqual([
{ definitionId: "item.silver-clasp", quantity: 1 },
]);
expect(result.run.adventurerSnapshot.inventory.carried).not.toEqual(
expect.arrayContaining([expect.objectContaining({ definitionId: "item.silver-clasp" })]),
);
});
it("queues treasure and sells it for item value", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.inventory.carried.push({
definitionId: "item.keeper-keyring",
quantity: 1,
});
const queued = queueTreasureForSale(
sampleContentPack,
run,
"item.keeper-keyring",
"2026-03-15T15:05:00.000Z",
).run;
const sold = sellPendingTreasure(
sampleContentPack,
queued,
"2026-03-15T15:06:00.000Z",
).run;
expect(sold.townState.pendingSales).toEqual([]);
expect(sold.adventurerSnapshot.inventory.currency.gold).toBe(5);
expect(sold.log.at(-1)?.text).toContain("for 5 gold");
});
});