public void removeItem(A_Item item, List <A_Item> storage) { A_Item invItem = storage.Find(x => x.GetType().Name.Equals(item.GetType().Name)); invItem.itemCount--; if (invItem.itemCount <= 0) { storage.Remove(item); } }
private A_Item returnStack(A_Item item, List <A_Item> storage) { foreach (A_Item invItem in storage) { if (invItem.GetType().Name.Equals(item.GetType().Name)) //get first item from stack { return(invItem); } } return(null); }
//for items storage public void addItem(A_Item item, List <A_Item> storage) { A_Item invItem = null; if (item.stackable) { invItem = returnStack(item, storage); } if (invItem != null) { storage.Find(x => x.GetType().Name.Equals(invItem.GetType().Name)).itemCount++; } else { storage.Add(item); } }