Compare commits
14 Commits
71bdc6d031
...
feature/ga
| Author | SHA1 | Date | |
|---|---|---|---|
| 40ce9644ab | |||
| 473ea83cdf | |||
| 7fb3bd6cf5 | |||
|
|
fb6cbfe9fb | ||
| 9c7acf6825 | |||
| 102cbfeaad | |||
| 377a533466 | |||
| e3f90ca545 | |||
| 79b9e448b7 | |||
| aea00d31e8 | |||
| fdaa2e3135 | |||
| 67453df51e | |||
| cff5f786a0 | |||
| 5debb5bd5e |
201
src/App.tsx
201
src/App.tsx
@@ -6,7 +6,6 @@ import {
|
|||||||
createRunState,
|
createRunState,
|
||||||
enterCurrentRoom,
|
enterCurrentRoom,
|
||||||
getAvailableMoves,
|
getAvailableMoves,
|
||||||
isCurrentRoomCombatReady,
|
|
||||||
resolveRunEnemyTurn,
|
resolveRunEnemyTurn,
|
||||||
resolveRunPlayerTurn,
|
resolveRunPlayerTurn,
|
||||||
startCombatInCurrentRoom,
|
startCombatInCurrentRoom,
|
||||||
@@ -48,72 +47,16 @@ function getRoomTitle(run: RunState, roomId?: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefinitionName(definitionId: string) {
|
|
||||||
const item =
|
|
||||||
sampleContentPack.items.find((candidate) => candidate.id === definitionId) ??
|
|
||||||
sampleContentPack.weapons.find((candidate) => candidate.id === definitionId) ??
|
|
||||||
sampleContentPack.armour.find((candidate) => candidate.id === definitionId) ??
|
|
||||||
sampleContentPack.scrolls.find((candidate) => candidate.id === definitionId) ??
|
|
||||||
sampleContentPack.potions.find((candidate) => candidate.id === definitionId);
|
|
||||||
|
|
||||||
return item?.name ?? definitionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatInventoryEntry(definitionId: string, quantity: number) {
|
|
||||||
const name = getDefinitionName(definitionId);
|
|
||||||
return quantity > 1 ? `${quantity}x ${name}` : name;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTreasureItemIds() {
|
|
||||||
return new Set(
|
|
||||||
sampleContentPack.items
|
|
||||||
.filter((item) => item.itemType === "treasure")
|
|
||||||
.map((item) => item.id),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSupportItemIds() {
|
|
||||||
return new Set(
|
|
||||||
sampleContentPack.items
|
|
||||||
.filter((item) => item.itemType !== "treasure")
|
|
||||||
.map((item) => item.id),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConsumableItemIds() {
|
|
||||||
return new Set(
|
|
||||||
sampleContentPack.items
|
|
||||||
.filter((item) => item.consumable || item.itemType === "ration")
|
|
||||||
.map((item) => item.id),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const treasureItemIds = getTreasureItemIds();
|
|
||||||
const supportItemIds = getSupportItemIds();
|
|
||||||
const consumableItemIds = getConsumableItemIds();
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [run, setRun] = React.useState<RunState>(() => createDemoRun());
|
const [run, setRun] = React.useState<RunState>(() => createDemoRun());
|
||||||
const currentLevel = run.dungeon.levels[run.currentLevel];
|
const currentLevel = run.dungeon.levels[run.currentLevel];
|
||||||
const currentRoom = run.currentRoomId ? currentLevel?.rooms[run.currentRoomId] : undefined;
|
const currentRoom = run.currentRoomId ? currentLevel?.rooms[run.currentRoomId] : undefined;
|
||||||
const availableMoves = getAvailableMoves(run);
|
const availableMoves = getAvailableMoves(run);
|
||||||
const combatReadyEncounter = isCurrentRoomCombatReady(run);
|
const combatReadyEncounter = Boolean(
|
||||||
const carriedTreasure = run.adventurerSnapshot.inventory.carried.filter((entry) =>
|
currentRoom?.encounter?.resolved &&
|
||||||
treasureItemIds.has(entry.definitionId),
|
currentRoom.encounter.creatureNames &&
|
||||||
|
currentRoom.encounter.creatureNames.length > 0,
|
||||||
);
|
);
|
||||||
const carriedConsumables = run.adventurerSnapshot.inventory.carried.filter(
|
|
||||||
(entry) =>
|
|
||||||
consumableItemIds.has(entry.definitionId) ||
|
|
||||||
entry.definitionId.startsWith("potion.") ||
|
|
||||||
entry.definitionId.startsWith("scroll."),
|
|
||||||
);
|
|
||||||
const carriedGear = run.adventurerSnapshot.inventory.carried.filter(
|
|
||||||
(entry) =>
|
|
||||||
supportItemIds.has(entry.definitionId) &&
|
|
||||||
!consumableItemIds.has(entry.definitionId),
|
|
||||||
);
|
|
||||||
const equippedItems = run.adventurerSnapshot.inventory.equipped;
|
|
||||||
const latestLoot = run.lootedItems.slice(-4).reverse();
|
|
||||||
|
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
setRun(createDemoRun());
|
setRun(createDemoRun());
|
||||||
@@ -161,10 +104,11 @@ function App() {
|
|||||||
<section className="hero">
|
<section className="hero">
|
||||||
<div>
|
<div>
|
||||||
<p className="eyebrow">2D6 Dungeon Web</p>
|
<p className="eyebrow">2D6 Dungeon Web</p>
|
||||||
<h1>Dungeon Loop Shell</h1>
|
<h1>Playable Rules Shell</h1>
|
||||||
<p className="lede">
|
<p className="lede">
|
||||||
Traverse generated rooms, auto-resolve room entry, and engage combat
|
The core loop now runs inside the app: move through generated rooms,
|
||||||
when a room reveals a real encounter.
|
resolve room state on entry, and fight when a room produces a real
|
||||||
|
encounter.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -179,22 +123,6 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{combatReadyEncounter && !run.activeCombat ? (
|
|
||||||
<section className="alert-banner">
|
|
||||||
<div>
|
|
||||||
<span className="alert-kicker">Encounter Ready</span>
|
|
||||||
<strong>{currentRoom?.encounter?.resultLabel}</strong>
|
|
||||||
<p>
|
|
||||||
This room contains a combat-ready encounter. Engage now to enter
|
|
||||||
tactical resolution.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<button className="button button-primary" onClick={handleStartCombat}>
|
|
||||||
Engage Encounter
|
|
||||||
</button>
|
|
||||||
</section>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<section className="dashboard-grid">
|
<section className="dashboard-grid">
|
||||||
<article className="panel panel-highlight">
|
<article className="panel panel-highlight">
|
||||||
<div className="panel-header">
|
<div className="panel-header">
|
||||||
@@ -220,10 +148,6 @@ function App() {
|
|||||||
<span>Precision</span>
|
<span>Precision</span>
|
||||||
<strong>{run.adventurerSnapshot.stats.precision}</strong>
|
<strong>{run.adventurerSnapshot.stats.precision}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<span>XP</span>
|
|
||||||
<strong>{run.adventurerSnapshot.xp}</strong>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<p className="supporting-text">
|
<p className="supporting-text">
|
||||||
{run.adventurerSnapshot.name} is equipped with a{" "}
|
{run.adventurerSnapshot.name} is equipped with a{" "}
|
||||||
@@ -232,107 +156,6 @@ function App() {
|
|||||||
)?.name ?? "weapon"}
|
)?.name ?? "weapon"}
|
||||||
.
|
.
|
||||||
</p>
|
</p>
|
||||||
<p className="supporting-text">
|
|
||||||
Run rewards: {run.xpGained} XP, {run.goldGained} gold,{" "}
|
|
||||||
{run.defeatedCreatureIds.length} foes defeated.
|
|
||||||
</p>
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<article className="panel panel-inventory">
|
|
||||||
<div className="panel-header">
|
|
||||||
<h2>Inventory</h2>
|
|
||||||
<span>{run.adventurerSnapshot.inventory.carried.length} carried entries</span>
|
|
||||||
</div>
|
|
||||||
<div className="inventory-summary">
|
|
||||||
<div className="inventory-badge">
|
|
||||||
<span>Gold</span>
|
|
||||||
<strong>{run.adventurerSnapshot.inventory.currency.gold}</strong>
|
|
||||||
</div>
|
|
||||||
<div className="inventory-badge">
|
|
||||||
<span>Rations</span>
|
|
||||||
<strong>{run.adventurerSnapshot.inventory.rationCount}</strong>
|
|
||||||
</div>
|
|
||||||
<div className="inventory-badge">
|
|
||||||
<span>Treasure</span>
|
|
||||||
<strong>{carriedTreasure.length}</strong>
|
|
||||||
</div>
|
|
||||||
<div className="inventory-badge">
|
|
||||||
<span>Latest Loot</span>
|
|
||||||
<strong>{run.lootedItems.reduce((total, entry) => total + entry.quantity, 0)}</strong>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="inventory-grid">
|
|
||||||
<section className="inventory-section">
|
|
||||||
<span className="inventory-label">Equipped</span>
|
|
||||||
<div className="inventory-list">
|
|
||||||
{equippedItems.map((entry) => (
|
|
||||||
<article key={`equipped-${entry.definitionId}`} className="inventory-card inventory-card-equipped">
|
|
||||||
<strong>{formatInventoryEntry(entry.definitionId, entry.quantity)}</strong>
|
|
||||||
<span>Ready for use</span>
|
|
||||||
</article>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section className="inventory-section">
|
|
||||||
<span className="inventory-label">Consumables</span>
|
|
||||||
<div className="inventory-list">
|
|
||||||
{carriedConsumables.length === 0 ? (
|
|
||||||
<p className="supporting-text">No consumables carried.</p>
|
|
||||||
) : (
|
|
||||||
carriedConsumables.map((entry) => (
|
|
||||||
<article key={`consumable-${entry.definitionId}`} className="inventory-card">
|
|
||||||
<strong>{formatInventoryEntry(entry.definitionId, entry.quantity)}</strong>
|
|
||||||
<span>Combat or run utility</span>
|
|
||||||
</article>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section className="inventory-section">
|
|
||||||
<span className="inventory-label">Pack Gear</span>
|
|
||||||
<div className="inventory-list">
|
|
||||||
{carriedGear.length === 0 ? (
|
|
||||||
<p className="supporting-text">No general gear carried.</p>
|
|
||||||
) : (
|
|
||||||
carriedGear.map((entry) => (
|
|
||||||
<article key={`gear-${entry.definitionId}`} className="inventory-card">
|
|
||||||
<strong>{formatInventoryEntry(entry.definitionId, entry.quantity)}</strong>
|
|
||||||
<span>Travel and exploration kit</span>
|
|
||||||
</article>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section className="inventory-section">
|
|
||||||
<span className="inventory-label">Treasure Stash</span>
|
|
||||||
<div className="inventory-list">
|
|
||||||
{carriedTreasure.length === 0 ? (
|
|
||||||
<p className="supporting-text">No treasure recovered yet.</p>
|
|
||||||
) : (
|
|
||||||
carriedTreasure.map((entry) => (
|
|
||||||
<article key={`treasure-${entry.definitionId}`} className="inventory-card inventory-card-treasure">
|
|
||||||
<strong>{formatInventoryEntry(entry.definitionId, entry.quantity)}</strong>
|
|
||||||
<span>Sellable dungeon spoils</span>
|
|
||||||
</article>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<div className="loot-ribbon">
|
|
||||||
<span className="inventory-label">Recent Spoils</span>
|
|
||||||
{latestLoot.length === 0 ? (
|
|
||||||
<p className="supporting-text">Win a fight to populate the loot ribbon.</p>
|
|
||||||
) : (
|
|
||||||
<div className="loot-ribbon-list">
|
|
||||||
{latestLoot.map((entry) => (
|
|
||||||
<article key={`recent-${entry.definitionId}`} className="loot-pill">
|
|
||||||
<strong>{formatInventoryEntry(entry.definitionId, entry.quantity)}</strong>
|
|
||||||
</article>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
<article className="panel">
|
<article className="panel">
|
||||||
@@ -402,9 +225,7 @@ function App() {
|
|||||||
key={roomId}
|
key={roomId}
|
||||||
className={`map-node${active ? " map-node-active" : ""}`}
|
className={`map-node${active ? " map-node-active" : ""}`}
|
||||||
>
|
>
|
||||||
<span>
|
<span>{room.position.x},{room.position.y}</span>
|
||||||
{room.position.x},{room.position.y}
|
|
||||||
</span>
|
|
||||||
<strong>{getRoomTitle(run, roomId)}</strong>
|
<strong>{getRoomTitle(run, roomId)}</strong>
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
@@ -471,8 +292,8 @@ function App() {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<p className="supporting-text">
|
<p className="supporting-text">
|
||||||
No active combat. Travel until a room reveals a hostile encounter,
|
No active combat. Travel through the dungeon until a room generates
|
||||||
then engage it from the banner or room panel.
|
a creature encounter, then start combat from that room.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { lookupTable } from "@/rules/tables";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
findCreatureByName,
|
findCreatureByName,
|
||||||
findItemById,
|
|
||||||
findRoomTemplateForLookup,
|
findRoomTemplateForLookup,
|
||||||
findTableByCode,
|
findTableByCode,
|
||||||
} from "./contentHelpers";
|
} from "./contentHelpers";
|
||||||
@@ -58,11 +57,4 @@ describe("level 1 content helpers", () => {
|
|||||||
expect(creature.id).toBe("creature.level1.guard");
|
expect(creature.id).toBe("creature.level1.guard");
|
||||||
expect(creature.hp).toBeGreaterThan(0);
|
expect(creature.hp).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("finds a loot item definition by id", () => {
|
|
||||||
const item = findItemById(sampleContentPack, "item.silver-clasp");
|
|
||||||
|
|
||||||
expect(item.name).toBe("Silver Clasp");
|
|
||||||
expect(item.itemType).toBe("treasure");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type {
|
import type {
|
||||||
ContentPack,
|
ContentPack,
|
||||||
CreatureDefinition,
|
CreatureDefinition,
|
||||||
ItemDefinition,
|
|
||||||
RoomTemplate,
|
RoomTemplate,
|
||||||
TableDefinition,
|
TableDefinition,
|
||||||
} from "@/types/content";
|
} from "@/types/content";
|
||||||
@@ -62,26 +61,3 @@ export function findCreatureByName(
|
|||||||
|
|
||||||
return creature;
|
return creature;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findCreatureById(
|
|
||||||
content: ContentPack,
|
|
||||||
creatureId: string,
|
|
||||||
): CreatureDefinition {
|
|
||||||
const creature = content.creatures.find((entry) => entry.id === creatureId);
|
|
||||||
|
|
||||||
if (!creature) {
|
|
||||||
throw new Error(`Unknown creature id: ${creatureId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return creature;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findItemById(content: ContentPack, itemId: string): ItemDefinition {
|
|
||||||
const item = content.items.find((entry) => entry.id === itemId);
|
|
||||||
|
|
||||||
if (!item) {
|
|
||||||
throw new Error(`Unknown item id: ${itemId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,79 +13,6 @@ const samplePack = {
|
|||||||
],
|
],
|
||||||
tables: [
|
tables: [
|
||||||
...level1EncounterTables,
|
...level1EncounterTables,
|
||||||
{
|
|
||||||
id: "table.level1.humanoid-loot",
|
|
||||||
code: "L1HL",
|
|
||||||
name: "Level 1 Humanoid Loot",
|
|
||||||
category: "loot",
|
|
||||||
level: 1,
|
|
||||||
page: 122,
|
|
||||||
diceKind: "d6",
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
key: "1-2",
|
|
||||||
min: 1,
|
|
||||||
max: 2,
|
|
||||||
label: "Scavenged coins",
|
|
||||||
effects: [{ type: "gain-gold", amount: 1, target: "self" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "3-4",
|
|
||||||
min: 3,
|
|
||||||
max: 4,
|
|
||||||
label: "Bone Charm",
|
|
||||||
references: [{ type: "item", id: "item.bone-charm" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "5",
|
|
||||||
exact: 5,
|
|
||||||
label: "Silver Clasp and coins",
|
|
||||||
references: [{ type: "item", id: "item.silver-clasp" }],
|
|
||||||
effects: [{ type: "gain-gold", amount: 2, target: "self" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "6",
|
|
||||||
exact: 6,
|
|
||||||
label: "Key Ring and coin purse",
|
|
||||||
references: [{ type: "item", id: "item.keeper-keyring" }],
|
|
||||||
effects: [{ type: "gain-gold", amount: 3, target: "self" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
notes: ["Starter loot table for martial and humanoid encounters."],
|
|
||||||
mvp: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "table.level1.beast-loot",
|
|
||||||
code: "L1BL",
|
|
||||||
name: "Level 1 Beast Loot",
|
|
||||||
category: "loot",
|
|
||||||
level: 1,
|
|
||||||
page: 122,
|
|
||||||
diceKind: "d6",
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
key: "1-4",
|
|
||||||
min: 1,
|
|
||||||
max: 4,
|
|
||||||
label: "Nothing useful",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "5",
|
|
||||||
exact: 5,
|
|
||||||
label: "Trophy Fang",
|
|
||||||
references: [{ type: "item", id: "item.trophy-fang" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "6",
|
|
||||||
exact: 6,
|
|
||||||
label: "Trophy Fang and stray coin",
|
|
||||||
references: [{ type: "item", id: "item.trophy-fang" }],
|
|
||||||
effects: [{ type: "gain-gold", amount: 1, target: "self" }],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
notes: ["Starter loot table for basic animal encounters."],
|
|
||||||
mvp: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "table.weapon-manoeuvres-1",
|
id: "table.weapon-manoeuvres-1",
|
||||||
code: "WMT1",
|
code: "WMT1",
|
||||||
@@ -196,42 +123,6 @@ const samplePack = {
|
|||||||
consumable: false,
|
consumable: false,
|
||||||
mvp: true,
|
mvp: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: "item.bone-charm",
|
|
||||||
name: "Bone Charm",
|
|
||||||
itemType: "treasure",
|
|
||||||
stackable: false,
|
|
||||||
consumable: false,
|
|
||||||
valueGp: 2,
|
|
||||||
mvp: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "item.silver-clasp",
|
|
||||||
name: "Silver Clasp",
|
|
||||||
itemType: "treasure",
|
|
||||||
stackable: false,
|
|
||||||
consumable: false,
|
|
||||||
valueGp: 4,
|
|
||||||
mvp: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "item.keeper-keyring",
|
|
||||||
name: "Keeper Keyring",
|
|
||||||
itemType: "treasure",
|
|
||||||
stackable: false,
|
|
||||||
consumable: false,
|
|
||||||
valueGp: 5,
|
|
||||||
mvp: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "item.trophy-fang",
|
|
||||||
name: "Trophy Fang",
|
|
||||||
itemType: "treasure",
|
|
||||||
stackable: true,
|
|
||||||
consumable: false,
|
|
||||||
valueGp: 1,
|
|
||||||
mvp: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
potions: [
|
potions: [
|
||||||
{
|
{
|
||||||
@@ -272,7 +163,6 @@ const samplePack = {
|
|||||||
numberAppearing: "1-2",
|
numberAppearing: "1-2",
|
||||||
},
|
},
|
||||||
xpReward: 1,
|
xpReward: 1,
|
||||||
lootTableCodes: ["L1BL"],
|
|
||||||
sourcePage: 102,
|
sourcePage: 102,
|
||||||
traits: ["level-1", "sample"],
|
traits: ["level-1", "sample"],
|
||||||
mvp: true,
|
mvp: true,
|
||||||
@@ -292,7 +182,6 @@ const samplePack = {
|
|||||||
armour: 1,
|
armour: 1,
|
||||||
},
|
},
|
||||||
xpReward: 2,
|
xpReward: 2,
|
||||||
lootTableCodes: ["L1HL"],
|
|
||||||
sourcePage: 102,
|
sourcePage: 102,
|
||||||
traits: ["level-1", "martial"],
|
traits: ["level-1", "martial"],
|
||||||
mvp: true,
|
mvp: true,
|
||||||
@@ -312,7 +201,6 @@ const samplePack = {
|
|||||||
armour: 1,
|
armour: 1,
|
||||||
},
|
},
|
||||||
xpReward: 3,
|
xpReward: 3,
|
||||||
lootTableCodes: ["L1HL"],
|
|
||||||
sourcePage: 102,
|
sourcePage: 102,
|
||||||
traits: ["level-1", "martial"],
|
traits: ["level-1", "martial"],
|
||||||
mvp: true,
|
mvp: true,
|
||||||
@@ -329,7 +217,6 @@ const samplePack = {
|
|||||||
damage: 1,
|
damage: 1,
|
||||||
},
|
},
|
||||||
xpReward: 1,
|
xpReward: 1,
|
||||||
lootTableCodes: ["L1HL"],
|
|
||||||
sourcePage: 102,
|
sourcePage: 102,
|
||||||
traits: ["level-1", "martial"],
|
traits: ["level-1", "martial"],
|
||||||
mvp: true,
|
mvp: true,
|
||||||
@@ -346,7 +233,6 @@ const samplePack = {
|
|||||||
damage: 1,
|
damage: 1,
|
||||||
},
|
},
|
||||||
xpReward: 1,
|
xpReward: 1,
|
||||||
lootTableCodes: ["L1BL"],
|
|
||||||
sourcePage: 102,
|
sourcePage: 102,
|
||||||
traits: ["level-1", "beast"],
|
traits: ["level-1", "beast"],
|
||||||
mvp: true,
|
mvp: true,
|
||||||
@@ -363,7 +249,6 @@ const samplePack = {
|
|||||||
damage: 1,
|
damage: 1,
|
||||||
},
|
},
|
||||||
xpReward: 2,
|
xpReward: 2,
|
||||||
lootTableCodes: ["L1BL"],
|
|
||||||
sourcePage: 102,
|
sourcePage: 102,
|
||||||
traits: ["level-1", "beast"],
|
traits: ["level-1", "beast"],
|
||||||
mvp: true,
|
mvp: true,
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
|
|
||||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
|
||||||
|
|
||||||
import { createStartingAdventurer } from "./character";
|
|
||||||
import { startCombatFromRoom } from "./combat";
|
|
||||||
import { resolveCombatLoot } from "./loot";
|
|
||||||
|
|
||||||
function createSequenceRoller(values: number[]) {
|
|
||||||
let index = 0;
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
const next = values[index];
|
|
||||||
index += 1;
|
|
||||||
return next;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createAdventurer() {
|
|
||||||
return createStartingAdventurer(sampleContentPack, {
|
|
||||||
name: "Aster",
|
|
||||||
weaponId: "weapon.short-sword",
|
|
||||||
armourId: "armour.leather-vest",
|
|
||||||
scrollId: "scroll.lesser-heal",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("loot resolution", () => {
|
|
||||||
it("awards loot from defeated creatures into carried inventory", () => {
|
|
||||||
const room = {
|
|
||||||
id: "room.level1.start",
|
|
||||||
level: 1,
|
|
||||||
position: { x: 0, y: 0 },
|
|
||||||
dimensions: { width: 4, height: 4 },
|
|
||||||
roomClass: "start" as const,
|
|
||||||
exits: [],
|
|
||||||
discovery: {
|
|
||||||
generated: true,
|
|
||||||
entered: true,
|
|
||||||
cleared: false,
|
|
||||||
searched: false,
|
|
||||||
},
|
|
||||||
encounter: {
|
|
||||||
id: "room.level1.start.encounter",
|
|
||||||
sourceTableCode: "L1G",
|
|
||||||
creatureIds: ["room.level1.start.creature.1"],
|
|
||||||
creatureNames: ["Guard"],
|
|
||||||
resultLabel: "Guard",
|
|
||||||
resolved: true,
|
|
||||||
},
|
|
||||||
objects: [],
|
|
||||||
notes: ["Entry Chamber"],
|
|
||||||
flags: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const started = startCombatFromRoom({
|
|
||||||
content: sampleContentPack,
|
|
||||||
adventurer: createAdventurer(),
|
|
||||||
room,
|
|
||||||
at: "2026-03-15T14:02:00.000Z",
|
|
||||||
});
|
|
||||||
|
|
||||||
started.combat.enemies[0]!.hpCurrent = 0;
|
|
||||||
|
|
||||||
const loot = resolveCombatLoot({
|
|
||||||
content: sampleContentPack,
|
|
||||||
combat: started.combat,
|
|
||||||
inventory: createAdventurer().inventory,
|
|
||||||
roller: createSequenceRoller([5]),
|
|
||||||
at: "2026-03-15T14:03:00.000Z",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(loot.goldAwarded).toBe(2);
|
|
||||||
expect(loot.itemsAwarded).toEqual([
|
|
||||||
{
|
|
||||||
definitionId: "item.silver-clasp",
|
|
||||||
quantity: 1,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
expect(loot.inventory.currency.gold).toBe(2);
|
|
||||||
expect(loot.inventory.carried).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
definitionId: "item.silver-clasp",
|
|
||||||
quantity: 1,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
expect(loot.logEntries.some((entry) => entry.type === "loot")).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
import { findCreatureById, findItemById, findTableByCode } from "@/data/contentHelpers";
|
|
||||||
import type { ContentPack } from "@/types/content";
|
|
||||||
import type { CombatState, InventoryEntry, InventoryState } from "@/types/state";
|
|
||||||
import type { LogEntry } from "@/types/rules";
|
|
||||||
|
|
||||||
import type { DiceRoller } from "./dice";
|
|
||||||
import { lookupTable } from "./tables";
|
|
||||||
|
|
||||||
export type ResolveCombatLootOptions = {
|
|
||||||
content: ContentPack;
|
|
||||||
combat: CombatState;
|
|
||||||
inventory: InventoryState;
|
|
||||||
roller?: DiceRoller;
|
|
||||||
at: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ResolveCombatLootResult = {
|
|
||||||
inventory: InventoryState;
|
|
||||||
itemsAwarded: InventoryEntry[];
|
|
||||||
goldAwarded: number;
|
|
||||||
logEntries: LogEntry[];
|
|
||||||
};
|
|
||||||
|
|
||||||
function cloneInventory(inventory: InventoryState): InventoryState {
|
|
||||||
return {
|
|
||||||
...inventory,
|
|
||||||
carried: inventory.carried.map((entry) => ({ ...entry })),
|
|
||||||
equipped: inventory.equipped.map((entry) => ({ ...entry })),
|
|
||||||
stored: inventory.stored.map((entry) => ({ ...entry })),
|
|
||||||
currency: { ...inventory.currency },
|
|
||||||
lightSources: inventory.lightSources.map((entry) => ({ ...entry })),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createInventoryEntry(definitionId: string, quantity = 1): InventoryEntry {
|
|
||||||
return {
|
|
||||||
definitionId,
|
|
||||||
quantity,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeInventoryEntry(
|
|
||||||
content: ContentPack,
|
|
||||||
entries: InventoryEntry[],
|
|
||||||
definitionId: string,
|
|
||||||
quantity: number,
|
|
||||||
) {
|
|
||||||
const item = findItemById(content, definitionId);
|
|
||||||
|
|
||||||
if (item.stackable) {
|
|
||||||
const existing = entries.find((entry) => entry.definitionId === definitionId);
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
existing.quantity += quantity;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
entries.push(createInventoryEntry(definitionId, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
function createLootLog(
|
|
||||||
id: string,
|
|
||||||
at: string,
|
|
||||||
text: string,
|
|
||||||
relatedIds: string[],
|
|
||||||
): LogEntry {
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
at,
|
|
||||||
type: "loot",
|
|
||||||
text,
|
|
||||||
relatedIds,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function summarizeLoot(
|
|
||||||
goldAwarded: number,
|
|
||||||
itemsAwarded: InventoryEntry[],
|
|
||||||
content: ContentPack,
|
|
||||||
) {
|
|
||||||
const parts: string[] = [];
|
|
||||||
|
|
||||||
if (goldAwarded > 0) {
|
|
||||||
parts.push(`${goldAwarded} gold`);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const item of itemsAwarded) {
|
|
||||||
const itemName = findItemById(content, item.definitionId).name;
|
|
||||||
parts.push(item.quantity > 1 ? `${item.quantity}x ${itemName}` : itemName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts.length > 0 ? parts.join(", ") : "nothing useful";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveCombatLoot(
|
|
||||||
options: ResolveCombatLootOptions,
|
|
||||||
): ResolveCombatLootResult {
|
|
||||||
const inventory = cloneInventory(options.inventory);
|
|
||||||
const itemsAwarded: InventoryEntry[] = [];
|
|
||||||
const logEntries: LogEntry[] = [];
|
|
||||||
let goldAwarded = 0;
|
|
||||||
|
|
||||||
const defeatedCreatures = options.combat.enemies.filter(
|
|
||||||
(enemy) => enemy.hpCurrent === 0 && enemy.sourceDefinitionId,
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const enemy of defeatedCreatures) {
|
|
||||||
const creature = findCreatureById(options.content, enemy.sourceDefinitionId!);
|
|
||||||
const lootTableCodes = creature.lootTableCodes ?? [];
|
|
||||||
|
|
||||||
for (const tableCode of lootTableCodes) {
|
|
||||||
const table = findTableByCode(options.content, tableCode);
|
|
||||||
const lookup = lookupTable(table, { roller: options.roller });
|
|
||||||
const rollTotal = lookup.roll.modifiedTotal ?? lookup.roll.total;
|
|
||||||
|
|
||||||
logEntries.push({
|
|
||||||
id: `${options.combat.id}.${creature.id}.${tableCode}.roll`,
|
|
||||||
at: options.at,
|
|
||||||
type: "roll",
|
|
||||||
text: `Rolled loot ${lookup.roll.diceKind} [${lookup.roll.rolls.join(", ")}] on ${tableCode} for ${rollTotal}: ${lookup.entry.label}.`,
|
|
||||||
relatedIds: [options.combat.id, creature.id, tableCode],
|
|
||||||
});
|
|
||||||
|
|
||||||
let creatureGold = 0;
|
|
||||||
const creatureItems: InventoryEntry[] = [];
|
|
||||||
|
|
||||||
for (const effect of lookup.entry.effects ?? []) {
|
|
||||||
if (effect.type === "gain-gold" && effect.amount) {
|
|
||||||
creatureGold += effect.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (effect.type === "add-item" && effect.referenceId) {
|
|
||||||
mergeInventoryEntry(options.content, inventory.carried, effect.referenceId, effect.amount ?? 1);
|
|
||||||
mergeInventoryEntry(options.content, itemsAwarded, effect.referenceId, effect.amount ?? 1);
|
|
||||||
mergeInventoryEntry(options.content, creatureItems, effect.referenceId, effect.amount ?? 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const reference of lookup.entry.references ?? []) {
|
|
||||||
if (reference.type !== "item") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeInventoryEntry(options.content, inventory.carried, reference.id, 1);
|
|
||||||
mergeInventoryEntry(options.content, itemsAwarded, reference.id, 1);
|
|
||||||
mergeInventoryEntry(options.content, creatureItems, reference.id, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (creatureGold > 0) {
|
|
||||||
inventory.currency.gold += creatureGold;
|
|
||||||
goldAwarded += creatureGold;
|
|
||||||
}
|
|
||||||
|
|
||||||
logEntries.push(
|
|
||||||
createLootLog(
|
|
||||||
`${options.combat.id}.${creature.id}.${tableCode}.loot`,
|
|
||||||
options.at,
|
|
||||||
`${creature.name} yielded ${summarizeLoot(creatureGold, creatureItems, options.content)}.`,
|
|
||||||
[options.combat.id, creature.id, tableCode],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
inventory,
|
|
||||||
itemsAwarded,
|
|
||||||
goldAwarded,
|
|
||||||
logEntries,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
createRunState,
|
createRunState,
|
||||||
enterCurrentRoom,
|
enterCurrentRoom,
|
||||||
getAvailableMoves,
|
getAvailableMoves,
|
||||||
isCurrentRoomCombatReady,
|
|
||||||
resolveRunEnemyTurn,
|
resolveRunEnemyTurn,
|
||||||
resolveRunPlayerTurn,
|
resolveRunPlayerTurn,
|
||||||
startCombatInCurrentRoom,
|
startCombatInCurrentRoom,
|
||||||
@@ -176,7 +175,7 @@ describe("run state flow", () => {
|
|||||||
run: withCombat,
|
run: withCombat,
|
||||||
manoeuvreId: "manoeuvre.guard-break",
|
manoeuvreId: "manoeuvre.guard-break",
|
||||||
targetEnemyId: withCombat.activeCombat!.enemies[0]!.id,
|
targetEnemyId: withCombat.activeCombat!.enemies[0]!.id,
|
||||||
roller: createSequenceRoller([6, 6, 5]),
|
roller: createSequenceRoller([6, 6]),
|
||||||
at: "2026-03-15T14:03:00.000Z",
|
at: "2026-03-15T14:03:00.000Z",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -185,26 +184,6 @@ describe("run state flow", () => {
|
|||||||
expect(result.run.dungeon.levels["1"]!.rooms["room.level1.start"]!.encounter?.rewardPending).toBe(
|
expect(result.run.dungeon.levels["1"]!.rooms["room.level1.start"]!.encounter?.rewardPending).toBe(
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
expect(result.run.adventurerSnapshot.xp).toBe(2);
|
|
||||||
expect(result.run.xpGained).toBe(2);
|
|
||||||
expect(result.run.adventurerSnapshot.inventory.currency.gold).toBe(2);
|
|
||||||
expect(result.run.goldGained).toBe(2);
|
|
||||||
expect(result.run.defeatedCreatureIds).toEqual(["creature.level1.guard"]);
|
|
||||||
expect(result.run.lootedItems).toEqual([
|
|
||||||
{
|
|
||||||
definitionId: "item.silver-clasp",
|
|
||||||
quantity: 1,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
expect(result.run.adventurerSnapshot.inventory.carried).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
definitionId: "item.silver-clasp",
|
|
||||||
quantity: 1,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
expect(result.run.log.at(-1)?.text).toContain("Victory rewards");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("lists available traversable exits for the current room", () => {
|
it("lists available traversable exits for the current room", () => {
|
||||||
@@ -248,25 +227,4 @@ describe("run state flow", () => {
|
|||||||
);
|
);
|
||||||
expect(result.run.log[0]?.text).toContain("Travelled north");
|
expect(result.run.log[0]?.text).toContain("Travelled north");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("flags combat-ready rooms once entry resolves a hostile encounter", () => {
|
|
||||||
const run = createRunState({
|
|
||||||
content: sampleContentPack,
|
|
||||||
campaignId: "campaign.1",
|
|
||||||
adventurer: createAdventurer(),
|
|
||||||
at: "2026-03-15T14:00:00.000Z",
|
|
||||||
});
|
|
||||||
const room = run.dungeon.levels["1"]!.rooms["room.level1.start"]!;
|
|
||||||
|
|
||||||
room.encounter = {
|
|
||||||
id: `${room.id}.encounter`,
|
|
||||||
sourceTableCode: "L1G",
|
|
||||||
creatureIds: ["a", "b"],
|
|
||||||
creatureNames: ["Guard", "Warrior"],
|
|
||||||
resultLabel: "Guard and Warrior",
|
|
||||||
resolved: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(isCurrentRoomCombatReady(run)).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import type {
|
|||||||
RunState,
|
RunState,
|
||||||
} from "@/types/state";
|
} from "@/types/state";
|
||||||
import type { LogEntry } from "@/types/rules";
|
import type { LogEntry } from "@/types/rules";
|
||||||
import { findCreatureById } from "@/data/contentHelpers";
|
|
||||||
|
|
||||||
import { startCombatFromRoom } from "./combat";
|
import { startCombatFromRoom } from "./combat";
|
||||||
import { resolveCombatLoot } from "./loot";
|
|
||||||
import {
|
import {
|
||||||
resolveEnemyTurn,
|
resolveEnemyTurn,
|
||||||
resolvePlayerAttack,
|
resolvePlayerAttack,
|
||||||
@@ -164,10 +162,6 @@ function cloneRun(run: RunState): RunState {
|
|||||||
globalFlags: [...run.dungeon.globalFlags],
|
globalFlags: [...run.dungeon.globalFlags],
|
||||||
},
|
},
|
||||||
activeCombat: run.activeCombat ? cloneCombat(run.activeCombat) : undefined,
|
activeCombat: run.activeCombat ? cloneCombat(run.activeCombat) : undefined,
|
||||||
defeatedCreatureIds: [...run.defeatedCreatureIds],
|
|
||||||
xpGained: run.xpGained,
|
|
||||||
goldGained: run.goldGained,
|
|
||||||
lootedItems: run.lootedItems.map((entry) => ({ ...entry })),
|
|
||||||
log: run.log.map((entry) => ({
|
log: run.log.map((entry) => ({
|
||||||
...entry,
|
...entry,
|
||||||
relatedIds: entry.relatedIds ? [...entry.relatedIds] : undefined,
|
relatedIds: entry.relatedIds ? [...entry.relatedIds] : undefined,
|
||||||
@@ -238,80 +232,6 @@ function appendLogs(run: RunState, logEntries: LogEntry[]) {
|
|||||||
run.log.push(...logEntries);
|
run.log.push(...logEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRewardLog(
|
|
||||||
id: string,
|
|
||||||
at: string,
|
|
||||||
text: string,
|
|
||||||
relatedIds: string[],
|
|
||||||
): LogEntry {
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
at,
|
|
||||||
type: "progression",
|
|
||||||
text,
|
|
||||||
relatedIds,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyCombatRewards(
|
|
||||||
content: ContentPack,
|
|
||||||
run: RunState,
|
|
||||||
completedCombat: CombatState,
|
|
||||||
roller: DiceRoller | undefined,
|
|
||||||
at: string,
|
|
||||||
) {
|
|
||||||
const defeatedCreatureIds = completedCombat.enemies
|
|
||||||
.filter((enemy) => enemy.hpCurrent === 0 && enemy.sourceDefinitionId)
|
|
||||||
.map((enemy) => enemy.sourceDefinitionId!);
|
|
||||||
const xpAwarded = defeatedCreatureIds.reduce((total, creatureId) => {
|
|
||||||
return total + (findCreatureById(content, creatureId).xpReward ?? 0);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
run.defeatedCreatureIds.push(...defeatedCreatureIds);
|
|
||||||
run.xpGained += xpAwarded;
|
|
||||||
run.adventurerSnapshot.xp += xpAwarded;
|
|
||||||
|
|
||||||
const lootResult = resolveCombatLoot({
|
|
||||||
content,
|
|
||||||
combat: completedCombat,
|
|
||||||
inventory: run.adventurerSnapshot.inventory,
|
|
||||||
roller,
|
|
||||||
at,
|
|
||||||
});
|
|
||||||
|
|
||||||
run.adventurerSnapshot.inventory = lootResult.inventory;
|
|
||||||
run.goldGained += lootResult.goldAwarded;
|
|
||||||
|
|
||||||
for (const item of lootResult.itemsAwarded) {
|
|
||||||
const existing = run.lootedItems.find(
|
|
||||||
(entry) => entry.definitionId === item.definitionId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
existing.quantity += item.quantity;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
run.lootedItems.push({ ...item });
|
|
||||||
}
|
|
||||||
const rewardLogs = [...lootResult.logEntries];
|
|
||||||
|
|
||||||
if (xpAwarded === 0 && lootResult.goldAwarded === 0 && lootResult.itemsAwarded.length === 0) {
|
|
||||||
return rewardLogs;
|
|
||||||
}
|
|
||||||
|
|
||||||
rewardLogs.push(
|
|
||||||
createRewardLog(
|
|
||||||
`${completedCombat.id}.rewards`,
|
|
||||||
at,
|
|
||||||
`Victory rewards: gained ${xpAwarded} XP, ${lootResult.goldAwarded} gold, and ${lootResult.itemsAwarded.reduce((total, item) => total + item.quantity, 0)} loot item${lootResult.itemsAwarded.reduce((total, item) => total + item.quantity, 0) === 1 ? "" : "s"} from ${defeatedCreatureIds.length} defeated creature${defeatedCreatureIds.length === 1 ? "" : "s"}.`,
|
|
||||||
[completedCombat.id, ...defeatedCreatureIds],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return rewardLogs;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createRunState(options: CreateRunOptions): RunState {
|
export function createRunState(options: CreateRunOptions): RunState {
|
||||||
const at = options.at ?? new Date().toISOString();
|
const at = options.at ?? new Date().toISOString();
|
||||||
const levelState = initializeDungeonLevel({
|
const levelState = initializeDungeonLevel({
|
||||||
@@ -336,10 +256,6 @@ export function createRunState(options: CreateRunOptions): RunState {
|
|||||||
globalFlags: [],
|
globalFlags: [],
|
||||||
},
|
},
|
||||||
adventurerSnapshot: options.adventurer,
|
adventurerSnapshot: options.adventurer,
|
||||||
defeatedCreatureIds: [],
|
|
||||||
xpGained: 0,
|
|
||||||
goldGained: 0,
|
|
||||||
lootedItems: [],
|
|
||||||
log: [],
|
log: [],
|
||||||
pendingEffects: [],
|
pendingEffects: [],
|
||||||
};
|
};
|
||||||
@@ -382,16 +298,6 @@ export function getAvailableMoves(run: RunState): AvailableMove[] {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCurrentRoomCombatReady(run: RunState) {
|
|
||||||
const room = requireCurrentRoom(run);
|
|
||||||
|
|
||||||
return Boolean(
|
|
||||||
room.encounter?.resolved &&
|
|
||||||
room.encounter.creatureNames &&
|
|
||||||
room.encounter.creatureNames.length > 0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function travelCurrentExit(
|
export function travelCurrentExit(
|
||||||
options: TravelCurrentExitOptions,
|
options: TravelCurrentExitOptions,
|
||||||
): RunTransitionResult {
|
): RunTransitionResult {
|
||||||
@@ -521,17 +427,9 @@ export function resolveRunPlayerTurn(
|
|||||||
appendLogs(run, result.logEntries);
|
appendLogs(run, result.logEntries);
|
||||||
|
|
||||||
if (result.combatEnded) {
|
if (result.combatEnded) {
|
||||||
const completedCombat = result.combat;
|
|
||||||
const levelState = requireCurrentLevel(run);
|
const levelState = requireCurrentLevel(run);
|
||||||
const roomId = requireCurrentRoomId(run);
|
const roomId = requireCurrentRoomId(run);
|
||||||
const room = levelState.rooms[roomId];
|
const room = levelState.rooms[roomId];
|
||||||
const rewardLogs = applyCombatRewards(
|
|
||||||
options.content,
|
|
||||||
run,
|
|
||||||
completedCombat,
|
|
||||||
options.roller,
|
|
||||||
options.at ?? new Date().toISOString(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (room?.encounter) {
|
if (room?.encounter) {
|
||||||
room.encounter.rewardPending = false;
|
room.encounter.rewardPending = false;
|
||||||
@@ -539,7 +437,6 @@ export function resolveRunPlayerTurn(
|
|||||||
}
|
}
|
||||||
|
|
||||||
run.activeCombat = undefined;
|
run.activeCombat = undefined;
|
||||||
appendLogs(run, rewardLogs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -214,10 +214,6 @@ export const runStateSchema = z.object({
|
|||||||
dungeon: dungeonStateSchema,
|
dungeon: dungeonStateSchema,
|
||||||
adventurerSnapshot: adventurerStateSchema,
|
adventurerSnapshot: adventurerStateSchema,
|
||||||
activeCombat: combatStateSchema.optional(),
|
activeCombat: combatStateSchema.optional(),
|
||||||
defeatedCreatureIds: z.array(z.string()),
|
|
||||||
xpGained: z.number().int().nonnegative(),
|
|
||||||
goldGained: z.number().int().nonnegative(),
|
|
||||||
lootedItems: z.array(inventoryEntrySchema),
|
|
||||||
log: z.array(logEntrySchema),
|
log: z.array(logEntrySchema),
|
||||||
pendingEffects: z.array(ruleEffectSchema),
|
pendingEffects: z.array(ruleEffectSchema),
|
||||||
});
|
});
|
||||||
|
|||||||
164
src/styles.css
164
src/styles.css
@@ -98,39 +98,6 @@ select {
|
|||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert-banner {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 1rem;
|
|
||||||
align-items: center;
|
|
||||||
margin-top: 1rem;
|
|
||||||
padding: 1rem 1.2rem;
|
|
||||||
border: 1px solid rgba(255, 176, 94, 0.3);
|
|
||||||
background:
|
|
||||||
linear-gradient(90deg, rgba(117, 43, 21, 0.92), rgba(48, 22, 18, 0.92)),
|
|
||||||
rgba(48, 22, 18, 0.92);
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-kicker {
|
|
||||||
display: block;
|
|
||||||
color: #ffbf78;
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.12em;
|
|
||||||
font-size: 0.74rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-banner strong {
|
|
||||||
display: block;
|
|
||||||
margin-top: 0.25rem;
|
|
||||||
font-size: 1.15rem;
|
|
||||||
color: #fff4de;
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-banner p {
|
|
||||||
margin: 0.35rem 0 0;
|
|
||||||
color: rgba(244, 239, 227, 0.82);
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard-grid {
|
.dashboard-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(12, minmax(0, 1fr));
|
grid-template-columns: repeat(12, minmax(0, 1fr));
|
||||||
@@ -152,13 +119,6 @@ select {
|
|||||||
rgba(25, 19, 16, 0.9);
|
rgba(25, 19, 16, 0.9);
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-inventory {
|
|
||||||
grid-column: span 8;
|
|
||||||
background:
|
|
||||||
linear-gradient(180deg, rgba(43, 32, 24, 0.92), rgba(22, 17, 14, 0.92)),
|
|
||||||
rgba(25, 19, 16, 0.9);
|
|
||||||
}
|
|
||||||
|
|
||||||
.panel-log {
|
.panel-log {
|
||||||
grid-column: span 12;
|
grid-column: span 12;
|
||||||
}
|
}
|
||||||
@@ -191,7 +151,6 @@ select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stat-strip div,
|
.stat-strip div,
|
||||||
.inventory-badge,
|
|
||||||
.encounter-box,
|
.encounter-box,
|
||||||
.combat-status {
|
.combat-status {
|
||||||
padding: 0.9rem;
|
padding: 0.9rem;
|
||||||
@@ -200,8 +159,6 @@ select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stat-strip span,
|
.stat-strip span,
|
||||||
.inventory-badge span,
|
|
||||||
.inventory-label,
|
|
||||||
.encounter-label,
|
.encounter-label,
|
||||||
.combat-status span,
|
.combat-status span,
|
||||||
.room-meta span,
|
.room-meta span,
|
||||||
@@ -214,7 +171,6 @@ select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stat-strip strong,
|
.stat-strip strong,
|
||||||
.inventory-badge strong,
|
|
||||||
.encounter-box strong,
|
.encounter-box strong,
|
||||||
.combat-status strong {
|
.combat-status strong {
|
||||||
display: block;
|
display: block;
|
||||||
@@ -228,81 +184,6 @@ select {
|
|||||||
color: rgba(244, 239, 227, 0.76);
|
color: rgba(244, 239, 227, 0.76);
|
||||||
}
|
}
|
||||||
|
|
||||||
.inventory-summary,
|
|
||||||
.inventory-grid {
|
|
||||||
display: grid;
|
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-summary {
|
|
||||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-grid {
|
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-section {
|
|
||||||
padding: 1rem;
|
|
||||||
border: 1px solid rgba(255, 231, 196, 0.08);
|
|
||||||
background:
|
|
||||||
linear-gradient(180deg, rgba(255, 245, 223, 0.04), rgba(255, 245, 223, 0.02));
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-label {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 0.7rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-list,
|
|
||||||
.loot-ribbon-list {
|
|
||||||
display: grid;
|
|
||||||
gap: 0.65rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-card,
|
|
||||||
.loot-pill {
|
|
||||||
padding: 0.85rem 0.9rem;
|
|
||||||
border: 1px solid rgba(255, 231, 196, 0.08);
|
|
||||||
background: rgba(11, 8, 7, 0.32);
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-card strong,
|
|
||||||
.loot-pill strong {
|
|
||||||
display: block;
|
|
||||||
color: #fff2d6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-card span {
|
|
||||||
display: block;
|
|
||||||
margin-top: 0.25rem;
|
|
||||||
color: rgba(244, 239, 227, 0.62);
|
|
||||||
font-size: 0.84rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-card-equipped {
|
|
||||||
border-color: rgba(113, 176, 152, 0.35);
|
|
||||||
background: rgba(56, 86, 73, 0.18);
|
|
||||||
}
|
|
||||||
|
|
||||||
.inventory-card-treasure,
|
|
||||||
.loot-pill {
|
|
||||||
border-color: rgba(214, 168, 86, 0.35);
|
|
||||||
background: rgba(111, 76, 20, 0.18);
|
|
||||||
}
|
|
||||||
|
|
||||||
.loot-ribbon {
|
|
||||||
margin-top: 1rem;
|
|
||||||
padding-top: 1rem;
|
|
||||||
border-top: 1px solid rgba(255, 231, 196, 0.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
.loot-ribbon-list {
|
|
||||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
|
||||||
margin-top: 0.7rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.room-title {
|
.room-title {
|
||||||
margin: 0 0 0.35rem;
|
margin: 0 0 0.35rem;
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
@@ -363,20 +244,17 @@ select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.move-list,
|
.move-list,
|
||||||
.mini-map,
|
.mini-map {
|
||||||
.enemy-list {
|
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mini-map,
|
.mini-map {
|
||||||
.enemy-list {
|
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.move-card,
|
.move-card,
|
||||||
.map-node,
|
.map-node {
|
||||||
.enemy-card {
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding: 0.95rem;
|
padding: 0.95rem;
|
||||||
@@ -413,16 +291,14 @@ select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.move-card strong,
|
.move-card strong,
|
||||||
.map-node strong,
|
.map-node strong {
|
||||||
.enemy-card strong {
|
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 0.3rem;
|
margin-top: 0.3rem;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
color: #fff2d6;
|
color: #fff2d6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.move-card em,
|
.move-card em {
|
||||||
.enemy-card span {
|
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 0.3rem;
|
margin-top: 0.3rem;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
@@ -434,6 +310,28 @@ select {
|
|||||||
background: rgba(243, 186, 115, 0.12);
|
background: rgba(243, 186, 115, 0.12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.enemy-list {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.enemy-card {
|
||||||
|
padding: 0.95rem;
|
||||||
|
border: 1px solid rgba(255, 231, 196, 0.08);
|
||||||
|
background: rgba(255, 245, 223, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.enemy-card strong {
|
||||||
|
display: block;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
color: #fff2d6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.enemy-card span {
|
||||||
|
color: rgba(244, 239, 227, 0.66);
|
||||||
|
}
|
||||||
|
|
||||||
.log-list {
|
.log-list {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
@@ -466,8 +364,7 @@ select {
|
|||||||
padding-top: 0.75rem;
|
padding-top: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hero,
|
.hero {
|
||||||
.alert-banner {
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
}
|
}
|
||||||
@@ -479,9 +376,4 @@ select {
|
|||||||
.stat-strip {
|
.stat-strip {
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
.inventory-summary,
|
|
||||||
.inventory-grid {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,10 +215,6 @@ export type RunState = {
|
|||||||
dungeon: DungeonState;
|
dungeon: DungeonState;
|
||||||
adventurerSnapshot: AdventurerState;
|
adventurerSnapshot: AdventurerState;
|
||||||
activeCombat?: CombatState;
|
activeCombat?: CombatState;
|
||||||
defeatedCreatureIds: string[];
|
|
||||||
xpGained: number;
|
|
||||||
goldGained: number;
|
|
||||||
lootedItems: InventoryEntry[];
|
|
||||||
log: LogEntry[];
|
log: LogEntry[];
|
||||||
pendingEffects: RuleEffect[];
|
pendingEffects: RuleEffect[];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user