public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container) { HtmlDocument doc = container.ResponseHtml.Value; HtmlNodeCollection listItemFields = doc.DocumentNode.SelectNodes("//div[@id='buttonz']/div[@class='content']//ul[@id='military' or @id='civil']/li"); if (listItemFields == null) { yield break; } // 1 = fleets // 2 = expeditions // 3 = tactical retreat HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='fleetStatus']//span[contains(@class, 'tooltip')]"); if (nodes != null) { FleetSlotCount count = new FleetSlotCount(); string fleetText = nodes[0].InnerText; Match match = FleetsRegex.Match(fleetText); if (match.Success) { count.Current = int.Parse(match.Groups[1].Value); count.Max = int.Parse(match.Groups[2].Value); yield return(count); } else { Logger.Instance.Log(LogLevel.Error, $"Could not parse fleet count match: {fleetText}"); } } foreach (HtmlNode node in listItemFields) { Ship type = ((ShipType)int.Parse(node.Id.Substring(6, 3))); string countText = node.SelectSingleNode(".//span[@class='level']").ChildNodes.Last(s => s.NodeType == HtmlNodeType.Text).InnerText; int count = int.Parse(countText, NumberStyles.Integer | NumberStyles.AllowThousands, client.ServerCulture); yield return(new DetectedShip { Ship = type, Count = count }); } }
public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container) { HtmlDocument doc = container.ResponseHtml.Value; HtmlNodeCollection imageFields = doc.DocumentNode.SelectNodes("//div[starts-with(@id, 'fleet')]"); if (imageFields == null) { yield break; } FleetSlotCount count = new FleetSlotCount(); HtmlNode slots = doc.DocumentNode.SelectSingleNode("//div[@id='content']//div[@class='fleetStatus']/span[@class='fleetSlots']"); count.Current = int.Parse(slots.SelectSingleNode("./span[@class='current']").InnerText); count.Max = int.Parse(slots.SelectSingleNode("./span[@class='all']").InnerText); yield return(count); foreach (HtmlNode node in imageFields) { string idText = node.GetAttributeValue("id", null); int id = int.Parse(FleetIdRegex.Match(idText).Groups[1].Value, NumberStyles.AllowThousands | NumberStyles.Integer, client.ServerCulture); FleetMissionDetails missionDetails = FleetUtilityParser.ParseFleetMissionDetails(node); HtmlNode fleetInfo = node.SelectSingleNode(".//span[@class='starStreak']"); FleetComposition composition = FleetUtilityParser.ParseFleetInfoTable((OGameClient)client, fleetInfo); FleetEndpointInfo endpointOrigin = ParseEndpoint(node.SelectSingleNode("./span[@class='originData']")); FleetEndpointInfo endpointDestination = ParseEndpoint(node.SelectSingleNode("./span[@class='destinationData']")); yield return(new FleetInfo { Id = id, ArrivalTime = missionDetails.ArrivalTime, IsReturning = missionDetails.IsReturn, MissionType = missionDetails.Mission, Origin = endpointOrigin, Destination = endpointDestination, Composition = composition }); } }
public bool OnBeforeAttack() { var resp = _client.IssueRequest(_client.RequestBuilder.GetPage(PageType.Fleet)); int?cargoCount = resp.GetParsed <DetectedShip>().Where(s => s.Ship == ShipType.LargeCargo).FirstOrDefault()?.Count; _cargoCount = cargoCount.HasValue ? (int)cargoCount : 0; if (!AreCargosAvailable()) { Logger.Instance.Log(LogLevel.Error, "There are no cargos on the planet"); return(false); } _slots = resp.GetParsedSingle <FleetSlotCount>(); if (!AreSlotsAvailable()) { Logger.Instance.Log(LogLevel.Error, "There are no fleet slots available"); return(false); } return(true); }