feat: add character creation utility functions
This commit is contained in:
parent
34583c8eff
commit
6ecdda51f6
1 changed files with 48 additions and 0 deletions
48
client/src/utils/character-creation.ts
Normal file
48
client/src/utils/character-creation.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import { getModifier } from "./modifiers.js";
|
||||||
|
import { getShadowdarkTitle } from "./shadowdark-titles.js";
|
||||||
|
|
||||||
|
const CLASS_HIT_DIE: Record<string, number> = {
|
||||||
|
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<string, number> {
|
||||||
|
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) ?? "";
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue