Skip to content

Chapter 57 — Composition Guide

AI RPG Engine ships 10 starter worlds. They are examples, not templates. Each one demonstrates how to combine engine modules into a game with its own combat identity, resource economy, and narrative pressure.

This chapter shows you how to build your own game by composing the same pieces the starters use.


Every game built on the engine has the same structure:

stat mapping → combat stack → modules → content → Engine constructor

You define stats, configure combat, pick the modules you need, create your content (entities, zones, dialogue), and wire it all into new Engine(). That’s the whole pattern.

The starters add demo glue on top — scripted event listeners for item gifts, audio cues, and fallout hooks. Those are polish, not architecture.


Every game needs a stat mapping — three stat roles that drive every combat formula:

RoleWhat It DrivesExample Names
AttackDamage, guard breakthroughvigor, might, brawn, chrome, grit, fitness
PrecisionHit chance, disengage, guard counterinstinct, agility, cunning, reflex, perception, wits
ResolveGuard absorption, brace resistance, moralewill, composure, sea-legs, command, presence, nerve

The golden rule: three distinct stats, never collapse attack = resolve. If your attack and resolve map to the same stat, guard breakthrough becomes trivial and combat loses its tension.

const statMapping = { attack: 'might', precision: 'agility', resolve: 'will' };

You can define stats beyond these three — exploration stats, social stats, crafting stats. The mapping only governs combat formulas.


buildCombatStack is the recommended entry point. It generates formulas, wraps them with engagement and resource modifiers, sets up review tracing, and returns a module array.

Minimal combat (no resources, no engagement roles)

Section titled “Minimal combat (no resources, no engagement roles)”
import { buildCombatStack } from '@ai-rpg-engine/modules';
const combat = buildCombatStack({
statMapping: { attack: 'might', precision: 'agility', resolve: 'will' },
playerId: 'hero',
});
const combat = buildCombatStack({
statMapping: { attack: 'might', precision: 'agility', resolve: 'will' },
playerId: 'hero',
resourceProfile: {
packId: 'my-game',
gains: [
{ trigger: 'attack-hit', resourceId: 'momentum', amount: 2 },
],
spends: [
{ action: 'attack', resourceId: 'momentum', amount: 5, effects: { damageBonus: 2 } },
],
drains: [],
aiModifiers: [],
},
});
const combat = buildCombatStack({
statMapping: { attack: 'might', precision: 'agility', resolve: 'will' },
playerId: 'hero',
engagement: {
backlineTags: ['ranged', 'caster'],
protectorTags: ['bodyguard'],
},
biasTags: ['undead', 'beast'],
});

See Build a Combat Pack for deep combat authoring.


Pick the modules your game needs:

import { Engine } from '@ai-rpg-engine/core';
import { traversalCore, statusCore, buildCombatStack, createDialogueCore, createCognitionCore, /* ... */ } from '@ai-rpg-engine/modules';
const combat = buildCombatStack({ /* ... */ });
const engine = new Engine({
manifest: { id: 'my-game', title: 'My Game', version: '1.0.0' },
seed: 42,
modules: [
traversalCore,
statusCore,
...combat.modules,
createDialogueCore(myDialogues),
createCognitionCore({ decay: { baseRate: 0.02 } }),
// ... add what you need
],
});
If your game has…You need
Rooms to move betweentraversalCore
CombatbuildCombatStack
NPC dialoguecreateDialogueCore
NPC beliefs and memorycreateCognitionCore
Items and equipmentcreateInventoryCore
FactionscreateFactionCognition
Character abilitiescreateAbilityCore + createAbilityEffects
Boss encounterscreateBossPhaseListener

engine.store.addZone({ id: 'cave', name: 'Goblin Cave', tags: ['dark'], exits: [{ to: 'clearing' }] });
engine.store.addEntity({ id: 'hero', type: 'player', name: 'Fighter', tags: ['human'], stats: { might: 6, agility: 5, will: 4 }, resources: { hp: 25, maxHp: 25 }, inventory: [], equipment: {}, statuses: [] });
engine.store.state.playerId = 'hero';
engine.store.state.locationId = 'cave';

StarterBest Pattern to Borrow
FantasySimplest combat wiring — no resources, no engagement roles
Weird WestbuildCombatStack usage, dual resource profile
CyberpunkSquad engagement with backline/protector tags
DetectiveDefensive resource spending
PirateCrew morale as shared group resource
ZombieConsequence-only resource (infection)
VampireOpposing dual resources (bloodlust vs humanity)
GladiatorPerformance economy, 3-phase boss
RoninMultiple protector roles, dual-layer resources