Blog

Latest news and updates from the PlayFab developers

by Melissa Benua 2015-05-04

New Feature: Stackable Inventory Items

Since launch, PlayFab has provided a robust, fully-featured purchasing and inventory system that allows for things like bundles, virtual currencies, and consumables. Each item in the user's inventory is managed with an assigned ID tag, which allows for it to be independently managed by the game via PlayFab API calls.

But what if your game needs a LOT of items? For example, in the case of collectible card games like Dragon Foundry's forthcoming Nova Blitz, a player may have tons of instances of the same item. In order to make the scale easier for developers to manage, we at PlayFab are happy to introduce a simplified inventory system for managing stacks of items.

Built on top of the existing consumable system, the new stacking system allows you to indicate whether an item in your catalog is allowed to be stacked. If it is, players can buy thousands of instances without forcing developers to manage thousands of items.

How it works: When an item is marked as stacked, it will only ever return one ItemInstanceId and the value in RemainingUses will be incremented or decremented as more of the items are purchased or used up.

Here is the JSON of a catalog item that uses the new system. You can see the Usage Count is 10, and IsStackable is true:

  {
     "ItemId": "PinkPonyCard",
     "ItemClass": "Cards",
     "CatalogVersion": "FirstCatalog",
     "DisplayName": "Pink Pony Card",
     "Description": "A high-powered card of fun.",
     "VirtualCurrencyPrices": {
       "MB": 33
     },
     "RealCurrencyPrices": null,
     "Tags": [],
     "CustomData": "null",
     "GrantedIfPlayerHas": null,
     "Consumable": {
       <strong>"UsageCount": 10,</strong>
       "UsagePeriod": null,
       "UsagePeriodGroup": null
     },
     "Container": {
       "KeyItemId": null,
       "ItemContents": null,
       "ResultTableContents": null,
       "VirtualCurrencyContents": null
     },
     "Bundle": {
       "BundledItems": [],
       "BundledResultTables": [],
       "BundledVirtualCurrencies": null
     },
     "CanBecomeCharacter": false,
     "OneTimeGrantWith": null,
     "OneTimeGrantAnnotation": null,
     <strong>"IsStackable": true</strong>
   }

 

That's it! Every time a player is granted a PinkPonyCard, the number of RemainingUses on the first granted item will be incremented instead of a new ItemInstance being generated. The items that were granted will be available to view as a history of the purchase, but will not be listed as usable items.

For example, if the above item were to be granted to a player three times, her inventory would show one "Succeeded" item with a total of 30 uses. In Game Manager, you would also see the two other items with a status of "stacked" and 10 uses left each.

Card games aren't the only place that stackable items are useful. If you're building an RPG with a crafting system, players may need to collect many instances of the same item, such as wood or straw. Using PlayFab's stackable inventory process makes implementing that at scale much easier.