using DominionBase.Currencies; using DominionBase.Enums; using DominionBase.Piles; using DominionBase.Players; using DominionBase.Properties; using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; namespace DominionBase.Cards.Guilds2ndEdition { public static class TypeClass { public static readonly Type Advisor = typeof(Advisor); public static readonly Type Baker = typeof(Baker); public static readonly Type Butcher = typeof(Butcher); public static readonly Type CandlestickMaker = typeof(CandlestickMaker); public static readonly Type Doctor = typeof(Doctor); public static readonly Type Herald = typeof(Herald); public static readonly Type Journeyman = typeof(Journeyman); public static readonly Type Masterpiece = typeof(Masterpiece); public static readonly Type MerchantGuild = typeof(MerchantGuild); public static readonly Type Plaza = typeof(Plaza); public static readonly Type Soothsayer = typeof(Soothsayer); public static readonly Type Stonemason = typeof(Stonemason); public static readonly Type Taxman = typeof(Taxman); } public class Advisor : Guilds.Advisor { public Advisor() : base(Edition.Second) { } } public class Baker : Card { public Baker() : base(Categories.Action, Source.Guilds, Location.Kingdom, Traits.Component | Traits.PlusCard | Traits.PlusAction | Traits.PlusCoffer | Traits.Cantrip, edition: Edition.Second) { Edition = Edition.Second; BaseCost = new Cost(5); Benefit.Cards = 1; Benefit.Actions = 1; Benefit.Coffers = 1; } public override bool Finalize(IGame game, ISupply supply) { Contract.Requires(game != null, "game cannot be null"); if (base.Finalize(game, supply)) return true; foreach (var player in game.Players) player.ReceiveBenefit(this, new CardBenefit { Coffers = 1 }); return false; } } public class Butcher : Card { public Butcher() : base(Categories.Action, Source.Guilds, Location.Kingdom, Traits.Component | Traits.Gainer | Traits.PlusCoffer | Traits.RemoveCurses | Traits.Terminal | Traits.Trasher, edition: Edition.Second) { BaseCost = new Cost(5); Benefit.Coffers = 2; } public override void FollowInstructions(IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.FollowInstructions(player); var choiceTrash = new Choice(Resource.ChooseToTrashOptional, this, player.Hand, ChoiceOutcome.Trash, player, minimum: 0); var resultTrash = player.MakeChoice(choiceTrash); if (resultTrash.Cards.Any()) { player.Trash(this, player.RetrieveCardsFrom(DeckLocation.Hand, resultTrash.Cards)); var options = new List(); for (var i = 0; i <= player.Coffers; i++) options.Add(i.ToString(CultureInfo.InvariantCulture)); var choiceOverpay = new Choice("You may remove any number of Coffers tokens", this, new ICardBaseCollection { this }, options, player); var resultOverpay = player.MakeChoice(choiceOverpay); var overpayAmount = int.Parse(resultOverpay.Options[0], CultureInfo.InvariantCulture); player._Game.SendMessage(player, this, overpayAmount); player.ReceiveBenefit(this, new CardBenefit { Coffers = -overpayAmount }); var trashedCardCost = player._Game.ComputeCost(resultTrash.Cards[0]); var gainableSupplies = new SupplyCollection( player._Game.Table.TableEntities.FindAll( supply => supply.CanGain() && supply.CurrentCost <= trashedCardCost + new Coin(overpayAmount))); var choice = new Choice(Resource.GainCard, this, gainableSupplies, ChoiceOutcome.Gain, player, false); var result = player.MakeChoice(choice); if (result.Supply != null) player.Gain(result.Supply, this); } } } public class CandlestickMaker : Card { public CandlestickMaker() : base(Categories.Action, Source.Guilds, Location.Kingdom, Traits.Component | Traits.PlusCoffer | Traits.PlusAction | Traits.PlusBuy, edition: Edition.Second) { BaseCost = new Cost(2); Benefit.Actions = 1; Benefit.Buys = 1; Benefit.Coffers = 1; } } public class Doctor : Guilds.Doctor { public Doctor() : base(Edition.Second) { } } public class Herald : Guilds.Herald { public Herald() : base(Edition.Second) { } } public class Journeyman : Guilds.Journeyman { public Journeyman() : base(Edition.Second) { } } public class Masterpiece : Guilds.Masterpiece { public Masterpiece() : base(Edition.Second) { } } public class MerchantGuild : Card { private CardBoughtEventHandler _cardBoughtHandler; public MerchantGuild() : base(Categories.Action, Source.Guilds, Location.Kingdom, Traits.Component | Traits.PlusBuy | Traits.PlusCoffer | Traits.Terminal | Traits.ReactToBuy, edition: Edition.Second) { BaseCost = new Cost(5); Benefit.Buys = 1; Benefit.Currency = new Currency(1); } public override void AddedTo(DeckLocation location, IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.AddedTo(location, player); if (location == DeckLocation.InPlay) { if (_cardBoughtHandler != null) player.CardBought -= _cardBoughtHandler; _cardBoughtHandler = new CardBoughtEventHandler(Player_CardBought); player.CardBought += _cardBoughtHandler; } } private void Player_CardBought(object sender, CardBuyEventArgs e) { // Already been cancelled or processed -- don't need to process this one if (e.Cancelled || e.HandledBy.Contains(this) || !e.Card.Type.IsSubclassOf(typeof(Card))) return; e.HandledBy.Add(this); var player = (IPlayer)sender; player.ReceiveBenefit(this, new CardBenefit { Coffers = 1 }); } public override void RemovedFrom(DeckLocation location, IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.RemovedFrom(location, player); if (_cardBoughtHandler != null) player.CardBought -= _cardBoughtHandler; _cardBoughtHandler = null; } } public class Plaza : Card { public Plaza() : base(Categories.Action, Source.Guilds, Location.Kingdom, Traits.Component | Traits.PlusCoffer | Traits.Discard | Traits.PlusAction | Traits.PlusMultipleActions | Traits.PlusCard | Traits.Cantrip, edition: Edition.Second) { BaseCost = new Cost(4); Benefit.Cards = 1; Benefit.Actions = 2; } public override void FollowInstructions(IPlayer player) { Contract.Requires(player != null, "player cannot be null"); base.FollowInstructions(player); var choice = new Choice("You may choose a Treasure card to discard", this, player.Hand[Categories.Treasure], ChoiceOutcome.Discard, player, minimum: 0); var result = player.MakeChoice(choice); if (result.Cards.Any()) { player.Discard(DeckLocation.Hand, result.Cards[0]); player.ReceiveBenefit(this, new CardBenefit { Coffers = 1 }); } } } public class Soothsayer : Guilds.Soothsayer { public Soothsayer() : base(Edition.Second) { } } public class Stonemason : Guilds.Stonemason { public Stonemason() : base(Edition.Second) { } } public class Taxman : Guilds.Taxman { public Taxman() : base(Edition.Second) { } } }