public override string ToString() { var builder = new StringBuilder(); if (Gold.Any()) { builder.AppendLine($"<Gold> ${GoldAmount}"); builder.AppendLine($"##Gold - {GoldAmount}"); } if (Gems.Any()) { builder.AppendLine($"<Gem> ${GemsAmount}"); foreach (var gem in Gems.OrderByDescending(g => g.Value.Name).ThenBy(g => g.Value.Amount)) { builder.AppendLine($"##{gem.Value.Name} - {gem.Value.Amount}"); } } if (AllCash.Any()) { builder.AppendLine($"<Cash> ${CashAmount}"); foreach (var cash in AllCash.OrderByDescending(c => c.Value.Name).ThenBy(c => c.Value.Amount)) { builder.AppendLine($"##{cash.Value.Name} - {cash.Value.Amount}"); } } return(builder.ToString()); }
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; } }