Battle System Architecture

The RPGReact battle system is a collection of React components that work together to render battles using data from RPG Maker MZ's battle engine. This guide explains the architecture, component relationships, and how to customize the battle UI.

Architecture Overview

The battle system uses a single-direction data flow from RMMZ to React:

RMMZ Battle Engine (Game_Battler, BattleManager, etc.)

Override Files (override_scene_battle.js, override_battle_manager.js)

RPGBridge Events (RPGEventType.BATTLE_*)

React Battle Components (observe and render)

React components never modify game state directly. They only:

  1. Observe MobX-wrapped game objects

  2. Render UI based on that state

  3. Call RMMZ commands through pageData.commands

Core Components

BattleMain.tsx

Location: menus/src/views/battle/BattleMain.tsx

The root battle component that orchestrates all battle UI elements.

Key responsibilities:

  • Mounts all battle sub-components

  • Manages battle phase transitions

  • Handles battle end/victory/defeat

  • Coordinates between input, display, and results screens

Structure:

Props: Standard BaseMenuScreenProps

BattleParty.tsx

Location: menus/src/views/battle/BattleParty.tsx

Displays all party members' HP/MP/TP gauges and status.

Features:

  • Real-time HP/MP updates using MobX observers

  • Status ailment icons

  • ATB gauge integration

  • Click-to-target (if target selection active)

Key code pattern:

BattleInput.tsx

Location: menus/src/views/battle/BattleInput.tsx

Handles command input for the active battler (Attack, Skill, Guard, Item, etc.).

Flow:

  1. Shows when BattleManager.isInputting() is true

  2. Displays commands for current actor

  3. Calls pageData.commands.battleCommand(commandName) on selection

  4. May trigger SubSelectionWindow for skills/items

  5. May trigger target selection

Command types:

  • Attack → Target selection

  • Skill → Skill list → Target selection

  • Guard → Immediate action

  • Item → Item list → Target selection

SubSelectionWindow.tsx

Location: menus/src/views/battle/SubSelectionWindow.tsx

Generic selection window for skills/items during battle input.

Props:

  • items - Array of skills or items

  • onSelect(item) - Callback when item chosen

  • onCancel() - Back to command menu

Uses:

  • Chooser component for list navigation

  • Shows item/skill costs and descriptions

TargetCursor.tsx & TargetCancel.tsx

Location: menus/src/views/battle/TargetCursor.tsx, TargetCancel.tsx

Visual indicators for target selection.

TargetCursor:

  • Renders cursor over selected enemy/ally

  • Positioned using battler sprite coordinates

  • Shows flashing/animated cursor

TargetCancel:

  • "Cancel" button to return to command menu

  • Always visible during target selection

BattleLog.tsx

Location: menus/src/views/battle/BattleLog.tsx

Scrolling combat log showing actions, damage, and effects.

Features:

  • Auto-scrolls to latest entry

  • Color-coded messages (damage red, healing green)

  • Special code support for rich text

Message format:

BattleAtb.tsx

Location: menus/src/views/battle/BattleAtb.tsx

ATB (Active Time Battle) gauge display for Time Progress or Active battle modes.

Only renders if:

Shows:

  • Individual ATB gauges for each battler

  • Turn order preview

  • Cast time indicators

BattleResults.tsx

Location: menus/src/views/battle/BattleResults.tsx

Victory screen showing EXP, gold, items, and level-ups.

Components used:

  • PartyMemberReward - Shows XP gain animation and level-ups for each member

  • Displays total gold and item drops

  • "Next" button to continue

Flow:

  1. Fades in after victory

  2. Animates XP bars for each party member

  3. Shows level-up notifications

  4. Waits for player confirmation

  5. Calls onContinue() to close and return to map

Component Communication

Event-Driven Updates

Battle state changes trigger events from overrides:

React components listen via RPGBridge.AddEventHandler():

Command Execution

React calls RMMZ commands through the pageData commands object:

Commands are defined in the overrides and execute RMMZ battle logic.

Battle Flow

Turn-Based Battle

ATB Battle

Customization Examples

Custom Battle UI Layout

Custom Party Member Display

Custom Battle Log Formatting

Adding Custom Battle HUD Elements

Performance Considerations

Use Observer Granularly

Avoid Expensive Calculations in Render

Debugging Battle Issues

Check Battle State

Log Battle Events

See Also

Last updated