Exemplo n.º 1
0
        public override void Setup(Game game, Supply supply)
        {
            base.Setup(game, supply);

            IList <Card> availableCards = null;

            try
            {
                if (game.Settings.Preset != null)
                {
                    availableCards = game.Settings.Preset.CardCards[game.Settings.Preset.Cards.First(c => c.CardType == typeof(BlackMarket))];
                    // Shuffle the preset cards -- these should definitely not be set up in a known order
                    Utilities.Shuffler.Shuffle(availableCards);
                }
                else
                {
                    int cardsToUse = 25;
                    //Boolean errorOnNotEnoughCards = true;
                    Boolean shouldUseGameConstraints   = true;
                    ConstraintCollection bmConstraints = new ConstraintCollection();
                    if (game.Settings.CardSettings.ContainsKey("Black Market"))
                    {
                        CardsSettings bmSettings = game.Settings.CardSettings["Black Market"];
                        cardsToUse = (int)bmSettings.CardSettingCollection[typeof(BlackMarket.BlackMarket_NumberOfCards)].Value;
                        //errorOnNotEnoughCards = (Boolean)bmSettings.CardSettingCollection[typeof(BlackMarket.BlackMarket_ErrorOnNotEnoughCards)].Value;
                        shouldUseGameConstraints = (Boolean)bmSettings.CardSettingCollection[typeof(BlackMarket.BlackMarket_UseGameConstraints)].Value;
                        bmConstraints            = (ConstraintCollection)bmSettings.CardSettingCollection[typeof(BlackMarket.BlackMarket_Constraints)].Value;
                    }

                    // need to set up a supply pile for Black Market; randomly pick an unused supply card and add it to the pile until we have the requisite number of cards
                    availableCards = game.CardsAvailable;
                    if (shouldUseGameConstraints)
                    {
                        // Skip all "Must Use" constraints
                        ConstraintCollection constraints = new ConstraintCollection(game.Settings.Constraints.Where(c => c.ConstraintType != ConstraintType.CardMustUse));
                        availableCards = constraints.SelectCards(availableCards, cardsToUse);
                    }
                    else
                    {
                        availableCards = bmConstraints.SelectCards(availableCards, cardsToUse);
                    }
                }
            }
            catch (DominionBase.Cards.ConstraintException ce)
            {
                throw new BlackMarketConstraintException(String.Format("Problem setting up Black Market constraints: {0}", ce.Message));
            }

            foreach (Card cardToUse in availableCards)
            {
                game.CardsAvailable.Remove(cardToUse);
                supply.AddTo(cardToUse);
            }
        }
Exemplo n.º 2
0
        public override void Setup(Game game, Supply supply)
        {
            base.Setup(game, supply);

            Card baneCard = null;

            try
            {
                if (game.Settings.Preset != null)
                {
                    baneCard = game.Settings.Preset.CardCards[game.Settings.Preset.Cards.First(c => c.CardType == this.CardType)].ElementAt(0);
                }
                else
                {
                    IList <Card>         availableBaneCards       = null;
                    Boolean              shouldUseGameConstraints = true;
                    ConstraintCollection ywConstraints            = new ConstraintCollection();
                    if (game.Settings.CardSettings.ContainsKey(this.Name))
                    {
                        CardsSettings ywSettings = game.Settings.CardSettings[this.Name];
                        shouldUseGameConstraints = (Boolean)ywSettings.CardSettingCollection[typeof(YoungWitch_UseGameConstraints)].Value;
                        ywConstraints            = (ConstraintCollection)ywSettings.CardSettingCollection[typeof(YoungWitch_Constraints)].Value;
                    }

                    // need to setup a bane supply pile here; randomly pick an unused supply card type of cost $2 or $3 from
                    // the Kingdom cards, create a new supply pile of it, and mark it with a Bane token
                    availableBaneCards = game.CardsAvailable.Where(c => c.BaseCost == new Cost(2) || c.BaseCost == new Cost(3)).ToList();
                    if (shouldUseGameConstraints)
                    {
                        // Skip all "Must Use" constraints
                        ConstraintCollection constraints = new ConstraintCollection(game.Settings.Constraints.Where(c => c.ConstraintType != ConstraintType.CardMustUse));
                        availableBaneCards = constraints.SelectCards(availableBaneCards, 1);
                    }
                    else
                    {
                        availableBaneCards = ywConstraints.SelectCards(availableBaneCards, 1);
                    }
                    baneCard = availableBaneCards[0];
                }
            }
            catch (DominionBase.Cards.ConstraintException ce)
            {
                throw new YoungWitchConstraintException(String.Format("Problem setting up Young Witch constraints: {0}", ce.Message));
            }

            game.CardsAvailable.Remove(baneCard);
            game.Table.AddKingdomSupply(game.Players, baneCard.CardType);
            game.Table.Supplies[baneCard].Setup();
            game.Table.Supplies[baneCard].SnapshotSetup();
            game.Table.Supplies[baneCard].AddToken(new BaneToken());
        }
Exemplo n.º 3
0
        public static Settings Load()
        {
            CardCollection allCards = CardCollection.GetAllCards(c => true);

            Settings settings = null;

            try
            {
                XmlSerializer mySerializer = new XmlSerializer(typeof(Settings), GetAllSerializingTypes(allCards).ToArray());
                // This should only need to be here temporarily -- probably 3-5 releases -- until all the other versions get transitioned to the new saving area
                String filename = Settings.Filename;
                if (!System.IO.File.Exists(Settings.Filename))
                {
                    filename = Settings.OldFilename;
                }
                using (FileStream myFileStream = new FileStream(filename, FileMode.Open))
                {
                    settings = (Settings)mySerializer.Deserialize(myFileStream);
                }
            }
            catch
            {
                settings = new Settings();
            }

            while (settings.PlayerSettings.Count < 6)
            {
                settings.PlayerSettings.Add(new PlayerSettings()
                {
                    Name        = String.Format("Player {0}", settings.PlayerSettings.Count + 1),
                    AIClassType = typeof(DominionBase.Players.AI.Standard),
                    UIColor     = HLSColor.HlsToRgb(24 * (settings.PlayerSettings.Count * 2), 0.85, 1, 1)
                });
            }


            // Go through each card to make sure that the card's default settings are defined
            foreach (Card card in allCards)
            {
                CardSettingCollection csc = card.GenerateSettings();
                if (csc.Count == 0)                 // This card has no custom settings, so we can skip it
                {
                    continue;
                }

                if (!settings.CardSettings.ContainsKey(card.Name))
                {
                    settings.CardSettings[card.Name] = new CardsSettings(card.Name);
                }

                CardsSettings cardSettings = settings.CardSettings[card.Name];

                // Go through each setting defined for the card & make sure it exists
                foreach (CardSetting cSetting in csc)
                {
                    if (!cardSettings.CardSettingCollection.ContainsKey(cSetting.GetType()))
                    {
                        cardSettings.CardSettingCollection[cSetting.GetType()] = cSetting;
                    }
                }

                card.FinalizeSettings(cardSettings.CardSettingCollection);
            }

            return(settings);
        }