using System.Collections.Generic;
public InventoryOwnerType type;
public InventoryOwner(int id, InventoryOwnerType type)
public InventoryOwner ownerInfo;
public DateTime createTime;
public Item(int id, int type, int amount, InventoryOwner ownerInfo = default, DateTime createTime = default)
this.ownerInfo = ownerInfo;
this.createTime = createTime == default ? DateTime.Now : createTime;
items = new Inventory(id, InventoryOwnerType.InventoryItem);
Console.WriteLine($"[ownerId: {ownerInfo.id} | ownerType: {ownerInfo.type}]");
Console.WriteLine($"[id: {id} | type: {type} | amount: {amount} | createTime: {createTime}]");
public static int createdInventoryCount;
public InventoryOwner ownerInfo { get; private set; }
private List<Item> _items = new List<Item>();
private set => _items = value;
public Inventory(int ownerId, InventoryOwnerType ownerType = InventoryOwnerType.None)
ownerInfo = new InventoryOwner(ownerId, ownerType);
Inventory.createdInventoryCount++;
public Item this[int index]
public void AddItem(Item item)
item.ownerInfo.id = ownerInfo.id;
item.ownerInfo.type = ownerInfo.type;
public void AddItem(params Item[] arrItems)
foreach(var item in arrItems)
public int GetItemsCount()
public void PrintItemsInfo()
Console.WriteLine($"| inventoryOwnerInfo [id: {ownerInfo.id} | type: {ownerInfo.type}]");
Console.WriteLine( "| itemsCount: " + GetItemsCount() + "\n|");
foreach(var item in items)
Console.WriteLine($"| id: {item.id} | type: {item.type} | amount: {item.amount} | createTime: {item.createTime}");
if(item.items.GetItemsCount() > 0)
item.items.PrintItemsInfo();
public static void Main()
Console.WriteLine("Hello World");
var inventory = new Inventory(1, InventoryOwnerType.Player);
inventory.PrintItemsInfo();
var inventory2 = new Inventory(2, InventoryOwnerType.Player);
invRef = invRef[0].items;
invRef.AddItem(new Item(15, 3, 100));
invRef.AddItem(new Item(16, 3, 120));
invRef.AddItem(new Item(17, 3, 140));
inventory2.PrintItemsInfo();
inventory2[1].PrintInfo();
inventory2[0].items[2].PrintInfo();
Console.WriteLine("\ninventoryCreated: " + Inventory.createdInventoryCount);