private CommandQueueElement Farm() { using (Client.EnterPlanetExclusive(this)) { IEnumerable <Planet> farms = Strategy.GetFarms(_from, _to); Logger.Instance.Log(LogLevel.Info, $"Got {farms.Count()} farms, probing..."); SendProbes(farms); Logger.Instance.Log(LogLevel.Info, "Sending probes finished, waiting to come back and read messages"); WaitForProbes(); // Read messages ReadAllMessagesCommand cmd = new ReadAllMessagesCommand(); cmd.Run(); // Get the newly read messages, but limit to planets in range, in case there was something else going on in the meantime // or unread messages from earlier var messages = cmd.ParsedObjects.OfType <EspionageReport>() .Where(m => m.Coordinate >= _from.LowerCoordinate && m.Coordinate <= _to.UpperCoordinate); Logger.Instance.Log(LogLevel.Info, $"{messages.Count()} Messages parsed, sending ships."); if (Strategy.OnBeforeAttack()) { Resources totalPlunder = Attack(messages); Strategy.OnAfterAttack(); Logger.Instance.Log(LogLevel.Info, $"Job done, theoretical total plunder: {totalPlunder}"); } else { Logger.Instance.Log(LogLevel.Info, $"Strategy decided not to attack, job done."); } } return(null); }
public void OnAfterAttack() { // Wait one minute for the probes to come back // #todo extract method from FarmingBot Thread.Sleep(60000); ReadAllMessagesCommand cmd = new ReadAllMessagesCommand(); cmd.Run(); }
protected override void RunInternal() { if (_lastCount == null || _lastRun > _lastCountTime) { return; } _lastRun = DateTime.UtcNow; if (_lastCount.NewMessages <= 0) { return; } Logger.Instance.Log(LogLevel.Debug, $"Checking for new messages, {_lastCount.NewMessages:N0} reported at {_lastCountTime}"); // Read all messages ReadAllMessagesCommand cmd = new ReadAllMessagesCommand(_client); cmd.Run(); List <MessagesPage> messagePages = cmd.ParsedObjects.OfType <MessagesPage>().ToList(); List <int> messageIds = messagePages.SelectMany(s => s.MessageIds).Select(s => s.Item1).ToList(); HashSet <int> existing; using (BotDb db = new BotDb()) existing = db.Messages.Where(s => messageIds.Contains(s.MessageId)).Select(s => s.MessageId).ToHashset(); foreach (MessagesPage messagesPage in messagePages) { // Request each message foreach (Tuple <int, MessageType> message in messagesPage.MessageIds) { if (existing.Contains(message.Item1)) { // Already fetched continue; } if (message.Item2 == MessageType.EspionageReport) { HttpRequestMessage req = _client.RequestBuilder.GetMessagePage(message.Item1, MessageTabType.FleetsEspionage); _client.IssueRequest(req); } } } }
protected override void RunInternal() { if (_lastCount == null || _lastRun > _lastCountTime) { return; } _lastRun = DateTime.UtcNow; if (_lastCount.NewMessages <= 0 && !_isFirstRun) { return; } _isFirstRun = false; Logger.Instance.Log(LogLevel.Debug, $"Checking for new messages, {_lastCount.NewMessages:N0} reported at {_lastCountTime}"); ReadAllMessagesCommand cmd = new ReadAllMessagesCommand(); cmd.Run(); }