Beispiel #1
0
        public void CreateSetsInstance()
        {
            var testList = new Octgn.DataNew.Entities.Game();

            //var ss = StateSave<List<string>>.Create(testList);
            //Assert.AreEqual(testList, ss.GetInstance());
        }
Beispiel #2
0
        /// <summary>
        /// Parses and verifies the card count of the deck filename.  The filename must match
        /// those found in /DeckFiles/
        /// </summary>
        /// <param name="deckFileName">The filename of the deck to verify</param>
        /// <param name="scratchDirectory">The directory to create the deck file in</param>
        /// <param name="game">The Game that should be chosen in the Wizard</param>
        public static void VerifyDeckFile(
            string deckFileName,
            IEnumerable <ExpectedDeckSection> expectedSectionsStats,
            string scratchDirectory,
            Octgn.DataNew.Entities.Game game)
        {
            Assert.IsTrue(DeckFileResourceHelpers.CopyDeckFileResourceToDirectory(
                              scratchDirectory,
                              deckFileName));

            ConverterDeck converterDeck = ConvertDeckFileUsingWizard(Path.Combine(scratchDirectory, deckFileName), game);

            foreach (ConverterSection converterSection in converterDeck.ConverterSections)
            {
                ExpectedDeckSection expectedSectionStats =
                    expectedSectionsStats.First(eds => eds.SectionName == converterSection.SectionName);

                Assert.AreEqual(expectedSectionStats.TotalCardCount, converterSection.SectionCount);
                Assert.AreEqual(expectedSectionStats.UniqueCardCount, converterSection.SectionMappings.Count(sm => sm.PotentialOCTGNCards.Count > 0));

                foreach (ConverterMapping converterMapping in converterSection.SectionMappings)
                {
                    // At least one potential match should have been found
                    Assert.IsTrue(converterMapping.PotentialOCTGNCards.Count() > 0);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Converts a URL into a ConverterDeck, then returns it
        /// </summary>
        /// <param name="deckURL">The URL of the deck to get</param>
        /// <param name="game">The Game that should be chosen in the Wizard</param>
        /// <returns>a ConverterDeck containing cards parsed from the deck file</returns>
        public static OCTGNDeckConverter.Model.ConverterDeck ConvertURLUsingWizard(
            string deckURL,
            Octgn.DataNew.Entities.Game game)
        {
            ImportDeckWizardVM idwvm = new ImportDeckWizardVM();

            // If more than one Game is installed, the ChooseGame page will be active.  Select the game
            if (idwvm.CurrentWizardPageVM is WizardPage_ChooseGame)
            {
                (idwvm.CurrentWizardPageVM as WizardPage_ChooseGame).ChooseGameCommand.Execute(game);
            }

            Assert.IsTrue(idwvm.CurrentWizardPageVM is WizardPage_ChooseDeckSourceType);
            (idwvm.CurrentWizardPageVM as WizardPage_ChooseDeckSourceType).ChooseDeckSourceTypeCommand.Execute(DeckSourceTypes.Webpage);

            Assert.IsTrue(idwvm.CurrentWizardPageVM is WizardPage_EnterWebpage);
            idwvm.Converter.DeckURL = deckURL;
            idwvm.MoveToNextStep();

            // It might take some time for the conversion, (or for the database to load) so wait for it
            DateTime waitForConversionUntil = DateTime.Now.Add(TimeSpan.FromSeconds(300));

            while (!(idwvm.CurrentWizardPageVM is WizardPage_CompareCards) && DateTime.Now < waitForConversionUntil)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(100));
            }

            Assert.IsTrue(idwvm.CurrentWizardPageVM is WizardPage_CompareCards);

            return(idwvm.Converter.ConverterDeck);
        }
Beispiel #4
0
        public void CreateSetsInstance()
        {
            var testList = new Octgn.DataNew.Entities.Game();

            //var ss = StateSave<List<string>>.Create(testList);
            //Assert.AreEqual(testList, ss.GetInstance());
        }
        /// <summary>
        /// Gets the ConverterGame corresponding to the specified OCTGN Game.  It will be created if it doesn't exist
        /// </summary>
        /// <param name="octgnGame">The corresponding OCTGN game to get the ConverterGame for</param>
        /// <returns>The corresponding ConverterGame</returns>
        public ConverterGame GetConverterGame(Octgn.DataNew.Entities.Game octgnGame)
        {
            if (this._ConverterGameDictionary[octgnGame] == null)
            {
                this._ConverterGameDictionary[octgnGame] = new ConverterGame(octgnGame);
            }

            return(this._ConverterGameDictionary[octgnGame]);
        }
Beispiel #6
0
        /// <summary>
        /// The begin host game.
        /// </summary>
        /// <param name="game">
        /// The game.
        /// </param>
        /// <param name="gamename">
        /// The gamename.
        /// </param>
        public void BeginHostGame(Octgn.DataNew.Entities.Game game, string gamename, string password)
        {
            string data = string.Format("{0},:,{1},:,{2},:,{3}", game.Id.ToString(), game.Version, gamename, password ?? "");

            Log.InfoFormat("BeginHostGame {0}", data);
            var m = new Message(this.Config.GameBotUser.JidUser, this.Me.JidUser, MessageType.normal, data, "hostgame");

            m.GenerateId();
            this.xmpp.Send(m);
        }
        /// <summary>
        /// Initializes a new instance of the ConverterGame class.
        /// </summary>
        /// <param name="game">The OCTGN game definition to use for conversion</param>
        public ConverterGame(Octgn.DataNew.Entities.Game game)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            this.Game = game;
            this.Initialize();
        }
Beispiel #8
0
 public void GetSetInstanceWorks()
 {
     var testList = new Octgn.DataNew.Entities.Game()
     {
         Name = "Chicken"
     };
     //var ss = StateSave<Octgn.DataNew.Entities.Game>.Create(new Octgn.DataNew.Entities.Game());
     //Assert.AreNotEqual(testList.Name, (ss.GetInstance() as Octgn.DataNew.Entities.Game).Name);
     //ss.SetInstance(testList);
     //Assert.AreEqual(testList,ss.GetInstance());
 }
        /// <summary>
        /// This is run before the set of Tests, and is necessary because it loads the OCTGN LoTR game.
        /// (This cannot be done via [ClassInitialize] attribute because it won't call it if it is on the base class)
        /// </summary>
        static LoTRBase()
        {
            DeckBuilderPluginController.SimpleDeckBuilderPluginController sdbpc = new DeckBuilderPluginController.SimpleDeckBuilderPluginController();
            OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.LoadGames(sdbpc.Games.Games);

            LoTRBase.lotrGame = OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.OctgnGames.FirstOrDefault(
                g => g.Id == OCTGNDeckConverter.Model.ConvertEngine.Game.LoTR.GameGuidStatic);

            if (LoTRBase.lotrGame == null)
            {
                throw new Exception("The OCTGN Game LoTR is not installed, so unit tests cannot be run.");
            }
        }
Beispiel #10
0
        /// <summary>
        /// This is run before the set of Tests, and is necessary because it loads the OCTGN MTG game.
        /// (This cannot be done via [ClassInitialize] attribute because it won't call it if it is on the base class)
        /// </summary>
        static MTGBase()
        {
            DeckBuilderPluginController.SimpleDeckBuilderPluginController sdbpc = new DeckBuilderPluginController.SimpleDeckBuilderPluginController();
            OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.LoadGames(sdbpc.Games.Games);

            MTGBase.mtgGame = OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.OctgnGames.FirstOrDefault(
                g => g.Id == OCTGNDeckConverter.Model.ConvertEngine.Game.MTG.GameGuidStatic);

            if (MTGBase.mtgGame == null)
            {
                throw new Exception("The OCTGN Game MTG is not installed, so unit tests cannot be run.");
            }
        }
Beispiel #11
0
        /// <summary>
        /// The begin host game.
        /// </summary>
        /// <param name="game">
        /// The game.
        /// </param>
        /// <param name="gamename">
        /// The gamename.
        /// </param>
        public void BeginHostGame(Octgn.DataNew.Entities.Game game, string gamename,
                                  string password, string actualgamename, string gameIconUrl, Version sasVersion, bool specators)
        {
            var hgr = new HostGameRequest(game.Id, game.Version, gamename, actualgamename, gameIconUrl, password ?? "", sasVersion, specators);

            //string data = string.Format("{0},:,{1},:,{2},:,{3},:,{4}", game.Id.ToString(), game.Version, gamename, password ?? "",actualgamename);
            Log.InfoFormat("BeginHostGame {0}", hgr);
            var m = new Message(this.Config.GameBotUser.JidUser, this.Me.JidUser, MessageType.normal, "", "hostgame");

            m.GenerateId();
            m.AddChild(hgr);
            this.xmpp.Send(m);
        }
Beispiel #12
0
        /// <summary>
        /// The begin host game.
        /// </summary>
        /// <param name="game">
        /// The game.
        /// </param>
        /// <param name="gamename">
        /// The gamename.
        /// </param>
        public void BeginHostGame(Octgn.DataNew.Entities.Game game, string gamename)
        {
            string data = string.Format("{0},:,{1},:,{2}", game.Id.ToString(), game.Version, gamename);

            Log.InfoFormat("BeginHostGame {0}", data);
            var m = new Message(new Jid("gameserv@" + Host), this.Me.JidUser, MessageType.normal, data, "hostgame");

            m.GenerateId();
            this.xmpp.Send(m);
            //m = new Message(new Jid("gameserv2@" + Host), this.Me.JidUser, MessageType.normal, data, "hostgame");
            //m.GenerateId();
            //this.xmpp.Send(m);
        }
        public static void ClassInitialize(TestContext testContext)
        {
            DeckBuilderPluginController.SimpleDeckBuilderPluginController sdbpc = new DeckBuilderPluginController.SimpleDeckBuilderPluginController();
            OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.LoadGames(sdbpc.Games.Games);

            MW.mwGame = OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.OctgnGames.FirstOrDefault(
                g => g.Id == OCTGNDeckConverter.Model.ConvertEngine.Game.MW.GameGuidStatic);

            if (MW.mwGame == null)
            {
                throw new Exception("The OCTGN Game MW is not installed, so unit tests cannot be run.");
            }
        }
Beispiel #14
0
        public async Task <HostedGameInfo> HostGame(Octgn.DataNew.Entities.Game game, string gamename,
                                                    string password, string actualgamename, string gameIconUrl, Version sasVersion, bool specators)
        {
            var request = new HostGameRequest(game.Id, game.Version, gamename, actualgamename, gameIconUrl, password ?? "", sasVersion, specators);

            Log.Info($"{request}");

            var result = await _client.Request(new Package(_config.GameBotUser.UserName, request));

            if (result == null)
            {
                throw new InvalidOperationException("Host game failed. No game data returned.");
            }
            return((result as Package)?.Contents as HostedGameInfo);
        }
Beispiel #15
0
        public static T GetGameSetting <T>(Octgn.DataNew.Entities.Game game, string propName, T def)
        {
            var defSettings = new Hashtable();

            defSettings["name"] = game.Name;
            var settings = Config.Instance.ReadValue("GameSettings_" + game.Id.ToString(), defSettings);

            if (settings.ContainsKey(propName))
            {
                if (settings[propName] is T)
                {
                    return((T)settings[propName]);
                }
            }
            SetGameSetting(game, propName, def);
            return(def);
        }
Beispiel #16
0
        /// <summary>
        /// Parses and verifies the card count of the deck URL.
        /// </summary>
        /// <param name="deckURL">The URL of the deck to verify</param>
        /// <param name="scratchDirectory">The directory to create the deck file in</param>
        /// <param name="game">The Game that should be chosen in the Wizard</param>
        public static void VerifyURL(
            string deckURL,
            IEnumerable <ExpectedDeckSection> expectedSectionsStats,
            Octgn.DataNew.Entities.Game game)
        {
            ConverterDeck converterDeck = ConvertURLUsingWizard(deckURL, game);

            foreach (ConverterSection converterSection in converterDeck.ConverterSections)
            {
                ExpectedDeckSection expectedSectionStats =
                    expectedSectionsStats.First(eds => eds.SectionName == converterSection.SectionName);

                Assert.AreEqual(expectedSectionStats.TotalCardCount, converterSection.SectionCount);
                Assert.AreEqual(expectedSectionStats.UniqueCardCount, converterSection.SectionMappings.Count(sm => sm.PotentialOCTGNCards.Count > 0));

                foreach (ConverterMapping converterMapping in converterSection.SectionMappings)
                {
                    // At least one potential match should have been found
                    Assert.IsTrue(converterMapping.PotentialOCTGNCards.Count() > 0);
                }
            }
        }
        /// <summary>
        /// Returns an Image of the Octgn Card with corresponding Guid.  If there is an error (including if the Card Guid is not found)
        /// then the default back of the card is returned.
        /// </summary>
        /// <param name="cardID">The Guid of the Card to get a Bitmap picture of</param>
        /// <param name="game">The OCTGN game to find the Card from</param>
        /// <returns>The BitmapImage of the Octgn Card with corresponding Guid</returns>
        public static BitmapImage GetCardBitmapImage(Guid cardID, Octgn.DataNew.Entities.Game game)
        {
            var bim = new BitmapImage();

            bim.BeginInit();
            bim.CacheOption = BitmapCacheOption.OnLoad;

            try
            {
                Octgn.DataNew.Entities.Card octgnCard = game.AllCards().First(c => c.Id == cardID);
                bim.UriSource = new Uri(octgnCard.GetPicture());
                bim.EndInit();
            }
            catch (Exception)
            {
                bim             = new BitmapImage();
                bim.CacheOption = BitmapCacheOption.OnLoad;
                bim.BeginInit();
                bim.UriSource = new Uri(game.CardSize.Front);
                bim.EndInit();
            }

            return(bim);
        }
        /// <summary>
        /// Returns a Dictionary who's keys are Guids which represent Octgn Sets, and who's values are corresponding
        /// ConverterSet objects.
        /// </summary>
        /// <param name="game">The Octgn.DataNew.Entities.Game object to use to read sets from</param>
        /// <returns>A Dictionary of Octgn Set Guids and corresponding ConverterSet objects</returns>
        private static Dictionary <Guid, ConverterSet> BuildCardDatabase(Octgn.DataNew.Entities.Game game)
        {
            if (game == null)
            {
                throw new ArgumentNullException();
            }

            Logger.Info("Building the card database for game " + game.Name);

            // MTG has a property "MultiVerseId" which should be grabbed if it exists
            Octgn.DataNew.Entities.PropertyDef multiverseIdPropertyDef =
                game.CustomProperties.FirstOrDefault(p => p.Name.Equals("MultiVerseId", StringComparison.InvariantCultureIgnoreCase));

            Dictionary <Guid, ConverterSet> sets = new Dictionary <Guid, ConverterSet>();

            foreach (Octgn.DataNew.Entities.Set octgnSet in game.Sets())
            {
                Logger.Info("Adding cards from set " + octgnSet.Name);

                sets[octgnSet.Id] = new ConverterSet(octgnSet);
                foreach (Octgn.DataNew.Entities.Card card in octgnSet.Cards)
                {
                    // Try to dig the MultiverseID property out of the Octgn.DataNew.Entities.Card
                    // During testing, all properties seemed nested under the first KeyValuePair in card.Properties
                    int multiverseID = 0;
                    if (multiverseIdPropertyDef != null)
                    {
                        if (card.Properties.Count > 0)
                        {
                            KeyValuePair <string, Octgn.DataNew.Entities.CardPropertySet> firstCardPropertyKVP = card.Properties.First();
                            object multiverseIdString = null;
                            if (firstCardPropertyKVP.Value.Properties.TryGetValue(multiverseIdPropertyDef, out multiverseIdString))
                            {
                                int.TryParse(multiverseIdString.ToString(), out multiverseID);
                            }
                        }
                    }

                    string name = card.Name;

                    // CoC uses special characters at the beginning of the card name to represent properties such as Unique and Steadfast.
                    // These characters should not be included as part of the name for comparison.
                    if (game.Id == ConvertEngine.Game.CoC.GameGuidStatic)
                    {
                        name = name.Trim(new Char[] { '{', '}', '[', ']', '<', '>', '_', '^', '*', ' ' });
                    }

                    sets[octgnSet.Id].AddNewConverterCard
                    (
                        card.Id,
                        name,
                        multiverseID
                    );
                }
            }

            foreach (KeyValuePair <Guid, ConverterSet> kvp in sets)
            {
                kvp.Value.SortConverterCards();

                if (SettingsManager.SingletonInstance.SetsExcludedFromSearches.Contains(kvp.Key))
                {
                    kvp.Value.IncludeInSearches = false;
                }
            }

            return(sets);
        }
Beispiel #19
0
        public static void ClassInitialize(TestContext testContext)
        {
            DeckBuilderPluginController.SimpleDeckBuilderPluginController sdbpc = new DeckBuilderPluginController.SimpleDeckBuilderPluginController();
            OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.LoadGames(sdbpc.Games.Games);

            MW.mwGame = OCTGNDeckConverter.Model.ConverterDatabase.SingletonInstance.OctgnGames.FirstOrDefault(
                g => g.Id == OCTGNDeckConverter.Model.ConvertEngine.Game.MW.GameGuidStatic);

            if (MW.mwGame == null)
            {
                throw new Exception("The OCTGN Game MW is not installed, so unit tests cannot be run.");
            }
        }
Beispiel #20
0
 public void GetSetInstanceWorks()
 {
     var testList = new Octgn.DataNew.Entities.Game()
                        {
                            Name = "Chicken"
                        };
     //var ss = StateSave<Octgn.DataNew.Entities.Game>.Create(new Octgn.DataNew.Entities.Game());
     //Assert.AreNotEqual(testList.Name, (ss.GetInstance() as Octgn.DataNew.Entities.Game).Name);
     //ss.SetInstance(testList);
     //Assert.AreEqual(testList,ss.GetInstance());
 }