Set Up Pragma Engine to Handle Parties #

The first part of building out a game flow is managing parties, and the first step in getting started with parties is setting up the party protos and building the Party Plugin.

As this is a simplified tutorial, we’re completing a basic implementation of the Party Plugin. See the Party Plugin API reference docs to learn more about other methods.

Build Pragma Engine #

You must have Pragma Engine and its associated protos A format for efficiently serializing structured data that's cross-platform and compatible with several languages. built and have a boilerplate 5-ext project ready.

Run the following command in the terminal from the platform directory:

make skip-tests protos engine ext


Define party functionality with protobufs #

In your 5-ext/ext-protos/src/main/proto/shared/partyRpcExt.proto file, edit the existing ExtPlayerSelections and ExtUpdatePlayerSelectionsRequest messages so they match the code below:

// ext field for player selection state within a party
message ExtPlayerSelections {
    // if your character selection is visible, show it here
	party.Character visible_character = 1;
	int64 team_number = 2;
}


// request ext field for updating a player selection
message ExtUpdatePlayerSelectionsRequest {
	oneof update {
    	party.Character new_character = 1;
	}
}

You only need to edit the proto messages covered in the code block. The other messages in partyRpcExt.proto should remain unmodified.

Method overview

We create the protos that define which data is available in the party.

  • ExtPlayerSelections contains information that will be shown to players in the same party.
  • ExtUpdatePlayerSelectionsRequest defines the structure of the request that game clients make when players make changes to their selections while in a party.

While still working in partyRpcExt.proto, create a new proto enum Character:

enum Character {
	UNSPECIFIED = 0;
	KNIGHT = 1;
	MAGE = 2;
	ROGUE = 3;
}
Method overview
We define the selectable characters. This enum is also used by the Unreal game client as it’s available to the client via the Pragma SDK.

Build the protos so they’re available for use when implementing the Party Plugin by running the following command in the terminal from the platform directory:

make ext-protos

Create the Party Plugin #

Create a new Kotlin file at the following location: 5-ext/ext/src/main/kotlin/party/GameFlowTutorialPartyPlugin.kt. Create directories as necessary.

In this file, create a GameFlowTutorialPartyPlugin class that implements the PartyPlugin interface, then implement the following methods:

override suspend fun updatePlayer(
    playerToUpdate: PartyPlayer,
    requestExt: ExtUpdatePlayerSelectionsRequest,
    party: Party,
    partyConfig: PartyConfig
) {
    when (requestExt.updateCase) {
        ExtUpdatePlayerSelectionsRequest.UpdateCase.NEW_CHARACTER -> {
            setNewCharacterSelection(playerToUpdate, requestExt.newCharacter)
        }
        else -> {
            throw Exception("Invalid update case")
        }
    }
}
Method overview
This method is called when a player makes a change to their own personal selections, such as changing a character, skin, or loadout. In our simplified example, this method allows players to change their character.
private fun setNewCharacterSelection(
    playerToUpdate: PartyPlayer,
    character: Character,
) {
    val updatedSelections: ExtPlayerSelections.Builder =
        playerToUpdate.extPlayerSelections.toBuilder()
    updatedSelections.visibleCharacter = character

    playerToUpdate.ready =
        updatedSelections.visibleCharacter != Character.UNSPECIFIED

    playerToUpdate.extPlayerSelections = updatedSelections.build()
}
Method overview
This is the method that actually handles the character selection. It sets a player’s extPlayerSelection.visibleCharacter to their selected character. If the character the player selected is not UNSPECIFIED, it sets their ready state to true.

Now that we’ve finished creating the party plugin, we need to compile both our 5-ext and the Pragma SDK. Run the following command in a terminal from the platform directory:

make ext pragma-sdks

Enable the Party Plugin #

We need to edit our configuration file so that the engine knows to use our new Party Plugin. Edit 5-ext/config/dev.yml by adding the following configuration:

game:
  pluginConfigs:
    PartyService.partyPlugin:
      class: "party.GameFlowTutorialPartyPlugin"