public void CheckForSeriesOfCriteria(Achievement achievement, bool checkCriteria)
        {
            if (achievement.Series != null)
            {
                return;
            }
            string html = DownloadHtml.GetHtmlFromUrl(new Uri("http://www.wowhead.com/achievement=" + achievement.BlizzardID));
            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(html);

            HtmlNode seriesNode = document.DocumentNode.SelectSingleNode("//table[@class='series']");
            HtmlNode criteriaNode = document.DocumentNode.SelectSingleNode("//h3[contains(text(),'Criteria')]");

            bool seriesOrMeta = false;

            if (seriesNode != null)
            {
                seriesOrMeta = true;
                // First check if this quest is already in a series
                if (achievement.Series == null)
                {

                    Console.WriteLine("Adding Achivement {0} to a new series", achievement.Name);
                    // lets fill in series
                    HtmlNodeCollection tableRows = seriesNode.SelectNodes(".//tr");
                    int order = 10;
                    AchievementSeries series = new AchievementSeries();

                    foreach (HtmlNode row in tableRows)
                    {
                        HtmlNode linkNode = row.SelectSingleNode(".//a");
                        if (linkNode == null)
                        {
                            series.AddAchievementToSeries(achievement);
                            achievement.SeriesOrder = order;
                            Console.WriteLine("\t [{0}] Series includes Achievement {1}", order, achievement.Name);
                        }
                        else
                        {
                            Match m = seriesLinkRegex.Match(linkNode.Attributes["href"].Value);
                            if (m.Success)
                            {
                                string achivementid = m.Groups["achievementid"].Value;
                                int blizzardId = 0;
                                int.TryParse(achivementid, out blizzardId);
                                Achievement nextAchievement = _achievementRepository.Find(blizzardId);
                                if (nextAchievement != null)
                                {
                                    Console.WriteLine("\t [{0}] Series includes Achievement {1}", order, nextAchievement.Name);
                                    series.AddAchievementToSeries(nextAchievement);
                                    nextAchievement.SeriesOrder = order;
                                }
                            }
                        }

                        order += 10;
                    }
                }

                // We have a series, this achievement will be blanked out
            }
            if (checkCriteria && criteriaNode != null)
            {
                HtmlNodeCollection linkNodes = criteriaNode.SelectNodes("..//table[@class='iconlist']//a[contains(@href,'achievement')]");
                if (linkNodes != null)
                {
                    seriesOrMeta = true;
                    Console.WriteLine("Found Meta Achivement : {0}, adding sub achivements", achievement.Name);

                    if (achievement.SubAchievements == null)
                    {
                        achievement.SubAchievements = new List<int>();
                    }

                    achievement.Criteria.Clear();
                    foreach (HtmlNode linkNode in linkNodes)
                    {
                        Match m = seriesLinkRegex.Match(linkNode.Attributes["href"].Value);
                        if (m.Success)
                        {
                            string achivementid = m.Groups["achievementid"].Value;
                            int blizzardId = 0;
                            int.TryParse(achivementid, out blizzardId);
                            Achievement requiredAchievement = _achievementRepository.Find(blizzardId);
                            if (requiredAchievement != null)
                            {
                                achievement.SubAchievements.Add(requiredAchievement.BlizzardID);
                                Console.WriteLine("\t Criteria includes Achievement {0}", requiredAchievement.Name);
                            }
                        }
                    }
                }
            }

            if (!seriesOrMeta)
            {
                Console.WriteLine("Single achivement '{0}' for '{1}' points", achievement.Name, achievement.Points);
            }
            else
            {
                _achievementRepository.Save(achievement);
            }
        }
Esempio n. 2
0
 public int GetHighestAchievementInSeries(AchievementSeries series)
 {
     int maxAchievement = 0;
     for (int i = 0; i < series.AchievementIds.Count; i++)
     {
         if (HasAchieved(series.AchievementIds[i]))
         {
             maxAchievement = series.AchievementIds[i];
         }
     }
     return maxAchievement;
 }