Battle events
How a battle travels over the socket, turn by turn.
A battle is a short conversation between the client and the server.
Lifecycle
-
The server sends
encounter(a wild battle, withdisplayset tofullscreenorpanel) orbattle-start(every other kind) with aBattleView. When the battle has a turn timer,deadlineis the Unix time in milliseconds when the turn ends. -
The client sends
battle-actionwith thebattleId, the currentturnand oneBattleAction:{ "t": "battle-action", "battleId": "…", "turn": 3, "action": { "kind": "move", "slot": 0 } }Actions are
move(slot 0 to 3),switch(party index),item(item id, target party index, optional move index),runandforfeit. Only actions listed in the view'slegalActionsare accepted. -
When both sides have chosen (or the timer has run out), the server resolves the turn and sends
battle-updatewith the newBattleView, the turn'seventsand the nextdeadline. -
The last update is
battle-end, with the final events andrewards(money, points, experience, level-ups, new moves, a caught Pokémon, a badge, new Pokédex entries) ornullfor battles without rewards.
An action for an old turn is rejected with stale-turn; an action when nothing is needed with not-your-turn. Battles are pushed to every open tab of the trainer.
Events
events is an ordered list. Play them back in order to animate the turn; the BattleView that comes with them is the state after the last one.
| Event | Meaning |
|---|---|
turn | A new turn number begins. |
text | A line for the text box, already written ("Wild Rattata used Tackle!"). |
send-out / withdraw | A Pokémon enters or leaves the field. |
use-move | A Pokémon uses a move: name and type, for the animation. |
miss | The move missed. |
damage | HP lost, new HP, effectiveness, whether it was critical, and the source (move, status, recoil, confusion, Leech Seed, trap, Struggle). |
heal | HP restored. |
status | A major status was set or cured. |
volatile | A volatile effect started or ended (confusion, Leech Seed, Substitute…). |
stat-stage | A stat stage changed, with the new stage. |
faint | A Pokémon fainted. |
item | An item was used from the bag. |
held-item | A held item or berry activated, and whether it was used up. |
ball-throw | A ball was thrown: which ball, 0 to 3 shakes, caught or not. |
run | An escape attempt and whether it worked. |
transform | Transform copied another species. |
weather | The weather started, changed or ended. |
end | The battle is over, with the winner and the reason. |
Every narrative line arrives as a text event, so a client can show the battle with nothing but the text box. The structured events exist for animation and never need to be turned into words.
Reasons a battle ends
faint (one side has no Pokémon left), run, catch, forfeit, timeout, turn-limit (tournament matches after 60 turns, decided by remaining HP) and flee (the wild Pokémon left, for example after Whirlwind or Roar).
TapIn Pokémon is an unofficial fan project. Pokémon and all related names and artwork are trademarks and © of Nintendo, Game Freak and Creatures. Legal