Sorry for the rather long text, but I hope this explains what I want to archive.
I hope someone can explain the best practices for granting reward items.
At the moment we use two methods:
1. At strategic best matching places (e.g. when starting the game, after finishing an event) we call a cloud script function like checkForRewards() and return a list of items which should be granted to the user along with a explanation text why the item will be granted.
In the game, if we receive such items we display then a dialog: You have been granted item X because of Y.
2. In case of a Task granting such items (e.g. Top ranked in leaderboard on reset) things are a bit more complicated. In such a case we grant a item (GrantableRewardItem) to the user. In the custom item properties we add a string for the reason why it was granted and a reference to the actual item to be granted. Optionally if the item changes the virtual currency balance we also include the amount of VC to be granted). Then, at strategic best matching places we call the same method as described in the previous point. There we find the GrantableRewardItem, return it to game code, display the dialog, and when the user closes the dialog we call another cloud script function with the GrantableRewardItem as parameter which then actually grants the item to the user inventory, or optionally add VCs. (the amount of VC to be granted because of rewards is very dynamic, so we can't create items for each and every case).
Another reason why we use this 2 step process is that the user doesn't have his virtual currency balance already increased when he starts the game but actually recognises the change of this balance when he accepts the reward.
The main reason we don't just use GrantItems (e.g. from a Task) is that when the user starts the app and we initially query the inventory, balance, etc.. we don't want this reward items to be reflected in the virtual currency balance already. People should "see" the virtual currency balance change or the popup of new item only after a dialog told them why they got new things. This should also work across devices, so we can't keep a record of items to check if something was added to the inventory between two sessions.
To conclude, whenever we grant a reward we do following:
Server side:
- Grant GrantableRewardItem.
Custom Item Properties:
- OPTIONAL: Reference to a item. (e.g. ItemBattlePack)
- OPTIONAL: Amount of VC to be granted (e.g. 17 coins)
- REQUIRED: Reason (You earned 17 coins for ranking up)
Client side:
- Call checkForReward()
Get a list of all GrantableRewardItems in the users inventory
For each GrantableRewardItem display a dialog why item will be granted
On Dialog close, call rewardItem(thisItem) on the server
Server code:
- Reward the either optional reference item or change virtual currency balance
Remove the GrantableRewardItem from the inventory
Return new inventory list and new virtual currency balance
Client side:
- Update virtual currency balance (e.g. in the status bar in each menus display current amount of virtual currency)
Although this works really nice and stable, I ask myself if there isn't a more integrated way of doing this.