Inventory #

Players can obtain weapons and utility items via an Inventory system in Squad Alpha by Say Games.
Players can obtain weapons and utility items via an Inventory system in Squad Alpha by Say Games.

Inventory is a Hiro GDK meta system which enables players to collect, upgrade, and consume items in your game. These in-game items can be anything from a cosmetic item like a flag or costume, to a power up like a spawner or boost, to a currency like gems or coins.

Inventory items can be purchased from the virtual store, or earned through gameplay.

See the customization parameters for inventory items here.

Regardless of the exact form, in-game items will generally fall into one of two categories: collectables and consumables.

Listing the user’s inventory #

You can list a user’s inventory.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
var inventory = await economySystem.ListInventoryAsync();

foreach (var collectableKvp in inventory.Collectables)
{
    var id = collectableKvp.Key;
    var collectable = collectableKvp.Value;
    Debug.Log($"Collectable {id}: {collectable.Name} - {collectable.Description}");
}

foreach (var consumableKvp in inventory.Consumables)
{
    var id = consumableKvp.Key;
    var consumable = consumableKvp.Value;
    Debug.Log($"Consumable {id}: {consumable.Name} - {consumable.Description}. Count: {consumable.Count}");
}

You can also filter the inventory by collectable and consumable categories.

1
2
3
4
var collectableCategory = "<category1>";
var consumableCategory = "<category2>";

var inventory = await economySystem.ListInventoryAsync(collectableCategory, consumableCategory);

Granting inventory items #

You can grant inventory items to the user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
var currencies = new Dictionary<string, long>
{
    { "coins", 100 },
    { "gems", 5 }
};

var consumables = new Dictionary<string, long>
{
    { "<consumableId1>", 1 },
    { "<consumableId2>", 10 }
};

var collectables = new List<string> { "<collectableId1>", "<collectableId2>" };

await economySystem.GrantAsync(currencies, consumables, collectables);

Collectables #

Collectables are items that can be obtained or removed but only ever represent a single value (e.g. a costume).

Listing available collectables #

You can list available collectables.

1
2
3
4
5
6
foreach (var collectableKvp in economySystem.Collectables)
{
    var id = collectableKvp.Key;
    var collectable = collectableKvp.Value;
    Debug.Log($"Collectable {id}: {collectable.Name} - {collectable.Description}. Owned: {collectable.IsOwned}");
}

Refreshing collectables #

You can refresh the economy system’s collectables data.

1
await economySystem.RefreshCollectablesAsync();

Removing collectables #

You can remove collectables from a user.

1
await economySystem.RemoveCollectablesAsync(new[] { "<collectableId1>", "<collectableId2>" });

Consumables #

Consumables have a count, and optionally a max count which indicates it is limited to some defined value. When consumed the value is always clamped to zero. A max count of 0 (zero) means that an unlimited number of that item can be owned.

When a consumable is consumed it can be indicated whether the value can be “overconsumed” before it is clamped. This is useful for items like a spawner which can be used to spawn multiple units at once.

Listing available consumables #

You can list available consumables.

1
2
3
4
5
6
foreach (var consumableKvp in economySystem.Consumables)
{
    var id = consumableKvp.Key;
    var consumable = consumableKvp.Value;
    Debug.Log($"Consumable {id}: {consumable.Name} - {consumable.Description}. Owned: {consumable.IsOwned}");
}

Consuming consumables #

You can consume consumables for the user. You can specify whether or not the user is allowed to overconsume (use more than they have).

1
2
3
4
5
6
7
8
9
var toConsume = new Dictionary<string, long>
{
    {"<consumableId1>", 2},
    {"<consumableId2>", 1}
};

var overconsume = false;

await economySystem.ConsumeAsync(toConsume, overconsume);

Refreshing consumables #

You can refresh the economy system’s collectables data.

1
await economySystem.RefreshConsumablesAsync();