Files
dflike/CLAUDE.md
T
root 458fd99495 docs: update CLAUDE.md and README.md for NPC stats system
- Fix stale test count (29 -> 86) and system order in CLAUDE.md
- Add new key entry points for stat system files
- Add shared build command
- Document stat conventions (3d6, modifiers, drift, wire protocol)
- Add NPC Stats section to README with stat descriptions and effects
- Add Game Constants table pointing to shared/src/constants.ts
- Update follow mode description with stats display

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 14:49:02 +00:00

3.4 KiB

CLAUDE.md

Project

Multiplayer NPC simulation game (Dwarf Fortress-inspired). Server-authoritative ECS architecture.

Structure

  • shared/ -- Types and constants (no runtime code)
  • server/ -- Node.js + Socket.io game server with ECS
  • client/ -- Phaser 3 + TypeScript renderer
  • chars/ -- Character sprite assets (do not modify)
  • docs/plans/ -- Design and implementation docs

Commands

  • npm install -- install all workspace dependencies
  • npm -w server run dev -- start server (port 3001)
  • npm -w server run test -- run server tests (86 tests)
  • npm -w server run test:watch -- run server tests in watch mode
  • npm -w client run dev -- start client dev server (port 3000)
  • npm -w client run build -- build client for production
  • npx -w shared tsc -- rebuild shared types (required after modifying shared/src/)

Tooling

  • ESM modules throughout ("type": "module")
  • Server: tsx (runtime), vitest (tests)
  • Client: vite (bundler), Phaser 3
  • Shared: compiled to shared/dist/ (auto-built)

Key Entry Points

  • server/src/main.ts -- server startup
  • server/src/game/GameLoop.ts -- tick loop orchestration
  • server/src/spawner/appearanceGenerator.ts -- NPC appearance + portrait feature generation
  • server/src/spawner/nameGenerator.ts -- NPC name generation
  • server/src/spawner/statGenerator.ts -- 3d6 stat generation for NPCs
  • server/src/systems/statHelpers.ts -- getEffectiveStat (base + modifiers, clamped 3-18)
  • server/src/systems/statModifierSystem.ts -- modifier decay and needs-based modifiers
  • server/src/systems/socialSystem.ts -- NPC social interaction phases and stat integration
  • client/src/main.ts -- Phaser game bootstrap
  • client/src/scenes/GameScene.ts -- main game scene (camera/avatar/follow modes)
  • client/src/sprites/CharacterCompositor.ts -- sprite layer compositing
  • client/src/sprites/PortraitCompositor.ts -- portrait layer compositing (data URL output)
  • client/src/ui/NpcInfoPanel.ts -- follow-mode NPC info panel (HTML/CSS overlay)
  • shared/src/types.ts -- protocol types
  • shared/src/constants.ts -- game constants (incl. portrait slots, folder mapping)

Key Conventions

  • ECS components are plain data objects, systems are pure functions
  • Server owns all game state; clients are renderers
  • Character sprites are 48x48 per frame, 6 cols x 4 rows spritesheet layout
  • Compositing: skins + accessories layered in z-order, cached as single textures
  • Portraits: skin-specific layers composited client-side, exported as data URLs for HTML panel
  • Portrait assets are in chars/baseman/accessories/portraits/ organized by skin folder (skin01-07)
  • Sprite skin shape00_skinXX maps to portrait folder skin{XX+1}, base file skin{XX}.png
  • Shared types ensure client/server protocol agreement
  • Systems run in order: statModifier -> needsDecay -> npcBrain -> social -> movement -> broadcast
  • Follow mode shows EarthBound-styled NPC info panel with live-updating needs bars and stats
  • NPC stats use 3d6 generation (range 3-18, bell curve): 5 physical (STR/DEX/CON/INT/PER) + 5 personality (SOC/COU/CUR/EMP/TMP)
  • Stats have transient modifiers (needs-based permanent + event-based decaying); effective value = base + modifiers, clamped 3-18
  • Base stats are floats (drift slowly from experience); getEffectiveStat floors to int for gameplay use
  • Wire protocol sends effective (computed) stats only; modifiers stay server-side