question

Markus Henschel avatar image
Markus Henschel asked

Guidance on how to implement a complex inventory

Hello!

We have an inventory in our game that needs to store store frequently changing data for each item instance. Items can also be containers with other items inside.

So we store this per item instance.

Inventory Item Instance:

  • Count
  • x,y Position in a container
  • Durability
  • List of contained items

The player can modify the inventory basically at any time. This is a session based game with a dedicated server so bulk updates to the inventory will happen at the end of a match. When not being in a match the player can also modify the inventory. It will also be possible to add items in some way as items have a certain stack size and can be split and combined by the user.

Currently we are storing all of this as Character/Player Data which has the advantage that the whole inventory can be updated with a single cloud script call. We didn't implement validation yet in cloud script but in theory it should be doable. (Just check if the call didn't change the overall number of a certain item type)

I see issues though later when going life because this lacks features like transaction history and is harder to connect to some kind of shop. We would have to rely on very carefully crafted cloud script to make it work safely.

Looking at the inventory system PlayFab provides it seems like we could use it in theory as it provides metadata of item instances for storing our custom item data (position, durability,contained items).

But practically this would require a quite high amount of API calls. What is now a single call to to write the new inventory would then later be:

Our inventory has a lot of items in it. Every character can have 30 items and the shared storage (like the big chest in diablo) can have more than 100.

I have a hard time imagining how to implement this. The dedicated server is most probably not the biggest problem since it is a trusted source and can do all the updates required to the inventory in several steps even though this would not be ideal.

But when the client want's to do inventory management when not playing a game it would mean every change has to happen with PlayFab. That could be a lot of calls to:

  • grant item
  • revoke item
  • modify item uses
  • update custom data

Is there a rate limit on on any of those calls I just found a limit on how many custom data key/value pairs can be modified at once.

In general, would you recommend using the PlayFab inventory system for something like that?

Best Regards

Markus

In-Game EconomyPlayer Inventory
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

·
Seth Du avatar image
Seth Du answered

I think it should work fine and in most of the time, it won’t exceed the limit. The item management related API limit is not specified because it won’t exceed easily and most of the limit is player-specific, which means different players won’t share the same limit. In the meantime, Server API will have a more tolerable rate.

We will need to know a proximate number of update frequency of your game to provide suggestions. Since it is a bulk update, you may also try to reduce API frequency to increase stability. For example, if you have multiple users and items, try to use GrantItemsToUsers APIs instead of multiple GrantItemsToUser APIs.

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.

Markus Henschel avatar image Markus Henschel commented ·

Hi.

Thanks for the hint with GrantItemsToUsers. This also seem to allow specifying item instance metadata but unfortunately not item uses.

I don't really understand what KeysToRemove is supposed to do in ItemGrant. When granting new items and adding item instance metadata via the Data member what would be the point of removing keys from the new item instance at this point? The metadata should be empty anyway unless I put something into the Data member?

So I don't see a way to set the whole inventory with one API call. In the worst case I still have to do multiple inventory API calls per item instance like setting the use count, moving the item between user and characters and inside their parent container.

The frequency of item updates would be in the worst case every second if the player moves items around all the time. Usually those updates would be less frequent though. Let's say usually the user does like 30 updates to items in a minute. Then a match is played on the dedicated server for 15 minutes and the server then needs to sync the changed inventory from the match back to PlayFab which would be 30 item updates.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Markus Henschel commented ·

I think it is necessary to have a checkpoint setting for your game to collection update information and send corresponding PlayFab API once a while to reduce the frequency. The requirement you have mentioned is not suitable for a service based on RESTful API. Even in a dedicated host server, it is unnecessary to keep the data up-to-date unless it is MMO game. If it is a session-based game, which PlayFab supports better, usually the changes can be cached temporarily until the end of the game and the updates should be during finishing the game and before the server is shut down.

0 Likes 0 ·
Markus Henschel avatar image Markus Henschel Seth Du ♦ commented ·

The dedicated server will definitely send any updates it has once at the end of the session. The case where the frequency of updates is potentially higher is when the player is not playing a session right now but is in the menu. There players can also do inventory updates that need to be persisted to PlayFab. Also there updates can be batched together but this is creating quite some complex logic that I hoped to avoid. The client would have to do this via cloudscript since some validations have to be made. What would be an acceptable frequency for the inventory updates?

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.