Inventory #
The Inventory meta-system in Hiro enables players to collect, upgrade, and consume items in your game. These in-game items can be anything from a piece of equipment like a sword or chestplate, to a cosmetic item like a flag or costume, to a power up like a spawner or boost.
Inventory items can be purchased from the virtual store, or earned through gameplay.
Customization parameters #
The following JSON represents the customization parameters you can use to configure the default user experience for the inventory system.
|
|
The JSON schema defines several objects which define the various items and item sets that will be available in your game. You can configure as few or as many of each as needed for your desired gameplay.
items
#
The items
object is structured as follows:
Property | Description |
---|---|
name | The name for this item. |
description | The description for this item. |
category | The category for this item. |
item_sets | An array of string values that indicate which item sets this item belongs to. |
max_count | The maximum number of this item a user can own. |
stackable | A bool value indicating whether this item can stack. |
consumable | A bool value indicating whether this item can be consumed. |
consume_reward | A reward object that defines what rewards a user can or will receive for consuming the item. |
string_properties | A map of string values that define item specific metadata. |
numeric_properties | A map of number values that define item specific metadata. |
Item definitions #
Item categories #
Every item definition has a category
property. This is a simple string
property that defines which broad collection the item belongs to and is useful for listing items. For example, you may wish to separate your items into categories such as weapons
, armor
, and potions
.
Item sets #
Item definitions can optionally define an array of item_sets
that they belong to. Item sets differ from categories in that an item can belong to multiple sets at once. These item sets can be used as tags for the items in your game such as rare
and sword
.
Item sets are used in the reward system to allow users to be rewarded with a random item that belongs to specific sets (see example below).
Item rewards #
A powerful feature of the Inventory system is the ability for game designers to add consume rewards to item definitions. When a user consumes the item, they will be granted the reward accordingly. Due to the power and flexibility of the Hiro reward system, this allows game designers the opportunity to create all manner of consumables.
Consider the following scenarios and associated item definitions:
A potion that restores 50 health
|
|
A coin pouch that rewards between 100 and 500 gold coins in multiples of 10
|
|
A loot chest that rewards a sword and a random rare weapon
|
|
A loot chest that rewards a weighted random currency
|
|
Item instances #
When a user is granted an item, whether from a Store Purchase, as a Reward, or any other means, it is stored as an item instance inside their inventory. The inventory itself is stored inside the Storage Engine under a special collection/key for that user.
A user’s inventory has the following JSON schema.
|
|
The inventory is a map of item instance IDs and the associated item instance data, where each item instance has the following structure.
Property | Description |
---|---|
item_id | The ID of the item definition this is an instance of. |
owned_time | The time that this item was acquired. |
update_time | The time that this item was last updated. |
count | How many of this item the user currently has. |
string_properties | A map of string values that define item instance specific metadata. |
numeric_properties | A map of number values that define item instance specific metadata. |
Item properties #
Each item instance will copy across any properties that are defined in the string_properties
and numeric_properties
of the item definition by default.
Because item instances have their own metadata, this allows you to build systems where a user can customize, rank up, or modify the items they own. For example, you may have a weapon rank system that allows your players to “level up” their weapons, or a “gem slot” system that allows players to improve the stats of their items by socketing various gems to them, or perhaps you just want to keep track of how many monsters a user has defeated with a particular weapon as shown in the example above.
Item stacking #
Where an item is granted that is defined as stackable
, the inventory system will first check to see if the user currently has an item instance for that item ID. If they do, the count
property of that particular instance will be increased accordingly. If they don’t, or if the item is not stackable
, a new item instance will be generated instead and added to the user’s inventory.
Interacting with the Inventory system #
Listing the available items #
You can list the available items in the inventory system.
|
|
Listing the user’s inventory #
You can list a user’s inventory.
|
|
You can also filter the inventory by categories.
|
|
Granting inventory items #
You can grant inventory items to the user.
|
|
Consuming items #
You can consume items for a user that have the consumable
flag. You can specify whether or not the user is allowed to overconsume (use more than they have).
overconsume
to true
can be useful when handling multiple device scenarios. This allows consumption of the item, even if the local device’s resource data is out of sync. However, once the item reaches zero, further consumption is prevented, irrespective of the overconsume setting. This provides developers flexibility in managing inventory inconsistencies across devices.
|
|
Refreshing the inventory system #
You can refresh the inventory system’s data.
|
|