Web socket messages - Miol-Mor/battle-game GitHub Wiki

All messages are in JSON format


Table of contents


Client messages

Click

Coordinates of hex where player has been clicked

{
    "cmd": "click",
    "target": {
        "x": 0, 
        "y": 0,
    },
}
  • x: integer - value of x coordinate
  • y: integer - value of y coordinate

Skip

Pass turn to the next player

{
    "cmd": "skip_turn",
}

Server messages

Field

Sends to create new game or restart current one

{
    "cmd": "field",
    "num_x": 3,
    "num_y": 5,
    "field": {
        "hexes": [{
            "x": 0, 
            "y": 0, 
        }, {
            "x": 1,
            "y": 0,
            "unit": {
                "player": 1,
                "hp": 10,
                "damage": [2, 5],
                "speed": 3,
            },
        }, {
            "x": 0, 
            "y": 1,
            "content": "wall",
        },
        ...
        ]
    }
}
  • cmd: string - always "field" for this message
  • num_x: integer - field's width
  • num_y: integer - field's height
  • field: array[Hex] - array of hexes that are located on the field

Selecting

Sends when unit should be selected

{
    "cmd": "selecting",
    "target": {
        "x": 0,
        "y": 0,
    },
    "highlight_hexes": [{
        "x": 0,
        "y": 1,
    }, {
        "x": 1,
        "y": 0,
    }],
}
  • cmd: string - always "selecting" for this message
  • target: Point - coordinates of hex where unit should be selected
  • highlight_hexes: array[Point] - coordinates of hexes that should be highlighted

Deselecting

Sends when unit selection should be canceled

{
    "cmd": "deselecting",
    "target": {
        "x": 0,
        "y": 0,
    },
}
  • cmd: string - always "deselecting" for this message
  • target: Point - coordinates of hex where unit should be deselected

Moving

Sends when unit should be moved

{
    "cmd": "moving",
    "coords": [{
        "x": 0,
        "y": 0,
    }, {
        "x": 1,
        "y": 2,
    }]
}
  • cmd: string - always "moving" for this message
  • coords: array[Point] - pair of points from which and to which unit should be moved

Attacking

Sends when unit have been attacked

{
    "cmd": "attacking",
    "from": {
        "x": 0,
        "y": 0,
    },
    "to": {
        "x": 1,
        "y": 0,
    },
    "changes": {
        "hurt": [],
        "die": [],
    }
}
  • cmd: string - always "attacking" for this message
  • from: Point - coordinates of unit that attacking
  • to: Point - coordinates of unit that has been attacked
  • changes: Changes - two arrays with hexes where units have been died and hurt

State

Sends when game state have been changed for the player and after error

{
    "cmd": "state",
    "state": "attack",
}
  • cmd: string - always "state" for this message
  • state: string - current game state for player. One of wait, select, action, watch or attack

Queue

Sends when players connect/disconnect from the game to track there position in queue

{
    "cmd": "queue",
    "players_number": 5,
    "your_number": 3,
}
  • cmd: string - always "queue" for this message
  • players_number: int - how many players connected to the game
  • your_number: int - your position in players queue. Can not be more than players_number

End

Sends when game ends

{
    "cmd": "end",
    "you_win": true,
}
  • cmd: string - always "end" for this message
  • you_win: boolean - true if you win, false if not

Error

Sends when error have been occurred

{
    "cmd": "error",
    "message": "GFY",
}
  • cmd: string - always "error" for this message
  • message: string - information about error

Complex types

Point

{
    "x": 0,
    "y": 0,
}
  • x integer - coordinate x
  • y integer - coordinate y

Unit

{
    "player": 1,
    "hp": 10,
    "damage": [2, 5],
    "speed": 3,
}
  • player: integer - player's number
  • hp: integer - unit's health points
  • damage: [integer, integer] - array with two values: minimal and maximum damage, that unit may cause
  • speed: integer - number of hexes that unit can pass during movement phase

Hex

{
    "x": 0,
    "y": 0,
    "unit": {
        "player": 1,
        "hp": 10,
        "damage": [2, 5],
        "speed": 3,
    },
    "content": "wall",
}
  • x: integer - value of hex's x coordinate
  • y: integer - value of hex's y coordinate
  • unit: Unit optional - unit located in hex
  • content: string optional - name of content located in hex

Changes

{
    "hurt": [{
        "x": 0,
        "y": 0,
        "unit": {
            "player": 1,
            "hp": 6,
            "damage": [2, 5],
            "speed": 3,
        },
    }],
    "die": [{
        "x": 0,
        "y": 1,
    }],
}
  • hurt: array[Hex] - array of hexes where units have been hurt
  • die: array[Hex] - array of hexes where units have been died