Skip to main content

Turn-based battle

@rpgjs/turn-battle adds turn-based fights to a game: the server owns the rules (turn order, damage, AI, rewards), the client plays a battle scene above the map. It works in standalone RPG mode and in MMORPG mode, solo, in co-op and in player versus player, and other players can watch. Unlike the Action Battle System, nothing happens on the map itself: your server code calls startTurnBattle, the battle scene covers the map for the players who fight, and the map comes back when it ends. Unlike the tactical battle, there is no grid and no movement: heroes and enemies face each other and act in turn. See Combat modes to compare the three. It is built on @rpgjs/battle-kit, the foundation shared by the RPGJS battle systems, and does not depend on any other battle system: a game can install it next to @rpgjs/tactical-rpg or alone.

Install

The styles of the battle HUD are part of @rpgjs/ui-css (rpg-ui-turn-battle-* classes): a game that links the ui-css stylesheet has them, and its theme restyles the battle too.
Without provideTurnBattleServer, startTurnBattle has no rules to run; without provideTurnBattleClient, the player has no battle scene. Add both.

Quick start

A goblin troop in the database, and a goblin on the map that starts the battle when the player talks to it.
1

Plug the server and client providers

Add provideTurnBattleServer() to the server providers and provideTurnBattleClient() to the client providers, as shown in Install.
2

Add an enemy and a troop to the database

battler is the id of a spritesheet registered on the client, like any other spritesheet (see Customization). The player’s hero reads its HP, SP and parameters from the RpgPlayer.
3

Start the battle from an event

Place the event on a map (maps: [{ id: "simplemap", events: [{ id: "goblin-1", x: 200, y: 120, event: GoblinEvent() }] }], see Create an event), walk to it and press the action key.
When the battle ends, the result is already written on the player: HP, SP, items spent, EXP, gold and drops.

Next steps

Start a battle

Every way to start a battle, the result, solo and multiplayer (co-op, PvP, spectators).

Battle data

Skills, items, weapons, enemies, troops, summons and actions in the database.

Customization

Server and client options, hooks, texts and controls.

Battle kit

The foundation shared with the tactical battle.