/// <summary> /// For smithy usage /// </summary> /// <param name="html"></param> /// <returns></returns> public static List <TroopLevel> GetTroopLevels(HtmlDocument html) { var list = new List <TroopLevel>(); //Get all researched units var researches = html.DocumentNode.Descendants("div").Where(x => x.HasClass("research")); if (researches == null || researches.Count() == 0) { return(null); } foreach (var research in researches) { var lvl = research.Descendants("span").First(x => x.HasClass("level")).InnerText; if (lvl.Contains("+")) //troop is currently being improved. Only get current level { lvl = lvl.Split('+')[0]; } var troop = new TroopLevel(); troop.Troop = GetTroopFromImage(research); troop.Level = (int)Parser.RemoveNonNumeric(lvl); if (troop.Level != 20) // If max level, there is no upgrade/time cost { troop.UpgradeCost = ResourceParser.GetResourceCost(research .Descendants("div") .FirstOrDefault(x => x.HasClass("showCosts") || x.HasClass("resourceWrapper"))); troop.TimeCost = TimeParser.ParseDuration(research); //TODO! } list.Add(troop); } return(list); }
public static TimeSpan GetTimeOfMovement(HtmlDocument html) { var content = html.GetElementbyId("content"); var div = content.Descendants("div").FirstOrDefault(x => x.HasClass("in")); return(TimeParser.ParseDuration(div.InnerText)); }
public static DateTime GetServerTime(HtmlDocument html) { var serverTime = html.GetElementbyId("servertime"); var timer = serverTime.Descendants("span").FirstOrDefault(x => x.HasClass("timer")); var dur = TimeParser.ParseDuration(timer.InnerText); return(DateTime.Today.Add(dur)); }
public static DateTime GetArrivalTime(HtmlDocument html) { var content = html.GetElementbyId("content"); var div = content.Descendants("div").FirstOrDefault(x => x.HasClass("at")); var timer = div.Descendants("span").FirstOrDefault(x => x.HasClass("timer")); var dur = TimeParser.ParseDuration(timer.InnerText); return(DateTime.Today.Add(dur)); }
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(null); } 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 = CoordinateParser.GetCoordinates(adv.Descendants("td").FirstOrDefault(x => x.HasClass("coords")).InnerText); var difficulty = (adv.Descendants("img").FirstOrDefault().GetAttributeValue("alt", "") == "Normal") ? 1 : 2; 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); }
// Return how long troop trains (in ms) and how much it costs public static (TimeSpan, Resources) GetTrainCost(HtmlDocument htmlDoc, Classificator.TroopsEnum troop) { var troopNode = htmlDoc.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("u" + (int)troop)); if (troopNode == null) { return(new TimeSpan(), null); } while (!troopNode.HasClass("details")) { troopNode = troopNode.ParentNode; } var duration = troopNode.Descendants("div").FirstOrDefault(x => x.HasClass("duration")); TimeSpan dur = TimeParser.ParseDuration(duration); var resWrapper = troopNode.Descendants("div").FirstOrDefault(x => x.HasClass("resourceWrapper")); Resources res = ResourceParser.GetResourceCost(resWrapper); return(dur, res); }
public static TimeSpan GetBuildDuration(HtmlAgilityPack.HtmlNode node, Classificator.ServerVersionEnum version) { var duration = node.Descendants("div").FirstOrDefault(x => x.HasClass("duration")); if (duration != null) { switch (version) { case Classificator.ServerVersionEnum.T4_4: return(TimeParser.ParseDuration(duration.InnerText)); case Classificator.ServerVersionEnum.T4_5: var dur = duration.Descendants("span").FirstOrDefault(x => x.HasClass("value")); if (dur != null) { return(TimeParser.ParseDuration(dur.InnerText)); } break; } } return(new TimeSpan()); }