コード例 #1
0
        public bool Load()
        {
            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(AssetManager.Get().GetAsset(DBPath));

                foreach (XmlNode ttNode in xdoc.DocumentElement.ChildNodes)
                {
                    XmlElement ttElem = (XmlElement)ttNode;
                    if (ttElem != null && ttElem.Name == "tournament")
                    {
                        try
                        {
                            List <TriadGameModifier> rules = new List <TriadGameModifier>();
                            foreach (XmlNode innerNode in ttElem.ChildNodes)
                            {
                                XmlElement testElem = (XmlElement)innerNode;
                                if (testElem != null)
                                {
                                    if (testElem.Name == "rule")
                                    {
                                        int ruleId = int.Parse(testElem.GetAttribute("id"));
                                        rules.Add(TriadGameModifierDB.Get().mods[ruleId].Clone());
                                    }
                                }
                            }

                            TriadTournament newTournament = new TriadTournament(int.Parse(ttElem.GetAttribute("id")), rules);
                            while (tournaments.Count <= newTournament.Id)
                            {
                                tournaments.Add(null);
                            }
                            tournaments[newTournament.Id] = newTournament;
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteLine("Loading failed! Exception:" + ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Loading failed! Exception:" + ex);
            }

            Logger.WriteLine("Loaded tournaments: " + tournaments.Count);
            return(tournaments.Count > 0);
        }
コード例 #2
0
        public bool Load()
        {
            List <TriadTournament> loadedTypes = new List <TriadTournament>();

            List <TriadGameModifier> modObjects = new List <TriadGameModifier>();

            foreach (Type type in Assembly.GetAssembly(typeof(TriadGameModifier)).GetTypes())
            {
                if (type.IsSubclassOf(typeof(TriadGameModifier)))
                {
                    modObjects.Add((TriadGameModifier)Activator.CreateInstance(type));
                }
            }

            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(AssetManager.Get().GetAsset(DBPath));

                foreach (XmlNode ttNode in xdoc.DocumentElement.ChildNodes)
                {
                    XmlElement ttElem = (XmlElement)ttNode;
                    if (ttElem != null && ttElem.Name == "tournament")
                    {
                        try
                        {
                            List <TriadGameModifier> rules = new List <TriadGameModifier>();
                            foreach (XmlNode innerNode in ttElem.ChildNodes)
                            {
                                XmlElement testElem = (XmlElement)innerNode;
                                if (testElem != null)
                                {
                                    if (testElem.Name == "rule")
                                    {
                                        rules.Add(ParseRule(testElem.GetAttribute("name"), modObjects));
                                    }
                                }
                            }

                            TriadTournament newTournament = new TriadTournament(
                                WebUtility.HtmlDecode(ttElem.GetAttribute("name")),
                                rules);

                            loadedTypes.Add(newTournament);
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteLine("Loading failed! Exception:" + ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Loading failed! Exception:" + ex);
            }

            if (loadedTypes.Count > 0)
            {
                tournaments.Clear();
                tournaments.AddRange(loadedTypes);
            }

            Logger.WriteLine("Loaded tournaments: " + tournaments.Count);
            return(tournaments.Count > 0);
        }
コード例 #3
0
        private bool UpdateTournaments(GameDataLists gameDataLists, Dictionary <string, TriadGameModifier> mapRuleNames)
        {
            Logger.WriteLine("Updating tournament list...");

            // TODO: not sure how to find it in .csv data,
            // hardcode entries + rules for now
            // alert new new unique entry appears

            var uniqueTournamentNames    = new List <string>();
            var uniqueTournamentLocNames = new List <LocString>();

            foreach (var tourData in gameDataLists.tournamentNames)
            {
                var codeName = tourData.Name.GetCodeName();
                if (!string.IsNullOrEmpty(codeName))
                {
                    if (!uniqueTournamentNames.Contains(codeName))
                    {
                        uniqueTournamentNames.Add(codeName);
                        uniqueTournamentLocNames.Add(tourData.Name);
                    }
                }
            }

            string[] hardcodedNames = { "the Manderville Tournament of Champions", "the Spinner's Pull", "the Durai Memorial", "the Rowena Cup Classic" };
            string[] hardcodedRules =
            {
                "All Open",   "Plus",
                "Three Open", "Swap",
                "Order",      "Same",
                "Roulette",   "Roulette",
            };

            if (uniqueTournamentNames.Count != hardcodedNames.Length)
            {
                Logger.WriteLine("FAILED tournament update, hardcoded list diff! [{0}]", string.Join(", ", uniqueTournamentNames));
                return(false);
            }

            TriadTournamentDB tournamentDB = TriadTournamentDB.Get();

            for (int idx = 0; idx < uniqueTournamentNames.Count; idx++)
            {
                if (uniqueTournamentNames[idx] != hardcodedNames[idx])
                {
                    Logger.WriteLine("FAILED tournament update, id:{0} mismatch!", idx);
                    return(false);
                }

                TriadTournament tourOb = (idx < tournamentDB.tournaments.Count) ? tournamentDB.tournaments[idx] : null;
                if (tourOb == null)
                {
                    while (tournamentDB.tournaments.Count <= idx)
                    {
                        tournamentDB.tournaments.Add(new TriadTournament(idx, new List <TriadGameModifier>()));
                    }

                    tourOb = tournamentDB.tournaments[idx];
                }

                tourOb.Name.Text = uniqueTournamentLocNames[idx].Text;

                tourOb.Rules.Clear();
                int ruleStartIdx = idx * 2;
                for (int ruleIdx = 0; ruleIdx < 2; ruleIdx++)
                {
                    tourOb.Rules.Add(mapRuleNames[hardcodedRules[ruleIdx + ruleStartIdx]]);
                }
            }

            return(true);
        }