using DominionBase.Currencies; using DominionBase.Enums; using DominionBase.Piles; using DominionBase.Players; using DominionBase.Properties; using System.Diagnostics.Contracts; namespace DominionBase.Cards.Nocturne { public class Cobbler : Card { private IPlayer _turnStartedPlayer; public Cobbler() : base(Categories.Night | Categories.Duration, Source.Nocturne, Location.Kingdom, Traits.Gainer) { BaseCost = new Cost(5); } public override void TearDown(IGame game) { base.TearDown(game); if (_turnStartedPlayer != null) _turnStartedPlayer.TurnStarted -= Player_TurnStarted; _turnStartedPlayer = null; } public override void FollowInstructions(IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.FollowInstructions(player); CanCleanUpPlayed.Add(false); player.TurnStarted -= Player_TurnStarted; _turnStartedPlayer = player; _turnStartedPlayer.TurnStarted += Player_TurnStarted; } private void Player_TurnStarted(object sender, TurnStartedEventArgs e) { var key = ToString(); if (!e.Resolvers.ContainsKey(key)) e.Resolvers[key] = new TurnStartedResolver(e.Player, this, Resource.ResolveCard.Replace("{card}", PhysicalCard.ToString()), Player_Action, true); } internal void Player_Action(IPlayer player, ref TurnStartedEventArgs e) { ResolveDuration(e.Player); CanCleanUpPlayed.Remove(false); e.Player.TurnStarted -= Player_TurnStarted; _turnStartedPlayer = null; } public override void ResolveDuration(IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.ResolveDuration(player); var gainableSupplies = new SupplyCollection(player._Game.Table.TableEntities.FindAll(supply => supply.CanGain() && supply.CurrentCost <= new Coin(4))); var choice = new Choice(Resource.GainUpTo4ToHand, this, gainableSupplies, ChoiceOutcome.Gain, player, false); var result = player.MakeChoice(choice); // TODO -- Currently Nomad Camp will override the DeckLocation specification. I need to modify the .Gain() method to allow an absolute override. if (result.Supply != null) player.Gain(result.Supply, this, DeckLocation.Hand); } } }