using DominionBase.Enums; using DominionBase.Piles; using DominionBase.Players; using DominionBase.Properties; using System.Diagnostics.Contracts; using System.Linq; namespace DominionBase.Cards.Menagerie { public class Pursue : Event { public Pursue() : base(Source.Menagerie, 2, Traits.CardOrdering | Traits.Discard | Traits.PlusBuy) { Benefit.Buys = 1; } public override void Bought(IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.Bought(player); var availableSupplies = new SupplyCollection(player._Game.Table.TableEntities.FindAll( kvp => (kvp.Randomizer != null && !kvp.Randomizer.Traits.HasFlag(Traits.Randomizer)) || kvp.Location == Location.General )); var cards = new CardCollection(); var choice = new Choice(Resource.NameCard, this, availableSupplies, ChoiceOutcome.Select, player, false); foreach (var supply in player._Game.Table.TableEntities.Values.OfType().Union(player._Game.Table.SpecialPiles.Values.OfType())) { cards.AddRange( from type in supply.Types where choice.Supplies.All(kvp => kvp.Value is ISupply kvpSupply && kvpSupply.Type != type) select Card.CreateInstance(type) ); } cards.Sort(); choice.AddCards(cards); var result = player.MakeChoice(choice); IDisplayable namedCard; if (result.Supply != null) namedCard = result.Supply; else namedCard = result.Cards[0]; player._Game.SendMessage(player, this, namedCard); player.Draw(4, DeckLocation.Revealed); player.AddCardsToDeck(player.RetrieveCardsFrom(DeckLocation.Revealed, c => c.Name == namedCard.Name), DeckPosition.Top); player.DiscardRevealed(); } } }