using DominionBase.Enums; using DominionBase.Piles; using DominionBase.Players; using DominionBase.Properties; using System.Diagnostics.Contracts; namespace DominionBase.Cards.Menagerie { public class CamelTrain : Card { public CamelTrain() : base(Categories.Action, Source.Menagerie, Location.Kingdom, Traits.Exiler | Traits.Gainer | Traits.ReactToGain | Traits.Terminal) { BaseCost = new Cost(3); } public override void SetupCard(IGame game) { Contract.Requires(game != null, "game cannot be null"); base.SetupCard(game); foreach (var player in game.Players) player.CardGained += Player_CardGained; } public override void TearDown(IGame game) { Contract.Requires(game != null, "game cannot be null"); base.TearDown(game); foreach (var player in game.Players) player.CardGained -= Player_CardGained; } private void Player_CardGained(object sender, Players.CardGainEventArgs e) { var player = sender as IPlayer; var key = TypeClass.CamelTrain.ToString(); // This is not the card you are looking for if (e.Card != this || e.Resolvers.ContainsKey(key) || e.HandledBy.Contains(this)) return; e.Resolvers[key] = new CardGainResolver(player, this, "ResolveCard", $"Resolve {Name}", (IPlayer playerAction, ref Players.CardGainEventArgs eAction) => { if (playerAction._Game.Table.Gold.Count > 0) ExileFromSupply(playerAction, playerAction._Game.Table.Gold); eAction.HandledBy.Add(this); }, true); } public override void FollowInstructions(IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.FollowInstructions(player); var exileableSupplies = new SupplyCollection(player._Game.Table.TableEntities.FindAll( supply => supply.TopCard != null && !supply.TopCard.Category.HasFlag(Categories.Victory) )); var choiceExile = new Choice(Resource.ExileNonVictoryFromSupply, this, exileableSupplies, ChoiceOutcome.Trash, player, false); var resultExile = player.MakeChoice(choiceExile); if (resultExile.Supply != null) ExileFromSupply(player, resultExile.Supply); } private void ExileFromSupply(IPlayer player, ISupply supply) { var toExile = supply.Take(); player.AddCardInto(TypeClass.Exile, toExile); toExile.ReceivedBy(player); player._Game.SendMessage(player, this, "Exile", toExile); } } }