✨Feature: add creature lookup functionality and combat state management
This commit is contained in:
@@ -2,7 +2,11 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { lookupTable } from "@/rules/tables";
|
||||
|
||||
import { findRoomTemplateForLookup, findTableByCode } from "./contentHelpers";
|
||||
import {
|
||||
findCreatureByName,
|
||||
findRoomTemplateForLookup,
|
||||
findTableByCode,
|
||||
} from "./contentHelpers";
|
||||
import { sampleContentPack } from "./sampleContentPack";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
@@ -46,4 +50,11 @@ describe("level 1 content helpers", () => {
|
||||
expect(roomTemplate.title).toBe("Slate Shrine");
|
||||
expect(roomTemplate.roomClass).toBe("large");
|
||||
});
|
||||
|
||||
it("finds a creature definition by display name", () => {
|
||||
const creature = findCreatureByName(sampleContentPack, "Guard");
|
||||
|
||||
expect(creature.id).toBe("creature.level1.guard");
|
||||
expect(creature.hp).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import type { ContentPack, RoomTemplate, TableDefinition } from "@/types/content";
|
||||
import type {
|
||||
ContentPack,
|
||||
CreatureDefinition,
|
||||
RoomTemplate,
|
||||
TableDefinition,
|
||||
} from "@/types/content";
|
||||
import type { TableLookupResult } from "@/rules/tables";
|
||||
|
||||
export function findTableByCode(content: ContentPack, code: string): TableDefinition {
|
||||
@@ -36,3 +41,23 @@ export function findRoomTemplateForLookup(
|
||||
|
||||
return findRoomTemplateById(content, roomReference.id);
|
||||
}
|
||||
|
||||
function normalizeName(value: string) {
|
||||
return value.trim().toLowerCase().replace(/\s+/g, " ");
|
||||
}
|
||||
|
||||
export function findCreatureByName(
|
||||
content: ContentPack,
|
||||
creatureName: string,
|
||||
): CreatureDefinition {
|
||||
const normalizedTarget = normalizeName(creatureName);
|
||||
const creature = content.creatures.find(
|
||||
(entry) => normalizeName(entry.name) === normalizedTarget,
|
||||
);
|
||||
|
||||
if (!creature) {
|
||||
throw new Error(`Unknown creature name: ${creatureName}`);
|
||||
}
|
||||
|
||||
return creature;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,92 @@ const samplePack = {
|
||||
traits: ["level-1", "sample"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.guard",
|
||||
name: "Guard",
|
||||
level: 1,
|
||||
category: "humanoid",
|
||||
hp: 4,
|
||||
attackProfile: {
|
||||
discipline: 1,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
defenceProfile: {
|
||||
armour: 1,
|
||||
},
|
||||
xpReward: 2,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.warrior",
|
||||
name: "Warrior",
|
||||
level: 1,
|
||||
category: "humanoid",
|
||||
hp: 5,
|
||||
attackProfile: {
|
||||
discipline: 2,
|
||||
precision: 1,
|
||||
damage: 2,
|
||||
},
|
||||
defenceProfile: {
|
||||
armour: 1,
|
||||
},
|
||||
xpReward: 3,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.thug",
|
||||
name: "Thug",
|
||||
level: 1,
|
||||
category: "humanoid",
|
||||
hp: 3,
|
||||
attackProfile: {
|
||||
discipline: 0,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
xpReward: 1,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.work-dog",
|
||||
name: "Work Dog",
|
||||
level: 1,
|
||||
category: "beast",
|
||||
hp: 3,
|
||||
attackProfile: {
|
||||
discipline: 0,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
xpReward: 1,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "beast"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.guard-dog",
|
||||
name: "Guard Dog",
|
||||
level: 1,
|
||||
category: "beast",
|
||||
hp: 4,
|
||||
attackProfile: {
|
||||
discipline: 1,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
xpReward: 2,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "beast"],
|
||||
mvp: true,
|
||||
},
|
||||
],
|
||||
roomTemplates: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user