Incentives #

Read more about the Incentives system in Hiro here.

Initializing the incentives system #

The incentives system relies on the Nakama System, Economy System, Energy System, and Inventory System. All must be passed in as dependencies via the constructor.

1
2
var incentivesSystem = new IncentivesSystem(nakamaSystem, economySystem, energySystem, inventorySystem);
systems.Add(incentivesSystem);

Subscribing to changes in the incentives system #

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

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

Refreshing the incentives system #

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

1
await incentivesSystem.RefreshAsync();

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 incentivesLists = await incentivesSystem.SenderList();
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 incentivesSystem.SenderCreate(incentiveId);
Debug.Log($"Created incentive with code: {incentive.Code}");

Claiming sender incentives #

You can claim a sender incentive for the user.

1
2
var incentiveId = "<incentiveId>";
var incentive = await incentivesSystem.SenderClaim(incentiveId);

Deleting sender incentives #

You can delete a sender incentive for the user.

1
2
var incentiveId = "<incentiveId>";
await incentivesSystem.SenderDelete(incentiveId);

Recipient incentives #

Getting recipient incentives #

You can get a recipient incentive for the user.

1
2
var incentiveCode = "<incentiveCode>";
var incentive = await incentivesSystem.RecipientGet(incentiveCode);

Claiming recipient incentives #

You can claim a recipient incentive for the user.

1
2
var incentiveCode = "<incentiveCode>";
var incentive = await incentivesSystem.RecipientClaim(incentiveCode);