/// <summary> /// Parses the her home village href /// </summary> /// <param name="htmlDoc">Html</param> /// <returns>Hero's home village href id</returns> public static int?GetHeroVillageHref(HtmlDocument htmlDoc) { var node = htmlDoc.GetElementbyId("attributes"); if (node == null) { node = htmlDoc.GetElementbyId("content"); } if (node == null) { return(null); } return(MapParser.GetKarteHref(node)); }
/// <summary> /// Parse troops from the overview tab inside the rally point /// </summary> public static List <TroopsMovementRallyPoint> ParseTroopsOverview(Account acc, HtmlDocument html) { var ret = new List <TroopsMovementRallyPoint>(); var attacks = html.DocumentNode.Descendants("table").Where(x => x.HasClass("troop_details")); if (attacks == null) { return(ret); } var now = TimeParser.GetServerTime(html); foreach (var attackNode in attacks) { var attack = new TroopsMovementRallyPoint(); var movementClass = attackNode.GetClasses().FirstOrDefault(x => x != "troop_details"); attack.MovementType = ParseMovementClass(movementClass); // If attack.Troops.Sum() is less than 11, we are able to view troop types attacking attack.Troops = ParseIncomingTroops(attackNode); var infos = attackNode.Descendants("tbody").FirstOrDefault(x => x.HasClass("infos")); attack.Arrival = now.Add(TimeParser.ParseTimer(infos)); var sourceId = MapParser.GetKarteHref(attackNode.Descendants("td").First(x => x.HasClass("role"))); attack.SourceCoordinates = MapHelper.CoordinatesFromKid(sourceId, acc); var targetId = MapParser.GetKarteHref(attackNode.Descendants("td").First(x => x.HasClass("troopHeadline"))); attack.TargetCoordinates = MapHelper.CoordinatesFromKid(targetId, acc); var unitImg = attackNode.Descendants("img").First(x => x.HasClass("unit")); var unitInt = Parser.RemoveNonNumeric(unitImg.GetClasses().First(x => x != "unit")); int tribeInt = (int)(unitInt / 10); // ++ since the first element in Classificator.TribeEnum is Any, second is Romans. tribeInt++; attack.Tribe = ((Classificator.TribeEnum)tribeInt); ret.Add(attack); } return(ret); }
public static List <Adventure> GetAdventures(HtmlAgilityPack.HtmlDocument htmlDoc, Classificator.ServerVersionEnum version) { List <Adventure> adventuresList = new List <Adventure>(); var adventures = htmlDoc.GetElementbyId("adventureListForm"); if (adventures == null) { return(adventuresList); } foreach (var adv in adventures.Descendants("tr")) { if (string.IsNullOrEmpty(adv.Id)) { continue; } var sec = (int)TimeParser.ParseDuration(adv.Descendants("td").FirstOrDefault(x => x.HasClass("moveTime")).InnerText).TotalSeconds; var coordinates = MapParser.GetCoordinates(adv.Descendants("td").FirstOrDefault(x => x.HasClass("coords")).InnerText); DifficultyEnum difficulty = DifficultyEnum.Normal; switch (version) { case ServerVersionEnum.T4_4: difficulty = adv.Descendants("img").FirstOrDefault().GetAttributeValue("alt", "") == "Normal" ? DifficultyEnum.Normal : DifficultyEnum.Difficult; break; case ServerVersionEnum.T4_5: difficulty = adv.Descendants("img").FirstOrDefault().GetAttributeValue("class", "") == "adventureDifficulty1" ? DifficultyEnum.Normal : DifficultyEnum.Difficult; break; } var secStr = adv.Descendants("td").FirstOrDefault(x => x.HasClass("timeLeft"))?.InnerText; int secRemaining = int.MaxValue; if (!string.IsNullOrEmpty(secStr)) { secRemaining = (int)TimeParser.ParseDuration(secStr).TotalSeconds; } switch (version) { case Classificator.ServerVersionEnum.T4_4: var href = adv.Descendants("a").FirstOrDefault(x => x.HasClass("gotoAdventure")).GetAttributeValue("href", "").Replace("amp;", ""); adventuresList.Add(new Adventure() { Coordinates = coordinates, DurationSeconds = sec, TimeLeftSeconds = secRemaining, Difficulty = difficulty, Ref = href }); break; case Classificator.ServerVersionEnum.T4_5: var elementId = adv.Descendants("td").FirstOrDefault(x => x.HasClass("goTo")).Id; adventuresList.Add(new Adventure() { Coordinates = coordinates, DurationSeconds = sec, TimeLeftSeconds = secRemaining, Difficulty = difficulty, AdventureId = elementId }); break; } } return(adventuresList); }