Skip to content

Chapter 6 — Modules

Part II — Engine Architecture

How mechanics plug into the engine.

  • Module lifecycleregister(), init(), teardown()
  • Event listeners — subscribing to simulation events
  • Formula registration — contributing calculations to the engine
  • Namespaced state — per-module data attached to world state

Over 30 modules ship in the @ai-rpg-engine/modules package:

ModulePurpose
traversal-coreMovement between zones
combat-coreAttack, guard, disengage resolution, damage, defeat
inventory-coreItem management and usage
dialogue-coreConversation trees and state
status-coreBuffs, debuffs, and timed effects
cognition-coreAI beliefs, memory, morale, and intent
perception-filterEntity-level truth layers with sensory channels
progression-coreCurrency, trees, and advancement
environment-coreDynamic zone properties, hazards, and decay
narrative-authorityTruth concealment, distortion, and contradiction tracking
ModulePurpose
combat-tacticsTactical triangle (brace, reposition), round flags
combat-resourcesGenre resource integration (gains, spends, drains)
combat-intentAI combat decision scoring with pack biases
combat-reviewFormula tracing and combat transparency
combat-recoveryPost-combat wounds, morale aftermath
combat-state-narrationNarrative descriptions of combat state changes
engagement-coreEngagement states (engaged, protected, backline, isolated)
engagement-narrationNarrative descriptions of engagement changes
defeat-falloutPost-defeat consequences
defeat-narrationNarrative descriptions of defeat events
combat-rolesRole templates, encounter composition, boss phases
encounter-libraryReusable encounter archetypes (patrol, ambush, horde, duel, boss)
combat-summaryEncounter auditing, region summaries, combat content overview
ModulePurpose
ability-coreAbility resolution with costs, cooldowns, stat checks
ability-effectsTyped effect handlers (damage, heal, status apply, cleanse)
ability-reviewAbility trace recording
ability-intentAI ability scoring with self/AoE/single-target evaluation
ability-buildersHelper functions for common ability patterns
ability-summaryPack auditing and cross-pack comparison
status-semantics11-tag semantic vocabulary, resistance/vulnerability
unified-decisionMerges combat + ability scoring into one decision
ModulePurpose
faction-cognitionFaction-level shared beliefs with propagation delay
rumor-propagationKnowledge spreading between entities and factions
district-coreZone-level event aggregation into district metrics
district-moodDistrict mood computation and modifiers
belief-provenanceEnd-to-end belief trace reconstruction
observer-presentationSubjective event rendering per observer
social-consequenceStance derivation, reputation consequences, title evolution
player-rumorPlayer-originated rumors with mutation and spread
pressure-systemWorld pressures that drive faction and NPC behavior
pressure-resolutionPressure fallout computation
faction-agencyFaction goal evaluation and autonomous action
player-leverageStructured social play (social, rumor, diplomacy, sabotage verbs)
npc-agencyNPC goal evaluation, obligations, consequence chains
item-recognitionNPC item recognition based on knowledge and context
companion-coreParty state, companion morale, cohesion
companion-reactionsCompanion departure risk and reaction evaluation
ModulePurpose
strategic-mapDistrict, faction, and hotspot aggregation
move-advisorDeterministic scoring engine for action recommendations
opportunity-coreEmergent opportunity generation and lifecycle
opportunity-resolutionOpportunity fallout computation
arc-detectionStory arc momentum tracking
endgame-detectionEndgame trigger evaluation
economy-coreDistrict-level supply tracking
trade-valueContext-sensitive item valuation
crafting-coreMaterial tracking and salvage
crafting-recipesRecipe resolution, repair, modification
tag-taxonomyTag classification and validation

Modules extend the engine without modifying core. Each module is self-contained, registering its verbs, event handlers, and formulas during initialization.

Use buildCombatStack() to wire the combat modules automatically. See the Composition Guide for the recommended approach.

These packages provide types and logic that work independently or alongside the built-in modules. Install them separately from npm.

PackagePurpose
@ai-rpg-engine/presentationNarration plan schema, render contracts, voice profiles
@ai-rpg-engine/audio-directorCue scheduling, priority, ducking, cooldown logic
@ai-rpg-engine/soundpack-coreSound pack manifests, content-addressable registry
@ai-rpg-engine/campaign-memoryPersistent NPC memory, relationship axes, campaign journal
@ai-rpg-engine/rumor-systemRumor lifecycle, mutation mechanics, spread tracking
@ai-rpg-engine/character-creationArchetypes, backgrounds, traits, multiclassing, build validation
@ai-rpg-engine/asset-registryContent-addressed storage for portraits, icons, and media
@ai-rpg-engine/image-genHeadless portrait generation pipeline with provider abstraction
@ai-rpg-engine/equipmentEquipment slots, item catalogs, and loadout management
@ai-rpg-engine/character-profilePersistent character profiles with progression, injuries, and save/load

Standalone packages have no engine dependency — they define types and logic that game runtimes consume. The built-in modules handle engine integration (event listeners, world state mutation), while standalone packages handle domain logic (how memories decay, how rumors mutate).

Pre-built worlds that wire modules with genre-specific rulesets, content, and progression. Each is a composition example demonstrating different patterns.

PackageGenreStatsUnique Verbs
@ai-rpg-engine/starter-fantasyDark fantasyvigor, instinct, willpray, rest
@ai-rpg-engine/starter-cyberpunkCyberpunkchrome, reflex, netrunningjack-in
@ai-rpg-engine/starter-detectiveVictorian mysteryperception, eloquence, gritinterrogate, deduce
@ai-rpg-engine/starter-pirateHigh-seas piratebrawn, cunning, sea-legsplunder, navigate
@ai-rpg-engine/starter-zombieZombie survivalfitness, wits, nervebarricade, scavenge
@ai-rpg-engine/starter-weird-westWeird westgrit, draw-speed, loredraw, commune
@ai-rpg-engine/starter-colonySci-fi colonyengineering, command, awarenessscan, allocate
@ai-rpg-engine/starter-roninFeudal Japandiscipline, reflex, honormeditate, shadow-step
@ai-rpg-engine/starter-vampireVampire horrorpresence, cunning, bloodlinefeed, mesmerize
@ai-rpg-engine/starter-gladiatorHistorical gladiatormight, agility, showmanshiptaunt, rally