Esempio n. 1
0
        public void SyncExternalLinking(Achievement achievement)
        {
            var petBattleLinks = dataManager.GetWithAchievementID(achievement.ID);

            petBattleLinks.AddRange(dataManager.GetWithParentID($"A{achievement.ID}"));

            foreach (var petBattleLink in petBattleLinks)
            {
                var xuFuEncounters = xuFuEncounterDataManager.GetMatches(petBattleLink);
                if (xuFuEncounters.Count == 0)
                {
                    MessageBox.Show($"No match found (count 0) for {petBattleLink.Name}");
                    continue;
                }

                XuFuEncounter xuFuEncounter = null;
                if (xuFuEncounters.Count > 1)
                {
                    WebClient x           = new WebClient();
                    string    source      = x.DownloadString($"https://www.wowhead.com/achievement={achievement.ID}");
                    string    name        = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?) - Achievement - World of Warcraft\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
                    string    description = Regex.Match(source, "<meta name=\"description\" content=\"(?<Description>.*?)\">", RegexOptions.IgnoreCase).Groups["Description"].Value;

                    var msBx = new CustomMessageBox($"Please select one of the following options for the achievement criteria that best matches this achievement{Environment.NewLine}{Environment.NewLine}{name}{Environment.NewLine}{Environment.NewLine}{description}{Environment.NewLine}{Environment.NewLine}{string.Join(Environment.NewLine, xuFuEncounters)}", xuFuEncounters.Select(x => x.ID.ToString()).ToList());
                    msBx.ShowDialog();

                    xuFuEncounter = xuFuEncounters.Single(x => x.ID == Convert.ToInt32(msBx.Selection));
                }
                else
                {
                    xuFuEncounter = xuFuEncounters[0];
                }

                if (xuFuEncounter == null)
                {
                    MessageBox.Show($"No match found (null) for {petBattleLink.Name}");
                    continue;
                }
                petBattleLink.ExternalLink = $"https://www.wow-petguide.com/Encounter/{xuFuEncounter.ID}";
                dataManager.UpdateExternalLink(petBattleLink);
            }
        }
Esempio n. 2
0
        public void ExportPetBattles()
        {
            var sb = new StringBuilder();

            sb.AppendLine($"-- [[ Exported at {DateTime.Now:yyyy-MM-dd HH-mm-ss} ]] --");
            sb.AppendLine($"-- [[ This code is automatically generated as an export from ]] --");
            sb.AppendLine($"-- [[ an SQLite database and is not meant for manual edit. ]] --");
            sb.AppendLine("");
            sb.AppendLine("-- [[ Namespaces ]] --");
            sb.AppendLine("local _, addon = ...;");
            sb.AppendLine("local objects = addon.Objects;");
            sb.AppendLine("local data = addon.Data;");
            sb.AppendLine("data.ExportedPetBattles = {};");
            sb.AppendLine("local exportedPetBattles = data.ExportedPetBattles;");
            sb.AppendLine("");
            sb.AppendLine("function exportedPetBattles.Load(rcMenExtras)");
            sb.AppendLineTabbed(1, "for i, _ in next, rcMenExtras do");
            sb.AppendLineTabbed(2, "rcMenExtras[i] = nil;");
            sb.AppendLineTabbed(1, "end");
            sb.AppendLine("");
            sb.AppendLineTabbed(1, "local url = \"https://www.wow-petguide.com/\";");
            sb.AppendLine("");

            var categories = achCatDatMan.GetAll();

            foreach (var category in categories)
            {
                var achievements = achDatMan.GetWithCategory(category);
                foreach (var achievement in achievements)
                {
                    var criteria = petBatLinDatMan.GetWithAchievementID(achievement.ID);
                    if (criteria.Any())
                    {
                        foreach (var criterion in criteria)
                        {
                            if (!string.IsNullOrEmpty(criterion.ExternalLink))
                            {
                                string externalLink;
                                if (criterion.ExternalLink.Contains("https://www.wow-petguide.com"))
                                {
                                    externalLink = criterion.ExternalLink.Replace("https://www.wow-petguide.com/", "url .. \"");
                                }
                                else
                                {
                                    externalLink = $"\"{criterion.ExternalLink}";
                                }

                                var list = $"rcMenExtras[{achievement.ID}]";
                                sb.AppendTabbed(1, $"{list} = objects.MenuItem:NewExtLink(addon.L[\"Xu-Fu's Pet Guides\"]");
                                sb.Append(", ");
                                sb.Append(externalLink);
                                sb.AppendLine($"\"); -- {criterion.Name}");

                                var subCriteria = petBatLinDatMan.GetWithParentID(criterion.ID);
                                GetSubCriteria(sb, criterion.ID.Substring(1), subCriteria, list: list);
                            }
                        }
                    }
                }
            }

            sb.AppendLine("end");

            using var file = new StreamWriter(@"../../../../../Krowi_AchievementFilter/Data/ExportedPetBattles.lua");
            file.WriteLine(sb.ToString());
        }