Incentives #

Read more about the Incentive system in Hiro here.

Initializing the incentive system #

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

1
2
var incentiveSystem = new IncentiveSystem(logger, nakamaSystem);
systems.Add(incentiveSystem);

Subscribing to changes in the incentive system #

You can listen for changes in the incentive 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<IncentiveSystem>.Create(incentiveSystem, system => {
    Instance.Logger.Info($"System updated.");

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

Sender incentives #

Listing sender incentives #

You can list all sender incentives for the user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
var incentivesList = await incentiveSystem.SenderListAsync();
foreach (var incentive in incentivesList)
{
    foreach (var (key, value) in incentive.Claims)
    {
        Debug.Log($"{key} claimed at {value.ClaimTimeSec}.");
    }

    foreach (var userId in incentive.UnclaimedRecipients)
    {
        Debug.Log($"{userId} has not yet claimed.");
    }
}

Creating sender incentives #

You can create a sender incentive for the user.

1
2
3
var incentiveId = "<incentiveId>";
var incentive = await incentiveSystem.SenderCreateAsync(incentiveId);
Debug.Log($"Created incentive with code: {incentive.Code}");

Claiming sender incentives #

You can claim a sender incentive for the user.

1
2
var incentiveCode = "<incentiveCode>";
var incentive = await incentiveSystem.SenderClaimAsync(incentiveCode);

Deleting sender incentives #

You can delete a sender incentive for the user.

1
2
var incentiveCode = "<incentiveCode>";
await incentiveSystem.SenderDeleteAsync(incentiveCode);

Recipient incentives #

Getting recipient incentives #

You can get a recipient incentive for the user.

1
2
var incentiveCode = "<incentiveCode>";
var incentive = await incentiveSystem.RecipientGetAsync(incentiveCode);

Claiming recipient incentives #

You can claim a recipient incentive for the user.

1
2
var incentiveCode = "<incentiveCode>";
var incentive = await incentiveSystem.RecipientClaimAsync(incentiveCode);