using System.Collections.Generic;
public static string TabCountPrint(int count)
for(int i=0; i < count; i++)
public enum InventoryOwnerType
public struct InventoryOwner
public InventoryOwnerType type;
public InventoryOwner() : this(0, InventoryOwnerType.None) { }
public InventoryOwner(int id, InventoryOwnerType type)
public DateTime _create_time;
private Inventory _items;
_items = new Inventory();
public Item(int id, int type, int amount)
_create_time = DateTime.Now;
public InventoryOwner ownerInfo = new InventoryOwner();
public List<Item> items = new List<Item>();
public Inventory(int ownerId)
public Inventory(int ownerId, InventoryOwnerType ownerType)
ownerInfo.type = ownerType;
public Inventory(List<Item> items)
public void AddItem(Item item)
public void RemoveItem(Item item)
public bool IsContains(Item item)
return this.items.Contains(item);
public int GetitemSCount()
public int GetItemsCountAll()
int count = GetitemSCount();
foreach(var item in this.items)
if(item.items?.GetitemSCount() > 0)
count += item.items.GetItemsCountAll();
public void ShowItemInfo(Item item, int tabCount = 0)
Console.WriteLine($"{TabCountPrint(tabCount)}| id: {item._id} | type: {item._type} | amount: {item._amount} | create_time: {item._create_time} | itemsCount: {item.items?.GetitemSCount() ?? 0}");
public void ShowItemInfo(int index)
ShowItemInfo(this.items[index]);
public void ShowItemsList(int tabCount = 0)
string tabStr = TabCountPrint(tabCount);
Console.WriteLine(tabStr + "| invetory > owner_id: " + ownerInfo.id + " | owner_type: " + ownerInfo.type);
foreach(var item in this.items)
ShowItemInfo(item, tabCount);
if(item.items?.GetitemSCount() > 0)
item.items.ShowItemsList(tabCount + 1);
Console.WriteLine(tabStr + "| ItemsCount: " + GetitemSCount());
Console.WriteLine(tabStr + "| ItemsCountAll: " + GetItemsCountAll());
if(ownerInfo.type != InventoryOwnerType.InventoryItem)
public static void Main()
Inventory inventory = new Inventory(1, InventoryOwnerType.Player)
inventory.ShowItemsList();
Inventory inventory1 = new Inventory(2, InventoryOwnerType.Player);
inventory1.AddItem(new Item(1, 50, 10));
inventory1.AddItem(new Item(2, 60, 12));
inventory1.AddItem(new Item(3, 70, 14));
inventory1.items[0].items.AddItem(new Item(3, 70, 14));
inventory1.ShowItemsList();