private void TravelToAgentsStation() { try { StationDestination baseDestination = Traveler.Destination as StationDestination; if (baseDestination == null || baseDestination.StationId != Cache.Instance.Agent.StationId) { Traveler.Destination = new StationDestination(Cache.Instance.Agent.SolarSystemId, Cache.Instance.Agent.StationId, Cache.Instance.DirectEve.GetLocationName( Cache.Instance.Agent.StationId)); } } catch (Exception ex) { Logging.Log("DebugHangarsBehavior", "TravelToAgentsStation: Exception caught: [" + ex.Message + "]", Logging.Red); return; } if (Cache.Instance.InSpace) { if (!Cache.Instance.ActiveShip.Entity.IsCloaked || (Cache.Instance.LastSessionChange.AddSeconds(60) > DateTime.UtcNow)) { Combat.ProcessState(); Drones.ProcessState(); //do we really want to use drones here? } } if (Cache.Instance.InSpace && !Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { Cache.Instance.IsMissionPocketDone = true; //tells drones.cs that we can pull drones //Logging.Log("CombatmissionBehavior","TravelToAgentStation: not pointed",Logging.White); } Traveler.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State", "is " + _States.CurrentTravelerState, Logging.White); } }
private void OnFrame(object sender, EventArgs e) { var watch = new Stopwatch(); // Only pulse state changes every 1.5s if (DateTime.Now.Subtract(_lastPulse).TotalMilliseconds < 1500) { return; } _lastPulse = DateTime.Now; // Session is not ready yet, do not continue if (!Cache.Instance.DirectEve.Session.IsReady) { return; } // If Questor window not visible, show it if (!m_Parent.Visible) { m_Parent.Visible = true; } // We are not in space or station, don't do shit yet! if (!Cache.Instance.InSpace && !Cache.Instance.InStation) { return; } // New frame, invalidate old cache Cache.Instance.InvalidateCache(); // Update settings (settings only load if character name changed) Settings.Instance.LoadSettings(); CharacterName = Cache.Instance.DirectEve.Me.Name; // Check 3D rendering if (Cache.Instance.DirectEve.Session.IsInSpace && Cache.Instance.DirectEve.Rendering3D != !Disable3D) { Cache.Instance.DirectEve.Rendering3D = !Disable3D; } // Invalid settings, quit while we're ahead if (!ValidSettings) { if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 15) { ValidateSettings(); _lastAction = DateTime.Now; } return; } foreach (var window in Cache.Instance.Windows) { // Telecom messages are generally mission info messages if (window.Name == "telecom") { Logging.Log("Questor: Closing telecom message..."); Logging.Log("Questor: Content of telecom window (HTML): [" + (window.Html ?? string.Empty).Replace("\n", "").Replace("\r", "") + "]"); window.Close(); } // Modal windows must be closed // But lets only close known modal windows if (window.Name == "modal") { bool close = false; if (!string.IsNullOrEmpty(window.Html)) { // Server going down close |= window.Html.Contains("Please make sure your characters are out of harms way"); // In space "shit" close |= window.Html.Contains("Item cannot be moved back to a loot container."); close |= window.Html.Contains("you do not have the cargo space"); close |= window.Html.Contains("cargo units would be required to complete this operation."); close |= window.Html.Contains("You are too far away from the acceleration gate to activate it!"); close |= window.Html.Contains("maximum distance is 2500 meters"); // Stupid warning, lets see if we can find it close |= window.Html.Contains("Do you wish to proceed with this dangerous action?"); // Yes we know the mission isnt complete, Questor will just redo the mission close |= window.Html.Contains("Please check your mission journal for further information."); // Lag :/ close |= window.Html.Contains("This gate is locked!"); close |= window.Html.Contains("The Zbikoki's Hacker Card"); close |= window.Html.Contains(" units free."); } if (close) { Logging.Log("Questor: Closing modal window..."); Logging.Log("Questor: Content of modal window (HTML): [" + (window.Html ?? string.Empty).Replace("\n", "").Replace("\r", "") + "]"); window.Close(); } } } // We always check our defense state if we're in space, regardless of questor state // We also always check panic if (Cache.Instance.InSpace) { watch.Reset(); watch.Start(); if (ExitSta == false) { _defense.ProcessState(); } watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Defense.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } } // Defense is more important then pause, rest (even panic) isnt! if (Paused) { return; } // Panic always runs, not just in space watch.Reset(); watch.Start(); _panic.InMission = State == QuestorState.ExecuteMission; if (State == QuestorState.Storyline && _storyline.State == StorylineState.ExecuteMission) { _panic.InMission |= _storyline.StorylineHandler is GenericCombatStoryline && (_storyline.StorylineHandler as GenericCombatStoryline).State == GenericCombatStorylineState.ExecuteMission; } _panic.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Panic.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (_panic.State == PanicState.Panic || _panic.State == PanicState.Panicking) { // If Panic is in panic state, questor is in panic state :) State = State == QuestorState.Storyline ? QuestorState.StorylinePanic : QuestorState.Panic; if (Settings.Instance.DebugStates) { Logging.Log("State = " + State); } } else if (_panic.State == PanicState.Resume) { // Reset panic state _panic.State = PanicState.Normal; // Ugly storyline resume hack if (State == QuestorState.StorylinePanic) { State = QuestorState.Storyline; if (_storyline.StorylineHandler is GenericCombatStoryline) { (_storyline.StorylineHandler as GenericCombatStoryline).State = GenericCombatStorylineState.GotoMission; } } else { // Head back to the mission _traveler.State = TravelerState.Idle; State = QuestorState.GotoMission; } if (Settings.Instance.DebugStates) { Logging.Log("State = " + State); } } if (Settings.Instance.DebugStates) { Logging.Log("Panic.State = " + _panic.State); } // When in warp there's nothing we can do, so ignore everything if (Cache.Instance.InWarp) { return; } DirectAgentMission mission; switch (State) { case QuestorState.Idle: if (Cache.Instance.StopTimeSpecified) { if (DateTime.Now >= Cache.Instance.StopTime) { Logging.Log("Time to stop. Quitting game."); Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdQuitGame); return; } } if (Cache.Instance.InSpace) { // Questor doesnt handle inspace-starts very well, head back to base to try again Logging.Log("Questor: Started questor while in space, heading back to base in 15 seconds"); _lastAction = DateTime.Now; State = QuestorState.DelayedGotoBase; break; } if (DateTime.Now.Subtract(Program.startTime).Minutes > Program.maxRuntime) { // quit questor Logging.Log("Questor: Maximum runtime exceeded. Quiting..."); Application.Exit(); } mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (!string.IsNullOrEmpty(Mission) && (mission == null || mission.Name != Mission || mission.State != (int)MissionState.Accepted)) { // Do not save statistics if loyalty points == -1 // Seeing as we completed a mission, we will have loyalty points for this agent if (Cache.Instance.Agent.LoyaltyPoints == -1) { return; } // Get the path var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filename = Path.Combine(path, Cache.Instance.FilterPath(CharacterName) + ".statistics.log"); // Write the header if (!File.Exists(filename)) { File.AppendAllText(filename, "Date;Mission;Time;Isk;Loot;LP;\r\n"); } // Build the line var line = string.Format("{0:dd/MM/yyyy HH:mm:ss}", DateTime.Now) + ";"; line += Mission + ";"; line += ((int)DateTime.Now.Subtract(Started).TotalMinutes) + ";"; line += ((int)(Cache.Instance.DirectEve.Me.Wealth - Wealth)) + ";"; line += ((int)LootValue) + ";"; line += (Cache.Instance.Agent.LoyaltyPoints - LoyaltyPoints) + ";"; line += ((int)LostDrones) + ";"; line += ((int)AmmoConsumption) + ";"; line += ((int)AmmoValue) + ";\r\n"; // The mission is finished File.AppendAllText(filename, line); // Disable next log line Mission = null; } if (AutoStart) { // Dont start missions hour before downtime if (DateTime.UtcNow.Hour == 10) { break; } // Dont start missions in downtime if (DateTime.UtcNow.Hour == 11 && DateTime.UtcNow.Minute < 15) { break; } if (Settings.Instance.RandomDelay > 0 || Settings.Instance.MinimumDelay > 0) { _randomDelay = (Settings.Instance.RandomDelay > 0 ? _random.Next(Settings.Instance.RandomDelay) : 0) + Settings.Instance.MinimumDelay; _lastAction = DateTime.Now; State = QuestorState.DelayedStart; Logging.Log("Questor: Random mission start delay of [" + _randomDelay + "] seconds"); } else { State = QuestorState.Start; } } else if (ExitWhenIdle) { LavishScript.ExecuteCommand("exit"); } break; case QuestorState.DelayedStart: if (DateTime.Now.Subtract(_lastAction).TotalSeconds < _randomDelay) { break; } State = QuestorState.Start; break; case QuestorState.DelayedGotoBase: if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 15) { break; } Logging.Log("Questor: Heading back to base"); State = QuestorState.GotoBase; break; case QuestorState.Start: if (_agentInteraction.State == AgentInteractionState.Idle) { if (Settings.Instance.EnableStorylines && _storyline.HasStoryline()) { Logging.Log("Questor: Storyline detected, doing storyline."); _storyline.Reset(); State = QuestorState.Storyline; break; } Logging.Log("AgentInteraction: Start conversation [Start Mission]"); _agentInteraction.State = AgentInteractionState.StartConversation; _agentInteraction.Purpose = AgentInteractionPurpose.StartMission; // Update statistic values Wealth = Cache.Instance.DirectEve.Me.Wealth; LootValue = 0; LoyaltyPoints = Cache.Instance.Agent.LoyaltyPoints; Started = DateTime.Now; Mission = string.Empty; LostDrones = 0; AmmoConsumption = 0; AmmoValue = 0; } _agentInteraction.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("AgentInteraction.State = " + _agentInteraction.State); } if (_agentInteraction.State == AgentInteractionState.Done) { mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (mission != null) { // Update loyalty points again (the first time might return -1) LoyaltyPoints = Cache.Instance.Agent.LoyaltyPoints; Mission = mission.Name; } _agentInteraction.State = AgentInteractionState.Idle; State = QuestorState.Arm; } break; case QuestorState.Arm: if (_arm.State == ArmState.Idle) { Logging.Log("Arm: Begin"); _arm.State = ArmState.Begin; // Load right ammo based on mission _arm.AmmoToLoad.Clear(); _arm.AmmoToLoad.AddRange(_agentInteraction.AmmoToLoad); } _arm.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("Arm.State = " + _arm.State); } if (_arm.State == ArmState.Done) { _arm.State = ArmState.Idle; State = QuestorState.WarpOutStation; } break; case QuestorState.WarpOutStation: var _bookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.bookmarkWarpOut ?? "").OrderBy(b => b.CreatedOn).FirstOrDefault(); var _solarid = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; if (_bookmark == null) { Logging.Log("WarpOut: No Bookmark"); State = QuestorState.GotoMission; } else if (_bookmark.LocationId == _solarid) { if (_traveler.Destination == null) { Logging.Log("WarpOut: Warp at " + _bookmark.Title); _traveler.Destination = new BookmarkDestination(_bookmark); ExitSta = true; } _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { Logging.Log("WarpOut: Safe!"); ExitSta = false; State = QuestorState.GotoMission; _traveler.Destination = null; } } else { Logging.Log("WarpOut: No Bookmark in System"); State = QuestorState.GotoMission; } break; case QuestorState.GotoMission: var missionDestination = _traveler.Destination as MissionBookmarkDestination; if (missionDestination == null || missionDestination.AgentId != Cache.Instance.AgentId) // We assume that this will always work "correctly" (tm) { _traveler.Destination = new MissionBookmarkDestination(Cache.Instance.GetMissionBookmark(Cache.Instance.AgentId, "Encounter")); } if (Cache.Instance.PriorityTargets.Any(pt => pt != null && pt.IsValid)) { Logging.Log("GotoMission: Priority targets found, engaging!"); _combat.ProcessState(); } _traveler.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State = " + _traveler.State); } if (_traveler.State == TravelerState.AtDestination) { State = QuestorState.ExecuteMission; // Seeing as we just warped to the mission, start the mission controller _missionController.State = MissionControllerState.Start; _combat.State = CombatState.CheckTargets; _traveler.Destination = null; } break; case QuestorState.CombatHelper: _combat.ProcessState(); _drones.ProcessState(); _salvage.ProcessState(); break; case QuestorState.ExecuteMission: watch.Reset(); watch.Start(); _combat.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Combat.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("Combat.State = " + _combat.State); } watch.Reset(); watch.Start(); _drones.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Drones.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("Drones.State = " + _drones.State); } watch.Reset(); watch.Start(); _salvage.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Salvage.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("Salvage.State = " + _salvage.State); } watch.Reset(); watch.Start(); _missionController.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("MissionController.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("MissionController.State = " + _missionController.State); } // If we are out of ammo, return to base, the mission will fail to complete and the bot will reload the ship // and try the mission again if (_combat.State == CombatState.OutOfAmmo) { Logging.Log("Combat: Out of Ammo!"); State = QuestorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } if (_missionController.State == MissionControllerState.Done) { State = QuestorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } // If in error state, just go home and stop the bot if (_missionController.State == MissionControllerState.Error) { Logging.Log("MissionController: Error"); State = QuestorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } break; case QuestorState.GotoBase: var baseDestination = _traveler.Destination as StationDestination; if (baseDestination == null || baseDestination.StationId != Cache.Instance.Agent.StationId) { _traveler.Destination = new StationDestination(Cache.Instance.Agent.SolarSystemId, Cache.Instance.Agent.StationId, Cache.Instance.DirectEve.GetLocationName(Cache.Instance.Agent.StationId)); } if (Cache.Instance.PriorityTargets.Any(pt => pt != null && pt.IsValid)) { Logging.Log("GotoBase: Priority targets found, engaging!"); _combat.ProcessState(); } _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (_missionController.State == MissionControllerState.Error) { State = QuestorState.Error; } else if (_combat.State != CombatState.OutOfAmmo && mission != null && mission.State == (int)MissionState.Accepted) { State = QuestorState.CompleteMission; } else { State = QuestorState.UnloadLoot; } _traveler.Destination = null; } if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State = " + _traveler.State); } break; case QuestorState.CompleteMission: if (_agentInteraction.State == AgentInteractionState.Idle) { // Lost drone statistics // (inelegantly located here so as to avoid the necessity to switch to a combat ship after salvaging) if (Settings.Instance.UseDrones) { var droneBay = Cache.Instance.DirectEve.GetShipsDroneBay(); if (droneBay.Window == null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenDroneBayOfActiveShip); break; } if (!droneBay.IsReady) { break; } if (Cache.Instance.InvTypesById.ContainsKey(Settings.Instance.DroneTypeId)) { var drone = Cache.Instance.InvTypesById[Settings.Instance.DroneTypeId]; LostDrones = (int)Math.Floor((droneBay.Capacity - droneBay.UsedCapacity) / drone.Volume); Logging.Log("DroneStats: Logging the number of lost drones: " + LostDrones.ToString()); } else { Logging.Log("DroneStats: Couldn't find the drone TypeID specified in the settings.xml; this shouldn't happen!"); } } // Lost drone statistics stuff ends here // Ammo Consumption statistics // Is cargo open? var cargoship = Cache.Instance.DirectEve.GetShipsCargo(); if (cargoship.Window == null) { // No, command it to open Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip); break; } if (!cargoship.IsReady) { break; } var correctAmmo1 = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType); var AmmoCargo = cargoship.Items.Where(i => correctAmmo1.Any(a => a.TypeId == i.TypeId)); foreach (var item in AmmoCargo) { var Ammo1 = Settings.Instance.Ammo.Where(a => a.TypeId == item.TypeId).FirstOrDefault(); var AmmoType = Cache.Instance.InvTypesById[item.TypeId]; AmmoConsumption = (Ammo1.Quantity - item.Quantity); AmmoValue = (AmmoType.MedianBuy ?? 0) * AmmoConsumption; } Logging.Log("AgentInteraction: Start Conversation [Complete Mission]"); _agentInteraction.State = AgentInteractionState.StartConversation; _agentInteraction.Purpose = AgentInteractionPurpose.CompleteMission; } _agentInteraction.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("AgentInteraction.State = " + _agentInteraction.State); } if (_agentInteraction.State == AgentInteractionState.Done) { _agentInteraction.State = AgentInteractionState.Idle; State = QuestorState.UnloadLoot; } break; case QuestorState.UnloadLoot: if (_unloadLoot.State == UnloadLootState.Idle) { Logging.Log("UnloadLoot: Begin"); _unloadLoot.State = UnloadLootState.Begin; } _unloadLoot.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("UnloadLoot.State = " + _unloadLoot.State); } if (_unloadLoot.State == UnloadLootState.Done) { Logging.Log("UnloadLoot: Done"); _unloadLoot.State = UnloadLootState.Idle; // Update total loot value LootValue += _unloadLoot.LootValue; mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (_combat.State != CombatState.OutOfAmmo && Settings.Instance.AfterMissionSalvaging && Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " ").Count > 0 && (mission == null || mission.State == (int)MissionState.Offered)) { State = QuestorState.BeginAfterMissionSalvaging; } else if (_combat.State == CombatState.OutOfAmmo) { State = QuestorState.Start; } else { State = QuestorState.Idle; } } break; case QuestorState.BeginAfterMissionSalvaging: _GatesPresent = false; if (_arm.State == ArmState.Idle) { _arm.State = ArmState.SwitchToSalvageShip; } _arm.ProcessState(); if (_arm.State == ArmState.Done) { _arm.State = ArmState.Idle; var bookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " ").OrderBy(b => b.CreatedOn).FirstOrDefault(); if (bookmark == null) { State = QuestorState.Idle; break; } State = QuestorState.GotoSalvageBookmark; _traveler.Destination = new BookmarkDestination(bookmark); } break; case QuestorState.GotoSalvageBookmark: _traveler.ProcessState(); string target = "Acceleration Gate"; var targets = Cache.Instance.EntitiesByName(target); if (_traveler.State == TravelerState.AtDestination || GateInSalvage()) { State = QuestorState.Salvage; _traveler.Destination = null; } if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State = " + _traveler.State); } break; case QuestorState.Salvage: var cargo = Cache.Instance.DirectEve.GetShipsCargo(); // Is our cargo window open? if (cargo.Window == null) { // No, command it to open Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip); break; } if (Settings.Instance.UnloadLootAtStation && cargo.IsReady && (cargo.Capacity - cargo.UsedCapacity) < 100) { Logging.Log("Salvage: We are full, goto base to unload"); State = QuestorState.GotoBase; break; } if (Cache.Instance.UnlootedContainers.Count() == 0) { Logging.Log("Salvage: Finished salvaging the room"); bool GatesInRoom = GateInSalvage(); var bookmarks = Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " "); do { var bookmark = bookmarks.FirstOrDefault(b => Cache.Instance.DistanceFromMe(b.X ?? 0, b.Y ?? 0, b.Z ?? 0) < 250000); if (!GatesInRoom && _GatesPresent) // if there were gates, but we've gone through them all, delete all bookmarks { bookmark = bookmarks.FirstOrDefault(); } else if (GatesInRoom) { break; } if (bookmark == null) { break; } bookmark.Delete(); bookmarks.Remove(bookmark); } while (true); if (bookmarks.Count == 0 && !GatesInRoom) { Logging.Log("Salvage: We have salvaged all bookmarks, goto base"); State = QuestorState.GotoBase; } else { if (!GatesInRoom) { Logging.Log("Salvage: Goto the next salvage bookmark"); State = QuestorState.GotoSalvageBookmark; _traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).First()); } else if (Settings.Instance.UseGatesInSalvage) { Logging.Log("Salvage: Acceleration gate found - moving to next pocket"); State = QuestorState.SalvageUseGate; } else { Logging.Log("Salvage: Acceleration gate found, useGatesInSalvage set to false - Returning to base"); State = QuestorState.GotoBase; _traveler.Destination = null; } } break; } var closestWreck = Cache.Instance.UnlootedContainers.First(); if (closestWreck.Distance > 2500 && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != closestWreck.Id)) { if (closestWreck.Distance > 150000) { closestWreck.WarpTo(); } else { closestWreck.Approach(); } } else if (closestWreck.Distance <= 2500 && Cache.Instance.Approaching != null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdStopShip); } try { // Overwrite settings, as the 'normal' settings do not apply _salvage.MaximumWreckTargets = Math.Min(Cache.Instance.DirectEve.ActiveShip.MaxLockedTargets, Cache.Instance.DirectEve.Me.MaxLockedTargets); _salvage.ReserveCargoCapacity = 80; _salvage.LootEverything = true; _salvage.ProcessState(); } finally { ApplySettings(); } break; case QuestorState.SalvageUseGate: target = "Acceleration Gate"; targets = Cache.Instance.EntitiesByName(target); if (targets == null || targets.Count() == 0) { State = QuestorState.GotoSalvageBookmark; return; } _lastX = Cache.Instance.DirectEve.ActiveShip.Entity.X; _lastY = Cache.Instance.DirectEve.ActiveShip.Entity.Y; _lastZ = Cache.Instance.DirectEve.ActiveShip.Entity.Z; var closest = targets.OrderBy(t => t.Distance).First(); if (closest.Distance < 2500) { Logging.Log("Salvage: Acceleration gate found - GroupID=" + closest.GroupId); // Activate it and move to the next Pocket closest.Activate(); // Do not change actions, if NextPocket gets a timeout (>2 mins) then it reverts to the last action Logging.Log("Salvage: Activate [" + closest.Name + "] and change state to 'NextPocket'"); State = QuestorState.SalvageNextPocket; _lastPulse = DateTime.Now; } else if (closest.Distance < 150000) { // Move to the target if (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != closest.Id) { Logging.Log("Salvage: Approaching target [" + closest.Name + "][" + closest.Id + "]"); closest.Approach(); } } else { // Probably never happens closest.WarpTo(); } _lastPulse = DateTime.Now.AddSeconds(10); break; case QuestorState.SalvageNextPocket: var distance = Cache.Instance.DistanceFromMe(_lastX, _lastY, _lastZ); if (distance > 100000) { Logging.Log("Salvage: We've moved to the next Pocket [" + distance + "]"); State = QuestorState.Salvage; } else if (DateTime.Now.Subtract(_lastPulse).TotalMinutes > 2) { Logging.Log("Salvage: We've timed out, retry last action"); // We have reached a timeout, revert to ExecutePocketActions (e.g. most likely Activate) State = QuestorState.SalvageUseGate; } break; case QuestorState.Storyline: _storyline.ProcessState(); if (_storyline.State == StorylineState.Done) { Logging.Log("Questor: We have completed the storyline, returning to base"); State = QuestorState.GotoBase; break; } break; case QuestorState.Traveler: var destination = Cache.Instance.DirectEve.Navigation.GetDestinationPath(); if (destination == null || destination.Count == 0) { // should never happen, but still... Logging.Log("Traveler: No destination?"); State = QuestorState.Error; } else if (destination.Count == 1 && destination.First() == 0) { destination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; } if (_traveler.Destination == null || _traveler.Destination.SolarSystemId != destination.Last()) { var bookmarks = Cache.Instance.DirectEve.Bookmarks.Where(b => b.LocationId == destination.Last()); if (bookmarks != null && bookmarks.Count() > 0) { _traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).First()); } else { Logging.Log("Traveler: Destination: [" + Cache.Instance.DirectEve.Navigation.GetLocation(destination.Last()).Name + "]"); _traveler.Destination = new SolarSystemDestination(destination.Last()); } } else { _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { if (_missionController.State == MissionControllerState.Error) { Logging.Log("Questor stopped: an error has occured"); State = QuestorState.Error; } else if (Cache.Instance.InSpace) { Logging.Log("Traveler: Arrived at destination (in space, Questor stopped)"); State = QuestorState.Error; } else { Logging.Log("Traveler: Arrived at destination"); State = QuestorState.Idle; } } } break; } }
private void OnFrame(object sender, EventArgs e) { var watch = new Stopwatch(); // Only pulse state changes every 1.5s if (DateTime.Now.Subtract(_lastPulse).TotalMilliseconds < 1500) { return; } _lastPulse = DateTime.Now; // Session is not ready yet, do not continue if (!Cache.Instance.DirectEve.Session.IsReady) { return; } // We are not in space or station, don't do shit yet! if (!Cache.Instance.InSpace && !Cache.Instance.InStation) { return; } // New frame, invalidate old cache Cache.Instance.InvalidateCache(); // Update settings (settings only load if character name changed) Settings.Instance.LoadSettings(); CharacterName = Cache.Instance.DirectEve.Me.Name; // Check 3D rendering if (Cache.Instance.DirectEve.Session.IsInSpace && Cache.Instance.DirectEve.Rendering3D != !Disable3D) { Cache.Instance.DirectEve.Rendering3D = !Disable3D; } // Invalid settings, quit while we're ahead if (!ValidSettings) { if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 15) { ValidateSettings(); _lastAction = DateTime.Now; } return; } foreach (var window in Cache.Instance.Windows) { // Telecom messages are generally mission info messages if (window.Name == "telecom") { Logging.Log("Questor: Closing telecom message..."); Logging.Log("Questor: Content of telecom window (HTML): [" + (window.Html ?? string.Empty).Replace("\n", "").Replace("\r", "") + "]"); window.Close(); } // Modal windows must be closed // But lets only close known modal windows if (window.Name == "modal") { bool close = false; if (!string.IsNullOrEmpty(window.Html)) { // Server going down close |= window.Html.Contains("Please make sure your characters are out of harms way"); // In space "shit" close |= window.Html.Contains("Item cannot be moved back to a loot container."); close |= window.Html.Contains("you do not have the cargo space"); close |= window.Html.Contains("cargo units would be required to complete this operation."); close |= window.Html.Contains("You are too far away from the acceleration gate to activate it!"); close |= window.Html.Contains("maximum distance is 2500 meters"); // Stupid warning, lets see if we can find it close |= window.Html.Contains("Do you wish to proceed with this dangerous action?"); // Yes we know the mission isnt complete, Questor will just redo the mission close |= window.Html.Contains("Please check your mission journal for further information."); // Lag :/ close |= window.Html.Contains("The Zbikoki's Hacker Card"); close |= window.Html.Contains(" units free."); } if (close) { Logging.Log("Questor: Closing modal window..."); Logging.Log("Questor: Content of modal window (HTML): [" + (window.Html ?? string.Empty).Replace("\n", "").Replace("\r", "") + "]"); window.Close(); } } } // We always check our defense state if we're in space, regardless of questor state // We also always check panic if (Cache.Instance.InSpace) { watch.Reset(); watch.Start(); _defense.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Defense.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } } // Defense is more important then pause, rest (even panic) isnt! if (Paused) { return; } // Panic always runs, not just in space watch.Reset(); watch.Start(); _panic.InMission = State == QuestorState.ExecuteMission; if (State == QuestorState.Storyline && _storyline.State == StorylineState.ExecuteMission) { _panic.InMission |= _storyline.StorylineHandler is GenericCombatStoryline && (_storyline.StorylineHandler as GenericCombatStoryline).State == GenericCombatStorylineState.ExecuteMission; } _panic.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Panic.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (_panic.State == PanicState.Panic || _panic.State == PanicState.Panicking) { // If Panic is in panic state, questor is in panic state :) State = State == QuestorState.Storyline ? QuestorState.StorylinePanic : QuestorState.Panic; if (Settings.Instance.DebugStates) { Logging.Log("State = " + State); } } else if (_panic.State == PanicState.Resume) { // Reset panic state _panic.State = PanicState.Normal; // Ugly storyline resume hack if (State == QuestorState.StorylinePanic) { State = QuestorState.Storyline; if (_storyline.StorylineHandler is GenericCombatStoryline) { (_storyline.StorylineHandler as GenericCombatStoryline).State = GenericCombatStorylineState.GotoMission; } } else { // Head back to the mission _traveler.State = TravelerState.Idle; State = QuestorState.GotoMission; } if (Settings.Instance.DebugStates) { Logging.Log("State = " + State); } } if (Settings.Instance.DebugStates) { Logging.Log("Panic.State = " + _panic.State); } // When in warp there's nothing we can do, so ignore everything if (Cache.Instance.InWarp) { return; } DirectAgentMission mission; switch (State) { case QuestorState.Idle: if (Cache.Instance.InSpace) { // Questor doesnt handle inspace-starts very well, head back to base to try again Logging.Log("Questor: Started questor while in space, heading back to base in 15 seconds"); _lastAction = DateTime.Now; State = QuestorState.DelayedGotoBase; break; } mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (!string.IsNullOrEmpty(Mission) && (mission == null || mission.Name != Mission || mission.State != (int)MissionState.Accepted)) { // Do not save statistics if loyalty points == -1 // Seeing as we completed a mission, we will have loyalty points for this agent if (Cache.Instance.Agent.LoyaltyPoints == -1) { return; } // Get the path var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filename = Path.Combine(path, Cache.Instance.FilterPath(CharacterName) + ".statistics.log"); // Write the header if (!File.Exists(filename)) { File.AppendAllText(filename, "Mission;Time;Isk;Loot;LP;\r\n"); } // Build the line var line = Mission + ";"; line += ((int)DateTime.Now.Subtract(Started).TotalMinutes) + ";"; line += ((int)(Cache.Instance.DirectEve.Me.Wealth - Wealth)) + ";"; line += ((int)LootValue) + ";"; line += (Cache.Instance.Agent.LoyaltyPoints - LoyaltyPoints) + ";\r\n"; // The mission is finished File.AppendAllText(filename, line); // Disable next log line Mission = null; } if (AutoStart) { // Dont start missions hour before downtime if (DateTime.UtcNow.Hour == 10) { break; } // Dont start missions in downtime if (DateTime.UtcNow.Hour == 11 && DateTime.UtcNow.Minute < 15) { break; } if (Settings.Instance.RandomDelay > 0 || Settings.Instance.MinimumDelay > 0) { _randomDelay = (Settings.Instance.RandomDelay > 0 ? _random.Next(Settings.Instance.RandomDelay) : 0) + Settings.Instance.MinimumDelay; _lastAction = DateTime.Now; State = QuestorState.DelayedStart; Logging.Log("Questor: Random mission start delay of [" + _randomDelay + "] seconds"); } else { State = QuestorState.Start; } } else if (ExitWhenIdle) { LavishScript.ExecuteCommand("exit"); } break; case QuestorState.DelayedStart: if (DateTime.Now.Subtract(_lastAction).TotalSeconds < _randomDelay) { break; } State = QuestorState.Start; break; case QuestorState.DelayedGotoBase: if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 15) { break; } Logging.Log("Questor: Heading back to base"); State = QuestorState.GotoBase; break; case QuestorState.Start: if (_agentInteraction.State == AgentInteractionState.Idle) { if (Settings.Instance.EnableStorylines && _storyline.HasStoryline()) { Logging.Log("Questor: Storyline detected, doing storyline."); _storyline.Reset(); State = QuestorState.Storyline; break; } Logging.Log("AgentInteraction: Start conversation [Start Mission]"); _agentInteraction.State = AgentInteractionState.StartConversation; _agentInteraction.Purpose = AgentInteractionPurpose.StartMission; // Update statistic values Wealth = Cache.Instance.DirectEve.Me.Wealth; LootValue = 0; LoyaltyPoints = Cache.Instance.Agent.LoyaltyPoints; Started = DateTime.Now; Mission = string.Empty; } _agentInteraction.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("AgentInteraction.State = " + _agentInteraction.State); } if (_agentInteraction.State == AgentInteractionState.Done) { mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (mission != null) { // Update loyalty points again (the first time might return -1) LoyaltyPoints = Cache.Instance.Agent.LoyaltyPoints; Mission = mission.Name; } _agentInteraction.State = AgentInteractionState.Idle; State = QuestorState.Arm; } break; case QuestorState.Arm: if (_arm.State == ArmState.Idle) { Logging.Log("Arm: Begin"); _arm.State = ArmState.Begin; // Load right ammo based on mission _arm.AmmoToLoad.Clear(); _arm.AmmoToLoad.AddRange(_agentInteraction.AmmoToLoad); } _arm.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("Arm.State = " + _arm.State); } if (_arm.State == ArmState.Done) { _arm.State = ArmState.Idle; State = QuestorState.GotoMission; } break; case QuestorState.GotoMission: var missionDestination = _traveler.Destination as MissionBookmarkDestination; if (missionDestination == null || missionDestination.AgentId != Cache.Instance.AgentId) // We assume that this will always work "correctly" (tm) { _traveler.Destination = new MissionBookmarkDestination(Cache.Instance.GetMissionBookmark(Cache.Instance.AgentId, "Encounter")); } if (Cache.Instance.PriorityTargets.Any(pt => pt != null && pt.IsValid)) { Logging.Log("GotoMission: Priority targets found, engaging!"); _combat.ProcessState(); } _traveler.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State = " + _traveler.State); } if (_traveler.State == TravelerState.AtDestination) { State = QuestorState.ExecuteMission; // Seeing as we just warped to the mission, start the mission controller _missionController.State = MissionControllerState.Start; _combat.State = CombatState.CheckTargets; _traveler.Destination = null; } break; case QuestorState.CombatHelper: _combat.ProcessState(); _drones.ProcessState(); _salvage.ProcessState(); break; case QuestorState.ExecuteMission: watch.Reset(); watch.Start(); _combat.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Combat.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("Combat.State = " + _combat.State); } watch.Reset(); watch.Start(); _drones.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Drones.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("Drones.State = " + _drones.State); } watch.Reset(); watch.Start(); _salvage.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("Salvage.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("Salvage.State = " + _salvage.State); } watch.Reset(); watch.Start(); _missionController.ProcessState(); watch.Stop(); if (Settings.Instance.DebugPerformance) { Logging.Log("MissionController.ProcessState took " + watch.ElapsedMilliseconds + "ms"); } if (Settings.Instance.DebugStates) { Logging.Log("MissionController.State = " + _missionController.State); } // If we are out of ammo, return to base, the mission will fail to complete and the bot will reload the ship // and try the mission again if (_combat.State == CombatState.OutOfAmmo) { Logging.Log("Combat: Out of Ammo!"); State = QuestorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } if (_missionController.State == MissionControllerState.Done) { State = QuestorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } // If in error state, just go home and stop the bot if (_missionController.State == MissionControllerState.Error) { Logging.Log("MissionController: Error"); State = QuestorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } break; case QuestorState.GotoBase: var baseDestination = _traveler.Destination as StationDestination; if (baseDestination == null || baseDestination.StationId != Cache.Instance.Agent.StationId) { _traveler.Destination = new StationDestination(Cache.Instance.Agent.SolarSystemId, Cache.Instance.Agent.StationId, Cache.Instance.DirectEve.GetLocationName(Cache.Instance.Agent.StationId)); } if (Cache.Instance.PriorityTargets.Any(pt => pt != null && pt.IsValid)) { Logging.Log("GotoBase: Priority targets found, engaging!"); _combat.ProcessState(); } _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (_missionController.State == MissionControllerState.Error) { State = QuestorState.Error; } else if (_combat.State != CombatState.OutOfAmmo && mission != null && mission.State == (int)MissionState.Accepted) { State = QuestorState.CompleteMission; } else { State = QuestorState.UnloadLoot; } _traveler.Destination = null; } if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State = " + _traveler.State); } break; case QuestorState.CompleteMission: if (_agentInteraction.State == AgentInteractionState.Idle) { Logging.Log("AgentInteraction: Start Conversation [Complete Mission]"); _agentInteraction.State = AgentInteractionState.StartConversation; _agentInteraction.Purpose = AgentInteractionPurpose.CompleteMission; } _agentInteraction.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("AgentInteraction.State = " + _agentInteraction.State); } if (_agentInteraction.State == AgentInteractionState.Done) { _agentInteraction.State = AgentInteractionState.Idle; State = QuestorState.UnloadLoot; } break; case QuestorState.UnloadLoot: if (_unloadLoot.State == UnloadLootState.Idle) { Logging.Log("UnloadLoot: Begin"); _unloadLoot.State = UnloadLootState.Begin; } _unloadLoot.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("UnloadLoot.State = " + _unloadLoot.State); } if (_unloadLoot.State == UnloadLootState.Done) { Logging.Log("UnloadLoot: Done"); _unloadLoot.State = UnloadLootState.Idle; // Update total loot value LootValue += _unloadLoot.LootValue; mission = Cache.Instance.GetAgentMission(Cache.Instance.AgentId); if (_combat.State != CombatState.OutOfAmmo && Settings.Instance.AfterMissionSalvaging && Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " ").Count > 0 && (mission == null || mission.State == (int)MissionState.Offered)) { State = QuestorState.BeginAfterMissionSalvaging; } else if (_combat.State == CombatState.OutOfAmmo) { State = QuestorState.Start; } else { State = QuestorState.Idle; } } break; case QuestorState.BeginAfterMissionSalvaging: if (_arm.State == ArmState.Idle) { _arm.State = ArmState.SwitchToSalvageShip; } _arm.ProcessState(); if (_arm.State == ArmState.Done) { _arm.State = ArmState.Idle; var bookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " ").OrderBy(b => b.CreatedOn).FirstOrDefault(); if (bookmark == null) { State = QuestorState.Idle; break; } State = QuestorState.GotoSalvageBookmark; _traveler.Destination = new BookmarkDestination(bookmark); } break; case QuestorState.GotoSalvageBookmark: _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { State = QuestorState.Salvage; _traveler.Destination = null; } if (Settings.Instance.DebugStates) { Logging.Log("Traveler.State = " + _traveler.State); } break; case QuestorState.Salvage: var cargo = Cache.Instance.DirectEve.GetShipsCargo(); // Is our cargo window open? if (cargo.Window == null) { // No, command it to open Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip); break; } if (Settings.Instance.UnloadLootAtStation && cargo.IsReady && (cargo.Capacity - cargo.UsedCapacity) < 100) { Logging.Log("Salvage: We are full, goto base to unload"); State = QuestorState.GotoBase; break; } if (Cache.Instance.UnlootedContainers.Count() == 0) { Logging.Log("Salvage: Finished salvaging the room"); var bookmarks = Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " "); do { // Remove all bookmarks from address book var bookmark = bookmarks.FirstOrDefault(b => Cache.Instance.DistanceFromMe(b.X ?? 0, b.Y ?? 0, b.Z ?? 0) < 250000); if (bookmark == null) { break; } bookmark.Delete(); bookmarks.Remove(bookmark); } while (true); if (bookmarks.Count == 0) { Logging.Log("Salvage: We have salvaged all bookmarks, goto base"); State = QuestorState.GotoBase; } else { Logging.Log("Salvage: Goto the next salvage bookmark"); _traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).First()); State = QuestorState.GotoSalvageBookmark; } break; } var closestWreck = Cache.Instance.UnlootedContainers.First(); if (closestWreck.Distance > 2500 && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != closestWreck.Id)) { if (closestWreck.Distance > 150000) { closestWreck.WarpTo(); } else { closestWreck.Approach(); } } else if (closestWreck.Distance <= 2500 && Cache.Instance.Approaching != null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdStopShip); } try { // Overwrite settings, as the 'normal' settings do not apply _salvage.MaximumWreckTargets = Math.Min(Cache.Instance.DirectEve.ActiveShip.MaxLockedTargets, Cache.Instance.DirectEve.Me.MaxLockedTargets); _salvage.ReserveCargoCapacity = 80; _salvage.LootEverything = true; _salvage.ProcessState(); } finally { ApplySettings(); } break; case QuestorState.Storyline: _storyline.ProcessState(); if (_storyline.State == StorylineState.Done) { Logging.Log("Questor: We have completed the storyline, returning to base"); State = QuestorState.GotoBase; break; } break; } }
/// <summary> /// Do a mini-questor here (goto mission, execute mission, goto base) /// </summary> /// <returns></returns> public StorylineState ExecuteMission(Storyline storyline) { switch (_state) { case GenericCombatStorylineState.GotoMission: var missionDestination = _traveler.Destination as MissionBookmarkDestination; if (missionDestination == null || missionDestination.AgentId != storyline.AgentId) // We assume that this will always work "correctly" (tm) { _traveler.Destination = new MissionBookmarkDestination(Cache.Instance.GetMissionBookmark(storyline.AgentId, "Encounter")); } if (Cache.Instance.PriorityTargets.Any(pt => pt != null && pt.IsValid)) { Logging.Log("GenericCombatStoryline: Priority targets found while traveling, engaging!"); _combat.ProcessState(); } _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { _state = GenericCombatStorylineState.ExecuteMission; _traveler.Destination = null; } break; case GenericCombatStorylineState.ExecuteMission: _combat.ProcessState(); _drones.ProcessState(); _salvage.ProcessState(); _missionController.ProcessState(); // If we are out of ammo, return to base, the mission will fail to complete and the bot will reload the ship // and try the mission again if (_combat.State == CombatState.OutOfAmmo) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); Logging.Log("GenericCombatStoryline: Out of Ammo!"); return(StorylineState.ReturnToAgent); } if (_missionController.State == MissionControllerState.Done) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); return(StorylineState.ReturnToAgent); } // If in error state, just go home and stop the bot if (_missionController.State == MissionControllerState.Error) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); Logging.Log("MissionController: Error"); return(StorylineState.ReturnToAgent); } break; } return(StorylineState.ExecuteMission); }
/// <summary> /// Do a mini-questor here (goto mission, execute mission, goto base) /// </summary> /// <returns></returns> public StorylineState ExecuteMission(Storyline storyline) { switch (_state) { case GenericCombatStorylineState.WarpOutStation: var _bookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.bookmarkWarpOut ?? "").OrderByDescending(b => b.CreatedOn).Where(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId).FirstOrDefault(); var _solarid = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; if (_bookmark == null) { Logging.Log("WarpOut: No Bookmark"); if (_state == GenericCombatStorylineState.WarpOutStation) { _state = GenericCombatStorylineState.GotoMission; } } else if (_bookmark.LocationId == _solarid) { if (_traveler.Destination == null) { Logging.Log("WarpOut: Warp at " + _bookmark.Title); _traveler.Destination = new BookmarkDestination(_bookmark); Cache.Instance.DoNotBreakInvul = true; } _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { Logging.Log("WarpOut: Safe!"); Cache.Instance.DoNotBreakInvul = false; if (_state == GenericCombatStorylineState.WarpOutStation) { _state = GenericCombatStorylineState.GotoMission; } _traveler.Destination = null; } } else { Logging.Log("WarpOut: No Bookmark in System"); if (_state == GenericCombatStorylineState.WarpOutStation) { _state = GenericCombatStorylineState.GotoMission; } } break; case GenericCombatStorylineState.GotoMission: var missionDestination = _traveler.Destination as MissionBookmarkDestination; if (missionDestination == null || missionDestination.AgentId != storyline.AgentId) // We assume that this will always work "correctly" (tm) { _traveler.Destination = new MissionBookmarkDestination(Cache.Instance.GetMissionBookmark(storyline.AgentId, "Encounter")); } if (Cache.Instance.PriorityTargets.Any(pt => pt != null && pt.IsValid)) { Logging.Log("GenericCombatStoryline: Priority targets found while traveling, engaging!"); _combat.ProcessState(); } _traveler.ProcessState(); if (_traveler.State == TravelerState.AtDestination) { _state = GenericCombatStorylineState.ExecuteMission; _traveler.Destination = null; } break; case GenericCombatStorylineState.ExecuteMission: _combat.ProcessState(); _drones.ProcessState(); _salvage.ProcessState(); _missionController.ProcessState(); // If we are out of ammo, return to base, the mission will fail to complete and the bot will reload the ship // and try the mission again if (_combat.State == CombatState.OutOfAmmo) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); Logging.Log("GenericCombatStoryline: Out of Ammo!"); return(StorylineState.ReturnToAgent); } if (_missionController.State == MissionControllerState.Done) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); return(StorylineState.ReturnToAgent); } // If in error state, just go home and stop the bot if (_missionController.State == MissionControllerState.Error) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); Logging.Log("MissionController: Error"); return(StorylineState.ReturnToAgent); } break; } return(StorylineState.ExecuteMission); }
/// <summary> /// Do a mini-questor here (goto mission, execute mission, goto base) /// </summary> /// <returns></returns> public StorylineState ExecuteMission(Storyline storyline) { switch (_state) { case GenericCombatStorylineState.WarpOutStation: DirectBookmark warpOutBookMark = Cache.Instance.BookmarksByLabel(Settings.Instance.UndockBookmarkPrefix ?? "").OrderByDescending(b => b.CreatedOn).FirstOrDefault(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId); long solarid = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; if (warpOutBookMark == null) { Logging.Log("GenericCombatStoryline.WarpOut", "No Bookmark", Logging.Orange); _state = GenericCombatStorylineState.GotoMission; break; } if (warpOutBookMark.LocationId == solarid) { if (Traveler.Destination == null) { Logging.Log("GenericCombatStoryline.WarpOut", "Warp at " + warpOutBookMark.Title, Logging.White); Traveler.Destination = new BookmarkDestination(warpOutBookMark); Cache.Instance.DoNotBreakInvul = true; } Traveler.ProcessState(); if (_States.CurrentTravelerState == TravelerState.AtDestination) { Logging.Log("GenericCombatStoryline.WarpOut", "Safe!", Logging.White); Cache.Instance.DoNotBreakInvul = false; _state = GenericCombatStorylineState.GotoMission; Traveler.Destination = null; break; } break; } Logging.Log("GenericCombatStoryline.WarpOut", "No Bookmark in System", Logging.White); _state = GenericCombatStorylineState.GotoMission; break; case GenericCombatStorylineState.GotoMission: MissionBookmarkDestination missionDestination = Traveler.Destination as MissionBookmarkDestination; // // if we have no destination yet... OR if missionDestination.AgentId != storyline.CurrentStorylineAgentId // //if (missionDestination != null) Logging.Log("GenericCombatStoryline: missionDestination.AgentId [" + missionDestination.AgentId + "] " + "and storyline.CurrentStorylineAgentId [" + storyline.CurrentStorylineAgentId + "]"); //if (missionDestination == null) Logging.Log("GenericCombatStoryline: missionDestination.AgentId [ NULL ] " + "and storyline.CurrentStorylineAgentId [" + storyline.CurrentStorylineAgentId + "]"); if (missionDestination == null || missionDestination.AgentId != Cache.Instance.CurrentStorylineAgentId) // We assume that this will always work "correctly" (tm) { string nameOfBookmark = ""; if (Settings.Instance.EveServerName == "Tranquility") { nameOfBookmark = "Encounter"; } if (Settings.Instance.EveServerName == "Serenity") { nameOfBookmark = "遭遇战"; } if (nameOfBookmark == "") { nameOfBookmark = "Encounter"; } Logging.Log("GenericCombatStoryline", "Setting Destination to 1st bookmark from AgentID: [" + Cache.Instance.CurrentStorylineAgentId + "] with [" + nameOfBookmark + "] in the title", Logging.White); Traveler.Destination = new MissionBookmarkDestination(Cache.Instance.GetMissionBookmark(Cache.Instance.CurrentStorylineAgentId, nameOfBookmark)); } if (Cache.Instance.PotentialCombatTargets.Any()) { Logging.Log("GenericCombatStoryline", "Priority targets found while traveling, engaging!", Logging.White); Combat.ProcessState(); } Traveler.ProcessState(); if (_States.CurrentTravelerState == TravelerState.AtDestination) { _state = GenericCombatStorylineState.ExecuteMission; //_States.CurrentCombatState = CombatState.CheckTargets; Traveler.Destination = null; } break; case GenericCombatStorylineState.ExecuteMission: Combat.ProcessState(); Drones.ProcessState(); Salvage.ProcessState(); _combatMissionCtrl.ProcessState(); // If we are out of ammo, return to base, the mission will fail to complete and the bot will reload the ship // and try the mission again if (_States.CurrentCombatState == CombatState.OutOfAmmo) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); Logging.Log("GenericCombatStoryline", "Out of Ammo!", Logging.Orange); return(StorylineState.ReturnToAgent); } if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Done) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); return(StorylineState.ReturnToAgent); } // If in error state, just go home and stop the bot if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Error) { // Clear looted containers Cache.Instance.LootedContainers.Clear(); Logging.Log("MissionController", "Error", Logging.Red); return(StorylineState.ReturnToAgent); } break; } return(StorylineState.ExecuteMission); }
public void ProcessState() { if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < Time.Instance.QuestorPulse_milliseconds) //default: 1500ms { return; } _lastPulse = DateTime.UtcNow; if (Cache.Instance.SessionState == "Quitting") { BeginClosingQuestor(); } if (Cache.Instance.GotoBaseNow) { _States.CurrentMiningState = MiningState.GotoBase; } if ((DateTime.UtcNow.Subtract(Cache.Instance.QuestorStarted_DateTime).TotalSeconds > 10) && (DateTime.UtcNow.Subtract(Cache.Instance.QuestorStarted_DateTime).TotalSeconds < 60)) { if (Cache.Instance.QuestorJustStarted) { Cache.Instance.QuestorJustStarted = false; Cache.Instance.SessionState = "Starting Up"; // write session log Statistics.WriteSessionLogStarting(); } } _panic.ProcessState(); if (_States.CurrentPanicState == PanicState.Panic || _States.CurrentPanicState == PanicState.Panicking) { // If Panic is in panic state, questor is in panic States.CurrentCombatMissionBehaviorState :) _States.CurrentMiningState = MiningState.Panic; if (PanicStateReset) { _States.CurrentPanicState = PanicState.Normal; PanicStateReset = false; } } else if (_States.CurrentPanicState == PanicState.Resume) { // Reset panic state _States.CurrentPanicState = PanicState.Normal; _States.CurrentTravelerState = TravelerState.Idle; _States.CurrentMiningState = MiningState.GotoBelt; } if (Settings.Instance.DebugMiningBehavior) { Logging.Log("MiningBehavior", "Pre-switch", Logging.White); } switch (_States.CurrentMiningState) { case MiningState.Default: case MiningState.Idle: _States.CurrentMiningState = MiningState.Cleanup; break; case MiningState.Cleanup: if (Cache.Instance.LootAlreadyUnloaded == false) { _States.CurrentMiningState = MiningState.GotoBase; break; } Cleanup.CheckEVEStatus(); _States.CurrentMiningState = MiningState.Arm; break; case MiningState.GotoBase: DirectBookmark miningHome = Cache.Instance.BookmarksByLabel("Mining Home").FirstOrDefault(); //Cache.Instance.DirectEve.Navigation.GetDestinationPath Traveler.TravelToMiningHomeBookmark(miningHome, "Mining go to base"); if (_States.CurrentTravelerState == TravelerState.AtDestination) // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10) { if (Settings.Instance.DebugGotobase) { Logging.Log("MiningBehavior", "GotoBase: We are at destination", Logging.White); } Cache.Instance.GotoBaseNow = false; //we are there - turn off the 'forced' gotobase _States.CurrentMiningState = MiningState.UnloadLoot; Traveler.Destination = null; } break; case MiningState.UnloadLoot: // // this state should never be reached in space. if we are in space and in this state we should switch to gotobase // if (Cache.Instance.InSpace) { Logging.Log(_States.CurrentCombatMissionBehaviorState.ToString(), "We are in space, how did we get set to this state while in space? Changing state to: GotoBase", Logging.White); _States.CurrentMiningState = MiningState.GotoBase; } if (_States.CurrentUnloadLootState == UnloadLootState.Idle) { Logging.Log("MiningBehavior", "UnloadLoot: Begin", Logging.White); _States.CurrentUnloadLootState = UnloadLootState.Begin; } _unloadLoot.ProcessState(); if (_States.CurrentUnloadLootState == UnloadLootState.Done) { Cache.Instance.LootAlreadyUnloaded = true; _States.CurrentUnloadLootState = UnloadLootState.Idle; if (_States.CurrentCombatState == CombatState.OutOfAmmo) { Logging.Log("MiningBehavior.UnloadLoot", "We are out of ammo", Logging.Orange); _States.CurrentMiningState = MiningState.Idle; return; } _States.CurrentMiningState = MiningState.Idle; _States.CurrentQuestorState = QuestorState.Idle; Logging.Log("MiningBehavior.Unloadloot", "CharacterMode: [" + Settings.Instance.CharacterMode + "], AfterMissionSalvaging: [" + Settings.Instance.AfterMissionSalvaging + "], MiningState: [" + _States.CurrentMiningState + "]", Logging.White); return; } break; case MiningState.Start: Cache.Instance.OpenWrecks = false; _States.CurrentMiningState = MiningState.Arm; DirectBookmark asteroidShortcut = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault(); if (asteroidShortcut != null) { asteroidShortcut.Delete(); } break; case MiningState.Arm: // // this state should never be reached in space. if we are in space and in this state we should switch to gotobase // if (Cache.Instance.InSpace) { Logging.Log(_States.CurrentMiningState.ToString(), "We are in space, how did we get set to this state while in space? Changing state to: GotoBase", Logging.White); _States.CurrentMiningState = MiningState.GotoBase; } if (_States.CurrentArmState == ArmState.Idle) { Logging.Log("Arm", "Begin", Logging.White); _States.CurrentArmState = ArmState.Begin; // Load ammo... this "fixes" the problem I experienced with not reloading after second arm phase. The quantity was getting set to 0. Arm.AmmoToLoad.Clear(); Arm.AmmoToLoad.Add(Settings.Instance.Ammo.FirstOrDefault()); //FIXME: bad hack - this should be fixed differently / elsewhere Ammo FirstAmmoToLoad = Arm.AmmoToLoad.FirstOrDefault(); if (FirstAmmoToLoad != null && FirstAmmoToLoad.Quantity == 0) { FirstAmmoToLoad.Quantity = 333; } } Arm.ProcessState(); if (_States.CurrentArmState == ArmState.NotEnoughAmmo) { // we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime // we may be out of drones/ammo but disconnecting/reconnecting will not fix that so update the timestamp Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; Logging.Log("Arm", "Armstate.NotEnoughAmmo", Logging.Orange); _States.CurrentArmState = ArmState.Idle; _States.CurrentMiningState = MiningState.Error; } if (_States.CurrentArmState == ArmState.NotEnoughDrones) { // we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime // we may be out of drones/ammo but disconnecting/reconnecting will not fix that so update the timestamp Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; Logging.Log("Arm", "Armstate.NotEnoughDrones", Logging.Orange); _States.CurrentArmState = ArmState.Idle; _States.CurrentMiningState = MiningState.Error; } if (_States.CurrentArmState == ArmState.Done) { if (DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(45)) //do not try to leave the station until you have been docked for at least 45seconds! (this gives some overhead to load the station env + session change timer) { //we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; _States.CurrentArmState = ArmState.Idle; _States.CurrentDroneState = DroneState.WaitingForTargets; //exit the station Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); //set up a wait of 10 seconds so the undock can complete _lastPulse = DateTime.UtcNow.AddSeconds(10); _States.CurrentMiningState = MiningState.GotoBelt; } } break; case MiningState.GotoBelt: if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < Time.Instance.QuestorPulse_milliseconds * 2) { return; } if (Cache.Instance.InWarp || (!Cache.Instance.InSpace && !Cache.Instance.InStation)) { return; } // // this should goto a mining system bookmark (one of possibly many) // then goto the 1st belt. This would allow for mining in systems without stations // Logging.Log("MiningBehavior", "Setting Destination to 1st Asteroid belt.", Logging.White); DirectBookmark asteroidShortcutGTB = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault(); if (asteroidShortcutGTB != null) { if (Cache.Instance.EntityById(_currentBelt.Id).Distance < 65000) { _States.CurrentMiningState = MiningState.Mine; Traveler.Destination = null; } else { asteroidShortcutGTB.WarpTo(); _lastPulse = DateTime.UtcNow; } break; } IEnumerable <EntityCache> belts = Cache.Instance.Entities.Where(i => i.GroupId == (int)Group.AsteroidBelt && !i.Name.ToLower().Contains("ice") && !EmptyBelts.Contains(i.Id)); EntityCache belt = belts.OrderBy(x => x.Distance).FirstOrDefault(); _currentBelt = belt; //Traveler.Destination = new MissionBookmarkDestination(belt); if (belt != null) { if (belt.Distance < 35000) { _States.CurrentMiningState = MiningState.Mine; Traveler.Destination = null; } else { if (belt.WarpTo()) { _lastPulse = DateTime.UtcNow; } } break; } _States.CurrentMiningState = MiningState.GotoBase; Logging.Log("MiningBehavior", "Could not find a suitable Asteroid belt.", Logging.White); Settings.Instance.AutoStart = false; break; case MiningState.Mine: IEnumerable <EntityCache> _asteroidsOnGrid = Cache.Instance.EntitiesOnGrid.Where(i => i.Distance < (int)Distances.OnGridWithMe && i.CategoryId == (int)CategoryID.Asteroid).OrderBy(i => i.Distance); IEnumerable <EntityCache> _asteroidsInRange = _asteroidsOnGrid.Where(i => i.Distance < 65000).ToList(); EntityCache asteroid = null; if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Kernite)) { asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Kernite).OrderBy(i => i.Distance).FirstOrDefault(); } if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Plagioclase)) { asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Plagioclase).OrderBy(i => i.Distance).FirstOrDefault(); } if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Pyroxeres)) { asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Pyroxeres).OrderBy(i => i.Distance).FirstOrDefault(); } if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Scordite)) { asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Scordite).OrderBy(i => i.Distance).FirstOrDefault(); } if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Veldspar)) { asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Veldspar).OrderBy(i => i.Distance).FirstOrDefault(); } if (asteroid == null) { EmptyBelts.Add(_currentBelt.Id); DirectBookmark asteroidShortcutBM2 = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault(); if (asteroidShortcutBM2 != null) { asteroidShortcutBM2.Delete(); } Logging.Log("MiningBehavior", "Could not find a suitable Asteroid to mine in this belt.", Logging.White); _States.CurrentMiningState = MiningState.GotoBelt; break; } Logging.Log("Mining: [", "Target Rock is [" + asteroid.Name + "][" + Math.Round(asteroid.Distance / 1000, 0) + "k] ID [" + asteroid.MaskedId + "] GroupID [" + asteroid.GroupId + "]", Logging.White); _targetAsteroidID = asteroid.Id; _targetAsteroid.Approach(); _States.CurrentMiningState = MiningState.MineAsteroid; break; case MiningState.MineAsteroid: if (Cache.Instance.EntityById(_targetAsteroidID) == null) { Logging.Log("Mining: [", "Target Rock [" + Cache.Instance.MaskedID(_targetAsteroidID) + "] has been depleted. Searching for another target.", Logging.White); _States.CurrentMiningState = MiningState.Mine; return; } _targetAsteroid = Cache.Instance.EntityById(_targetAsteroidID); Combat.ProcessState(); Drones.ProcessState(); // If we are out of ammo, return to base, Arm should then grab the right ammo / crystals / drones if (_States.CurrentCombatState == CombatState.OutOfAmmo) { Logging.Log("Combat", "Out of Ammo!", Logging.Orange); _States.CurrentMiningState = MiningState.GotoBase; } //check if we're full // // we really ought to be checking for and using the OreHold if needed, not directly using the cargohold ffs! // if (Cache.Instance.CurrentShipsCargo == null) { return; } if (Cache.Instance.CurrentShipsCargo.IsValid && (Cache.Instance.CurrentShipsCargo.UsedCapacity >= Cache.Instance.CurrentShipsCargo.Capacity * .9) && Cache.Instance.CurrentShipsCargo.Capacity > 0) { if (_States.CurrentDroneState == DroneState.WaitingForTargets) { Logging.Log("Miner:MineAsteroid", "We are full, go to base to unload. Capacity is: " + Cache.Instance.CurrentShipsCargo.Capacity + ", Used: " + Cache.Instance.CurrentShipsCargo.UsedCapacity, Logging.White); _States.CurrentMiningState = MiningState.GotoBase; break; } if (_States.CurrentDroneState == DroneState.WaitingForTargets) { Logging.Log("Miner:MineAsteroid", "We are full, but drones are busy. Drone state: " + _States.CurrentDroneState.ToString(), Logging.White); } } // // do we need to make sure the rock is in targeting range? rats that damp, frigates with crap skills?, wormhole effects... // if (_targetAsteroid.Distance < 10000) { if (_targetAsteroid.Distance < 9400) { if (_asteroidBookmarkForID != _targetAsteroid.Id) { DirectBookmark asteroidShortcutBM = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault(); if (asteroidShortcutBM != null) { asteroidShortcutBM.UpdateBookmark("Asteroid Location", "Mining Shortcut"); } else { Cache.Instance.DirectEve.BookmarkCurrentLocation("Asteroid Location", "Mining Shortcut", null); } _asteroidBookmarkForID = _targetAsteroid.Id; } } if (Cache.Instance.Targeting.Contains(_targetAsteroid)) { if (Settings.Instance.DebugMiningBehavior) { Logging.Log("Miner:MineAsteroid", "Targeting asteroid.", Logging.White); } return; //wait } if (Cache.Instance.Targets.Contains(_targetAsteroid)) { if (Settings.Instance.DebugMiningBehavior) { Logging.Log("Miner:MineAsteroid", "Asteroid Targeted.", Logging.White); } //if(!_targetAsteroid.IsActiveTarget) _targetAsteroid.MakeActiveTarget(); List <ModuleCache> miningTools = Cache.Instance.Modules.Where(m => MiningToolGroupIDs.Contains(m.GroupId)).ToList(); _minerNumber = 0; foreach (ModuleCache miningTool in miningTools) { if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(miningTool.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[miningTool.ItemId].AddSeconds(3) > DateTime.UtcNow) { continue; } } _minerNumber++; // Are we on the right target? if (miningTool.IsActive) { if (miningTool.TargetId != _targetAsteroid.Id) { if (miningTool.Click()) { return; } return; } continue; } // Are we deactivating? if (miningTool.IsDeactivating) { continue; } if (miningTool.Activate(_targetAsteroid)) { //only activate one module per cycle Logging.Log("Mining", "Activating mining tool [" + _minerNumber + "] on [" + _targetAsteroid.Name + "][" + Cache.Instance.MaskedID(_targetAsteroid.Id) + "][" + Math.Round(_targetAsteroid.Distance / 1000, 0) + "k away]", Logging.Teal); return; } continue; } return; } //mine //asteroid is not targeted if (Settings.Instance.DebugMiningBehavior) { Logging.Log("Miner:MineAsteroid", "Asteroid not yet targeted.", Logging.White); } if (DateTime.UtcNow < Cache.Instance.NextTargetAction) //if we just did something wait a fraction of a second { return; } if (Cache.Instance.MaxLockedTargets == 0) { if (!_isJammed) { Logging.Log("Mining", "We are jammed and can't target anything", Logging.Orange); } _isJammed = true; return; } if (_isJammed) { // Clear targeting list as it does not apply Cache.Instance.TargetingIDs.Clear(); Logging.Log("Mining", "We are no longer jammed, ReTargeting", Logging.Teal); } _isJammed = false; _targetAsteroid.LockTarget("Mining.targetAsteroid"); Cache.Instance.NextTargetAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.TargetDelay_milliseconds); return; } //check 10K distance // // not inside 10k // if (Settings.Instance.DebugMiningBehavior) { Logging.Log("Miner:MineAsteroid", "Debug: Distance to Target [" + Math.Round(_targetAsteroid.Distance / 1000, 2) + "] > 10K.] Id [" + _targetAsteroid.Id + "] TargetingMe [" + Combat.TargetingMe.Count() + "]", Logging.White); } //this isn't working because Cache.Instance.Approaching.TargetValue always seems to return null. This will negatively impact combat since it won't orbit. Might want to check CombatState instead. if (Cache.Instance.IsApproaching(_targetAsteroidID) && !Cache.Instance.TargetedBy.Any()) { // // this will only approach every 15 sec // _targetAsteroid.Approach(); } break; } //ends MiningState switch } //ends ProcessState method
public void ProcessState() { // Invalid settings, quit while we're ahead if (!ValidSettings) { if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.ValidateSettings_seconds) //default is a 15 second interval { Logging.Log("CombatHelperBehavior", "Invalid Settings: Running ValidateCombatMissionSettings();", Logging.Orange); ValidateCombatMissionSettings(); LastAction = DateTime.UtcNow; } return; } if (Settings.Instance.FinishWhenNotSafe && (_States.CurrentCombatHelperBehaviorState != CombatHelperBehaviorState.GotoNearestStation /*|| State!=QuestorState.GotoBase*/)) { //need to remove spam if (Cache.Instance.InSpace && !Cache.Instance.LocalSafe(Settings.Instance.LocalBadStandingPilotsToTolerate, Settings.Instance.LocalBadStandingLevelToConsiderBad)) { EntityCache station = null; if (Cache.Instance.Stations != null && Cache.Instance.Stations.Any()) { station = Cache.Instance.Stations.OrderBy(x => x.Distance).FirstOrDefault(); } if (station != null) { Logging.Log("Local not safe", "Station found. Going to nearest station", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoNearestStation; } else { Logging.Log("Local not safe", "Station not found. Going back to base", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase; } Cache.Instance.StopBot = true; } } if (Cache.Instance.SessionState == "Quitting") { BeginClosingQuestor(); } if (Cache.Instance.GotoBaseNow) { _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase; } if ((DateTime.UtcNow.Subtract(Cache.Instance.QuestorStarted_DateTime).TotalSeconds > 10) && (DateTime.UtcNow.Subtract(Cache.Instance.QuestorStarted_DateTime).TotalSeconds < 60)) { if (Cache.Instance.QuestorJustStarted) { Cache.Instance.QuestorJustStarted = false; Cache.Instance.SessionState = "Starting Up"; // write session log Statistics.WriteSessionLogStarting(); } } // // Panic always runs, not just in space // DebugPerformanceClearandStartTimer(); _panic.ProcessState(); DebugPerformanceStopandDisplayTimer("Panic.ProcessState"); if (_States.CurrentPanicState == PanicState.Panic || _States.CurrentPanicState == PanicState.Panicking) { // If Panic is in panic state, questor is in panic States.CurrentCombatHelperBehaviorState :) _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Panic; DebugCombatHelperBehaviorStates(); if (PanicStateReset) { _States.CurrentPanicState = PanicState.Normal; PanicStateReset = false; } } else if (_States.CurrentPanicState == PanicState.Resume) { // Reset panic state _States.CurrentPanicState = PanicState.Normal; // Sit Idle and wait for orders. _States.CurrentTravelerState = TravelerState.Idle; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; DebugCombatHelperBehaviorStates(); } DebugPanicstates(); // // the slave processstate is meant to override any CombatHelper behavior (it is after all meant to help the master kill things) // //_slave.ProcessState(); // // done with slave process state // //Logging.Log("test"); switch (_States.CurrentCombatHelperBehaviorState) { case CombatHelperBehaviorState.Idle: if (Cache.Instance.StopBot) { // // this is used by the 'local is safe' routines - standings checks - at the moment is stops questor for the rest of the session. // if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("CombatHelperBehavior", "DebugIdle: StopBot [" + Cache.Instance.StopBot + "]", Logging.White); } return; } if (Cache.Instance.InSpace) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("CombatHelperBehavior", "DebugIdle: InSpace [" + Cache.Instance.InSpace + "]", Logging.White); } // Questor does not handle in space starts very well, head back to base to try again Logging.Log("CombatHelperBehavior", "Started questor while in space, heading back to base in 15 seconds", Logging.White); LastAction = DateTime.UtcNow; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.DelayedGotoBase; break; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(10)) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("CombatHelperBehavior", "DebugIdle: Cache.Instance.LastInSpace [" + Cache.Instance.LastInSpace.Subtract(DateTime.UtcNow).TotalSeconds + "] sec ago, waiting until we have been docked for 10+ seconds", Logging.White); } return; } _States.CurrentArmState = ArmState.Idle; _States.CurrentDroneState = DroneState.Idle; _States.CurrentSalvageState = SalvageState.Idle; _States.CurrentTravelerState = TravelerState.Idle; _States.CurrentUnloadLootState = UnloadLootState.Idle; _States.CurrentTravelerState = TravelerState.Idle; Logging.Log("CombatHelperBehavior", "Started questor in Combat Helper mode", Logging.White); LastAction = DateTime.UtcNow; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper; break; case CombatHelperBehaviorState.DelayedGotoBase: if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.DelayedGotoBase_seconds) { break; } Logging.Log("CombatHelperBehavior", "Heading back to base", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase; break; case CombatHelperBehaviorState.Arm: // // only used when someone manually selects the arm state. // if (_States.CurrentArmState == ArmState.Idle) { Logging.Log("Arm", "Begin", Logging.White); _States.CurrentArmState = ArmState.Begin; // Load right ammo based on mission Arm.AmmoToLoad.Clear(); Arm.LoadSpecificAmmo(new[] { Cache.Instance.MissionDamageType }); } Arm.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("Arm.State", "is" + _States.CurrentArmState, Logging.White); } if (_States.CurrentArmState == ArmState.NotEnoughAmmo) { // we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime // we may be out of drones/ammo but disconnecting/reconnecting will not fix that so update the timestamp Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; Logging.Log("Arm", "Armstate.NotEnoughAmmo", Logging.Orange); _States.CurrentArmState = ArmState.Idle; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error; } if (_States.CurrentArmState == ArmState.NotEnoughDrones) { // we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime // we may be out of drones/ammo but disconnecting/reconnecting will not fix that so update the timestamp Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; Logging.Log("Arm", "Armstate.NotEnoughDrones", Logging.Orange); _States.CurrentArmState = ArmState.Idle; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error; } if (_States.CurrentArmState == ArmState.Done) { //we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; _States.CurrentArmState = ArmState.Idle; _States.CurrentDroneState = DroneState.WaitingForTargets; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; } break; case CombatHelperBehaviorState.CombatHelper: if (Cache.Instance.InSpace) { DebugPerformanceClearandStartTimer(); Combat.ProcessState(); DebugPerformanceStopandDisplayTimer("Combat.ProcessState"); if (Settings.Instance.DebugStates) { Logging.Log("Combat.State is", _States.CurrentCombatState.ToString(), Logging.White); } DebugPerformanceClearandStartTimer(); Drones.ProcessState(); DebugPerformanceStopandDisplayTimer("Drones.ProcessState"); if (Settings.Instance.DebugStates) { Logging.Log("Drones.State is", _States.CurrentDroneState.ToString(), Logging.White); } DebugPerformanceClearandStartTimer(); Salvage.ProcessState(); DebugPerformanceStopandDisplayTimer("Salvage.ProcessState"); if (Settings.Instance.DebugStates) { Logging.Log("Salvage.State is", _States.CurrentSalvageState.ToString(), Logging.White); } // If we are out of ammo, return to base (do we want to do this with combat helper?!) if (_States.CurrentCombatState == CombatState.OutOfAmmo) { Logging.Log("Combat", "Out of Ammo!", Logging.Orange); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase; // Clear looted containers Cache.Instance.LootedContainers.Clear(); } } break; case CombatHelperBehaviorState.Salvage: if (!Cache.Instance.InSpace) { return; } if (Cache.Instance.CurrentShipsCargo == null) { return; } Cache.Instance.SalvageAll = true; if (Settings.Instance.SpeedTank || !Settings.Instance.SpeedTank) { Cache.Instance.OpenWrecks = true; } if (Settings.Instance.UnloadLootAtStation && Cache.Instance.CurrentShipsCargo.IsValid && (Cache.Instance.CurrentShipsCargo.Capacity - Cache.Instance.CurrentShipsCargo.UsedCapacity) < 100) { Logging.Log("CombatMissionsBehavior.Salvage", "We are full, go to base to unload", Logging.White); _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.GotoBase; break; } if (!Cache.Instance.UnlootedContainers.Any()) { return; } //we __cannot ever__ approach in salvage.cs so this section _is_ needed. Salvage.MoveIntoRangeOfWrecks(); try { // Overwrite settings, as the 'normal' settings do not apply Salvage.MaximumWreckTargets = Cache.Instance.MaxLockedTargets; Salvage.ReserveCargoCapacity = 80; Salvage.LootEverything = true; Salvage.ProcessState(); //Logging.Log("number of max cache ship: " + Cache.Instance.ActiveShip.MaxLockedTargets); //Logging.Log("number of max cache me: " + Cache.Instance.DirectEve.Me.MaxLockedTargets); //Logging.Log("number of max math.min: " + _salvage.MaximumWreckTargets); } finally { ApplyCombatHelperSettings(); } break; case CombatHelperBehaviorState.GotoBase: if (Settings.Instance.DebugGotobase) { Logging.Log("CombatHelperBehavior", "GotoBase: AvoidBumpingThings()", Logging.White); } if (Settings.Instance.AvoidBumpingThings) { NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjects.FirstOrDefault(), "CombatHelperBehaviorState.GotoBase"); } if (Settings.Instance.DebugGotobase) { Logging.Log("CombatHelperBehavior", "GotoBase: Traveler.TravelHome()", Logging.White); } Traveler.TravelHome("CombatHelperBehavior.TravelHome"); if (_States.CurrentTravelerState == TravelerState.AtDestination && DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(5)) // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10) { if (Settings.Instance.DebugGotobase) { Logging.Log("CombatHelperBehavior", "GotoBase: We are at destination", Logging.White); } Cache.Instance.GotoBaseNow = false; //we are there - turn off the 'forced' gotobase Cache.Instance.Mission = Cache.Instance.GetAgentMission(AgentID, false); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.UnloadLoot; Traveler.Destination = null; } break; case CombatHelperBehaviorState.UnloadLoot: if (_States.CurrentUnloadLootState == UnloadLootState.Idle) { Logging.Log("CombatHelperBehavior", "UnloadLoot: Begin", Logging.White); _States.CurrentUnloadLootState = UnloadLootState.Begin; } _unloadLoot.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("CombatHelperBehavior", "UnloadLoot.State is " + _States.CurrentUnloadLootState, Logging.White); } if (_States.CurrentUnloadLootState == UnloadLootState.Done) { Cache.Instance.LootAlreadyUnloaded = true; _States.CurrentUnloadLootState = UnloadLootState.Idle; Cache.Instance.Mission = Cache.Instance.GetAgentMission(AgentID, false); if (_States.CurrentCombatState == CombatState.OutOfAmmo) // on mission { Logging.Log("CombatHelperBehavior.UnloadLoot", "We are out of ammo", Logging.Orange); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Arm; return; } _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Arm; Logging.Log("CombatHelperBehavior.Unloadloot", "CharacterMode: [" + Settings.Instance.CharacterMode + "], AfterMissionSalvaging: [" + Settings.Instance.AfterMissionSalvaging + "], CombatHelperBehaviorState: [" + _States.CurrentCombatHelperBehaviorState + "]", Logging.White); Statistics.Instance.FinishedMission = DateTime.UtcNow; return; } break; case CombatHelperBehaviorState.WarpOutStation: DirectBookmark warpOutBookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.UndockBookmarkPrefix ?? "").OrderByDescending(b => b.CreatedOn).FirstOrDefault(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId); //DirectBookmark _bookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.bookmarkWarpOut + "-" + Cache.Instance.CurrentAgent ?? "").OrderBy(b => b.CreatedOn).FirstOrDefault(); long solarid = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; if (warpOutBookmark == null) { Logging.Log("BackgroundBehavior.WarpOut", "No Bookmark", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper; } else if (warpOutBookmark.LocationId == solarid) { if (Traveler.Destination == null) { Logging.Log("BackgroundBehavior.WarpOut", "Warp at " + warpOutBookmark.Title, Logging.White); Traveler.Destination = new BookmarkDestination(warpOutBookmark); Cache.Instance.DoNotBreakInvul = true; } Traveler.ProcessState(); if (_States.CurrentTravelerState == TravelerState.AtDestination) { Logging.Log("BackgroundBehavior.WarpOut", "Safe!", Logging.White); Cache.Instance.DoNotBreakInvul = false; _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper; Traveler.Destination = null; } } else { Logging.Log("BackgroundBehavior.WarpOut", "No Bookmark in System", Logging.Orange); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper; } break; case CombatHelperBehaviorState.Traveler: if (Settings.Instance.SpeedTank) { Cache.Instance.OpenWrecks = false; } List <int> destination = Cache.Instance.DirectEve.Navigation.GetDestinationPath(); if (destination == null || destination.Count == 0) { // happens if autopilot is not set and this QuestorState is chosen manually // this also happens when we get to destination (!?) Logging.Log("CombatHelperBehavior.Traveler", "No destination?", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error; } else if (destination.Count == 1 && destination.FirstOrDefault() == 0) { destination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; } if (destination != null && (Traveler.Destination == null || Traveler.Destination.SolarSystemId != destination.Last())) { IEnumerable <DirectBookmark> bookmarks = Cache.Instance.AllBookmarks.Where(b => b.LocationId == destination.Last()).ToList(); if (bookmarks.FirstOrDefault() != null && bookmarks.Any()) { Traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault()); } else { Logging.Log("CombatHelperBehavior.Traveler", "Destination: [" + Cache.Instance.DirectEve.Navigation.GetLocation(destination.Last()).Name + "]", Logging.White); Traveler.Destination = new SolarSystemDestination(destination.Last()); } } else { Traveler.ProcessState(); //we also assume you are connected during a manual set of questor into travel mode (safe assumption considering someone is at the kb) Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; if (_States.CurrentTravelerState == TravelerState.AtDestination) { if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Error) { Logging.Log("CombatHelperBehavior.Traveler", "an error has occurred", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error; } else if (Cache.Instance.InSpace) { Logging.Log("CombatHelperBehavior.Traveler", "Arrived at destination (in space, Questor stopped)", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error; } else { Logging.Log("CombatHelperBehavior.Traveler", "Arrived at destination", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; return; } } } break; case CombatHelperBehaviorState.GotoNearestStation: if (!Cache.Instance.InSpace || Cache.Instance.InWarp) { return; } EntityCache station = null; if (Cache.Instance.Stations != null && Cache.Instance.Stations.Any()) { station = Cache.Instance.Stations.OrderBy(x => x.Distance).FirstOrDefault(); } if (station != null) { if (station.Distance > (int)Distances.WarptoDistance) { if (station.WarpTo()) { Logging.Log("CombatHelperBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; } } else { if (station.Distance < 1900) { if (station.Dock()) { Logging.Log("CombatHelperBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); } } else { if (Cache.Instance.NextApproachAction < DateTime.UtcNow && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != station.Id)) { Logging.Log("CombatHelperBehavior.GotoNearestStation", "Approaching [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); station.Approach(); } } } } else { _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error; //should we goto idle here? } break; case CombatHelperBehaviorState.LogCombatTargets: //combat targets //List<EntityCache> combatentitiesInList = Cache.Instance.Entities.Where(t => t.IsNpc && !t.IsBadIdea && t.CategoryId == (int)CategoryID.Entity && !t.IsContainer && t.Distance < Cache.Instance.MaxRange && !Cache.Instance.IgnoreTargets.Contains(t.Name.Trim())).ToList(); List <EntityCache> combatentitiesInList = Cache.Instance.EntitiesOnGrid.Where(t => t.IsNpc && !t.IsBadIdea && t.CategoryId == (int)CategoryID.Entity && !t.IsContainer).ToList(); Statistics.EntityStatistics(combatentitiesInList); Cache.Instance.Paused = true; break; case CombatHelperBehaviorState.LogDroneTargets: //drone targets List <EntityCache> droneentitiesInList = Cache.Instance.EntitiesOnGrid.Where(e => e.IsNpc && !e.IsBadIdea && e.CategoryId == (int)CategoryID.Entity && !e.IsContainer && !e.IsSentry && !e.IsLargeCollidable).ToList(); Statistics.EntityStatistics(droneentitiesInList); Cache.Instance.Paused = true; break; case CombatHelperBehaviorState.LogStationEntities: //stations List <EntityCache> stationsInList = Cache.Instance.Entities.Where(e => !e.IsSentry && e.GroupId == (int)Group.Station).ToList(); Statistics.EntityStatistics(stationsInList); Cache.Instance.Paused = true; break; case CombatHelperBehaviorState.LogStargateEntities: //stargates List <EntityCache> stargatesInList = Cache.Instance.Entities.Where(e => !e.IsSentry && e.GroupId == (int)Group.Stargate).ToList(); Statistics.EntityStatistics(stargatesInList); Cache.Instance.Paused = true; break; case CombatHelperBehaviorState.LogAsteroidBelts: //Asteroid Belts List <EntityCache> asteroidbeltsInList = Cache.Instance.Entities.Where(e => !e.IsSentry && e.GroupId == (int)Group.AsteroidBelt).ToList(); Statistics.EntityStatistics(asteroidbeltsInList); Cache.Instance.Paused = true; break; case CombatHelperBehaviorState.Default: _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; break; } }
public static void TravelToHomeBookmark(DirectBookmark myHomeBookmark, string module) { // // defending yourself is more important that the traveling part... so it comes first. // if (Cache.Instance.InSpace && Settings.Instance.DefendWhileTraveling) { if (!Cache.Instance.ActiveShip.Entity.IsCloaked || (Cache.Instance.LastSessionChange.AddSeconds(60) > DateTime.UtcNow)) { if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: _combat.ProcessState()", Logging.White); } Combat.ProcessState(); if (!Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: we are not scrambled - pulling drones.", Logging.White); } Cache.Instance.IsMissionPocketDone = true; //tells drones.cs that we can pull drones //Logging.Log("CombatmissionBehavior","TravelToAgentStation: not pointed",Logging.White); } else if (Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { Cache.Instance.IsMissionPocketDone = false; if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: we are scrambled", Logging.Teal); } Drones.ProcessState(); return; } } } if (Settings.Instance.SpeedTank) { Cache.Instance.OpenWrecks = false; } /* * if (Settings.Instance.setEveClientDestinationWhenTraveling) //sets destination to Questors destination, so they match... (defaults to false, needs testing again and probably needs to be exposed as a setting) * { * if (DateTime.UtcNow > _nextGetDestinationPath || EVENavdestination == null) * { * if (Settings.Instance.DebugGotobase) Logging.Log(module, "TravelToAgentsStation: EVENavdestination = Cache.Instance.DirectEve.Navigation.GetDestinationPath();", Logging.White); * _nextGetDestinationPath = DateTime.UtcNow.AddSeconds(20); * _nextSetEVENavDestination = DateTime.UtcNow.AddSeconds(4); * EVENavdestination = Cache.Instance.DirectEve.Navigation.GetDestinationPath(); * if (Settings.Instance.DebugGotobase) if (EVENavdestination != null) Logging.Log(module, "TravelToAgentsStation: Cache.Instance.DirectEve.Navigation.GetLocation(EVENavdestination.Last()).LocationId [" + Cache.Instance.DirectEve.Navigation.GetLocation(EVENavdestination.Last()).LocationId + "]", Logging.White); * return; * } * * if (Cache.Instance.DirectEve.Navigation.GetLocation(EVENavdestination.Last()).LocationId != Cache.Instance.AgentSolarSystemID) * { * //Logging.Log("CombatMissionsBehavior", "TravelToAgentsStation: Cache.Instance.DirectEve.Navigation.GetLocation(EVENavdestination.Last()).LocationId [" + Cache.Instance.DirectEve.Navigation.GetLocation(EVENavdestination.Last()).LocationId + "]", Logging.White); * //Logging.Log("CombatMissionsBehavior", "TravelToAgentsStation: EVENavdestination.LastOrDefault() [" + EVENavdestination.LastOrDefault() + "]", Logging.White); * //Logging.Log("CombatMissionsBehavior", "TravelToAgentsStation: Cache.Instance.AgentSolarSystemID [" + Cache.Instance.AgentSolarSystemID + "]", Logging.White); * if (DateTime.UtcNow > _nextSetEVENavDestination) * { * if (Settings.Instance.DebugGotobase) Logging.Log(module, "TravelToAgentsStation: Cache.Instance.DirectEve.Navigation.SetDestination(Cache.Instance.AgentStationId);", Logging.White); * _nextSetEVENavDestination = DateTime.UtcNow.AddSeconds(7); * Cache.Instance.DirectEve.Navigation.SetDestination(Cache.Instance.AgentStationID); * Logging.Log(module, "Setting Destination to [" + Cache.Instance.AgentStationName + "'s] Station", Logging.White); * return; * } * } * else if (EVENavdestination != null || EVENavdestination.Count != 0) * { * if (EVENavdestination.Count == 1 && EVENavdestination.FirstOrDefault() == 0) * EVENavdestination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; * } * } */ if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: Cache.Instance.AgentStationId [" + Cache.Instance.AgentStationID + "]", Logging.White); } if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: Cache.Instance.AgentSolarSystemId [" + Cache.Instance.AgentSolarSystemID + "]", Logging.White); } if (_destination == null || _destination.SolarSystemId != Cache.Instance.AgentSolarSystemID) { Logging.Log(module, "Destination: [" + Cache.Instance.AgentStationName + "]", Logging.White); _destination = new StationDestination(Cache.Instance.AgentSolarSystemID, Cache.Instance.AgentStationID, Cache.Instance.AgentStationName); _States.CurrentTravelerState = TravelerState.Idle; return; } else { if (Settings.Instance.DebugGotobase) { if (Traveler.Destination != null) { Logging.Log("CombatMissionsBehavior", "TravelToAgentsStation: Traveler.Destination.SolarSystemId [" + Traveler.Destination.SolarSystemId + "]", Logging.White); } } Traveler.ProcessState(); //we also assume you are connected during a manual set of questor into travel mode (safe assumption considering someone is at the kb) Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; if (_States.CurrentTravelerState == TravelerState.AtDestination) { if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Error) { Logging.Log(module, "an error has occurred", Logging.White); if (_States.CurrentCombatMissionBehaviorState == CombatMissionsBehaviorState.Traveler) { _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.Error; } return; } if (Cache.Instance.InSpace) { Logging.Log(module, "Arrived at destination (in space, Questor stopped)", Logging.White); Cache.Instance.Paused = true; return; } Logging.Log(module, "Arrived at destination", Logging.White); if (_States.CurrentCombatMissionBehaviorState == CombatMissionsBehaviorState.Traveler) { _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.Idle; } if (_States.CurrentDedicatedBookmarkSalvagerBehaviorState == DedicatedBookmarkSalvagerBehaviorState.Traveler) { _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Idle; } if (_States.CurrentCombatHelperBehaviorState == CombatHelperBehaviorState.Traveler) { _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; } return; } } return; }
public static void TravelToAgentsStation(string module) { // // defending yourself is more important that the traveling part... so it comes first. // if (Cache.Instance.InSpace && Settings.Instance.DefendWhileTraveling) { if (!Cache.Instance.ActiveShip.Entity.IsCloaked || (Cache.Instance.LastSessionChange.AddSeconds(60) > DateTime.UtcNow)) { if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: _combat.ProcessState()", Logging.White); } try { Combat.ProcessState(); } catch (Exception exception) { Logging.Log("Travel.TravelToAgentsStation", "Exception [" + exception + "]", Logging.Debug); } if (!Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: we are not scrambled - pulling drones.", Logging.White); } Cache.Instance.IsMissionPocketDone = true; //tells drones.cs that we can pull drones //Logging.Log("CombatmissionBehavior","TravelToAgentStation: not pointed",Logging.White); } else if (Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { Cache.Instance.IsMissionPocketDone = false; if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: we are scrambled", Logging.Teal); } Drones.ProcessState(); return; } } } if (Settings.Instance.SpeedTank) { Cache.Instance.OpenWrecks = false; } if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: Cache.Instance.AgentStationId [" + Cache.Instance.AgentStationID + "]", Logging.White); } if (Settings.Instance.DebugGotobase) { Logging.Log(module, "TravelToAgentsStation: Cache.Instance.AgentSolarSystemId [" + Cache.Instance.AgentSolarSystemID + "]", Logging.White); } if (_destination == null || _destination.SolarSystemId != Cache.Instance.AgentSolarSystemID) { Logging.Log(module, "Destination: [" + Cache.Instance.AgentStationName + "]", Logging.White); _destination = new StationDestination(Cache.Instance.AgentSolarSystemID, Cache.Instance.AgentStationID, Cache.Instance.AgentStationName); _States.CurrentTravelerState = TravelerState.Idle; return; } else { if (Settings.Instance.DebugGotobase) { if (Traveler.Destination != null) { Logging.Log("CombatMissionsBehavior", "TravelToAgentsStation: Traveler.Destination.SolarSystemId [" + Traveler.Destination.SolarSystemId + "]", Logging.White); } } Traveler.ProcessState(); //we also assume you are connected during a manual set of questor into travel mode (safe assumption considering someone is at the kb) Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; if (_States.CurrentTravelerState == TravelerState.AtDestination) { if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Error) { Logging.Log(module, "an error has occurred", Logging.White); if (_States.CurrentCombatMissionBehaviorState == CombatMissionsBehaviorState.Traveler) { _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.Error; } return; } if (Cache.Instance.InSpace) { Logging.Log(module, "Arrived at destination (in space, Questor stopped)", Logging.White); Cache.Instance.Paused = true; return; } if (Settings.Instance.DebugTraveler) { Logging.Log(module, "Arrived at destination", Logging.White); } if (_States.CurrentCombatMissionBehaviorState == CombatMissionsBehaviorState.Traveler) { _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.Idle; _lastPulse = DateTime.UtcNow; return; } if (_States.CurrentDedicatedBookmarkSalvagerBehaviorState == DedicatedBookmarkSalvagerBehaviorState.Traveler) { _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Idle; _lastPulse = DateTime.UtcNow; return; } if (_States.CurrentCombatHelperBehaviorState == CombatHelperBehaviorState.Traveler) { _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle; _lastPulse = DateTime.UtcNow; return; } return; } } return; }