Deduct the given amounts from each energy for multiple users in a single atomic transaction. Either all users spend successfully or none do.
usersAmounts is a map of user IDs to energy amounts. Each user can spend from one or more energy types in the same call.
If any user has insufficient energy, the entire transaction fails and no energy is deducted for any user. Duplicate user IDs in usersAmounts are deduplicated automatically.
The function returns:
userEnergies: a map of user ID to energy ID to current Energy state after deduction
userRewards: a map of user ID to the aggregated Reward earned across all energy spends for that user
Set a custom reward function which will run after an energy reward’s value has been rolled.
1
2
3
4
5
6
systems.GetEnergySystem().SetOnSpendReward(OnSpendReward)funcOnSpendReward(ctxcontext.Context,loggerruntime.Logger,nkruntime.NakamaModule,userID,sourceIDstring,source*hiro.EnergyConfigEnergy,rewardConfig*hiro.EconomyConfigReward,reward*hiro.Reward)(*hiro.Reward,error){// Modify reward or take additional actions.
returnreward,nil}