//this needs to accept a distance parameter.... public static void NavigateToObject(EntityCache target, string module) { if (Settings.Instance.SpeedTank) { //this should be only executed when no specific actions if (DateTime.Now > Cache.Instance.NextOrbit) { if (target.Distance + (int)Cache.Instance.OrbitDistance < Cache.Instance.MaxRange) { Logging.Log(module, "StartOrbiting: Target in range", Logging.teal); if (!Cache.Instance.IsApproachingOrOrbiting) { Logging.Log("CombatMissionCtrl.NavigateToObject", "We are not approaching nor orbiting", Logging.teal); const bool orbitStructure = true; var structure = Cache.Instance.Entities.Where(i => i.GroupId == (int)Group.LargeCollidableStructure || i.Name.Contains("Gate") || i.Name.Contains("Beacon")).OrderBy(t => t.Distance).OrderBy(t => t.Distance).FirstOrDefault(); if (orbitStructure && structure != null) { structure.Orbit((int)Cache.Instance.OrbitDistance); Logging.Log(module, "Initiating Orbit [" + structure.Name + "][ID: " + structure.Id + "]", Logging.teal); } else { target.Orbit(Cache.Instance.OrbitDistance); Logging.Log(module, "Initiating Orbit [" + target.Name + "][ID: " + target.Id + "]", Logging.teal); } return; } } else { Logging.Log(module, "Possible out of range. ignoring orbit around structure", Logging.teal); target.Orbit(Cache.Instance.OrbitDistance); Logging.Log(module, "Initiating Orbit [" + target.Name + "][ID: " + target.Id + "]", Logging.teal); return; } } } else //if we aren't speed tanking then check optimalrange setting, if that isn't set use the less of targeting range and weapons range to dictate engagement range { if (DateTime.Now > Cache.Instance.NextApproachAction) { //if optimalrange is set - use it to determine engagement range // // this assumes that both optimal range and missile boats both want to be within 5k of the object they asked us to navigate to // if (target.Distance > Cache.Instance.MaxRange && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id)) { target.Approach((int)(Distance.SafeDistancefromStructure)); Logging.Log(module, "Using SafeDistanceFromStructure: Approaching target [" + target.Name + "][ID: " + target.Id + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.teal); } return; } } }
public static void NavigateIntoRange(EntityCache target, string module) { if (Cache.Instance.InWarp || Cache.Instance.InStation) return; if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange Started", Logging.white); if (Cache.Instance.OrbitDistance != Settings.Instance.OrbitDistance) { if (Cache.Instance.OrbitDistance == 0) { Cache.Instance.OrbitDistance = Settings.Instance.OrbitDistance; Logging.Log("CombatMissionCtrl", "Using default orbit distance: " + Cache.Instance.OrbitDistance + " (as the custom one was 0)", Logging.teal); } //else // Logging.Log("CombatMissionCtrl", "Using custom orbit distance: " + Cache.Instance.OrbitDistance, Logging.teal); } //if (Cache.Instance.OrbitDistance != 0) // Logging.Log("CombatMissionCtrl", "Orbit Distance is set to: " + (Cache.Instance.OrbitDistance / 1000).ToString(CultureInfo.InvariantCulture) + "k", Logging.teal); NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjectsandGates.FirstOrDefault(), "NavigateOnGrid: NavigateIntoRange"); if (Settings.Instance.SpeedTank) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: speedtank: orbitdistance is [" + Cache.Instance.OrbitDistance + "]", Logging.white); OrbitGateorTarget(target, module); } else //if we aren't speed tanking then check optimalrange setting, if that isn't set use the less of targeting range and weapons range to dictate engagement range { if (DateTime.Now > Cache.Instance.NextApproachAction) { //if optimalrange is set - use it to determine engagement range if (Settings.Instance.OptimalRange != 0) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: OptimalRange [ " + Settings.Instance.OptimalRange + "] Current Distance to [" + target.Name + "] is [" + target.Distance + "]", Logging.white); if (target.Distance > Settings.Instance.OptimalRange + (int)Distance.OptimalRangeCushion && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id)) { if (target.IsNPCFrigate) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + target.Distance + "]", Logging.white); OrbitGateorTarget(target, module); return; } target.Approach(Settings.Instance.OptimalRange); Logging.Log(module, "Using Optimal Range: Approaching target [" + target.Name + "][ID: " + target.Id + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.teal); } //I think when approach distance will be reached ship will be stopped so this is not needed if (target.Distance <= Settings.Instance.OptimalRange && Cache.Instance.Approaching != null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdStopShip); Cache.Instance.Approaching = null; Logging.Log(module, "Using Optimal Range: Stop ship, target at [" + Math.Round(target.Distance / 1000, 0) + "k away] is inside optimal", Logging.teal); } } //if optimalrange is not set use MaxRange (shorter of weapons range and targeting range) else { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: using MaxRange [" + Cache.Instance.MaxRange + "] target is [" + target.Name + "][" + target.Distance + "]", Logging.white); if (target.Distance > Cache.Instance.MaxRange && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id)) { if (target.IsNPCFrigate) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + target.Distance + "]", Logging.white); OrbitGateorTarget(target, module); return; } target.Approach((int)(Cache.Instance.WeaponRange * 0.8d)); Logging.Log(module, "Using Weapons Range * 0.8d [" + Math.Round(Cache.Instance.WeaponRange * 0.8d/1000,0) + " k]: Approaching target [" + target.Name + "][ID: " + target.Id + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.teal); } //I think when approach distance will be reached ship will be stopped so this is not needed if (target.Distance <= Cache.Instance.MaxRange && Cache.Instance.Approaching != null) { if (target.IsNPCFrigate) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + target.Distance + "]", Logging.white); OrbitGateorTarget(target, module); return; } Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdStopShip); Cache.Instance.Approaching = null; Logging.Log(module, "Using Weapons Range: Stop ship, target is in orbit range", Logging.teal); } } return; } } }
public void ProcessState() { //Logging.Log("DebugHangarsBehavior","ProcessState - every tick",Logging.Teal); if (Cache.Instance.SessionState == "Quitting") { BeginClosingQuestor(); } if (Cache.Instance.GotoBaseNow) { _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.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.CurrentDebugHangarBehaviorState :) _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Panic; DebugHangarsBehaviorStates(); 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.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Idle; DebugHangarsBehaviorStates(); } DebugPanicstates(); //Logging.Log("test"); switch (_States.CurrentDebugHangarBehaviorState) { case DebugHangarsBehaviorState.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("DebugHangarsBehavior", "DebugIdle: StopBot [" + Cache.Instance.StopBot + "]", Logging.White); } return; } if (Cache.Instance.InSpace) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("DebugHangarsBehavior", "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("DebugHangarsBehavior", "Started questor while in space, heading back to base in 15 seconds", Logging.White); LastAction = DateTime.UtcNow; _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.DelayedGotoBase; break; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(10)) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("DebugHangarsBehavior", "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; LastAction = DateTime.UtcNow; break; case DebugHangarsBehaviorState.DelayedGotoBase: if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.DelayedGotoBase_seconds) { break; } Logging.Log("DebugHangarsBehavior", "Heading back to base", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.GotoBase; break; case DebugHangarsBehaviorState.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.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.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.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.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.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Idle; } break; case DebugHangarsBehaviorState.Salvage: if (!Cache.Instance.InSpace) { return; } Cache.Instance.SalvageAll = true; Cache.Instance.OpenWrecks = true; if (Cache.Instance.CurrentShipsCargo == null) { return; } if (Settings.Instance.UnloadLootAtStation && Cache.Instance.CurrentShipsCargo.Window.IsReady && (Cache.Instance.CurrentShipsCargo.Capacity - Cache.Instance.CurrentShipsCargo.UsedCapacity) < 100) { Logging.Log("CombatMissionsBehavior.Salvage", "We are full, go to base to unload", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.GotoBase; break; } if (!Cache.Instance.UnlootedContainers.Any()) { break; } //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 { ApplyDebugSettings(); } break; case DebugHangarsBehaviorState.GotoBase: if (Settings.Instance.DebugGotobase) { Logging.Log("DebugHangarsBehavior", "GotoBase: AvoidBumpingThings()", Logging.White); } AvoidBumpingThings(); if (Settings.Instance.DebugGotobase) { Logging.Log("DebugHangarsBehavior", "GotoBase: TravelToAgentsStation()", Logging.White); } TravelToAgentsStation(); if (_States.CurrentTravelerState == TravelerState.AtDestination) // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10) { if (Settings.Instance.DebugGotobase) { Logging.Log("DebugHangarsBehavior", "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.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.UnloadLoot; Traveler.Destination = null; } break; case DebugHangarsBehaviorState.UnloadLoot: if (_States.CurrentUnloadLootState == UnloadLootState.Idle) { Logging.Log("DebugHangarsBehavior", "UnloadLoot: Begin", Logging.White); _States.CurrentUnloadLootState = UnloadLootState.Begin; } _unloadLoot.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("DebugHangarsBehavior", "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("DebugHangarsBehavior.UnloadLoot", "We are out of ammo", Logging.Orange); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Idle; return; } _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Idle; Logging.Log("DebugHangarsBehavior.Unloadloot", "CharacterMode: [" + Settings.Instance.CharacterMode + "], AfterMissionSalvaging: [" + Settings.Instance.AfterMissionSalvaging + "], DebugHangarsBehaviorState: [" + _States.CurrentDebugHangarBehaviorState + "]", Logging.White); Statistics.Instance.FinishedMission = DateTime.UtcNow; return; } break; case DebugHangarsBehaviorState.Traveler: 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("DebugHangarsBehavior.Traveler", "No destination?", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; return; } else if (destination.Count == 1 && destination.FirstOrDefault() == 0) { destination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; } if (Traveler.Destination == null || Traveler.Destination.SolarSystemId != destination.Last()) { IEnumerable <DirectBookmark> bookmarks = Cache.Instance.AllBookmarks.Where(b => b.LocationId == destination.Last()).ToList(); if (bookmarks != null && bookmarks.Any()) { Traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault()); } else { Logging.Log("DebugHangarsBehavior.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("DebugHangarsBehavior.Traveler", "an error has occurred", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; return; } if (Cache.Instance.InSpace) { Logging.Log("DebugHangarsBehavior.Traveler", "Arrived at destination (in space, Questor stopped)", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; return; } Logging.Log("DebugHangarsBehavior.Traveler", "Arrived at destination", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Idle; return; } } break; case DebugHangarsBehaviorState.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("DebugHangarsBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Idle; break; } break; } if (station.Distance < 1900) { if (station.Dock()) { Logging.Log("DebugBehavior.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)) { Cache.Instance.NextApproachAction = DateTime.UtcNow.AddSeconds(Time.Instance.ApproachDelay_seconds); Logging.Log("DebugHangarsBehavior.GotoNearestStation", "Approaching [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); station.Approach(); } } } else { _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; //should we goto idle here? } break; case DebugHangarsBehaviorState.ReadyItemsHangar: Logging.Log("DebugHangars", "DebugHangarsState.ReadyItemsHangar:", Logging.White); if (Cache.Instance.ItemHangar == null) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackItemsHangar: Logging.Log("DebugHangars", "DebugHangarsState.StackItemsHangar:", Logging.White); if (!Cache.Instance.StackItemsHangarAsAmmoHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseItemsHangar: Logging.Log("DebugHangars", "DebugHangarsState.CloseItemsHangar:", Logging.White); if (!Cache.Instance.CloseItemsHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenShipsHangar: Logging.Log("DebugHangars", "DebugHangarsState.OpenShipsHangar:", Logging.White); if (!Cache.Instance.OpenShipsHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackShipsHangar: Logging.Log("DebugHangars", "DebugHangarsState.StackShipsHangar:", Logging.White); if (!Cache.Instance.StackShipsHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseShipsHangar: Logging.Log("DebugHangars", "DebugHangarsState.CloseShipsHangar:", Logging.White); if (!Cache.Instance.CloseShipsHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenLootContainer: Logging.Log("DebugHangars", "DebugHangarsState.OpenLootContainer:", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackLootContainer: Logging.Log("DebugHangars", "DebugHangarsState.StackLootContainer:", Logging.White); if (!Cache.Instance.StackLootContainer("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseLootContainer: Logging.Log("DebugHangars", "DebugHangarsState.CloseLootContainer:", Logging.White); if (!Cache.Instance.CloseLootContainer("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; //Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenCorpAmmoHangar: Logging.Log("DebugHangars", "DebugHangarsState.OpenCorpAmmoHangar:", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); Logging.Log("OpenCorpAmmoHangar", "AmmoHangar Contains [" + Cache.Instance.AmmoHangar.Items.Count() + "] Items", Logging.Debug); try { int icount = 0; foreach (DirectItem itemfound in Cache.Instance.AmmoHangar.Items) { icount++; Logging.Log("Arm.MoveItems", "Found: Name [" + itemfound.TypeName + "] Quantity [" + itemfound.Quantity + "] in the AmmoHangar", Logging.Red); if (icount > 20) { Logging.Log("Arm.MoveItems", "max items to log reached (over 20). there are probably more items but we only log 20 of em.", Logging.Red); break; } continue; } } catch (Exception exception) { Logging.Log("OpenCorpLootHangar", "Exception was: [" + exception + "]", Logging.Debug); } _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackCorpAmmoHangar: Logging.Log("DebugHangars", "DebugHangarsState.StackCorpAmmoHangar:", Logging.White); if (!Cache.Instance.StackCorpAmmoHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseCorpAmmoHangar: Logging.Log("DebugHangars", "DebugHangarsState.CloseCorpAmmoHangar:", Logging.White); if (!Cache.Instance.CloseCorpHangar("DebugHangars", "AMMO")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenCorpLootHangar: Logging.Log("DebugHangars", "DebugHangarsState.OpenCorpLootHangar:", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); Logging.Log("OpenCorpLootHangar", "LootHangar Contains [" + Cache.Instance.LootHangar.Items.Count() + "] Items", Logging.Debug); try { int icount2 = 0; foreach (DirectItem itemfound in Cache.Instance.LootHangar.Items) { icount2++; Logging.Log("Arm.MoveItems", "Found: Name [" + itemfound.TypeName + "] Quantity [" + itemfound.Quantity + "] in the LootHangar", Logging.Red); if (icount2 > 20) { Logging.Log("Arm.MoveItems", "max items to log reached (over 20). there are probably more items but we only log 20 of em.", Logging.Red); break; } continue; } } catch (Exception exception) { Logging.Log("OpenCorpLootHangar", "Exception was: [" + exception + "]", Logging.Debug); } _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackCorpLootHangar: Logging.Log("DebugHangars", "DebugHangarsState.StackCorpLootHangar:", Logging.White); if (!Cache.Instance.StackCorpLootHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseCorpLootHangar: Logging.Log("DebugHangars", "DebugHangarsState.CloseCorpLootHangar:", Logging.White); if (!Cache.Instance.CloseCorpHangar("DebugHangars", "LOOT")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenAmmoHangar: Logging.Log("DebugHangars", "DebugHangarsState.OpenAmmoHangar:", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackAmmoHangar: Logging.Log("DebugHangars", "DebugHangarsState.StackAmmoHangar:", Logging.White); if (!Cache.Instance.StackAmmoHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseAmmoHangar: Logging.Log("DebugHangars", "DebugHangarsState.CloseAmmoHangar:", Logging.White); if (!Cache.Instance.CloseAmmoHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenLootHangar: Logging.Log("DebugHangars", "DebugHangarsState.OpenLootHangar:", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackLootHangar: Logging.Log("DebugHangars", "DebugHangarsState.StackLootHangar:", Logging.White); if (!Cache.Instance.StackLootHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseLootHangar: Logging.Log("DebugHangars", "DebugHangarsState.CloseLootHangar:", Logging.White); if (!Cache.Instance.CloseLootHangar("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseAllInventoryWindows: Logging.Log("DebugHangars", "DebugHangarsState.CloseAllInventoryWindows:", Logging.White); if (!Cleanup.CloseInventoryWindows()) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenCargoHold: Logging.Log("DebugHangars", "DebugHangarsState.StackLootHangar:", Logging.White); if (Cache.Instance.CurrentShipsCargo == null) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.StackCargoHold: Logging.Log("DebugHangars", "DebugHangarsState.CloseLootHangar:", Logging.White); if (!Cache.Instance.StackCargoHold("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.CloseCargoHold: Logging.Log("DebugHangars", "DebugHangarsState.CloseAllInventoryWindows:", Logging.White); if (!Cache.Instance.CloseCargoHold("DebugHangars")) { return; } Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.GetAmmoHangarID: Logging.Log("DebugHangars", "DebugHangarsState.GetAmmoHangarID:", Logging.White); if (!Cache.Instance.GetCorpAmmoHangarID()) { return; } Logging.Log("DebugHangars", "AmmoHangarId [" + Cache.Instance.AmmoHangarID + "]", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.GetLootHangarID: Logging.Log("DebugHangars", "DebugHangarsState.GetLootHangarID:", Logging.White); if (!Cache.Instance.GetCorpLootHangarID()) { return; } Logging.Log("DebugHangars", "LootHangarId [" + Cache.Instance.LootHangarID + "]", Logging.White); Cache.Instance.DebugInventoryWindows("DebugHangars"); _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenInventory: Logging.Log("DebugHangars", "DebugHangarsState.OpenInventory:", Logging.White); if (!Cache.Instance.OpenInventoryWindow("DebugHangarsState.OpenInventoryWindow")) { return; } _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.ListInvTree: Logging.Log("DebugHangars", "DebugHangarsState.ListInvTree:", Logging.White); if (!Cache.Instance.ListInvTree("DebugHangarsState.ListInvTree")) { return; } _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.OpenOreHold: Logging.Log("DebugHangars", "DebugHangarsState.OpenOreHold:", Logging.White); if (!Cache.Instance.OpenOreHold("DebugHangarsState.OpenOreHold")) { return; } _States.CurrentDebugHangarBehaviorState = DebugHangarsBehaviorState.Error; Cache.Instance.Paused = true; break; case DebugHangarsBehaviorState.Default: break; } }
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 { ValidateCombatMissionSettings(); LastAction = DateTime.UtcNow; } return; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //this local is safe check is useless as their is no LocalWatch processstate running every tick... //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //If local unsafe go to base and do not start mission again if (Settings.Instance.FinishWhenNotSafe && (_States.CurrentDirectionalScannerBehaviorState != DirectionalScannerBehaviorState.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.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.GotoNearestStation; } else { Logging.Log("Local not safe", "Station not found. Going back to base", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.GotoBase; } Cache.Instance.StopBot = true; } } if (Cache.Instance.SessionState == "Quitting") { BeginClosingQuestor(); } if (Cache.Instance.GotoBaseNow) { _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.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.CurrentDirectionalScannerBehaviorState :) _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Panic; DebugDirectionalScannerBehaviorStates(); 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.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Idle; DebugDirectionalScannerBehaviorStates(); } DebugPanicstates(); //Logging.Log("test"); switch (_States.CurrentDirectionalScannerBehaviorState) { case DirectionalScannerBehaviorState.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("DirectionalScannerBehavior", "DebugIdle: StopBot [" + Cache.Instance.StopBot + "]", Logging.White); } return; } if (Cache.Instance.InSpace) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("DirectionalScannerBehavior", "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("DirectionalScannerBehavior", "Started questor while in space, heading back to base in 15 seconds", Logging.White); LastAction = DateTime.UtcNow; _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.DelayedGotoBase; break; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(10)) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("DirectionalScannerBehavior", "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("DirectionalScannerBehavior", "Started questor in Directional Scanner (test) mode", Logging.White); LastAction = DateTime.UtcNow; break; case DirectionalScannerBehaviorState.DelayedGotoBase: if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.DelayedGotoBase_seconds) { break; } Logging.Log("DirectionalScannerBehavior", "Heading back to base", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.GotoBase; break; case DirectionalScannerBehaviorState.GotoBase: if (Settings.Instance.DebugGotobase) { Logging.Log("DirectionalScannerBehavior", "GotoBase: AvoidBumpingThings()", Logging.White); } NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjects.FirstOrDefault(), "DirectionalScannerBehaviorState.GotoBase"); if (Settings.Instance.DebugGotobase) { Logging.Log("DirectionalScannerBehavior", "GotoBase: Traveler.TravelHome()", Logging.White); } Traveler.TravelHome("DirectionalScannerBehavior"); if (_States.CurrentTravelerState == TravelerState.AtDestination) // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10) { if (Settings.Instance.DebugGotobase) { Logging.Log("DirectionalScannerBehavior", "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.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Idle; Traveler.Destination = null; } break; case DirectionalScannerBehaviorState.Traveler: 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("DirectionalScannerBehavior.Traveler", "No destination?", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Error; return; } if (destination.Count == 1 && destination.FirstOrDefault() == 0) { destination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; } if (Traveler.Destination == null || Traveler.Destination.SolarSystemId != destination.LastOrDefault()) { IEnumerable <DirectBookmark> bookmarks = Cache.Instance.AllBookmarks.Where(b => b.LocationId == destination.LastOrDefault()).ToList(); if (bookmarks.FirstOrDefault() != null && bookmarks.Any()) { Traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault()); } else { Logging.Log("DirectionalScannerBehavior.Traveler", "Destination: [" + Cache.Instance.DirectEve.Navigation.GetLocation(destination.Last()).Name + "]", Logging.White); Traveler.Destination = new SolarSystemDestination(destination.LastOrDefault()); } } 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("DirectionalScannerBehavior.Traveler", "an error has occurred", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Error; return; } if (Cache.Instance.InSpace) { Logging.Log("DirectionalScannerBehavior.Traveler", "Arrived at destination (in space, Questor stopped)", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Error; return; } Logging.Log("DirectionalScannerBehavior.Traveler", "Arrived at destination", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Idle; return; } } break; case DirectionalScannerBehaviorState.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("DirectionalScannerBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Idle; break; } break; } if (station.Distance < 1900) { if (station.Dock()) { Logging.Log("DebugBehavior.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("DirectionalScannerBehavior.GotoNearestStation", "Approaching [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); station.Approach(); } } } else { _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Error; //should we goto idle here? } break; case DirectionalScannerBehaviorState.PVPDirectionalScanHalfanAU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScanhalfanAU - Starting", Logging.White); List <EntityCache> pvpDirectionalScanHalfanAUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScanHalfanAUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVPDirectionalScan1AU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScan1AU - Starting", Logging.White); List <EntityCache> pvpDirectionalScan1AUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 1).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScan1AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVPDirectionalScan5AU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScan5AU - Starting", Logging.White); List <EntityCache> pvpDirectionalScan5AUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 5).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScan5AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVPDirectionalScan10AU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScan10AU - Starting", Logging.White); List <EntityCache> pvpDirectionalScan10AUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 10).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScan10AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVPDirectionalScan15AU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScan15AU - Starting", Logging.White); List <EntityCache> pvpDirectionalScan15AUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 15).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScan15AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVPDirectionalScan20AU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScan20AU - Starting", Logging.White); List <EntityCache> pvpDirectionalScan20AUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 20).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScan20AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVPDirectionalScan50AU: Logging.Log("DirectionalScannerBehavior", "PVPDirectionalScan50AU - Starting", Logging.White); List <EntityCache> pvpDirectionalScan50AUentitiesInList = Cache.Instance.Entities.Where(t => t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 50).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pvpDirectionalScan50AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScanHalfanAU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScanhalfanAU - Starting", Logging.White); List <EntityCache> pveDirectionalScanHalfanAUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScanHalfanAUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScan1AU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScan1AU - Starting", Logging.White); List <EntityCache> pveDirectionalScan1AUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 1).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScan1AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScan5AU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScan5AU - Starting", Logging.White); List <EntityCache> pveDirectionalScan5AUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 5).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScan5AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScan10AU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScan10AU - Starting", Logging.White); List <EntityCache> pveDirectionalScan10AUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 10).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScan10AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScan15AU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScan15AU - Starting", Logging.White); List <EntityCache> pveDirectionalScan15AUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 15).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScan15AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScan20AU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScan20AU - Starting", Logging.White); List <EntityCache> pveDirectionalScan20AUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 20).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScan20AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.PVEDirectionalScan50AU: Logging.Log("DirectionalScannerBehavior", "PVEDirectionalScan50AU - Starting", Logging.White); List <EntityCache> pveDirectionalScan50AUentitiesInList = Cache.Instance.Entities.Where(t => !t.IsPlayer && t.Distance < (double)Distances.DirectionalScannerCloseRange * 50).OrderBy(t => t.Distance).ToList(); Statistics.EntityStatistics(pveDirectionalScan50AUentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.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.Entities.Where(t => t.IsNpc && !t.IsBadIdea && t.CategoryId == (int)CategoryID.Entity && !t.IsContainer).ToList(); Statistics.EntityStatistics(combatentitiesInList); Cache.Instance.Paused = true; break; case DirectionalScannerBehaviorState.LogDroneTargets: //drone targets List <EntityCache> droneentitiesInList = Cache.Instance.Entities.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 DirectionalScannerBehaviorState.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 DirectionalScannerBehaviorState.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 DirectionalScannerBehaviorState.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 DirectionalScannerBehaviorState.Default: if (_States.CurrentDirectionalScannerBehaviorState == DirectionalScannerBehaviorState.Default) { _States.CurrentDirectionalScannerBehaviorState = DirectionalScannerBehaviorState.Idle; } break; } }
//public bool InMission { get; set; } public void ProcessState() { // Only pulse state changes every 500ms if (DateTime.UtcNow < _nextPanicProcessState || Settings.Instance.DebugDisablePanic) //default: 500ms { return; } _nextPanicProcessState = DateTime.UtcNow.AddMilliseconds(500); switch (_States.CurrentPanicState) { case PanicState.Idle: // // below is the reasons we will start the panic state(s) - if the below is not met do nothing // if (Cache.Instance.InSpace && Cache.Instance.ActiveShip.Entity != null && !Cache.Instance.ActiveShip.Entity.IsCloaked) { _States.CurrentPanicState = PanicState.Normal; return; } break; case PanicState.Normal: if (Cache.Instance.InStation) { _States.CurrentPanicState = PanicState.Idle; } if (Cache.Instance.ActiveShip.Entity != null) { _lastNormalX = Cache.Instance.ActiveShip.Entity.X; _lastNormalY = Cache.Instance.ActiveShip.Entity.Y; _lastNormalZ = Cache.Instance.ActiveShip.Entity.Z; } if (Cache.Instance.ActiveShip.Entity == null) { return; } if (DateTime.UtcNow < Cache.Instance.LastSessionChange.AddSeconds(10)) { return; } if ((long)Cache.Instance.ActiveShip.StructurePercentage == 0) //if your hull is 0 you are dead or bugged, wait. { return; } if (Settings.Instance.WatchForActiveWars && Cache.Instance.IsCorpInWar) { Logging.Log("Cache", "Your corp is involved in a war [" + Cache.Instance.IsCorpInWar + "] and WatchForActiveWars [" + Settings.Instance.WatchForActiveWars + "], Starting panic!", Logging.Orange); _States.CurrentPanicState = PanicState.StartPanicking; //return; } if (Cache.Instance.InSpace) { if (!Cache.Instance.InMission && Cache.Instance.ActiveShip.GroupId == (int)Group.Capsule) { Logging.Log("Panic", "You are in a Capsule, you must have died :(", Logging.Red); _States.CurrentPanicState = PanicState.BookmarkMyWreck; //_States.CurrentPanicState = PanicState.StartPanicking; return; } if (Cache.Instance.TargetedBy.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been locked by [" + Cache.Instance.TargetedBy.Count() + "] Entities", Logging.Debug); } List <EntityCache> EntitiesThatAreWarpScramblingMe = Cache.Instance.TargetedBy.Where(t => t.IsWarpScramblingMe).ToList(); if (EntitiesThatAreWarpScramblingMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been warp scrambled by [" + EntitiesThatAreWarpScramblingMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreWarpScramblingMe, DronePriority.WarpScrambler, "Panic", Settings.Instance.AddWarpScramblersToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreWarpScramblingMe, PrimaryWeaponPriority.WarpScrambler, "Panic", Settings.Instance.AddWarpScramblersToDronePriorityTargetList); } if (Settings.Instance.SpeedTank) { List <EntityCache> EntitiesThatAreWebbingMe = Cache.Instance.TargetedBy.Where(t => t.IsWebbingMe).ToList(); if (EntitiesThatAreWebbingMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been webbed by [" + EntitiesThatAreWebbingMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreWebbingMe, DronePriority.Webbing, "Panic", Settings.Instance.AddWebifiersToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreWebbingMe, PrimaryWeaponPriority.Webbing, "Panic", Settings.Instance.AddWebifiersToPrimaryWeaponsPriorityTargetList); } List <EntityCache> EntitiesThatAreTargetPaintingMe = Cache.Instance.TargetedBy.Where(t => t.IsTargetPaintingMe).ToList(); if (EntitiesThatAreTargetPaintingMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been target painted by [" + EntitiesThatAreTargetPaintingMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreTargetPaintingMe, DronePriority.PriorityKillTarget, "Panic", Settings.Instance.AddTargetPaintersToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreTargetPaintingMe, PrimaryWeaponPriority.TargetPainting, "Panic", Settings.Instance.AddTargetPaintersToPrimaryWeaponsPriorityTargetList); } } List <EntityCache> EntitiesThatAreNeutralizingMe = Cache.Instance.TargetedBy.Where(t => t.IsNeutralizingMe).ToList(); if (EntitiesThatAreNeutralizingMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been neuted by [" + EntitiesThatAreNeutralizingMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreNeutralizingMe, DronePriority.PriorityKillTarget, "Panic", Settings.Instance.AddNeutralizersToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreNeutralizingMe, PrimaryWeaponPriority.Neutralizing, "Panic", Settings.Instance.AddNeutralizersToPrimaryWeaponsPriorityTargetList); } List <EntityCache> EntitiesThatAreJammingMe = Cache.Instance.TargetedBy.Where(t => t.IsJammingMe).ToList(); if (EntitiesThatAreJammingMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been ECMd by [" + EntitiesThatAreJammingMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreJammingMe, DronePriority.PriorityKillTarget, "Panic", Settings.Instance.AddECMsToDroneTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreJammingMe, PrimaryWeaponPriority.Jamming, "Panic", Settings.Instance.AddECMsToPrimaryWeaponsPriorityTargetList); } List <EntityCache> EntitiesThatAreSensorDampeningMe = Cache.Instance.TargetedBy.Where(t => t.IsSensorDampeningMe).ToList(); if (EntitiesThatAreSensorDampeningMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been Sensor Damped by [" + EntitiesThatAreSensorDampeningMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreSensorDampeningMe, DronePriority.PriorityKillTarget, "Panic", Settings.Instance.AddDampenersToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreSensorDampeningMe, PrimaryWeaponPriority.Dampening, "Panic", Settings.Instance.AddDampenersToPrimaryWeaponsPriorityTargetList); } if (Cache.Instance.Modules.Any(m => m.IsTurret)) { // // tracking disrupting targets // List <EntityCache> EntitiesThatAreTrackingDisruptingMe = Cache.Instance.TargetedBy.Where(t => t.IsTrackingDisruptingMe).ToList(); if (EntitiesThatAreTrackingDisruptingMe.Any()) { if (Settings.Instance.DebugPanic) { Logging.Log("Panic.Normal", "We have been Tracking Disrupted by [" + EntitiesThatAreTrackingDisruptingMe.Count() + "] Entities", Logging.Debug); } if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(EntitiesThatAreTrackingDisruptingMe, DronePriority.PriorityKillTarget, "Panic", Settings.Instance.AddTrackingDisruptorsToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(EntitiesThatAreTrackingDisruptingMe, PrimaryWeaponPriority.Dampening, "Panic", Settings.Instance.AddTrackingDisruptorsToPrimaryWeaponsPriorityTargetList); } } } if (Math.Round(DateTime.UtcNow.Subtract(_lastPriorityTargetLogging).TotalSeconds) > Settings.Instance.ListPriorityTargetsEveryXSeconds) { _lastPriorityTargetLogging = DateTime.UtcNow; icount = 1; foreach (EntityCache target in Cache.Instance.DronePriorityEntities) { icount++; Logging.Log("Panic.ListDronePriorityTargets", "[" + icount + "][" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away] WARP[" + target.IsWarpScramblingMe + "] ECM[" + target.IsJammingMe + "] Damp[" + target.IsSensorDampeningMe + "] TP[" + target.IsTargetPaintingMe + "] NEUT[" + target.IsNeutralizingMe + "]", Logging.Teal); continue; } icount = 1; foreach (EntityCache target in Cache.Instance.PrimaryWeaponPriorityEntities) { icount++; Logging.Log("Panic.ListPrimaryWeaponPriorityTargets", "[" + icount + "][" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away] WARP[" + target.IsWarpScramblingMe + "] ECM[" + target.IsJammingMe + "] Damp[" + target.IsSensorDampeningMe + "] TP[" + target.IsTargetPaintingMe + "] NEUT[" + target.IsNeutralizingMe + "]", Logging.Teal); continue; } } if (Cache.Instance.ActiveShip.ArmorPercentage < 100) { Cache.Instance.NeedRepair = true; // // do not return here, we are just setting a flag for use by arm to repair or not repair... // } else { Cache.Instance.NeedRepair = false; } if (Cache.Instance.InMission && Cache.Instance.ActiveShip.CapacitorPercentage < Settings.Instance.MinimumCapacitorPct && Cache.Instance.ActiveShip.GroupId != 31) { // Only check for cap-panic while in a mission, not while doing anything else Logging.Log("Panic", "Start panicking, capacitor [" + Math.Round(Cache.Instance.ActiveShip.CapacitorPercentage, 0) + "%] below [" + Settings.Instance.MinimumCapacitorPct + "%] S[" + Math.Round(Cache.Instance.ActiveShip.ShieldPercentage, 0) + "%] A[" + Math.Round(Cache.Instance.ActiveShip.ArmorPercentage, 0) + "%] C[" + Math.Round(Cache.Instance.ActiveShip.CapacitorPercentage, 0) + "%]", Logging.Red); //Questor.panic_attempts_this_mission; Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; return; } if (Cache.Instance.ActiveShip.ShieldPercentage < Settings.Instance.MinimumShieldPct) { Logging.Log("Panic", "Start panicking, shield [" + Math.Round(Cache.Instance.ActiveShip.ShieldPercentage, 0) + "%] below [" + Settings.Instance.MinimumShieldPct + "%] S[" + Math.Round(Cache.Instance.ActiveShip.ShieldPercentage, 0) + "%] A[" + Math.Round(Cache.Instance.ActiveShip.ArmorPercentage, 0) + "%] C[" + Math.Round(Cache.Instance.ActiveShip.CapacitorPercentage, 0) + "%]", Logging.Red); Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; return; } if (Cache.Instance.ActiveShip.ArmorPercentage < Settings.Instance.MinimumArmorPct) { Logging.Log("Panic", "Start panicking, armor [" + Math.Round(Cache.Instance.ActiveShip.ArmorPercentage, 0) + "%] below [" + Settings.Instance.MinimumArmorPct + "%] S[" + Math.Round(Cache.Instance.ActiveShip.ShieldPercentage, 0) + "%] A[" + Math.Round(Cache.Instance.ActiveShip.ArmorPercentage, 0) + "%] C[" + Math.Round(Cache.Instance.ActiveShip.CapacitorPercentage, 0) + "%]", Logging.Red); Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; return; } BookmarkMyWreckAttempts = 1; // reset to 1 when we are known to not be in a pod anymore _delayedResume = false; if (Cache.Instance.InMission) { if (Cache.Instance.ActiveShip.GroupId == (int)Group.Capsule) { Logging.Log("Panic", "You are in a Capsule, you must have died in a mission :(", Logging.Red); _States.CurrentPanicState = PanicState.BookmarkMyWreck; } int frigates = Cache.Instance.EntitiesNotSelf.Count(e => e.IsFrigate && e.IsPlayer); int cruisers = Cache.Instance.EntitiesNotSelf.Count(e => e.IsCruiser && e.IsPlayer); int battlecruisers = Cache.Instance.EntitiesNotSelf.Count(e => e.IsBattlecruiser && e.IsPlayer); int battleships = Cache.Instance.EntitiesNotSelf.Count(e => e.IsBattleship && e.IsPlayer); if (Settings.Instance.FrigateInvasionLimit > 0 && frigates >= Settings.Instance.FrigateInvasionLimit) { _delayedResume = true; Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; Logging.Log("Panic", "Start panicking, mission invaded by [" + frigates + "] Frigates", Logging.Red); } if (Settings.Instance.CruiserInvasionLimit > 0 && cruisers >= Settings.Instance.CruiserInvasionLimit) { _delayedResume = true; Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; Logging.Log("Panic", "Start panicking, mission invaded by [" + cruisers + "] Cruisers", Logging.Red); } if (Settings.Instance.BattlecruiserInvasionLimit > 0 && battlecruisers >= Settings.Instance.BattlecruiserInvasionLimit) { _delayedResume = true; Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; Logging.Log("Panic", "Start panicking, mission invaded by [" + battlecruisers + "] BattleCruisers", Logging.Red); } if (Settings.Instance.BattleshipInvasionLimit > 0 && battleships >= Settings.Instance.BattleshipInvasionLimit) { _delayedResume = true; Cache.Instance.PanicAttemptsThisMission++; Cache.Instance.PanicAttemptsThisPocket++; _States.CurrentPanicState = PanicState.StartPanicking; Logging.Log("Panic", "Start panicking, mission invaded by [" + battleships + "] BattleShips", Logging.Red); } if (_delayedResume) { _randomDelay = (Settings.Instance.InvasionRandomDelay > 0 ? _random.Next(Settings.Instance.InvasionRandomDelay) : 0); _randomDelay += Settings.Instance.InvasionMinimumDelay; foreach (EntityCache enemy in Cache.Instance.EntitiesNotSelf.Where(e => e.IsPlayer)) { Logging.Log("Panic", "Invaded by: PlayerName [" + enemy.Name + "] ShipTypeID [" + enemy.TypeId + "] Distance [" + Math.Round(enemy.Distance, 0) / 1000 + "k] Velocity [" + Math.Round(enemy.Velocity, 0) + "]", Logging.Red); } } } } break; // NOTE: The difference between Panicking and StartPanicking is that the bot will move to "Panic" state once in warp & Panicking // and the bot wont go into Panic mode while still "StartPanicking" case PanicState.StartPanicking: case PanicState.Panicking: // // Add any warp scramblers to the priority list // Use the same rules here as you do before you panic, as we probably want to keep killing DPS if configured to do so // EntityCache EntityIsWarpScramblingMeWhilePanicing = Cache.Instance.TargetedBy.FirstOrDefault(t => t.IsWarpScramblingMe); if (EntityIsWarpScramblingMeWhilePanicing != null) { if (Cache.Instance.UseDrones) { Cache.Instance.AddDronePriorityTargets(Cache.Instance.TargetedBy.Where(t => t.IsWarpScramblingMe), DronePriority.WarpScrambler, "Panic", Settings.Instance.AddWarpScramblersToDronePriorityTargetList); } Cache.Instance.AddPrimaryWeaponPriorityTargets(Cache.Instance.TargetedBy.Where(t => t.IsWarpScramblingMe), PrimaryWeaponPriority.WarpScrambler, "Panic", Settings.Instance.AddWarpScramblersToPrimaryWeaponsPriorityTargetList); } // Failsafe, in theory would/should never happen if (_States.CurrentPanicState == PanicState.Panicking && Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { // Resume is the only state that will make Questor revert to combat mode _States.CurrentPanicState = PanicState.Resume; return; } if (Cache.Instance.InStation) { Logging.Log("Panic", "Entered a station, lower panic mode", Logging.White); Settings.Instance.LoadSettings(); _States.CurrentPanicState = PanicState.Panic; return; } // Once we have warped off 500km, assume we are "safer" if (_States.CurrentPanicState == PanicState.StartPanicking && Cache.Instance.DistanceFromMe(_lastNormalX, _lastNormalY, _lastNormalZ) > (int)Distances.PanicDistanceToConsiderSafelyWarpedOff) { Logging.Log("Panic", "We have warped off: My ShipType: [" + Logging.Yellow + Cache.Instance.ActiveShip.TypeName + Logging.White + "] My ShipName [" + Logging.Yellow + Cache.Instance.ActiveShip.GivenName + Logging.White + "]", Logging.White); _States.CurrentPanicState = PanicState.Panicking; } // We leave the panicking state once we actually start warping off EntityCache station = null; if (Cache.Instance.Stations != null && Cache.Instance.Stations.Any()) { station = Cache.Instance.Stations.FirstOrDefault(); } if (station != null && Cache.Instance.InSpace) { if (Cache.Instance.InWarp) { if (Cache.Instance.PrimaryWeaponPriorityEntities != null && Cache.Instance.PrimaryWeaponPriorityEntities.Any()) { Cache.Instance.RemovePrimaryWeaponPriorityTargets(Cache.Instance.PrimaryWeaponPriorityEntities.ToList()); } if (Cache.Instance.UseDrones && Cache.Instance.DronePriorityEntities != null && Cache.Instance.DronePriorityEntities.Any()) { Cache.Instance.RemoveDronePriorityTargets(Cache.Instance.DronePriorityEntities.ToList()); } break; } if (station.Distance > (int)Distances.WarptoDistance) { NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjectsandGates.FirstOrDefault(), "Panic"); if (Cache.Instance.DronePriorityEntities.Any(pt => pt.IsWarpScramblingMe) || Cache.Instance.PrimaryWeaponPriorityEntities.Any(pt => pt.IsWarpScramblingMe)) { EntityCache WarpScrambledBy = Cache.Instance.DronePriorityEntities.FirstOrDefault(pt => pt.IsWarpScramblingMe) ?? Cache.Instance.PrimaryWeaponPriorityEntities.FirstOrDefault(pt => pt.IsWarpScramblingMe); if (WarpScrambledBy != null && DateTime.UtcNow > _nextWarpScrambledWarning) { _nextWarpScrambledWarning = DateTime.UtcNow.AddSeconds(20); Logging.Log("Panic", "We are scrambled by: [" + Logging.White + WarpScrambledBy.Name + Logging.Orange + "][" + Logging.White + Math.Round(WarpScrambledBy.Distance, 0) + Logging.Orange + "][" + Logging.White + WarpScrambledBy.Id + Logging.Orange + "]", Logging.Orange); _lastWarpScrambled = DateTime.UtcNow; } } if (DateTime.UtcNow > Cache.Instance.NextWarpAction || DateTime.UtcNow.Subtract(_lastWarpScrambled).TotalSeconds < Time.Instance.WarpScrambledNoDelay_seconds) //this will effectively spam warpto as soon as you are free of warp disruption if you were warp disrupted in the past 10 seconds) { if (station.WarpTo()) { Logging.Log("Panic", "Warping to [" + Logging.Yellow + station.Name + Logging.Red + "][" + Logging.Yellow + Math.Round((station.Distance / 1000) / 149598000, 2) + Logging.Red + " AU away]", Logging.Red); Cache.Instance.IsMissionPocketDone = true; } } else { Logging.Log("Panic", "Warping will be attempted again after [" + Math.Round(Cache.Instance.NextWarpAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + "sec]", Logging.Red); } //if (Cache.Instance.ActiveShip.GroupId == (int)Group.Capsule) //{ // Logging.Log("Panic", "You are in a Capsule, you must have died :(", Logging.Red); //} return; } if (station.Distance < (int)Distances.DockingRange) { if (station.Dock()) { Logging.Log("Panic", "Docking with [" + Logging.Yellow + station.Name + Logging.Red + "][" + Logging.Yellow + Math.Round((station.Distance / 1000) / 149598000, 2) + Logging.Red + " AU away]", Logging.Red); } return; } if (DateTime.UtcNow > Cache.Instance.NextTravelerAction) { if (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != station.Id || Cache.Instance.MyShipEntity.Velocity < 50) { Logging.Log("Panic", "Approaching to [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.Red); station.Approach(); Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.ApproachDelay_seconds); return; } Logging.Log("Panic", "Already Approaching to: [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.Red); return; } Logging.Log("Panic", "Approaching has been delayed for [" + Math.Round(Cache.Instance.NextWarpAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + "sec]", Logging.Red); return; } if (Cache.Instance.InSpace) { if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 15) { Logging.Log("Panic", "No station found in local?", Logging.Red); } if (Cache.Instance.SafeSpotBookmarks.Any() && Cache.Instance.SafeSpotBookmarks.Any(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId)) { List <DirectBookmark> SafeSpotBookmarksInLocal = new List <DirectBookmark>(Cache.Instance.SafeSpotBookmarks .Where(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId) .OrderBy(b => b.CreatedOn)); if (SafeSpotBookmarksInLocal.Any()) { DirectBookmark offridSafeSpotBookmark = SafeSpotBookmarksInLocal.OrderBy(i => Cache.Instance.DistanceFromMe(i.X ?? 0, i.Y ?? 0, i.Z ?? 0)).FirstOrDefault(); if (offridSafeSpotBookmark != null) { if (Cache.Instance.InWarp) { _States.CurrentPanicState = PanicState.Panic; return; } if (Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { Logging.Log("Panic", "We are still warp scrambled!", Logging.Red); //This runs every 'tick' so we should see it every 1.5 seconds or so _lastWarpScrambled = DateTime.UtcNow; return; } if (DateTime.UtcNow > Cache.Instance.NextWarpAction || DateTime.UtcNow.Subtract(_lastWarpScrambled).TotalSeconds < 10) //this will effectively spam warpto as soon as you are free of warp disruption if you were warp disrupted in the past 10 seconds { if (offridSafeSpotBookmark.WarpTo()) { double DistanceToBm = Cache.Instance.DistanceFromMe(offridSafeSpotBookmark.X ?? 0, offridSafeSpotBookmark.Y ?? 0, offridSafeSpotBookmark.Z ?? 0); Logging.Log("Panic", "Warping to safespot bookmark [" + offridSafeSpotBookmark.Title + "][" + Math.Round((DistanceToBm / 1000) / 149598000, 2) + " AU away]", Logging.Red); return; } return; } Logging.Log("Panic", "Warping has been delayed for [" + Math.Round(Cache.Instance.NextWarpAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + "sec]", Logging.Red); return; } } } else { // What is this you say? No star? if (Cache.Instance.Star == null) { return; } if (Cache.Instance.Star.Distance > (int)Distances.WeCanWarpToStarFromHere) { if (Cache.Instance.InWarp) { return; } if (Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { Logging.Log("Panic", "We are still warp scrambled!", Logging.Red); //This runs every 'tick' so we should see it every 1.5 seconds or so _lastWarpScrambled = DateTime.UtcNow; return; } //this will effectively spam warpto as soon as you are free of warp disruption if you were warp disrupted in the past 10 seconds if (DateTime.UtcNow > Cache.Instance.NextWarpAction || DateTime.UtcNow.Subtract(_lastWarpScrambled).TotalSeconds < 10) { if (Cache.Instance.Star.WarpTo()) { Logging.Log("Panic", "Warping to [" + Logging.Yellow + Cache.Instance.Star.Name + Logging.Red + "][" + Logging.Yellow + Math.Round((Cache.Instance.Star.Distance / 1000) / 149598000, 2) + Logging.Red + " AU away]", Logging.Red); return; } return; } Logging.Log("Panic", "Warping has been delayed for [" + Math.Round(Cache.Instance.NextWarpAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + "sec]", Logging.Red); return; } } } Logging.Log("Panic", "At a safe location, lower panic mode", Logging.Red); Settings.Instance.LoadSettings(); _States.CurrentPanicState = PanicState.Panic; break; case PanicState.BookmarkMyWreck: BookmarkMyWreckAttempts++; if (Cache.Instance.Wrecks.Any(i => i.Name.Contains(Settings.Instance.CombatShipName))) { Cache.Instance.CreateBookmark("Wreck: " + Settings.Instance.CombatShipName); _States.CurrentPanicState = PanicState.StartPanicking; break; } if (BookmarkMyWreckAttempts++ > 3) { _States.CurrentPanicState = PanicState.StartPanicking; break; } break; case PanicState.Panic: // Do not resume until you're no longer in a capsule if (Cache.Instance.ActiveShip.GroupId == (int)Group.Capsule) { break; } if (Cache.Instance.InStation) { if (Cache.Instance.IsCorpInWar && Settings.Instance.WatchForActiveWars) { if (Settings.Instance.DebugWatchForActiveWars) { Logging.Log("Panic", "Cache.Instance.IsCorpInWar [" + Cache.Instance.IsCorpInWar + "] and Settings.Instance.WatchForActiveWars [" + Settings.Instance.WatchForActiveWars + "] staying in panic (effectively paused in station)", Logging.Debug); } Cache.Instance.Paused = true; Settings.Instance.AutoStart = false; return; } if (Cache.Instance.DirectEve.HasSupportInstances() && Settings.Instance.UseStationRepair) { if (!Cache.Instance.RepairItems("Repair Function")) { break; //attempt to use repair facilities if avail in station } } Logging.Log("Panic", "We're in a station, resume mission", Logging.Red); _States.CurrentPanicState = _delayedResume ? PanicState.DelayedResume : PanicState.Resume; } bool isSafe = Cache.Instance.ActiveShip.CapacitorPercentage >= Settings.Instance.SafeCapacitorPct; isSafe &= Cache.Instance.ActiveShip.ShieldPercentage >= Settings.Instance.SafeShieldPct; isSafe &= Cache.Instance.ActiveShip.ArmorPercentage >= Settings.Instance.SafeArmorPct; if (isSafe) { if (Cache.Instance.InSpace) { Cache.Instance.RepairAll = true; } Logging.Log("Panic", "We have recovered, resume mission", Logging.Red); _States.CurrentPanicState = _delayedResume ? PanicState.DelayedResume : PanicState.Resume; } if (_States.CurrentPanicState == PanicState.DelayedResume) { Logging.Log("Panic", "Delaying resume for " + _randomDelay + " seconds", Logging.Red); Cache.Instance.IsMissionPocketDone = false; _resumeTime = DateTime.UtcNow.AddSeconds(_randomDelay); } break; case PanicState.DelayedResume: if (DateTime.UtcNow > _resumeTime) { _States.CurrentPanicState = PanicState.Resume; } break; case PanicState.Resume: // Don't do anything here break; } }
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
internal static bool PerformFinalDestinationTask(long stationId, string stationName, ref DateTime nextAction) { if (Cache.Instance.InStation && Cache.Instance.DirectEve.Session.StationId == stationId) { Logging.Log("QuestorManager.StationDestination", "Arrived in station", Logging.White); return(true); } if (Cache.Instance.InStation) { // We are in a station, but not the correct station! if (Cache.Instance.NextUndockAction < DateTime.UtcNow) { 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) { Logging.Log("QuestorManager.StationDestination", "We're docked in the wrong station, undocking", Logging.White); Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); Cache.Instance.NextUndockAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerExitStationAmIInSpaceYet_seconds); return(false); } } // We are not there yet return(false); } if (!Cache.Instance.InSpace) { // We are not in station and not in space? Wait for a bit return(false); } if (nextAction > DateTime.UtcNow) { return(false); } EntityCache station = Cache.Instance.EntityByName(stationName); if (station == null) { // We are there but no station? Wait a bit return(false); } if (station.Distance < (int)Distances.DockingRange) { if (station.Dock()) { Logging.Log("StationDestination.StationDestination", "Dock at [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); nextAction = DateTime.UtcNow.AddSeconds(30); } return(false); } if (station.Distance < (int)Distances.WarptoDistance) { if (DateTime.UtcNow > Cache.Instance.NextApproachAction) { Logging.Log("TravelerDestination.StationDestination", "Approaching [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); station.Approach(); nextAction = DateTime.UtcNow.AddSeconds(30); return(false); } return(false); } if (station.WarpTo()) { Logging.Log("QuestorManager.StationDestination", "Warp to and dock at [" + station.Name + "]", Logging.White); nextAction = DateTime.UtcNow.AddSeconds(30); return(false); } return(false); }
public static void NavigateIntoRange(EntityCache target, string module, bool moveMyShip) { if (!Cache.Instance.InSpace || (Cache.Instance.InSpace && Cache.Instance.InWarp) || !moveMyShip) return; if (DateTime.UtcNow < NextNavigateIntoRange || Settings.Instance.DebugDisableNavigateIntoRange) return; NextNavigateIntoRange = DateTime.UtcNow.AddSeconds(5); //we cant move in bastion mode, do not try List<ModuleCache> bastionModules = null; bastionModules = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.Bastion && m.IsOnline).ToList(); if (bastionModules.Any(i => i.IsActive)) return; if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange Started", Logging.White); if (Cache.Instance.OrbitDistance != Settings.Instance.OrbitDistance) { if (Cache.Instance.OrbitDistance == 0) { Cache.Instance.OrbitDistance = Settings.Instance.OrbitDistance; Logging.Log("CombatMissionCtrl", "Using default orbit distance: " + Cache.Instance.OrbitDistance + " (as the custom one was 0)", Logging.Teal); } //else // Logging.Log("CombatMissionCtrl", "Using custom orbit distance: " + Cache.Instance.OrbitDistance, Logging.teal); } //if (Cache.Instance.OrbitDistance != 0) // Logging.Log("CombatMissionCtrl", "Orbit Distance is set to: " + (Cache.Instance.OrbitDistance / 1000).ToString(CultureInfo.InvariantCulture) + "k", Logging.teal); NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjectsandGates.FirstOrDefault(), "NavigateOnGrid: NavigateIntoRange"); if (Settings.Instance.SpeedTank) { if (target.Distance > Cache.Instance.MaxRange && !Cache.Instance.IsApproaching(target.Id)) { target.Approach((int)(Cache.Instance.MaxRange * 0.8d)); if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: speedtank: Moving into weapons range before initiating orbit", Logging.Teal); return; } if (target.Distance < Cache.Instance.MaxRange && !Cache.Instance.IsOrbiting(target.Id)) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: speedtank: orbitdistance is [" + Cache.Instance.OrbitDistance + "]", Logging.White); OrbitGateorTarget(target, module); return; } return; } else //if we are not speed tanking then check optimalrange setting, if that is not set use the less of targeting range and weapons range to dictate engagement range { if (DateTime.UtcNow > Cache.Instance.NextApproachAction) { //if optimalrange is set - use it to determine engagement range if (Cache.Instance.OptimalRange != 0) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: OptimalRange [ " + Cache.Instance.OptimalRange + "] Current Distance to [" + target.Name + "] is [" + Math.Round(target.Distance / 1000, 0) + "]", Logging.White); if (target.Distance > Cache.Instance.OptimalRange + (int)Distances.OptimalRangeCushion && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id)) { if (target.IsNPCFrigate && Cache.Instance.DoWeCurrentlyHaveTurretsMounted()) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + Math.Round(target.Distance / 1000, 0) + "]", Logging.White); OrbitGateorTarget(target, module); return; } target.Approach(Cache.Instance.OptimalRange); Logging.Log(module, "Using Optimal Range: Approaching target [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); return; } if (target.Distance <= Cache.Instance.OptimalRange) { if (target.IsNPCFrigate && ((Cache.Instance.Approaching != null && Cache.Instance.Approaching.Id != target.Id) || Cache.Instance.Approaching == null) && Cache.Instance.DoWeCurrentlyHaveTurretsMounted()) { Logging.Log(module, "Target is NPC Frigate and we got Turrets. Keeping target at Range to hit it.", Logging.Teal); target.Approach(Settings.Instance.OptimalRange); Logging.Log(module, "Initiating KeepAtRange [" + target.Name + "][at " + Math.Round((double)Settings.Instance.OptimalRange / 1000, 0) + "k][ID: " + Cache.Instance.MaskedID(target.Id) + "]", Logging.Teal); return; } else if (Cache.Instance.Approaching != null && Cache.Instance.MyShipEntity.Velocity != 0) { if (target.IsNPCFrigate && Cache.Instance.DoWeCurrentlyHaveTurretsMounted()) return; StopMyShip(); Logging.Log(module, "Using Optimal Range: Stop ship, target at [" + Math.Round(target.Distance / 1000, 0) + "k away] is inside optimal", Logging.Teal); return; } } } else if (!Cache.Instance.InMission && Cache.Instance.OptimalRange != Settings.Instance.OptimalRange) { Cache.Instance.OptimalRange = Settings.Instance.OptimalRange; return; } else //if optimalrange is not set use MaxRange (shorter of weapons range and targeting range) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: using MaxRange [" + Cache.Instance.MaxRange + "] target is [" + target.Name + "][" + target.Distance + "]", Logging.White); if (target.Distance > Cache.Instance.MaxRange && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id)) { if (target.IsNPCFrigate && Cache.Instance.DoWeCurrentlyHaveTurretsMounted()) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + target.Distance + "]", Logging.White); OrbitGateorTarget(target, module); return; } target.Approach((int)(Cache.Instance.MaxRange * 0.8d)); Logging.Log(module, "Using Weapons Range * 0.8d [" + Math.Round(Cache.Instance.MaxRange * 0.8d / 1000, 0) + " k]: Approaching target [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); return; } //I think when approach distance will be reached ship will be stopped so this is not needed if (target.Distance <= Cache.Instance.MaxRange - 5000 && Cache.Instance.Approaching != null) { if (target.IsNPCFrigate && Cache.Instance.DoWeCurrentlyHaveTurretsMounted()) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + target.Distance + "]", Logging.White); OrbitGateorTarget(target, module); return; } if (Cache.Instance.MyShipEntity.Velocity != 0) StopMyShip(); Logging.Log(module, "Using Weapons Range: Stop ship, target is more than 5k inside weapons range", Logging.Teal); return; } if (target.Distance <= Cache.Instance.MaxRange && Cache.Instance.Approaching == null) { if (target.IsNPCFrigate && Cache.Instance.DoWeCurrentlyHaveTurretsMounted()) { if (Settings.Instance.DebugNavigateOnGrid) Logging.Log("NavigateOnGrid", "NavigateIntoRange: target is NPC Frigate [" + target.Name + "][" + target.Distance + "]", Logging.White); OrbitGateorTarget(target, module); return; } } } return; } } }
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 { ValidateCombatMissionSettings(); LastAction = DateTime.UtcNow; } return; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //this local is safe check is useless as their is no LocalWatch processstate running every tick... //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //If local unsafe go to base and do not start mission again if (Settings.Instance.FinishWhenNotSafe && (_States.CurrentDebugBehaviorState != DebugBehaviorState.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.CurrentDebugBehaviorState = DebugBehaviorState.GotoNearestStation; } else { Logging.Log("Local not safe", "Station not found. Going back to base", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.GotoBase; } Cache.Instance.StopBot = true; } } if (Cache.Instance.SessionState == "Quitting") { BeginClosingQuestor(); } if (Cache.Instance.GotoBaseNow) { _States.CurrentDebugBehaviorState = DebugBehaviorState.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.CurrentDebugBehaviorState :) _States.CurrentDebugBehaviorState = DebugBehaviorState.Panic; DebugDebugBehaviorStates(); 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.CurrentDebugBehaviorState = DebugBehaviorState.Idle; DebugDebugBehaviorStates(); } DebugPanicstates(); //Logging.Log("test"); switch (_States.CurrentDebugBehaviorState) { case DebugBehaviorState.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("DebugBehavior", "DebugIdle: StopBot [" + Cache.Instance.StopBot + "]", Logging.White); } return; } if (Cache.Instance.InSpace) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("DebugBehavior", "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("DebugBehavior", "Started questor while in space, heading back to base in 15 seconds", Logging.White); LastAction = DateTime.UtcNow; _States.CurrentDebugBehaviorState = DebugBehaviorState.DelayedGotoBase; break; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(10)) { if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle) { Logging.Log("DebugBehavior", "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("DebugBehavior", "Started questor in Debug mode", Logging.White); LastAction = DateTime.UtcNow; break; case DebugBehaviorState.DelayedGotoBase: if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.DelayedGotoBase_seconds) { break; } Logging.Log("DebugBehavior", "Heading back to base", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.GotoBase; break; case DebugBehaviorState.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.CurrentDebugBehaviorState = DebugBehaviorState.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.CurrentDebugBehaviorState = DebugBehaviorState.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.CurrentDebugBehaviorState = DebugBehaviorState.Idle; } break; case DebugBehaviorState.Salvage: if (!Cache.Instance.InSpace) { return; } Cache.Instance.SalvageAll = true; Cache.Instance.OpenWrecks = true; if (Cache.Instance.CurrentShipsCargo == null) { return; } if (Settings.Instance.UnloadLootAtStation && Cache.Instance.CurrentShipsCargo.Window.IsReady && (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()) { break; } //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 { ApplyDebugSettings(); } break; case DebugBehaviorState.GotoBase: if (Settings.Instance.DebugGotobase) { Logging.Log("DebugBehavior", "GotoBase: AvoidBumpingThings()", Logging.White); } AvoidBumpingThings(); if (Settings.Instance.DebugGotobase) { Logging.Log("DebugBehavior", "GotoBase: TravelToAgentsStation()", Logging.White); } Traveler.TravelHome("DebugBehavior.TravelHome"); if (_States.CurrentTravelerState == TravelerState.AtDestination) // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10) { if (Settings.Instance.DebugGotobase) { Logging.Log("DebugBehavior", "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.CurrentDebugBehaviorState = DebugBehaviorState.UnloadLoot; Traveler.Destination = null; } break; case DebugBehaviorState.UnloadLoot: if (_States.CurrentUnloadLootState == UnloadLootState.Idle) { Logging.Log("DebugBehavior", "UnloadLoot: Begin", Logging.White); _States.CurrentUnloadLootState = UnloadLootState.Begin; } _unloadLoot.ProcessState(); if (Settings.Instance.DebugStates) { Logging.Log("DebugBehavior", "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("DebugBehavior.UnloadLoot", "We are out of ammo", Logging.Orange); _States.CurrentDebugBehaviorState = DebugBehaviorState.Idle; return; } _States.CurrentDebugBehaviorState = DebugBehaviorState.Idle; Logging.Log("DebugBehavior.Unloadloot", "CharacterMode: [" + Settings.Instance.CharacterMode + "], AfterMissionSalvaging: [" + Settings.Instance.AfterMissionSalvaging + "], DebugBehaviorState: [" + _States.CurrentDebugBehaviorState + "]", Logging.White); Statistics.Instance.FinishedMission = DateTime.UtcNow; return; } break; case DebugBehaviorState.Traveler: 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("DebugBehavior.Traveler", "No destination?", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.Error; return; } if (destination.Count == 1 && destination.FirstOrDefault() == 0) { destination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1; } if (Traveler.Destination == null || Traveler.Destination.SolarSystemId != destination.Last()) { IEnumerable <DirectBookmark> bookmarks = Cache.Instance.AllBookmarks.Where(b => b.LocationId == destination.Last()).ToList(); if (bookmarks != null && bookmarks.Any()) { Traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault()); } else { Logging.Log("DebugBehavior.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("DebugBehavior.Traveler", "an error has occurred", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.Error; return; } else if (Cache.Instance.InSpace) { Logging.Log("DebugBehavior.Traveler", "Arrived at destination (in space, Questor stopped)", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.Error; return; } else { Logging.Log("DebugBehavior.Traveler", "Arrived at destination", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.Idle; return; } } } break; case DebugBehaviorState.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("DebugBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); _States.CurrentDebugBehaviorState = DebugBehaviorState.Idle; break; } break; } else { if (station.Distance < 1900) { if (station.Dock()) { Logging.Log("DebugBehavior.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)) { Cache.Instance.NextApproachAction = DateTime.UtcNow.AddSeconds(Time.Instance.ApproachDelay_seconds); Logging.Log("DebugBehavior.GotoNearestStation", "Approaching [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White); station.Approach(); } } } } else { _States.CurrentDebugBehaviorState = DebugBehaviorState.Error; //should we goto idle here? } break; case DebugBehaviorState.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 DebugBehaviorState.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 DebugBehaviorState.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 DebugBehaviorState.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 DebugBehaviorState.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 DebugBehaviorState.LogCansAndWrecks: //Asteroid Belts List <EntityCache> cansandWrecksInList = Cache.Instance.EntitiesOnGrid.Where(e => !e.IsSentry && e.GroupId == (int)Group.CargoContainer && e.GroupId == (int)Group.Wreck).ToList(); Statistics.EntityStatistics(cansandWrecksInList); Cache.Instance.Paused = true; break; case DebugBehaviorState.Default: _States.CurrentDebugBehaviorState = DebugBehaviorState.Idle; break; } }
/// <summary> /// Navigate to a solar system /// </summary> /// <param name = "solarSystemId"></param> private static void NavigateToBookmarkSystem(long solarSystemId) { if (_nextTravelerAction > DateTime.UtcNow) { //Logging.Log("Traveler: will continue in [ " + Math.Round(_nextTravelerAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + " ]sec"); return; } if (DateTime.UtcNow < Cache.Instance.LastSessionChange.AddSeconds(10)) { if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "We just session changed less than 10 sec go, wait.", Logging.Teal); } _nextTravelerAction = Cache.Instance.LastSessionChange.AddSeconds(12); return; } Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2); if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "NavigateToBookmarkSystem - Iterating- next iteration should be in no less than [1] second ", Logging.Teal); } _destinationRoute = Cache.Instance.DirectEve.Navigation.GetDestinationPath(); if (_destinationRoute.Count == 0 || _destinationRoute.All(d => d != solarSystemId)) { if (Settings.Instance.DebugTraveler) { if (_destinationRoute.Count == 0) { Logging.Log("Traveler", "We have no destination", Logging.Teal); } } if (Settings.Instance.DebugTraveler) { if (_destinationRoute.All(d => d != solarSystemId)) { Logging.Log("Traveler", "the destination is not currently set to solarsystemId [" + solarSystemId + "]", Logging.Teal); } } // We do not have the destination set if (DateTime.UtcNow > _nextGetLocation || _location == null) { if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "NavigateToBookmarkSystem: getting Location of solarSystemId [" + solarSystemId + "]", Logging.Teal); } _nextGetLocation = DateTime.UtcNow.AddSeconds(10); _location = Cache.Instance.DirectEve.Navigation.GetLocation(solarSystemId); Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(2); return; } if (_location.IsValid) { _locationErrors = 0; Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Green); if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "Setting destination to [" + Logging.Yellow + _location.Name + Logging.Green + "]", Logging.Teal); } try { _location.SetDestination(); } catch (Exception) { Logging.Log("Traveler", "NavigateToBookmarkSystem: set destination to [" + _location.ToString() + "] failed ", Logging.Debug); } Cache.Instance.NextTravelerAction = DateTime.UtcNow.AddSeconds(3); return; } Logging.Log("Traveler", "Error setting solar system destination [" + Logging.Yellow + solarSystemId + Logging.Green + "]", Logging.Green); _locationErrors++; if (_locationErrors > 20) { _States.CurrentTravelerState = TravelerState.Error; return; } return; } _locationErrors = 0; if (!Cache.Instance.InSpace) { if (Cache.Instance.InStation) { 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) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation); _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerExitStationAmIInSpaceYet_seconds); } } Cache.Instance.NextActivateSupportModules = DateTime.UtcNow.AddSeconds(Cache.Instance.RandomNumber(2, 3)); // We are not yet in space, wait for it return; } // We are apparently not really in space yet... if (Cache.Instance.ActiveShip == null || Cache.Instance.ActiveShip.Entity == null) { return; } //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "Destination is set: processing...", Logging.Teal); // Find the first waypoint int waypoint = _destinationRoute.FirstOrDefault(); //if (Settings.Instance.DebugTraveler) Logging.Log("Traveler", "NavigateToBookmarkSystem: getting next way-points locationName", Logging.Teal); _locationName = Cache.Instance.DirectEve.Navigation.GetLocationName(waypoint); if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "]", Logging.Teal); } if (waypoint > 60000000) // this MUST be a station { //insert code to handle station destinations here } if (waypoint < 60000000) // this is not a station, probably a system { //useful?a } DirectSolarSystem solarSystemInRoute = Cache.Instance.DirectEve.SolarSystems[waypoint]; if (_States.CurrentQuestorState == QuestorState.CombatMissionsBehavior || _States.CurrentQuestorState == QuestorState.DedicatedBookmarkSalvagerBehavior) { if (solarSystemInRoute.Security < 0.45 && (Cache.Instance.ActiveShip.GroupId != (int)Group.Shuttle || Cache.Instance.ActiveShip.GroupId != (int)Group.Frigate || Cache.Instance.ActiveShip.GroupId != (int)Group.Interceptor)) { Logging.Log("Traveler", "NavigateToBookmarkSystem: Next Waypoint is: [" + _locationName + "] which is LOW SEC! This should never happen. Turning off AutoStart and going home.", Logging.Teal); Settings.Instance.AutoStart = false; if (_States.CurrentQuestorState == QuestorState.CombatMissionsBehavior) { _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.GotoBase; } if (_States.CurrentQuestorState == QuestorState.DedicatedBookmarkSalvagerBehavior) { _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase; } //if (_States.CurrentQuestorState == QuestorState.CombatHelperBehavior) //{ // _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase; //} return; } } // Find the stargate associated with it if (!Cache.Instance.Stargates.Any()) { // not found, that cant be true?!?!?!?! Logging.Log("Traveler", "Error [" + Logging.Yellow + _locationName + Logging.Green + "] not found, most likely lag waiting [" + Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds + "] seconds.", Logging.Red); _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.TravelerNoStargatesFoundRetryDelay_seconds); return; } // Warp to, approach or jump the stargate EntityCache MyNextStargate = Cache.Instance.StargateByName(_locationName); if (MyNextStargate != null) { if (MyNextStargate.Distance < (int)Distances.DecloakRange && !Cache.Instance.ActiveShip.Entity.IsCloaked) { if (MyNextStargate.Jump()) { Logging.Log("Traveler", "Jumping to [" + Logging.Yellow + _locationName + Logging.Green + "]", Logging.Green); return; } return; } if (MyNextStargate.Distance < (int)Distances.WarptoDistance && MyNextStargate.Distance != 0) { if (DateTime.UtcNow > Cache.Instance.NextApproachAction && !Cache.Instance.IsApproaching(MyNextStargate.Id)) { if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "NavigateToBookmarkSystem: approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal); } MyNextStargate.Approach(); //you could use a negative approach distance here but ultimately that is a bad idea.. Id like to go toward the entity without approaching it so we would end up inside the docking ring (eventually) return; } if (Settings.Instance.DebugTraveler) { Logging.Log("Traveler", "NavigateToBookmarkSystem: we are already approaching the stargate named [" + MyNextStargate.Name + "]", Logging.Teal); } return; } if (Cache.Instance.InSpace && !Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe)) { if (MyNextStargate.WarpTo()) { Logging.Log("Traveler", "Warping to [" + Logging.Yellow + _locationName + Logging.Green + "][" + Logging.Yellow + Math.Round((MyNextStargate.Distance / 1000) / 149598000, 2) + Logging.Green + " AU away]", Logging.Green); return; } return; } } _nextTravelerAction = DateTime.UtcNow.AddSeconds(Time.Instance.WarptoDelay_seconds); //this should probably use a different Time definition, but this works for now. (5 seconds) if (!Combat.ReloadAll(Cache.Instance.MyShipEntity)) { return; } return; }
internal static bool PerformFinalDestinationTask(long stationId, string stationName) { if (Cache.Instance.InStation && Cache.Instance.DirectEve.Session.StationId == stationId) { Logging.Log("TravelerDestination.StationDestination", "Arrived in station", Logging.Green); return(true); } if (Cache.Instance.InStation && DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(10)) { // We are in a station, but not the correct station! if (DateTime.UtcNow > Cache.Instance.NextUndockAction) { TravelerDestination.Undock(); return(false); } // We are not there yet return(false); } if ((DateTime.UtcNow > Cache.Instance.LastInStation.AddSeconds(10)) && !Cache.Instance.InSpace) { // We are not in station and not in space? Wait for a bit return(false); } if (_nextTravelerDestinationAction > DateTime.UtcNow) { return(false); } _undockAttempts = 0; if (!useInstaBookmark()) { return(false); } //else Logging.Log("TravelerDestination.BookmarkDestination","undock bookmark missing: " + Cache.Instance.DirectEve.GetLocationName((long)Cache.Instance.DirectEve.Session.StationId) + " and " + Settings.Instance.UndockPrefix + " did not both exist in a bookmark"); if (Cache.Instance.Stations == null) { // We are there but no stations? Wait a bit return(false); } EntityCache station = Cache.Instance.EntitiesByName(stationName, Cache.Instance.Stations).FirstOrDefault(); if (station == null) { // We are there but no station? Wait a bit return(false); } if (station.Distance < (int)Distances.DockingRange) { if (station.Dock()) { Logging.Log("TravelerDestination.StationDestination", "Dock at [" + Logging.Yellow + station.Name + Logging.Green + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.Green); return(false); //we do not return true until we actually appear in the destination (station in this case) } return(false); } if (station.Distance < (int)Distances.WarptoDistance) { if (DateTime.UtcNow > Cache.Instance.NextApproachAction) { Logging.Log("TravelerDestination.StationDestination", "Approaching[" + Logging.Yellow + station.Name + Logging.Green + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.Green); station.Approach(); return(false); } return(false); } if (station.WarpTo()) { Logging.Log("TravelerDestination.StationDestination", "Warp to and dock at [" + Logging.Yellow + station.Name + Logging.Green + "][" + Math.Round((station.Distance / 1000) / 149598000, 2) + " AU away]", Logging.Green); return(false); } return(false); }