Set Up Pragma Engine to Handle Parties #

The first step to building out a game flow is the Party flow, 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 are barely exercising the flexibility that Pragma Engine’s Party plugin brings. See our Party Plugin API reference document to learn more about the 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 following existing messages so that 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 are creating the protos that define what data will be made available where in the Party flow.

  • 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 the Party screen.

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 are defining the selectable characters. This enum is also used by the Unreal game client as it is made available to the client via the Pragma SDK.

Build the protos so that 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 their extPlayerSeslection.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/common.yml by inserting the following configuration:

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