Event Leaderboards #

Read more about the Event Leaderboards system in Hiro here.

Initializing the event leaderboards system #

The event leaderboards system system relies on the Nakama System and an ILogger, both must be passed in as dependencies via the constructor.

1
2
var eventLeaderboardsSystem = new EventLeaderboardsSystem(logger, nakamaSystem);
systems.Add(eventLeaderboardsSystem);

Subscribing to changes in the event leaderboards system #

You can listen for changes in the event leaderboards system so that you can respond appropriately, such as updating the UI, by implementing the IObserver pattern, or use the SystemObserver<T> type which handles it for you.

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

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

Getting an individual event leaderboard #

You can get an individual event leaderboard, including it’s records and information on it’s rewards.

1
var eventLeaderboard = await eventLeaderboardsSystem.GetEventLeaderboardAsync("<leaderboardId>");

Submitting an event leaderboard score #

You can submit an event leaderboard score for the user.

1
2
3
var score = 100;
var subscore = 10;
var eventLeaderboard = await eventLeaderboardsSystem.UpdateEventLeaderboardAsync("<leaderboardId>", score, subscore);

Claiming rewards #

You can claim event leaderboard rewards for the user.

1
var eventLeaderboard = await eventLeaderboardsSystem.ClaimEventLeaderboardAsync("<leaderboardId>");

Re-rolling an event leaderboard #

You can re-roll the cohort the user is in for a specific event leaderboard. A re-roll would occur when a user has previously joined an event leaderboard and claimed their reward but would now like to re-join again for another chance at claiming a reward, or to play against a different set of opponents.

1
await eventLeaderboardsSystem.RollEventLeaderboardAsync("<leaderboardId>");

Debugging an event leaderboard #

You can fill an event leaderboard with dummy users and assign random scores to them for testing purposes.

This is intended for debugging use only.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
var leaderboardId = "<leaderboardId>";
var targetCount = 50; // Optional target cohort size to fill to, otherwise fill to the max cohort size.

var minScore = 1;
var maxScore = 100;
var @operator = ApiOperator.SET;
var subscoreMin = 1;
var subscoreMax = 100;

// Fills cohort with debug players
await eventLeaderboardsSystem.DebugFillAsync(leaderboardId, targetCount);

// Sets randomly generated scores between a range for other players (does not change the user's score)
await eventLeaderboardsSystem.DebugRandomScoresAsync(leaderboardId, minScore, maxScore, @operator, subscoreMin, subscoreMax);