Event Leaderboards
Read more about the Event Leaderboards system in Hiro here.
Initialize 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.
| |
Event leaderboard response #
The IEventLeaderboard response object includes the following properties:
| Property | Type | Description |
|---|---|---|
BestRank | long | Best rank achieved across cohorts this phase. |
CanClaim | bool | Whether the player can claim their reward. |
CanRoll | bool | Whether the player can roll into a new cohort right now. |
CanRollWithClaim | bool | Whether the player can claim and roll in a single call. |
CanUpdate | bool | Whether the player can submit scores to their current cohort. |
IsActive | bool | Whether the event leaderboard’s current phase is live. |
MaxRolls | long | Maximum rolls allowed per phase. |
RerollCountFreeze | bool | Whether the next roll is “free” (does not count against MaxRolls). |
RollCooldownSec | long | Effective cooldown between rolls, in seconds. |
Rolls | long | Number of rolls the player has used this phase. |
ScoreTarget | long | Target score for cohort completion. |
ScoreTargetPlayers | long | How many players must reach the target. |
Tier | int | The player’s current tier (0-indexed). |
TierDeltaPerPhase | long | Tier adjustment applied when a phase expires. |
ClaimTimeSec | long | Unix timestamp when the player claimed their reward (0 if unclaimed). |
EndTimeSec | long | Unix timestamp when the player’s current cohort is scheduled to end. |
ExpiryTimeSec | long | Unix timestamp when the player’s phase pointer expires. |
RollCooldownEndsSec | long | When the current cooldown expires (UNIX timestamp). |
ScoreTimeLimitEndsSec | long | When this player’s time limit expires (UNIX timestamp). |
ScoreTimeLimitSec | long | Per-player time limit from roll time, in seconds. |
StartTimeSec | long | Unix timestamp when the player’s current cohort started. |
Determine event leaderboard state #
When the server returns an Event Leaderboard, its current state is represented by a combination of boolean properties. Check if the player can claim rewards and roll into a new cohort simultaneously by reading the CanRollWithClaim property in the response.
| IsActive | CanClaim | CanRoll | Description |
|---|---|---|---|
FALSE | FALSE | FALSE | Visible, but inactive. No actions are possible. |
FALSE | TRUE | FALSE | Visible, but inactive. A reward from a previous phase can be claimed. |
TRUE | FALSE | FALSE | Active, a valid cohort exists and the player can submit scores (CanUpdate is true). |
TRUE | FALSE | TRUE | Active, need to roll to get a cohort. |
TRUE | TRUE | FALSE | Active, a completed cohort exists with an unclaimed reward. The player has no remaining rolls after claiming, or is waiting for a roll cooldown to expire. |
Subscribe 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.
| |
List event leaderboards #
You can list all the available event leaderboards to the player by passing null as an argument.
| |
You can filter down the event leaderboards to only include those that belong to at least one of the given categories.
| |
By default, the response doesn’t include the scores of the event leaderboards. To have the response returning with the scores, set the boolean with_score on the request to true.
| |
Get an individual event leaderboard #
You can get an individual event leaderboard, including it’s records and information on it’s rewards.
| |
Submit an event leaderboard score #
You can submit an event leaderboard score for the user. Check CanUpdate on the response to determine whether the player can still submit scores to their current cohort.
| |
Claim rewards #
You can claim event leaderboard rewards for the user.
| |
Roll into a cohort #
You can roll (or re-roll) the user into a cohort for a specific event leaderboard. The first roll in a phase places the player into a cohort for the first time. Subsequent rolls within the same phase are re-rolls, where the player leaves a completed cohort and joins a new one with fresh opponents.
| |
To claim the current reward and roll into a new cohort in a single call, pass claimReward: true. This is the recommended approach for re-rolling as it avoids an extra round-trip.
| |
Multi-roll game loop #
For score-based events where players can compete in multiple cohorts within a single phase, the typical flow looks like this:
| |
Debug an event leaderboard #
You can fill an event leaderboard with dummy users and assign random scores to them for testing purposes.
| |
