Initial commit

This commit is contained in:
2026-09-22 16:27:53 +02:00
commit 9b29dc8253
70 changed files with 14726 additions and 0 deletions
+150
View File
@@ -0,0 +1,150 @@
# D&D 5e Rules Reference — Implementation Spec
This is the canonical math the backend must implement. Build it as a single shared
calculation module (e.g. `backend/src/game/calculations.ts`) that is the **only**
place these formulas live — every API route and the character builder call into it
rather than re-deriving numbers. This mirrors the logic already built and verified
in the "DnD Character Sheet Calculator.xlsx" workbook delivered earlier in this
project; treat that workbook as the reference implementation if anything below is
ambiguous.
All rules are 5e (2014 core rules).
## Ability Modifier
```
modifier = floor((score - 10) / 2)
```
Use `Math.floor`, not integer truncation — they differ for negative results
(e.g. score 7 → (7-10)/2 = -1.5 → floor = -2, not -1).
## Proficiency Bonus
```
proficiencyBonus = 2 + floor((level - 1) / 4)
```
Level 1–4 → +2, 5–8 → +3, 9–12 → +4, 13–16 → +5, 17–20 → +6.
## Final Ability Score
```
finalScore = rolledScore + speciesBonus(ability, species)
```
`speciesBonus` comes from the Species Ability Score Increase table below. See
`seed-data/species.json`.
## Saving Throws
```
saveBonus = abilityModifier + (proficient ? proficiencyBonus : 0)
```
Proficiency per ability comes from the Class Quick Facts table (`seed-data/classes.json`).
## Skills
```
skillBonus = governingAbilityModifier + (proficient ? proficiencyBonus : 0)
```
Governing ability per skill is fixed — see `seed-data/skills.json`. Proficiency is
a per-character, per-skill boolean the player/DM sets during character building
(`CharacterSkillProficiency` in the Prisma schema).
Passive Perception:
```
passivePerception = 10 + perceptionSkillBonus
```
## Armor Class
```
armorClass = 10 + dexModifier + armorBonus
```
`armorBonus` is a flat number the player enters representing whatever armor/shield
they have equipped (this matches the workbook's "Armor Bonus (from armor worn)"
input cell). Do not try to model armor types as a lookup table unless you want to
extend scope later — a plain integer field on `Character` is enough for v1.
## Initiative
```
initiative = dexModifier
```
## Speed
Comes from the species table (30 ft standard; 25 ft for Gnome, Dwarf, Halfling).
Store as `speed` on the species seed data; characters may override it
(`speedOverride` on `Character`) for future feature support (e.g. barbarian speed
boosts) without a schema change.
## Hit Points
Hit Die size comes from class (`seed-data/classes.json`).
```
hpMax(level) =
if level === 1:
hitDieMax + conModifier
else:
hitDieMax + conModifier
+ (level - 1) * (floor(hitDieSize / 2) + 1 + conModifier)
```
Important: **level 1 always uses the maximum possible roll of the Hit Die**, not
the average. Every level after 1 uses the fixed "average" value
`floor(hitDieSize / 2) + 1` (e.g. d10 → 6, d6 → 4, d12 → 7) plus the CON modifier
again. This was a bug caught and fixed while building the Excel calculator —
do not regress it.
`hitDice` available to spend on a short rest = character level (one die of the
class's Hit Die size per level).
## Spellcasting (only for classes with a Spellcasting Ability ≠ "None")
```
spellSaveDC = 8 + proficiencyBonus + spellcastingAbilityModifier
spellAttackBonus = proficiencyBonus + spellcastingAbilityModifier
```
Spellcasting ability per class is in `seed-data/classes.json` (Intelligence,
Wisdom, or Charisma). Classes with `"None"` have no spellcasting stats — the UI
should hide those fields entirely rather than show them as zero/blank.
## Species Ability Score Increases & Speed
See `seed-data/species.json` for the full table (10 species). Note: Half-Elf gets
+2 Charisma fixed, plus +1 to **two other** abilities of the player's choice — the
seed data defaults that flexible pair to STR/INT, but the character builder UI
must let the player pick which two abilities get the +1 during Half-Elf
character creation (don't hardcode the default in the UI).
## Class Quick Facts
See `seed-data/classes.json` for the full table (12 classes): Hit Die, Primary
Ability, the two Saving Throw proficiencies, and Spellcasting Ability.
## Skill → Governing Ability
See `seed-data/skills.json` (18 skills).
## "Quick Stats" View (combat-context panel)
When the frontend shows the contextual quick-stats panel during an attack action,
surface exactly these derived values (all computed via the module above, never
stored redundantly):
- Attack bonus for the equipped/selected weapon: `proficiencyBonus (if proficient) + relevantAbilityModifier` (STR normally, DEX for finesse/ranged weapons — see `seed-data/weapons.json`'s `attackAbility` field, which is `"STR"`, `"DEX"`, or `"FINESSE"` meaning "use whichever of STR/DEX is higher")
- Damage: weapon's damage dice + relevant ability modifier
- Current HP / Max HP / Temp HP
- AC
- Any special abilities/features flagged on the character (free-text list is fine for v1 — a `specialAbilities` text/JSON field on `Character` or a simple related table)
This is a read view assembled from existing data — it does not need its own
schema table.
+107
View File
@@ -0,0 +1,107 @@
# Roll-Your-Character Build Flow — Implementation Spec
This is the guided, dice-driven character creation flow referenced in the build
prompt. It should work for both a DM building a character for a player and a
player building their own, and the UI must tell the user exactly which die to
roll at each step (this is the whole point of the feature — it should feel like
rolling at a physical table, not filling out a form).
Model this as a state machine on `Character.buildStage` (see Prisma schema) with
the in-progress rolls/choices held in `Character.buildState` (JSON) until the
build is finalized, at which point the real columns (`species`, `characterClass`,
ability scores, proficiencies) get set and `buildStage` becomes `COMPLETE`.
## Step 1 — Roll Species (d6)
Tell the player: **"Roll a d6."** Then offer the choice(s) that result maps to.
Most rolls offer 2 species to pick between; keep the flavor text short.
| d6 Roll | Choose between |
|---|---|
| 1 | Human or Half-Elf |
| 2 | Elf or Gnome |
| 3 | Dwarf or Halfling |
| 4 | Dragonborn or Tiefling |
| 5 | Half-Orc or Orc |
| 6 | Wildcard — pick any species |
If the player rolls Half-Elf, immediately prompt for which two abilities (other
than Charisma) get the flexible +1 — this choice has to happen here, not be
silently defaulted (see GAME_RULES_REFERENCE.md).
## Step 2 — Roll Class (d8)
Tell the player: **"Roll a d8."**
| d8 Roll | Choose between |
|---|---|
| 1 | Fighter or Barbarian |
| 2 | Rogue or Ranger |
| 3 | Wizard or Sorcerer |
| 4 | Cleric or Paladin |
| 5 | Bard or Warlock |
| 6 | Druid or Monk |
| 7 | Reroll once, keep either result |
| 8 | Wildcard — pick any class |
## Step 3 — Roll Motivation (d6, optional flavor)
Tell the player: **"Roll a d6"** (optional — DM can skip this step for the whole
campaign via a campaign setting).
| d6 Roll | Motivation |
|---|---|
| 1 | Revenge for a past wrong |
| 2 | Seeking fortune or wealth |
| 3 | Protecting someone they love |
| 4 | Redemption for a past mistake |
| 5 | Driven by curiosity or knowledge |
| 6 | Duty or oath to a cause or order |
Store this as free text on the character (a `motivation` field, or fold it into
`notes`) — it's flavor, not a mechanical input.
## Step 4 — Roll Ability Scores
Standard method: **roll 4d6, drop the lowest die, sum the remaining 3** — six
times, once per ability (STR, DEX, CON, INT, WIS, CHA). Let the UI roll these
(server-side, so results can't be tampered with client-side) and then let the
player **assign** each of the six results to an ability score of their choice.
Show the running math live (base roll → + species bonus → final score →
modifier) as they assign, using the calculation module from
GAME_RULES_REFERENCE.md — don't let this drift out of sync with the sheet view.
## Step 5 — Skill & Save Proficiencies
Present the 18 skills with their governing ability (`seed-data/skills.json`) and
let the player check proficiencies — respect each class's normal "choose N
skills from list" limits if you want to be strict, or keep v1 permissive (DM can
always correct it). Saving throw proficiencies are **not** a choice — they're
fixed per class (`seed-data/classes.json`) and should just be set automatically.
## Step 6 — Starting Equipment
Pull `startingItemCount` and `startingSpellCount` from the campaign's settings
(DM configures these when creating/configuring the campaign — see
`Campaign.startingItemCount` / `Campaign.startingSpellCount` in the schema).
Let the player pick that many starting items from the campaign's weapon/item
pool and, if their class has spellcasting, that many starting spells from the
campaign's spell list.
## Step 7 — Finalize
Compute and freeze HP max (`currentHp = hpMax` on finalize), AC, initiative, and
all derived stats via the calculation module. Set `buildStage = COMPLETE`. From
this point the character sheet is editable directly (level up, stat changes,
inventory, notes) rather than walking the dice flow again.
## UI Notes
- Every step should show a big, obvious "Roll d_N_" button that triggers a
server-side roll (never trust a client-submitted roll result) and animates/
displays the die result before revealing the choice(s) it maps to.
- The DM should be able to build a character for a player using this exact same
flow (same component, different "who is this for" context) — don't build two
separate builders.
- Players building their own characters need the same flow, gated to campaigns
they're a member of.