question

sking avatar image
sking asked

(Beginner) What's a good solution for purchasing timed upgrades with playfab?

My company is currently making a Clash of Clans type game and I've been tasked with implementing the purchasing building and upgrades.

The player requires gold and a builder (both virtual currencies at the moment) to create a building or upgrade it start a timer, which when finished, should complete the build or upgrade it to the next level. Pretty common F2P stuff.

I want to know what would be a good way to approach this with playfabs economy and item management features. Would each level of a building need to be a Catalog Item? How would I create the time stamp on the server for when it the item should be complete? Can I create this timestamp at the same time the item purchase occurs with existing API? Or will I have to create a cloud function that both initiates the purchase and allocates the timestamp?

I'm trying to keep things as server auth as possible.

Cheers!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

If you want to implement it with PlayFab Economy and Inventory, please note that you can only use one type of virtual currency to purchase items, the consumption of the other type of virtual currency needs to be handled manually, and you can only call client APIs to purchase item.

You can choose whether to create a Catalog item for each level, if you choose to create it, you can record how long it takes to build a building and other necessary information in custom data of Catalog item. Once player wants to buy(upgrade) the building, you should:

  1. Verify necessary information
  2. Call client API to purchase building
  3. Execute CloudScript to delete current building, handle another virtual currency and call API UpdateUserInventoryItemCustomData to add a timestamp to the custom data of purchased building

If you choose not to create it, then you need to create a configuration file in Title Data to record the information like price and how long it takes to build of all the buildings. If player wants to buy the building, you should perform steps above, the only difference is that you need to add a level to the custom data of purchased building. If player wants to upgrade the building, you can execute a CloudScript to:

  1. Verify necessary information
  2. Handle virtual currencies
  3. Call API UpdateUserInventoryItemCustomData to add a new timestamp and new level to the custom data of purchased building

You can call API GetUserInventory to get the timestamp in the custom data to determine if this building is completed.

I don’t know if your development process has been determined, if possible, I recommend you to create a configuration file in Title Data, and then record the current buildings' info in the Player Read Only Data. Once player want to buy or upgrade the buildings, you can execute a CloudScript to:

  1. Verify necessary information
  2. Handle virtual currencies
  3. Call API UpdateUserReadOnlyData to modify the buildings' info in Play Read Only Data

You can call API GetUserReadOnlyData to get the buildings' info. This process is clearer, and it is easier to load the buildings on the client side.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sking avatar image sking commented ·

Thank you for writing such a comprehensive answer with 2 different solutions.

We were intending on storing player data in Entity Files, since this playfab article:

https://docs.microsoft.com/en-us/gaming/playfab/features/data/playerdata/

recommends to use the new Entity Data model. Our current setup uses Entity Objects, but we soon learned that they can't hold enough of the player data with the 1kb limit.

Do you think it's a mistake for us to use Entity Files? We haven't made the transition yet so it would be great to know.

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao sking commented ·

You need to decide whether it is suitable according to the usage scenario. PlayFab has three ways to store data which are Entity Files, Entity Objects and Player Data. In the common scenario, we use Player Data for the most time. For data with big size and doesn’t change frequently, we suggest you to use Entity Files. For data you want to control the access policy, you can use Entity Objects. To be clear, Title player account(Entity) can store up to 5 Objects with a size of 1000 bytes each.

1 Like 1 ·
sking avatar image sking Gosen Gao commented ·
To be clear, Title player account(Entity) can store up to 5 Objects with a size of 1000 bytes each. 

Yes we learned that the hard way :,)

Thanks so much for your input, feeling a lot more confident now!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.