Add advantage/disadvantage rolling for initiative
All checks were successful
CI / check (push) Successful in 1m17s
CI / build-image (push) Successful in 19s

Right-click or long-press the d20 button (per-combatant or Roll All)
to open a context menu with Advantage and Disadvantage options.
Normal left-click behavior is unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-18 09:16:04 +01:00
parent 7f38cbab73
commit 6584d8d064
12 changed files with 392 additions and 46 deletions

View File

@@ -61,7 +61,7 @@ describe("rollInitiativeUseCase", () => {
const result = rollInitiativeUseCase(
store,
combatantId("unknown"),
10,
[10],
() => undefined,
);
@@ -80,7 +80,7 @@ describe("rollInitiativeUseCase", () => {
const result = rollInitiativeUseCase(
store,
combatantId("Fighter"),
10,
[10],
() => undefined,
);
@@ -96,7 +96,7 @@ describe("rollInitiativeUseCase", () => {
const result = rollInitiativeUseCase(
store,
combatantId("Goblin"),
10,
[10],
() => undefined,
);
@@ -116,7 +116,7 @@ describe("rollInitiativeUseCase", () => {
const result = rollInitiativeUseCase(
store,
combatantId("Goblin"),
10,
[10],
(id) => (id === GOBLIN_ID ? creature : undefined),
);
@@ -124,6 +124,42 @@ describe("rollInitiativeUseCase", () => {
expect(requireSaved(store.saved).combatants[0].initiative).toBe(12);
});
it("uses higher roll with advantage", () => {
const creature = makeCreature();
const enc = encounterWithCreatureLink("Goblin", GOBLIN_ID);
const store = stubEncounterStore(enc);
// Dex 14 -> modifier +2, advantage picks max(5, 15) = 15, 15 + 2 = 17
const result = rollInitiativeUseCase(
store,
combatantId("Goblin"),
[5, 15],
(id) => (id === GOBLIN_ID ? creature : undefined),
"advantage",
);
expect(isDomainError(result)).toBe(false);
expect(requireSaved(store.saved).combatants[0].initiative).toBe(17);
});
it("uses lower roll with disadvantage", () => {
const creature = makeCreature();
const enc = encounterWithCreatureLink("Goblin", GOBLIN_ID);
const store = stubEncounterStore(enc);
// Dex 14 -> modifier +2, disadvantage picks min(5, 15) = 5, 5 + 2 = 7
const result = rollInitiativeUseCase(
store,
combatantId("Goblin"),
[5, 15],
(id) => (id === GOBLIN_ID ? creature : undefined),
"disadvantage",
);
expect(isDomainError(result)).toBe(false);
expect(requireSaved(store.saved).combatants[0].initiative).toBe(7);
});
it("applies initiative proficiency bonus correctly", () => {
// CR 5 -> PB 3, dex 16 -> mod +3, initiativeProficiency 1
// modifier = 3 + 1*3 = 6, roll 8 + 6 = 14
@@ -145,7 +181,7 @@ describe("rollInitiativeUseCase", () => {
const result = rollInitiativeUseCase(
store,
combatantId("Monster"),
8,
[8],
(id) => (id === GOBLIN_ID ? creature : undefined),
);