Skip to content

Latest commit

 

History

History
206 lines (143 loc) · 13.7 KB

quick-match.md

File metadata and controls

206 lines (143 loc) · 13.7 KB

Quick Match

Index

Summary

This sample demonstrates how to implement a Quick Match using PlayFab's services. This feature will allow the players to play a match instantly, without the need of looking for an specific match.

Systems Involved

Before starting explaining how this feature works, let's see how the game was implemented.



Regarding the Quick Match feature, we can add the next information:

  • Tic-Tac-Toe game: this is implemented in this project. Here we've the Quick Match option, where we can start a match.

Pre-requisites

Implementation

Process Flow



Process Description

The Quick Match feature allows players to play against others randomly-selected players. For starting this process, the players would have to click the Quick Match button from the Lobby menu:



Once this happens, the game creates a matchmaking ticket for the player, in order to pair him with another unknown player. After this, the game will request the ticket status until a match happens. This process is described in a more detailed way here.

Then, the game will determine the player one and two, based on the alphabetical order of their respective IDs. This is an important step, as each of these players has a different responsibility:

  • The Player One or Host will create the PlayFab Party Network, which main purpose is allowing players to share information used in the game. This process is described in a more detailed way here.
  • The Player Two or Guest will be joining the created network, triggering an event that starts the game for both players. This process is described in a more detailed way here.

As the host is the only one that has the party network ID, and the guest needs it for joining the network, we were in the need of defining a process for sharing information between two matched players. For this, we've decided to create a new matchmaking ticket, but in this case, we use the previous match ID as a Matching attribute, which ensure us that both players will be Matched again. In this new ticket, the host will pass the network ID. All these steps are performed in the PreparePartyQuickMatch method from the Lobby.cs file.

Once the second match happens, the guest will be joining to the Network. This will trigger an event that the host will handle with this method. Here, the host will send the Players Ready message (triggering a Network event), for notifying that both players are ready to play the game. This message will be processed here, and after that, the Game Flow will start.

Matchmaking

Matchmaking Queues

In this project we're currently using the PlayFab Matchmaking feature, which allows us to match two players given some specific attributes. For creating, querying status, and canceling tickets we've to use a matchmaking queue, but in our case we need to use two different queues:

  • TicTacToeQuickMatch queue: this queue will be in charge of matching two players in a random way.
  • PartyQueue queue: this queue will match two players based on a given attribute: the PreviousMatchId, which is the match ID that was previously created in the Quick-Match process.

Note: the host player will specify the party network attribute in the PartyQueue queue.

For having more information on how to configure these queues, check this document.

Matchmaking Handler

For managing all the matchmaking-related tasks, we have the MatchmakingHandler class. Here we wrap some useful PlayFab's API methods for using in our game, like the Matchmaking Ticket Creation, Getting the Ticket Status, Cancelling a Ticket, or for Getting the Match information.

As in our case we're managing two different classes of queues, the *TicTacToeQuickMatch- and *PartyQueue- queues (more info here), we decided to use the MatchmakingQueueConfiguration class and its hierarchy: QuickMatchQueueConfiguration and PartyQueueConfiguration. We decide which of this configuration use through the ChangeQueueConfiguration method at any time, specifying the type we want to use.

Creating Matchmaking Ticket

In the MatchmakingHandler class we have the CreateTicket method that allows us to create a matchmaking ticket. Here we're using the Create Ticket method from the PlayFab's API. Something important to highlight here is how we manage the creation for each queue type we have so far:

Getting a Matchmaking Ticket Status

In the MatchmakingHandler class we have the GetTicketStatus method for retrieving the ticket status. In this case, we're using the Get Matchmaking Ticket API method. Also, we have the EnsureGetTicketStatus method, which queries the ticket Status for an specified amount of time.

PlayFab Party Network

For communicating both players we're using the PartyNetworkHandler class, which uses the PlayFab's Party Network services.

Creating the Party Network

For creating the network, we're using the CreateAndJoinToNetwork method, which creates and joins the player to the network, retrieving its ID. More precisely, this is executed in this method of the Lobby.cs file.

Joining the Party Network

In the PartyNetworkHandler class we have the JoinNetwork method that allows a player joining to an specified network. We use this method here in the Lobby.cs file.

Party Network Events

In the Quick-Match process case we're working with two Network events:

  • OnRemotePlayerJoined: we handle this event with the OnRemotePlayerJoinedListener method. This event allows the host to know when the guest has joined the network. After this, the host will send a Players Ready message over the network, for notifying the network players that all of them are ready to play.
  • OnDataMessageNoCopyReceived: this event is triggered after a player sends a message over the network. We manage this event with the OnDataMessageNoCopyReceivedListener method, which allows the guest (and the other Network's players) when they can start the game.