RPG System
Overview
The RPG system is the cohesive rule engine that ties together Abilities, Effects, Skills, Items, Conditions, and Events. The CharacterService applies effects in a deterministic order with full audit trail.
Stat Calculation Pipeline
initializeAbilityScores()— Creates stat map from all abilities with base valuesapplyEntityEffects(skills)— Apply skill effectsapplyEntityEffects(items)— Apply item effectsapplyEntityEffects(conditions)— Apply condition effectsapplyEntityEffects(events)— Apply event effects
Effect Application
Each effect specifies:
abilities[]— Target ability IDsstat_id— Alternative single ability targetmodifier— Integer value to add/subtractmodification— "positive" (add) or "negative" (subtract)
Entity Preloading
The CharacterService constructor preloads ALL entities into memory indexed by ID, avoiding N+1 queries during stat calculation.
Audit Trail
Every ability modification is recorded with:
- Effect that caused the change
- Old value before modification
- New value after modification
Known Issues
allowed_negativefield exists in DB but is not enforced by the stat engineAbility.phpentity does not exposebaseandallowed_negativeingetJsonFields()
Technical Details
- Service:
lib/Service/CharacterService.php - Batch processing:
calculateAllCharacters()for all characters - Single processing:
calculateCharacter(array $character)for one character