Inventory "Storage Item" Implementation

Hey everybody!
I’m attempting to implement a “Storage Item” into my game. But I’m having trouble planning out how it would work. I already have an Inventory System made, but this Storage Item is giving me trouble.

The Storage Item basically acts as a pouch you hold in your inventory. Like a coin purse that holds your money, or a Potion sack that holds your potions. Like a mini inventory you hold in your actual inventory.

So far I have the following:

public class Inventory{
    public ItemStack[] inventory;
}
public class ItemStack{
    public Item item;
    publin int amount;
}
public abstract class StorageItem : Item{
    public Item storedItem;    //Specific Item the StorageItem can contain.
    public int storedMax;      //Maximum amount the StorageItem can contain
    //StorageItem's Item.maxStack = 1; Should never be stackeable, but should hold stacks of storedItem
}
public abstract class Item{
    public int id;
    public string name;
    public int maxStack;
}

Does anyone have an idea how they would get ItemStack and StorageItem to work together in an inventory System?

Example:
If I wanted to add a health potion, my inventory would search through, find all existing stacks, (Including StorageItems holding health potions), and attempt to fill them.
But the ItemStack that holds the StorageItem already has an amount, which corresponds to the actual StorageItem rather than the item it stores. And Since StorageItem should never be stack on itself (but stacks other items in itself), it is always ‘full’.

The way we have it set up in our project is a LootContainer class and a LootItem class. A single object can have the container and the item class on it, which makes it a container that can be added to another container. LootContainer is the base class that containers in the world, the player’s inventory, and containers that can be picked up all inherit from. LootItem handles things like picking up and dropping the item, and adding and removing it from a container.

1 Like

Thank you very much for the reply. Having a LootContainer class combined with a LootItem class seems like a neat idea that I haven’t quite thought about before. It might take some work to rewrite my Inventory System to work with that idea, but I’m sure in the end it would work better than what I have currently. Thanks again!