using DominionBase.Enums; using DominionBase.Players; using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; namespace DominionBase.Cards.Menagerie { public class WayOfTheMouse : Way { public Card MouseCard { get; private set; } public WayOfTheMouse() : base(Source.Menagerie, Traits.ConditionalBenefit | Traits.Terminal) { } public override string SpecialPresetKey => "Mouse"; public override void Setup() { base.Setup(); Card MouseRandomizer = null; try { if (_Game.Settings.Preset != null) { MouseRandomizer = _Game.Settings.Preset.CardCards[_Game.Settings.Preset.Cards.First(c => c.Type == Type)].OfType().ElementAt(0); } else { var shouldUseGameConstraints = true; var wotmConstraints = new ConstraintCollection(); if (_Game.Settings.CardSettings.ContainsKey(Name)) { var wotmSettings = _Game.Settings.CardSettings[Name]; shouldUseGameConstraints = (bool)wotmSettings.CardSettingCollection[typeof(UseGameConstraints)].Value; wotmConstraints = (ConstraintCollection)wotmSettings.CardSettingCollection[typeof(Constraints)].Value; } // need to set aside a Mouse card here; randomly pick an unused supply card type of cost $2 or $3 from // the Kingdom cards, create a single instance of it, and add it to the Way of the Mouse Set-Aside pile IList availableMouseCards = _Game.CardsAvailable.OfType().Where(c => c.Category.HasFlag(Categories.Action) && (c.BaseCost == new Cost(2) || c.BaseCost == new Cost(3))).Cast().ToList(); if (shouldUseGameConstraints) { // Skip all "Must Use" constraints var constraints = new ConstraintCollection(_Game.Settings.Constraints.Where(c => c.ConstraintType != ConstraintType.CardMustUse)); availableMouseCards = constraints.SelectCards(availableMouseCards, 1); } else availableMouseCards = wotmConstraints.SelectCards(availableMouseCards, 1); MouseRandomizer = availableMouseCards.OfType().ElementAt(0); } } catch (ConstraintException ce) { throw new WayOfTheMouseConstraintException($"Problem setting up Way of the Mouse constraints: {ce.Message}"); } if (MouseRandomizer != null) { if (!MouseRandomizer.Category.HasFlag(Categories.Action)) throw new WayOfTheMouseConstraintException($"Problem setting up Way of the Mouse constraints: Way of the Mouse card must be an Action card"); // Need to do full setup on the Supply pile, then take the top card _Game.CardsAvailable.Remove(MouseRandomizer); _Game.Table.AddTableItem(_Game.Players, MouseRandomizer.Type); _Game.Table.TableEntities[MouseRandomizer].Setup(); _Game.Table.TableEntities[MouseRandomizer].SnapshotSetup(); MouseCard = ((ISupply)_Game.Table.TableEntities[MouseRandomizer]).Take(); AddToken(new WayOfTheMouseToken(MouseCard)); } } public override void FinalizeSetup() { base.FinalizeSetup(); var mouseSupply = _Game.Table.TableEntities[MouseCard]; mouseSupply.FinalizeSetup(); _Game.Table.TableEntities.Remove(mouseSupply.Type); } protected override bool CardFollowingAllowed(CardFollowingInstructionsEventArgs e) { Contract.Requires(e != null, "e cannot be null"); // We disallow Way of the Mousing on the Moused card if (e.Card == MouseCard && !e.HandledBy.Contains(this)) { e.HandledBy.Add(this); return false; } return base.CardFollowingAllowed(e); } public override void FollowAlternateInstructions(IPlayer player, Card playedCard) { Contract.Requires(player != null, "player cannot be null"); Contract.Requires(playedCard != null, "playedCard cannot be null"); base.FollowAlternateInstructions(player, playedCard); throw new NotImplementedException(); player._Game.SendMessage(player, this, "PlayAs", MouseCard); //player. var previousMode = player.PlayerMode; player.PlayCard(MouseCard, previousMode); //if (!MouseCard.CanCleanUp) // playedCard.ChainedInto.Add(MouseCard); //playedCard.CanCleanUp = MouseCard.LogicalCard.CanCleanUp; } public override List GetSerializingTypes() { return new List { typeof(UseGameConstraints), typeof(Constraints) }; } public override CardSettingCollection GenerateSettings() { var csc = new CardSettingCollection { new UseGameConstraints { Value = false }, new Constraints { Value = new ConstraintCollection() } }; return csc; } [Serializable] public class UseGameConstraints : CardSetting { public override string Name => "UseGameConstraints"; public override string Text => "Use Game constraints instead of the ones listed below"; public override string Hint => "Use the defined Game constraints instead of the ones defined here"; public override Type Type => typeof(bool); } [Serializable] public class Constraints : CardSetting { public override string Name => "Constraints"; public override string Hint => "Constraints to use for selecting a Mouse card to set aside"; public override Type Type => typeof(ConstraintCollection); } } public class WayOfTheMouseConstraintException : ConstraintException { public WayOfTheMouseConstraintException() { } public WayOfTheMouseConstraintException(string message) : base(message) { } public WayOfTheMouseConstraintException(string message, Exception innerException) : base(message, innerException) { } internal WayOfTheMouseConstraintException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } } }