Game events - ggirou/risk GitHub Wiki

  • All server events are broadcasted.
  • All server events are stored in an event store.
  • All player events contains his playerId (except for JoinGame).
  • When player connects to the WebSocket, the server sends all events in history to be able to restore his game state.
  • The playerId is defined by the order of joining (PlayerJoined).

Players enrollment

Sent by Event Data Comments
Server Welcome {playerId: 2} The server sends a technical event immediately after the player connects to give him a playerId
Player /Server JoinGame {playerId: 2, name: "John", avatar: ...} The player joins the game
Player / Server LeaveGame {playerId: 2} The player lefts the game
...
Player StartGame {playerId: 2} The master player starts the game.
Player / Server StartGame {armies: 25, playersOrder: [2, 4, 1, 3]} The game starts with the number for of armies for each player and the players order.

Game setup

Sent by Event Data Comments
Server NextPlayer {playerId: 2} The first player plays
Player / Server AddArmy {playerId: 1, country: "usw"} The player adds one army to a country
Server NextPlayer {playerId: 4} The second player plays
...

Game turn

Sent by Event Data Comments
Server NextPlayer {playerId: 1, reinforcement: 8} Next player turn with armies reinforcement
Player / Server AddArmy {playerId: 1, country: "usw"} The player adds one army to a country
Player / Server Attack {playerId: 1, from: "usw", to: "use", armies: 3} The player attacks from a country to an adjacent one with n armies
Player / Server Defend {playerId: 2, armies: 2} The player defends his country with m armies
Server BattleEnded {attacker: {playerId: 1, dices: [6, 3, 2], country: "usw", loss: 1}, defender: {playerId: 2, dices: [5, 5], country: "use", loss: 1}} The result of the current battle
Player / Server Move {playerId: 1, from: "usw", to: "use", armies: 3} The player chooses the number of armies to move in the conquered country
Player EndAttack {playerId: 1} Attacks of player end
Player / Server Move {playerId: 1, from: "usw", to: "use", armies: 3} The player moves armies from a country to another one
Player EndTurn {playerId: 1} Turn of player ends
Server NextPlayer {playerId: 3, reinforcement: 13} Next player turn with armies reinforcement
...