Skip to content

II.B. Player

Polo Moine edited this page Apr 24, 2020 · 1 revision

As we said before, every instance of the Player class is linked to an actual Player playing to your game. Therefore, some messages are sent and received by this class, we will call them events and we will see the list just after.

Just one thing before we present you how a match works and the list of events. The Player class have a userIndex attribute, this is a unique identifier for the player which is generated like so:

Player + unique id

This can be overwritten by overriding the method getPlayerIndex of the Match class.

Match

Matches are always composed by teams even if they contain only one player.

Attributes

As presented in the previous chapter, the Match class has a lot of attributes, and they are not all very explicit so we will see them one by one now.

maxUser

Specifies the maximum number of player the match can handle.

minUser

Specifies the minimum number of player before the match can start. This means, when all the players are ready, if there is at least minUser player in the match, the match will start.

map

Specifies the map in which the match must be started.

type

Specifies the match type, this is helpful is you have different modes in your game.

password

Specifies the password, the players have to give in order to join the match, if it's leaved empty, there's no password and the match is public.

nbPlayersPerTeam

Specifies the number of players in each team. If you don't override anything, this number is 1.

allowedGap

Specifies the max gap between two team. This is useful to make real matchmaking if you have a score for each of your player and you don't want that two players with an enormous score difference could be in the same match. If you don't override anything, this will be set to 0.

isFull

Just to know if we can add another team in this match.

hasStart

Just to know if the match has start. When a match has been started, if you didn't override anything, no other team can join it.

gameServer

Specifies the game server that is handling this match.

teams

Specifies the different teams that composed this match. Each team is composed of

  • grade: the grade (score) of the team for advanced matchmaking
  • id: the team id
  • state: the state of the team
    • 0: the team has not joined the match yet
    • 1: the team has joined the match
  • players: the list of players composing the team with attributes:
    • client: the Player object of the player
    • key: the key of the player to use to join the match on the game server
    • state: the state of the player
      • 0: the player team has not joined the match yet
      • 1: the player team has joined the match
      • 2: the player is ready

Events

From the actual player

find_match

Description

Call when the player wants to find a match. This will look for the matches that correspond to the criteria and add the player inside a match or create a new match.

Data

{
  "maxUser": "number",
  "minUser": "number",
  "map": "string",
  "type": "string"
}

cancel_find_match

Description

Call when the player wants to cancel the search of a match. In the reality, it has no effect as the research is synchronous but you can override the search to make it asynchronous.

Data

{}

create_match

Description

Call to create a new match.

Data

{
  "maxUser": "number",
  "minUser": "number",
  "map": "string",
  "type": "string",
  "password": "string",
  "nbPlayersPerTeam": "number",
  "allowedGap": "number"
}

join_match

Description

Call when the player has found a match and now accept to join it. You can force it if you don't want to let the player choose if he accept or not the match.

Data

{
  "matchId": "number",
  "password": "string"
}

refuse_match

Description

Call when the player has found a match but refuses to join it.

Data

{}

ready_match

Description

Call when the player has join the match and is ready to start.

Data

{}

leave_match

Description

Call when the player leaves the match.

Data

{}

disconnection

Call when the player disconnects

This event has no data.

To the actual player

match_found

Description

Sent when a match has been found.

Data

{
  "matchId": "number",
}

match_created

Description

Sent when a match has been created.

Data

{
  "matchId": "number",
}

match_notfound

Description

Sent when the match specified cannot be found.

Data

{}

match_wrongpassword

Description

Sent when the given password to join a match is wrong.

Data

{}

match_joined

Description

Sent when a match has been joined.

Data

{
  "matchId": "number",
  "userId": "string",
  "teamId": "string"
}

match_team_joined

Description

Sent when a new team has joined the match.

Data

{
  "players": {
    "userId": "string",
    "ready": "bool"
  }[],
  "teamId": "string"
}

match_ready

Description

Sent has a confirmation that the player has change his status to ready.

Data

{
  "matchId": "number",
}

match_player_ready

Description

Sent when a player updated his status to ready.

Data

{
  "userId": "string"
}

match_player_leaved

Description

Sent when a player leaved the match.

Data

{
  "userId": "string"
}

match_team_leaved

Description

Sent when a team leaved the match.

Data

{
  "teamId": "string"
}

match_start

Description

Sent when every player is ready and a game server has been found.

Data

{
  "key": "string",
  "map": "string",
  "type": "string"
}