public void AddGem(string name, long value) { if (Capacity + value <= MaxCapacity && GetGoldAmount() >= GetGemsAmount() + value) { if (!Gems.Any(g => g.Name == name)) { Gems.Add(new Gem(name)); } var current = Gems.FirstOrDefault(g => g.Name == name); current.Value += value; Capacity += value; } }
public void AddGem(string name, long quantity) { if (IsEnoughSpace(quantity) && Gold >= Gems.Sum(g => g.Quantity) + quantity) { Gem gem = Gems.FirstOrDefault(g => g.Name == name); if (gem == null) { gem = new Gem(name); Gems.Add(gem); } gem.Quantity += quantity; } }
public IReadOnlyList <Gem> GetGemsInSlot(ItemSlot slot) => Gems.FirstOrDefault(gs => gs.First().ItemSlot == slot) ?? Array.Empty <Gem>();