using DominionBase.Enums; using System.Collections.Generic; using System.Text; namespace DominionBase { public interface ICost : ICardBase { Traits Traits { get; } void Bought(IPlayer player); bool CanBuy(IPlayer player, Currency currency); } public class ICostCollection : List { private readonly object _MyLock = new object(); public ICostCollection() { } public ICostCollection(int capacity) : base(capacity) { } public ICostCollection(IEnumerable collection) : base(collection) { } public string ToString(bool isCollated) { if (!isCollated) return ToString(); StringBuilder sb = new StringBuilder(); ICost _previousCard = null; int count = 0; lock (_MyLock) { for (int cIndex = 0; cIndex < Count; cIndex++) { if (_previousCard == null) _previousCard = this[cIndex]; if (_previousCard.Type != this[cIndex].Type) { if (sb.Length != 0) sb.Append(", "); if (count > 1) sb.AppendFormat("{0}x {1}", count, _previousCard); else sb.Append(_previousCard); _previousCard = this[cIndex]; count = 0; } count++; } } if (_previousCard != null) { if (sb.Length != 0) sb.Append(", "); if (count > 1) sb.AppendFormat("{0}x {1}", count, _previousCard); else sb.Append(_previousCard); } return sb.ToString(); } } }