question

drew avatar image
drew asked

Economy V2 - How to create Card game mechanics?

hi,

I am working on a classic CCG type mechanics game, similar to Heathstone and most other card games.

In these card games, you have a pack of cards which can be purchased for real life money, which contains random cards when opened of various rarity, and the cards can be destroyed in exchange for a different currency (in HS, it's called "dust") which can be spent to craft any card you like.

It was working great using the old Economy setup, I have each Card as a Container which is consumable and contains the currency. Then I have containers that represent packs which are consumable and contain drop tables which contain the Card containers.

This allows all of the basic CCG economy mechanics without writing a single line of code or worrying about atomic operations.

How can I achieve something similar using the new Economy setup? How can I disperse cards randomly and allow a user to consume a card and obtain a currency using an atomic transaction to prevent any possibilities of dupe type bugs?

apisIn-Game Economy
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

Since Economy v2 doesn’t include “Drop Tables” or “Containers”, and there are no built-in features suit for the features like convert cards to dust when player want to destroy the cards or randomly cards granted when players buy packs, you need to implement them with Azure Function. You mention that your game is working great with the Economy v1, you can keep using it.

4 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.

drew avatar image drew commented ·

thanks for the reply @Gosen Gao

My game is still in the prototyping phase, hoping to be released publicly in about 4 months.

The PlayFab documentation states that we should basically be using EconomyV2 since the EconomyV1 stuff is in "bug fix only mode".

It seems like now would be the ideal time to implement the new economy rather than later when the game is published and I have active users.

I am not afraid of using Azure Functions. Are there any examples of how to implement pack opening mechanics and dusting in Azure Functions?

Most importantly, how can I do an atomic operation where a player Consumes an Item and in exchange is granted a currency from the Server API?

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

Since Azure Function is highly customizable, we do not have examples for specific implementations like pack opening mechanics and dusting. Please refer to PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Learn and implement functions based on your requirements.

For ‘atomic operation’, you don’t have to worry about multiple requests consuming the same unique item being successful, and only one item is consumed but twice virtual currencies are granted. If the first request succeeds, the item instance will be destroyed, and subsequent requests will fail. It should be fine if your Azure Function only continues processing when the API is successful.

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

@Gosen Gao, Thanks so much for your reply. Azure Functions is highly customizable, which is why I'm pretty surprised that you guys haven't offered any best practices or guides on how to transition from InventoryV1 to InventoryV2. In the past, you have offered these in the docs and forums. In fact, in the PlayFab GitHub sample projects, there are examples of using the SDK in Azure functions. Are there really no GitHub example projects or docs/guides which show how to use InventoryV2 or how to transition from V1 API mechanics to V2 API mechanics? This will go a long way for you guys to get adoption of the new API.

0 Likes 0 ·
Show more comments
drew avatar image
drew answered

thanks for the reply @Gosen Gao

My game is still in the prototyping phase, hoping to be released publicly in about 4 months.

The PlayFab documentation states that we should basically be using EconomyV2 since the EconomyV1 stuff is in "bug fix only mode".

It seems like now would be the ideal time to implement the new economy rather than later when the game is published and I have active users.

I am not afraid of using Azure Functions. Are there any examples of how to implement pack opening mechanics and dusting in Azure Functions?

Most importantly, how can I do an atomic operation where a player Consumes an Item and in exchange is granted a currency from the Server API?

Thanks,

Drew

10 |1200

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

kylemc@microsoft.com avatar image
kylemc@microsoft.com answered

@drew we plan to provide more migration materials as Economy v2 moves into General Availability.

You can use the `ExecuteInventoryOperations` API to transactionally execute multiple operations against multiple stacks in the same collection.

PlayFab Inventory APIs - PlayFab | Microsoft Learn

5 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.

drew avatar image drew commented ·

thanks @kylemc@microsoft.com.

ExecuteInventoryOperations docs only mentions items, not currencies.

Did I misunderstand? Is it possible to remove or add a currency and remove or add an item in the same transaction using ExecuteInventoryOperations?

If not, how do you recommend item purchases to behave without errors? Is this something on the roadmap?

0 Likes 0 ·
drew avatar image drew commented ·

One other question/comment about ExecuteInventoryOperations.

It is limited to 5 actions only.

Most card games give 5 cards for opening a pack, which means you would subtract a Pack item and add 5 unique card Ids.

This would be 6 transactions total, so would be impossible to do with ExecuteInventoryOperations.

Is there a work-around or otherwise suggestion of how to purchase more than 4 items while spending another item using ExecuteInventoryOperations?

Thanks so much again

0 Likes 0 ·
kylemc@microsoft.com avatar image kylemc@microsoft.com drew commented ·

Currencies are items in V2. You can manage and use them in the same way.

We're considering raising the limit on ExecuteInventoryOperations once we get a better idea of how our preview customers are using it. We were investigating something the other day, and I noticed 5 might not actually be the limit we shipped. Give 6 a try.

0 Likes 0 ·
drew avatar image drew kylemc@microsoft.com commented ·

thanks @kylemc@microsoft.com. I think to keep parity with Drop Tables and Containers, you would need to allow more than 5, as you could do that with Drop Tables and Containers, without even needing to write any code. That being said, I appreciate you guys expanding this and making it better over time.

I am struggling to get my first Azure Function to work with InventoryV2. I have a simple Azure Function triggering using Rules. However, I can't see how to do this because AddInventoryItems expects title_player_account ID, and this ID does not exist in the payload for Azure Functions triggeered via rules (PlayerPlayStreamFunctionExecutionContext). How to get the title_player_account ID so I can add an inventory item inside a rule Azure Function? I have some custom logic and dont want to use Grant Item rule. Thanks!

0 Likes 0 ·
Show more comments

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.