Use this file to discover all available pages before exploring further.
The Battle class is the central state machine of the Pokémon Showdown client engine. It owns all four possible Side objects, manages turn progression, weather, and game-type metadata, and drives the animation pipeline by dispatching protocol messages through runMajor. The Side class represents one player’s slot in the battle and holds the active roster, side conditions, and faint counters. The Pokemon class tracks every observable property of an individual Pokémon — HP, status, volatile effects, move memory, and the sprite handle used for animations.
Licensing: The Pokémon Showdown client as a whole is licensed under AGPLv3. The battle engine files (battle*.ts) alone carry the more permissive MIT license, making them safe to embed in standalone replay viewers without the copyleft requirement.
A tuple-like array whose first element is always an ID string. Used to represent volatile, turn-status, and move-status effects attached to a Pokemon. Additional elements are effect-specific data.
PP used by a remembered move. A plain number means an exact value is known; a [min, max] tuple encodes a range when the exact value cannot be determined from the log.
Uniquely identifies the Pokémon within a message stream in the form "p1: Nickname" or "p2: Sparky". Empty between Team Preview and the first switch-in.
Human-readable details not included in ident: species, level (omitted at 100), gender (omitted if genderless), and shininess. Examples: "Mimikyu, L50, F", "Steelix, M, shiny".
Non-volatile status condition ID: 'par', 'psn', 'frz', 'slp', 'brn', 'tox' (badly poisoned), or '' (none). '???' is used for unknown status in old replays.
Records or updates a move entry in moveTrack. Handles Transform recursion guards. Automatically skips Struggle and starred (*-prefixed) transform copies.
Parses an HP string from the protocol (e.g. "185/250" or "(42%)") and mutates this.hp, this.maxhp, and this.hpcolor. Returns a [delta, denominator, percentDelta] or [delta, denominator, percentDelta, oldnum, oldcolor] tuple, or null on failure.
Resets all volatile state: restores base ability, clears boosts, volatiles, turn-statuses, move-statuses, and resets toxic/sleep counters appropriately for the current generation.
jQuery element for the battle animation canvas. Must be provided together with $logFrame. Omit both to create a headless (stub-scene) battle suitable for log parsing only.
Pre-loaded protocol lines. A newline-delimited string is split automatically. These populate stepQueue and begin replaying immediately unless paused is true.
Appends a protocol line to stepQueue and, if the queue had previously reached its end, resumes stepping.
add(command?: string): void
instantAdd(command)
Runs a command immediately (preemptively) for chat and timer messages, then also appends it to the queue so it plays in sequence. This is the mechanism behind real-time chat in a live battle.
instantAdd(command: string): void
subscribe(listener)
Replaces the current subscription callback. The listener receives one of the state strings on each significant transition.
subscribe(listener: Battle['subscription']): void
reset() / resetStep()
reset() pauses playback and calls resetStep(). resetStep() rolls all battle state back to initial values, clears both sides, and restarts the step queue from position 0.
reset(): voidresetStep(): void
seekTurn(turn, forceReset?)
Fast-forwards or rewinds the replay to a specific turn number. seeking is set to the target turn while processing, then cleared.
Extends both PokemonDetails and PokemonHealth with full server-side data sent in |request| messages: unboosted stats, move IDs, base ability, held item, pokéball, and Tera Type.
import { Battle } from './battle';// Minimal headless battle (no DOM required)const battle = new Battle({ paused: true, subscription: (state) => { if (state === 'turn') console.log('Now on turn', battle.turn); if (state === 'ended') console.log('Battle over'); },});// Feed protocol lines one at a timebattle.add('|player|p1|Alice|dawn|1200');battle.add('|player|p2|Bob|ethan|1100');battle.add('|gen|9');battle.add('|tier|[Gen 9] OU');battle.add('|gametype|singles');battle.add('|start');battle.add('|switch|p1a: Gardevoir|Gardevoir, L50, F|250/250');battle.add('|switch|p2a: Tyranitar|Tyranitar, L50, M|341/341');battle.add('|turn|1');battle.add('|move|p1a: Gardevoir|Moonblast|p2a: Tyranitar');battle.add('|-damage|p2a: Tyranitar|241/341');
For a read-only replay viewer that does not need animation, pass no $frame/$logFrame to the constructor. The BattleSceneStub shim will absorb all rendering calls, letting you parse battle state from the log without any DOM dependency.