Inventory¶
Inventory in games is a crucial feature for managing player-owned items and currencies. It tracks player acquisitions, whether through in-game purchases, rewards, or other means. Balancy seamlessly integrates inventory management, ensuring a smooth player experience.
Uses of Inventory¶
Inventory systems can be adapted for various game types, including:
- In-Game Currencies: Managing virtual money, gems, or resources.
- Storage in Farm Games: Keeping track of harvested crops, tools, and equipment.
- Bag and Inventory in RPGs: Holding weapons, potions, and other RPG essentials.
- Board in Merge Games: Organizing mergeable items or tiles.
Inventory Item Types¶
Each inventory is designed to store specific types of items. Currently, items are categorized into two types: Currency and Item.
Balancy's Built-in Inventories¶
Make sure you have the latest LiveOps package. In the latest package you can set the type for each Item:
- Currency: all the resources, such as Coins, Gems, Crystals, which can be spend to buy other items. Usually this list is very limited.
- Item: all other items, like boosters, weapons, runes, etc...
Balancy provides two default inventory systems in the system profile:
- Currencies Inventory: For managing virtual currencies. Accepts only Currency items.
- Storage Inventory: For general item storage. Can accept any kind of items.
var currenciesInventory = Balancy.LiveOps.Profile.Inventories.Currencies;
var itemsInventory = Balancy.LiveOps.Profile.Inventories.Items;
There are several methods to manipulate with all the inventories. While working with inventories, the inventories are used is the same order: Currencies ► Items ► Custom Inventories. If you decide to add currency items, they will be placed in the Currencies inventory even though the Items inventory can accept the currency as well. All built-in inventories are auto-expandable, so they can fit any amount of items.
var totalItems = Balancy.LiveOps.Profile.Inventories.GetTotalAmountOfItems(item);
Balancy.LiveOps.Profile.Inventories.RemoveItems(item, amount);
Balancy.LiveOps.Profile.Inventories.AddItems(item, amount);
//remove the items in the price from inventories
Balancy.LiveOps.Profile.Inventories.RemovePrice(price);
//add items in the reward to the inventories
Balancy.LiveOps.Profile.Inventories.AddReward(reward);
//a convenient method to check if you have anough items to do soft purchase
var enoughItems = Balancy.LiveOps.Profile.Inventories.HaveEnoughItems(price);
Inventory Class Structure¶
The Inventory
class encompasses:
- Config: Linked to
InventoryConfig
(temporary not used). - Slots: A list of inventory slots.
- Item: An instance of
ItemInstance
.- Id: Instance Id of the item.
- Item: Linked to SmartObjects.Item.
- Count: Quantity of the item.
- Created: Creation timestamp.
- Updated: Last update timestamp.
- Item: An instance of
Inventory Operations¶
With an inventory, you can:
GetCopyOfAllSlots()
: Retrieve the copy of all inventory slots.GetCopyOfItemInSlot(slotIndex)
: Retrieve the copy of the item in the specific slot.AddItem(Item, Count, [SlotIndex])
: Add an item to the inventory.CanAddItem(Item, Count)
: Check if an item can be added.ExchangeSlots(Slot1, Slot2)
: Swap items between two slots.GetTotalAmountOfItems(Item)
: Get total quantity of a specific item.RemoveItem(Item, Count)
: Remove a specified quantity of an item.RemoveItem(SlotIndex)
: Remove an item from a specific slot.Clear()
: Empty the inventory.RemoveEmptySlots()
: Remove all slots without items.
Custom Inventory¶
This feature is under construction. Once it's live, you will be able to add unlimited amount of inventories with unique configs.