Implement the 026-roll-initiative feature that adds d20 roll buttons for bestiary combatants' initiative using a click-to-edit pattern (d20 icon when empty, plain text when set), plus a Roll All button in the top bar that batch-rolls for all unrolled bestiary combatants, with randomness confined to the adapter layer and the domain receiving pre-resolved dice values
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
21
packages/domain/src/roll-initiative.ts
Normal file
21
packages/domain/src/roll-initiative.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { DomainError } from "./types.js";
|
||||
|
||||
/**
|
||||
* Pure function that computes initiative from a resolved dice roll and modifier.
|
||||
* The dice roll must be an integer in [1, 20].
|
||||
* Returns the sum (diceRoll + modifier) or a DomainError for invalid inputs.
|
||||
*/
|
||||
export function rollInitiative(
|
||||
diceRoll: number,
|
||||
modifier: number,
|
||||
): number | DomainError {
|
||||
if (!Number.isInteger(diceRoll) || diceRoll < 1 || diceRoll > 20) {
|
||||
return {
|
||||
kind: "domain-error",
|
||||
code: "invalid-dice-roll",
|
||||
message: `Dice roll must be an integer between 1 and 20, got ${diceRoll}`,
|
||||
};
|
||||
}
|
||||
|
||||
return diceRoll + modifier;
|
||||
}
|
||||
Reference in New Issue
Block a user