public void Add(Bag bag) { if (itemName.Length == 3) { category = "Cash"; } else if (itemName.ToLower().EndsWith("gem")) { category = "Gem"; } else if (itemName.ToLower() == "gold") { category = "Gold"; } if (category == "" || maxCapacity < bag.GetBagSum() + quantity) { return; } switch (category) { case "Gem": if (!bag.Contains(category)) { if (bag.Contains("Gold")) { if (quantity > bag.GetCategory("Gold").GetSum()) { return; } } else { return; } } else if (bag.GetCategory(category).GetSum() + quantity > bag.GetCategory("Gold").GetSum()) { return; } break; case "Cash": if (!bag.Contains(category)) { if (bag.Contains("Gem")) { if (quantity > bag.GetCategory("Gem").GetSum()) { return; } } else { return; } } else if (bag.GetCategory(category).GetSum() + quantity > bag.GetCategory("Gem").GetSum()) { return; } break; } if (!bag.Contains(category)) { bag.Add(category); } if (!bag.GetCategory(category).Contains(itemName)) { bag.GetCategory(category).AddItem(itemName); bag.GetCategory(category).GetItem(itemName).Quantity = 0; } bag.GetCategory(category).GetItem(itemName).Quantity += quantity; }