private IList<Achievement> ParseSubAchievements(Achievement achievement, HtmlNode subAchievementNode)
        {
            IList<Achievement> subAchievements = new List<Achievement>();
            HtmlNodeCollection achievements = subAchievementNode.SelectNodes("./li");
            if (achievements != null)
            {
                foreach (HtmlNode subNode in achievements)
                {
                    // TODO : Parse out achievement id
                    if ( subNode.Attributes["onmousemove"] != null )
                    {
                        Match match = parseTooltip.Match(subNode.Attributes["onmousemove"].Value);
                        if ( match.Success )
                        {
                            string subAchievementId = match.Groups["achievementid"].Value;
                            int blizzardId = 0;
                            int.TryParse(subAchievementId, out blizzardId);
                            Achievement subAchievement = _service.Find(blizzardId);
                            if (subAchievement == null)
                            {
                                subAchievement = new Achievement() { BlizzardID = blizzardId };
                                subAchievement.Name = GetValueAsString(subNode, ".//h3");
                                subAchievement.Description = GetValueAsString(subNode, ".//div[@class='color-tooltip-yellow']");
                                subAchievement.Points = GetValueAsInt32(subNode, ".//span[@class='points border-3']");
                                _service.Save(subAchievement);
                            }
                            achievement.Points = achievement.Points - subAchievement.Points;
                            subAchievements.Add(subAchievement);
                        }
                    }
                }
            }

            return subAchievements;
        }
        public static string MediumImage(Achievement achievement)
        {
            if (!string.IsNullOrEmpty(achievement.Icon))
             {
                 return string.Format("http://static.wowhead.com/images/wow/icons/medium/{0}.jpg",
                     achievement.Icon.ToLowerInvariant().Replace(" ", ""));
             }

             return "http://static.wowhead.com/images/wow/icons/medium/inv_bannerpvp_01.jpg";
        }
        public static string CategoryDisplay(Achievement achievement)
        {
            if (achievement.ParentCategory != "-1")
            {
                return string.Format("{0} > {1}",
                    CategoryName(achievement.ParentCategory),
                    CategoryName(achievement.Category));
            }

            return string.Format("{0}",
                    CategoryName(achievement.Category));
        }
 public void UpdateAchivementDetails(Achievement achievement, AchievementInfo achievementDetails, string category, int categoryId, int parentCategoryId)
 {
     achievement.BlizzardID = achievementDetails.Id;
     achievement.Name = achievementDetails.Title;
     achievement.Side = ReturnSide(achievementDetails.FactionId);
     achievement.Points = achievementDetails.Points;
     achievement.Icon = achievementDetails.Icon;
     achievement.Category = category;
     achievement.CategoryID = categoryId;
     achievement.ParentCategoryID = parentCategoryId;
     achievement.Description = achievementDetails.Description;
     foreach (AchievementCriteria criteria in achievementDetails.Criteria)
     {
         Criteria details = new Criteria();
         details.Description = criteria.Description;
         details.Id = criteria.Id;
         details.Max = criteria.Max;
         details.OrderIndex = criteria.OrderIndex;
         achievement.Criteria.Add(details);
     }
 }
        private void ProcessAchievementList(IEnumerable<AchievementInfo> achievements, string categoryName, int categoryId, int parentCategoryId)
        {
            foreach (AchievementInfo achievementDetails in achievements)
            {
                Achievement achievement = _achievementRepository.Find(achievementDetails.Id);
                if (achievement == null)
                {
                    achievement = new Achievement();
                }

                UpdateAchivementDetails(achievement, achievementDetails, categoryName, categoryId, parentCategoryId);
                _achievementRepository.Save(achievement);
            }
        }
 private Achievement CreateFromAchivementInfo(AchievementInfo achievementDetails, string category, int categoryId, int parentCategoryId)
 {
     Achievement achievement = new Achievement();
     UpdateAchivementDetails(achievement, achievementDetails, category, categoryId, parentCategoryId);
     return achievement;
 }
        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);
            }
        }
 public static string CategoryDisplay(Achievement achievement)
 {
     return string.Format("{0}",
             achievement.Category);
 }
 public bool HasAchieved(Achievement achievement)
 {
     if (achievement == null)
     {
         return false;
     }
     return Achievements.Where(aa => aa.BlizzardID == achievement.BlizzardID).Count() > 0;
 }
Beispiel #10
0
 public void AddNewAchivement(DateTime whenAchieved, Achievement achievement)
 {
     if (achievement != null)
     {
         Achievements.Add(new AchievedAchievement() { WhenAchieved = whenAchieved, BlizzardID = achievement.BlizzardID, Points = achievement.Points });
     }
 }
 public void AddAchievementToSeries(Achievement achievement)
 {
     AchievementIds.Add(achievement.BlizzardID);
     achievement.Series = this;
 }