Teams #

Players can join teams in Merge Chef 3D by Kyoso Interactive.
Players can join teams in Merge Chef 3D by Kyoso Interactive.

Teams are a Hiro meta system which allows the player to create, join, and search for teams of other players. Teams can be used to create guilds, clans, or any other organized unit of players useful for your gameplay.

The Teams system is build on top of the Nakama groups feature, and the chat feature, to enable players to communicate with each other, fetch historical chat messages, and even request donations.

Customization parameters #

The following JSON represents the customization parameters you can use to configure the default user experience for the teams system.

PropertySubpropertyDescription
max_team_sizeThe maximum number of members for a team.

Initializing the teams system #

The teams system relies on the Nakama System which must be passed in as a dependency via the constructor.

1
2
var teamsSystem = new TeamSystem(nakamaSystem);
systems.Add(teamsSystem);

Subscribing to changes in the teams system #

You can listen for changes in the teams system so that you can respond appropriately, such as updating the UI, by implementing the appropriate interface.

1
2
3
4
5
var disposer = SystemObserver<TeamSystem>.Create(teamsSystem, system => {
  Instance.Logger.Info($"System updated.");

  // Update UI elements etc as necessary here...
});

Refreshing the teams system #

To ensure the teams system has the latest information from Nakama you can refresh it.

1
await teamsSystem.RefreshAsync();

Getting the user’s current team #

You can get the user’s current team.

1
2
var team = teamsSystem.Team;
Debug.Log($"Current Team: {team.Name}. Total members: {team.EdgeCount}");

You can also determine if the user is an Admin or Superadmin of their current team.

1
2
var isAdmin = teamsSystem.IsAdmin;
var isSuperadmin = teamsSystem.IsSuperadmin;

Getting the user’s current team members #

You can get the user’s current team members.

1
2
3
4
5
6
foreach (var teamMemberKvp in teamsSystem.TeamMembers)
{
  var teamMember = teamMemberKvp.Value;
  var online = teamMember.User.Online ? "Online" : "Offline";
  Debug.Log($"{teamMember.User.Username} ({online})");
}

Getting team members for other teams #

You can get the team members in other teams by passing the team id or a team object.

1
2
var memberList = await teamsSystem.GetTeamMembersAsync("<teamId>");
var memberList = await teamsSystem.GetTeamMembersAsync(team);

Getting the chat history for the user’s team #

You can get the chat history for the user’s team.

1
2
3
4
foreach (var message in teamsSystem.ChatHistory)
{
    Debug.Log($"{message.User.Username}: {message.Content}");
}

Creating a team #

You can create a team for the user. You must provide a function that returns a boolean value indicating whether or not the user can create a team.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var name = "MyTeam";
var description = "My team description";
var open = true;
var icon = "<iconUrl>";
var setupMetadata = "<metadata>";
var team = await teamsSystem.CreateTeamAsync(name, description, open, icon, setupMetadata, (client, session) => {
  // Check if the user is eligible to create a team
  // e.g. Are they high enough level?
  return Task.FromResult(true);
});

Listing available teams #

You can list available teams by location.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var location = "uk";
var limit = 10;
var cursor = "<optionalCursor>";

var teamList = await teamsSystem.ListTeamsAsync(location, limit, cursor);

foreach (var team in teamList.Teams)
{
  Debug.Log($"Team: {team.Name}. Total members: {team.EdgeCount}");
}

Searching for teams #

You can search for teams based on their name or shortcode.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var name = "<name>";
var shortcode = "<optionalShortcode>";
var limit = 10;

var teamList = await teamsSystem.SearchTeamsAsync(name, shortcode, limit);

foreach (var team in teamList.Teams)
{
  Debug.Log($"Team: {team.Name}. Total members: {team.EdgeCount}");
}

Joining a team #

You can join a team for the user either by passing the team id or by passing a team object.

1
2
var team = await teamsSystem.JoinTeamAsync("<teamId>");
var team = await teamsSystem.JoinTeamAsync(team);

Listing join requests for the user’s current team #

You can list join requests for the user’s current team

1
2
3
4
foreach (var joinRequest in teamsSystem.JoinRequests)
{
  Debug.Log($"{joinRequest.User.Username} requested to join.");
}

Approving team join requests #

You can approve a single join request, either by passing the user id of the user requesting to join, or by directly passing the join request object.

1
2
await teamsSystem.ApproveJoinRequestAsync("<teamId>", "<userId>");
await teamsSystem.ApproveJoinRequestAsync("<teamId>", joinRequest);

You can also approve multiple join requests at once.

1
await teamsSystem.ApproveJoinRequestsAsync("<teamId>", new[] { "<userId1>", "<userId2>" });

Rejecting team join requests #

You can reject a single join request, either by passing the user id of the user requesting to join, or by directly passing the join request object.

1
2
await teamsSystem.RejectJoinRequestAsync("<teamId>", "<userId>");
await teamsSystem.RejectJoinRequestAsync("<teamId>", joinRequest);

You can also reject multiple join requests at once.

1
await teamsSystem.RejectJoinRequestsAsync("<teamId>", new[] { "<userId1>", "<userId2>" });

Promoting team members #

You can promote team members if the user has sufficient priviledges.

1
await teamsSystem.PromoteUsersAsync("<teamId>", new[] { "<userId1>", "<userId2>" });

Leaving a team #

You can leave a team for the user either by passing the team id.

1
var team = await teamsSystem.LeaveTeamAsync("<teamId>");

Or by passing a team object.

1
var team = await teamsSystem.LeaveTeamAsync(team);

Deleting a team #

You can delete a team, providing the user has sufficient priviledges.

1
await teamsSystem.DeleteTeamAsync("<teamId>");

Sending a chat message to the user’s team #

You can send a chat message to the user’s team.

1
var messageAck = await teamsSystem.WriteChatMessageAsync("<teamId>", "<contentJson>");