There is a item in my game, it needs gold and crystal to purchase it, how to do it?
There is a item in my game, it needs gold and crystal to purchase it, how to do it?
Prices in the catalog and its stores are "or" pricing - so specifying a price in more than one virtual currency is saying that the item can be purchase for X of VC 1 or Y of VC 2. This is a common model for free-to-play games, as they have both "grind" and "hard" currencies. To purchase an item for X of VC 1 plus Y of VC 2, you would need to use Cloud Script for now. The same applies to purchasing items with other items. In general, the flow would be:
1. Check that the player has what it takes to make the purchase,
2. Grant the item(s)
3. Subtract or revoke the VCs/item(s).
That way, in the rare instance where the script fails before the end, you won't have a case where you subtract the VC/item(s) before granting the purchase (greatly preferable to the opposite).
We do plan to add a "crafting/alchemy" type system in future, in which you will be able to define one or more items/VCs as both inputs and outputs to "recipes", which you could then use as a more complex purchasing system. This hasn't been scheduled as yet though, so the Cloud Script would be the way to go for the moment.
1. Check that the player has what it takes to make the purchase,
2. Grant the item(s)
3. Subtract or revoke the VCs/item(s).
This is a database transaction, right? I am not good at it.
Each is an API call:
1. https://api.playfab.com/documentation/server/method/GetUserInventory - so that you can check it for the VCs/items needed to make the purchase
2. https://api.playfab.com/documentation/server/method/GrantItemsToUser - to grant the item(s)
3. https://api.playfab.com/documentation/server/method/SubtractUserVirtualCurrency and/or https://api.playfab.com/documentation/server/method/RevokeInventoryItem - to remove the VCs/item(s)
After a quick searching, it seems that the server API does not support transaction like SQL.I don't know whether the Cloud Script is secure to do this.
2 People are following this question.