Inventory

devomage

Member
I'm diving a bit deeper into Inventory and have a couple questions. If you loop through your inventory:

C#:
//code snippets copied from InventoryBaseInspector.cs
var itemTypes = m_Inventory.GetAllItemTypes();
  • The only way to tell if an itemType is an item is if it is in a slot? => a bow is always an itemType until equipped?
  • How can you check if the itemType is a consumable?
If the itemType is an item equipped in a slot:

C#:
if (m_Inventory.GetItem(j) != null && m_Inventory.GetItem(j).ItemType == itemTypes[i])
  • How can I get a reference to the UsableItem?
  • Assuming I cant get a reference to UsableItem. How can I get a reference to the consumable?
 
The only way to tell if an itemType is an item is if it is in a slot? => a bow is always an itemType until equipped?

How can you check if the itemType is a consumable?
There isn't a way with the inventory - the inventory doesn't distinguish between regular item types and item types that are consumed.

How can I get a reference to the UsableItem?
Once you get the Item you can then loop through the ItemActions and determine if it is a usable item. Here's a code snippet:

Code:
            var item = m_Inventory.GetItem(slotID);
            if (item != null) {
                var itemActions = item.ItemActions;
                for (int i = 0; i < itemActions.Length; ++i) {
                    var usableItem = itemActions[i] as UltimateCharacterController.Items.Actions.IUsableItem;
                    if (usableItem != null) {
                       // do something
                    }
                }
            }
 
Top