From 6ecdda51f6a7ffaa666a0a17cde4edd2f204e36b Mon Sep 17 00:00:00 2001 From: Aaron Wood Date: Sat, 11 Apr 2026 11:51:37 -0400 Subject: [PATCH] feat: add character creation utility functions --- client/src/utils/character-creation.ts | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 client/src/utils/character-creation.ts diff --git a/client/src/utils/character-creation.ts b/client/src/utils/character-creation.ts new file mode 100644 index 0000000..6b30e49 --- /dev/null +++ b/client/src/utils/character-creation.ts @@ -0,0 +1,48 @@ +import { getModifier } from "./modifiers.js"; +import { getShadowdarkTitle } from "./shadowdark-titles.js"; + +const CLASS_HIT_DIE: Record = { + Fighter: 8, + Priest: 6, + Thief: 4, + Wizard: 4, +}; + +export function roll3d6(): number { + return ( + Math.ceil(Math.random() * 6) + + Math.ceil(Math.random() * 6) + + Math.ceil(Math.random() * 6) + ); +} + +export function rollAllStats(): Record { + return { + STR: roll3d6(), + DEX: roll3d6(), + CON: roll3d6(), + INT: roll3d6(), + WIS: roll3d6(), + CHA: roll3d6(), + }; +} + +export function rollStartingHp(charClass: string, conScore: number): number { + const die = CLASS_HIT_DIE[charClass] ?? 4; + const rolled = Math.ceil(Math.random() * die); + return Math.max(1, rolled + getModifier(conScore)); +} + +export function rollStartingGold(): number { + const d1 = Math.ceil(Math.random() * 6); + const d2 = Math.ceil(Math.random() * 6); + return (d1 + d2) * 5; +} + +export function startingGearSlots(strScore: number): number { + return 10 + getModifier(strScore); +} + +export function getStartingTitle(charClass: string, alignment: string): string { + return getShadowdarkTitle(charClass, alignment, 1) ?? ""; +}