✨Feature: add town systems, saves, recovery, and level progression
This commit is contained in:
71
src/rules/townServices.test.ts
Normal file
71
src/rules/townServices.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { createStartingAdventurer } from "./character";
|
||||
import { createRunState, returnToTown } from "./runState";
|
||||
import { useTownService } from "./townServices";
|
||||
|
||||
function createAdventurer() {
|
||||
return createStartingAdventurer(sampleContentPack, {
|
||||
name: "Aster",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
}
|
||||
|
||||
describe("town services", () => {
|
||||
it("heals the adventurer to full at the healer", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
});
|
||||
|
||||
run.adventurerSnapshot.hp.current = 3;
|
||||
run.adventurerSnapshot.inventory.currency.gold = 3;
|
||||
|
||||
const inTown = returnToTown(run, "2026-03-18T21:00:00.000Z").run;
|
||||
const result = useTownService({
|
||||
content: sampleContentPack,
|
||||
run: inTown,
|
||||
serviceId: "service.healer",
|
||||
at: "2026-03-18T21:05:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.run.adventurerSnapshot.hp.current).toBe(
|
||||
result.run.adventurerSnapshot.hp.max,
|
||||
);
|
||||
expect(result.run.adventurerSnapshot.inventory.currency.gold).toBe(1);
|
||||
expect(result.run.log.at(-1)?.text).toContain("restored the party to full health");
|
||||
});
|
||||
|
||||
it("buys a ration at the market", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
});
|
||||
|
||||
run.adventurerSnapshot.inventory.currency.gold = 2;
|
||||
|
||||
const inTown = returnToTown(run).run;
|
||||
const result = useTownService({
|
||||
content: sampleContentPack,
|
||||
run: inTown,
|
||||
serviceId: "service.market",
|
||||
});
|
||||
|
||||
expect(result.run.adventurerSnapshot.inventory.currency.gold).toBe(1);
|
||||
expect(result.run.adventurerSnapshot.inventory.rationCount).toBe(4);
|
||||
expect(result.run.adventurerSnapshot.inventory.carried).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
definitionId: "item.ration",
|
||||
quantity: 4,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user