Add 2014 DMG encounter difficulty calculation
All checks were successful
CI / check (push) Successful in 2m18s
CI / build-image (push) Successful in 17s

Support the 2014 DMG encounter difficulty as an alternative to the 5.5e
system behind the existing Rules Edition toggle. The 2014 system uses
Easy/Medium/Hard/Deadly thresholds, an encounter multiplier based on
monster count, and party size adjustment (×0.5–×5 range).

- Extract RulesEdition to its own domain module
- Refactor DifficultyTier to abstract numeric values (0–3)
- Restructure DifficultyResult with thresholds array
- Add 2014 XP thresholds table and encounter multiplier logic
- Wire edition from context into difficulty hooks
- Edition-aware labels in indicator and breakdown panel
- Show multiplier, adjusted XP, and party size note for 2014
- Rename settings label from "Conditions" to "Rules Edition"
- Update spec 008 with issue #23 requirements

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-04 14:52:23 +02:00
parent 94e1806112
commit 817cfddabc
17 changed files with 892 additions and 257 deletions

View File

@@ -12,6 +12,7 @@ import {
} from "../../__tests__/factories/index.js";
import { AllProviders } from "../../__tests__/test-providers.js";
import { useDifficultyBreakdown } from "../use-difficulty-breakdown.js";
import { useRulesEdition } from "../use-rules-edition.js";
beforeAll(() => {
Object.defineProperty(globalThis, "matchMedia", {
@@ -292,4 +293,56 @@ describe("useDifficultyBreakdown", () => {
expect(breakdown?.enemyCombatants).toHaveLength(1);
expect(breakdown?.enemyCombatants[0].combatant.name).toBe("Thug");
});
it("exposes encounterMultiplier and adjustedXp for 5e edition", async () => {
const wrapper = makeWrapper({
encounter: buildEncounter({
combatants: [
buildCombatant({
id: combatantId("c-1"),
name: "Hero",
playerCharacterId: pcId1,
}),
buildCombatant({
id: combatantId("c-2"),
name: "Goblin",
creatureId: goblinCreature.id,
}),
buildCombatant({
id: combatantId("c-3"),
name: "Thug",
cr: "1",
}),
],
}),
playerCharacters: [
{ id: pcId1, name: "Hero", ac: 15, maxHp: 30, level: 1 },
],
creatures: new Map([[goblinCreature.id, goblinCreature]]),
});
const { result: editionResult } = renderHook(() => useRulesEdition(), {
wrapper,
});
editionResult.current.setEdition("5e");
try {
const { result } = renderHook(() => useDifficultyBreakdown(), {
wrapper,
});
await waitFor(() => {
const breakdown = result.current;
expect(breakdown).not.toBeNull();
// 2 enemy monsters, 1 PC (<3) → base x1.5, shift up → x2
expect(breakdown?.encounterMultiplier).toBe(2);
// CR 1/4 (50) + CR 1 (200) = 250, x2 = 500
expect(breakdown?.totalMonsterXp).toBe(250);
expect(breakdown?.adjustedXp).toBe(500);
expect(breakdown?.thresholds).toHaveLength(4);
});
} finally {
editionResult.current.setEdition("5.5e");
}
});
});