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
                {
                    ValidateDedicatedSalvageSettings();
                    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.CurrentDedicatedBookmarkSalvagerBehaviorState != DedicatedBookmarkSalvagerBehaviorState.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.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoNearestStation;
                    }
                    else
                    {
                        Logging.Log("Local not safe", "Station not found. Going back to base", Logging.White);
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                    }
                    Cache.Instance.StopBot = true;
                }
            }

            if (Cache.Instance.SessionState == "Quitting")
            {
                BeginClosingQuestor();
            }

            if (Cache.Instance.GotoBaseNow)
            {
                _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.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)
            {
                DebugDedicatedBookmarkSalvagerBehaviorStates();
                if (PanicStateReset)
                {
                    _States.CurrentPanicState = PanicState.Normal;
                    PanicStateReset           = false;
                }
            }
            else if (_States.CurrentPanicState == PanicState.Resume)
            {
                // Reset panic state
                _States.CurrentPanicState = PanicState.Normal;
            }
            DebugPanicstates();

            switch (_States.CurrentDedicatedBookmarkSalvagerBehaviorState)
            {
            case DedicatedBookmarkSalvagerBehaviorState.Idle:

                if (Cache.Instance.StopBot)
                {
                    return;
                }

                _States.CurrentAgentInteractionState = AgentInteractionState.Idle;
                _States.CurrentArmState        = ArmState.Idle;
                _States.CurrentDroneState      = DroneState.Idle;
                _States.CurrentSalvageState    = SalvageState.Idle;
                _States.CurrentStorylineState  = StorylineState.Idle;
                _States.CurrentTravelerState   = TravelerState.Idle;
                _States.CurrentUnloadLootState = UnloadLootState.Idle;
                _States.CurrentTravelerState   = TravelerState.AtDestination;

                if (Cache.Instance.InSpace)
                {
                    // Questor does not handle in space starts very well, head back to base to try again
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "Started questor while in space, heading back to base in 15 seconds", Logging.White);
                    LastAction = DateTime.UtcNow;
                    Cache.Instance.NextSalvageTrip = DateTime.UtcNow;
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.CheckBookmarkAge;
                    break;
                }

                // only attempt to write the mission statistics logs if one of the mission stats logs is enabled in settings
                //if (Settings.Instance.SalvageStats1Log)
                //{
                //    if (!Statistics.Instance.SalvageLoggingCompleted)
                //    {
                //        Statistics.WriteSalvagerStatistics();
                //        break;
                //    }
                //}

                if (Settings.Instance.AutoStart)
                {
                    //we know we are connected here
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;

                    // Don't start a new action an hour before downtime
                    if (DateTime.UtcNow.Hour == 10)
                    {
                        if (Settings.Instance.DebugAutoStart)
                        {
                            Logging.Log("DedicatedBookmarkSalvagerBehavior", "Autostart: if (DateTime.UtcNow.Hour == 10)", Logging.White);
                        }
                        break;
                    }

                    // Don't start a new action near downtime
                    if (DateTime.UtcNow.Hour == 11 && DateTime.UtcNow.Minute < 15)
                    {
                        if (Settings.Instance.DebugAutoStart)
                        {
                            Logging.Log("DedicatedBookmarkSalvagerBehavior", "if (DateTime.UtcNow.Hour == 11 && DateTime.UtcNow.Minute < 15)", Logging.White);
                        }
                        break;
                    }

                    //Logging.Log("DedicatedBookmarkSalvagerBehavior::: _nextBookmarksrefresh.subtract(DateTime.UtcNow).totalminutes [" +
                    //            Math.Round(DateTime.UtcNow.Subtract(_nextBookmarkRefreshCheck).TotalMinutes,0) + "]");

                    //Logging.Log("DedicatedBookmarkSalvagerBehavior::: Next Salvage Trip Scheduled in [" +
                    //            _Cache.Instance.NextSalvageTrip.ToString(CultureInfo.InvariantCulture) + "min]");

                    if (DateTime.UtcNow > _nextBookmarkRefreshCheck)
                    {
                        _nextBookmarkRefreshCheck = DateTime.UtcNow.AddMinutes(1);
                        if (Cache.Instance.InStation && (DateTime.UtcNow > _nextBookmarksrefresh))
                        {
                            _nextBookmarksrefresh = DateTime.UtcNow.AddMinutes(Cache.Instance.RandomNumber(18, 24));
                            Logging.Log("DedicatedBookmarkSalvagerBehavior", "Next Bookmark refresh in [" +
                                        Math.Round(_nextBookmarksrefresh.Subtract(DateTime.UtcNow).TotalMinutes, 0) + "min]", Logging.White);
                            Cache.Instance.DirectEve.RefreshBookmarks();
                        }
                        else
                        {
                            Logging.Log("DedicatedBookmarkSalvagerBehavior", "Next Bookmark refresh in [" +
                                        Math.Round(_nextBookmarksrefresh.Subtract(DateTime.UtcNow).TotalMinutes, 0) + "min]", Logging.White);

                            Logging.Log("DedicatedBookmarkSalvagerBehavior", "Next Salvage Trip Scheduled in [" +
                                        Math.Round(Cache.Instance.NextSalvageTrip.Subtract(DateTime.UtcNow).TotalMinutes, 0) + "min]", Logging.White);
                        }
                    }

                    if (DateTime.UtcNow > Cache.Instance.NextSalvageTrip)
                    {
                        Logging.Log("DedicatedBookmarkSalvagerBehavior.BeginAftermissionSalvaging", "Starting Another Salvage Trip", Logging.White);
                        LastAction = DateTime.UtcNow;
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Start;
                        return;
                    }
                }
                else
                {
                    Cache.Instance.LastScheduleCheck = DateTime.UtcNow;
                    Questor.TimeCheck();       //Should we close questor due to stoptime or runtime?
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.DelayedGotoBase:
                if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.DelayedGotoBase_seconds)
                {
                    break;
                }

                Logging.Log("DedicatedBookmarkSalvagerBehavior", "Heading back to base", Logging.White);
                _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                break;

            case DedicatedBookmarkSalvagerBehaviorState.Start:
                Cache.Instance.OpenWrecks = true;
                ValidateDedicatedSalvageSettings();
                _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.UnloadLoot;
                break;

            case DedicatedBookmarkSalvagerBehaviorState.LocalWatch:
                if (Settings.Instance.UseLocalWatch)
                {
                    Cache.Instance.LastLocalWatchAction = DateTime.UtcNow;
                    if (Cache.Instance.LocalSafe(Settings.Instance.LocalBadStandingPilotsToTolerate, Settings.Instance.LocalBadStandingLevelToConsiderBad))
                    {
                        Logging.Log("DedicatedBookmarkSalvagerBehavior.LocalWatch", "local is clear", Logging.White);
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.BeginAfterMissionSalvaging;
                    }
                    else
                    {
                        Logging.Log("DedicatedBookmarkSalvagerBehavior.LocalWatch", "Bad standings pilots in local: We will stay 5 minutes in the station and then we will check if it is clear again", Logging.White);
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.WaitingforBadGuytoGoAway;
                        Cache.Instance.LastKnownGoodConnectedTime             = DateTime.UtcNow;
                        Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth;
                    }
                }
                else
                {
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.BeginAfterMissionSalvaging;
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.WaitingforBadGuytoGoAway:
                Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;
                if (DateTime.UtcNow.Subtract(Cache.Instance.LastLocalWatchAction).TotalMinutes < Time.Instance.WaitforBadGuytoGoAway_minutes)
                {
                    //TODO: add debug logging here
                    break;
                }
                _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.LocalWatch;
                break;

            case DedicatedBookmarkSalvagerBehaviorState.GotoBase:
                Cache.Instance.CurrentlyShouldBeSalvaging = false;
                if (Settings.Instance.DebugGotobase)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "GotoBase: AvoidBumpingThings()", Logging.White);
                }
                NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjects.FirstOrDefault(), "DedicatedBookmarkSalvagerBehaviorState.GotoBase");
                if (Settings.Instance.DebugGotobase)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "GotoBase: Traveler.TravelHome()", Logging.White);
                }
                Traveler.TravelHome("DedicatedBookmarkSalvagerBehavior");

                if (_States.CurrentTravelerState == TravelerState.AtDestination)     // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10)
                {
                    if (Settings.Instance.DebugGotobase)
                    {
                        Logging.Log("DedicatedBookmarkSalvagerBehavior", "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.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.UnloadLoot;
                    Traveler.Destination = null;
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.UnloadLoot:
                if (_States.CurrentUnloadLootState == UnloadLootState.Idle)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "UnloadLoot: Begin", Logging.White);
                    _States.CurrentUnloadLootState = UnloadLootState.Begin;
                }

                _unloadLoot.ProcessState();

                if (Settings.Instance.DebugStates)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "UnloadLoot.State = " + _States.CurrentUnloadLootState, Logging.White);
                }

                if (_States.CurrentUnloadLootState == UnloadLootState.Done)
                {
                    Cache.Instance.LootAlreadyUnloaded = true;
                    _States.CurrentUnloadLootState     = UnloadLootState.Idle;
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.CheckBookmarkAge;
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.CheckBookmarkAge:

                if (DateTime.UtcNow >= Cache.Instance.NextSalvageTrip || Cache.Instance.InSpace)
                {
                    if (Cache.Instance.GetSalvagingBookmark == null)
                    {
                        BookmarksThatAreNotReadyYet = Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " ");
                        if (BookmarksThatAreNotReadyYet != null && BookmarksThatAreNotReadyYet.Any())
                        {
                            Logging.Log("DedicatedBookmarkSalvagerBehavior", "CheckBookmarkAge: There are [" + BookmarksThatAreNotReadyYet.Count() + "] Salvage Bookmarks that have not yet aged [" + Settings.Instance.AgeofBookmarksForSalvageBehavior + "] min.", Logging.White);
                        }
                        Logging.Log("DedicatedBookmarkSalvagerBehavior", "CheckBookmarkAge: Character mode is BookmarkSalvager and no bookmarks are ready to salvage.", Logging.White);

                        //We just need a NextSalvagerSession timestamp to key off of here to add the delay
                        if (Cache.Instance.InSpace)
                        {
                            // Questor does not handle in space starts very well, head back to base to try again
                            LastAction = DateTime.UtcNow;
                            Cache.Instance.NextSalvageTrip = DateTime.UtcNow.AddMinutes(Time.Instance.DelayBetweenSalvagingSessions_minutes);
                            _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                            break;
                        }

                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Idle;
                        _States.CurrentQuestorState    = QuestorState.Idle;
                        Cache.Instance.NextSalvageTrip = DateTime.UtcNow.AddMinutes(Time.Instance.DelayBetweenSalvagingSessions_minutes);

                        break;
                    }

                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "CheckBookmarkAge: There are [ " + Cache.Instance.AfterMissionSalvageBookmarks.Count() + " ] more salvage bookmarks older then:" + Cache.Instance.AgedDate.ToString(CultureInfo.InvariantCulture) + ", left to process", Logging.White);
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.BeginAfterMissionSalvaging;
                    Statistics.Instance.StartedSalvaging = DateTime.UtcNow;
                }
                else
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "CheckBookmarkAge: next salvage timer not expired. Waiting...", Logging.White);
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Idle;
                    _States.CurrentQuestorState = QuestorState.Idle;
                    return;
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.BeginAfterMissionSalvaging:

                if (DateTime.UtcNow > Statistics.Instance.StartedSalvaging.AddMinutes(2))
                {
                    Logging.Log("DedicatedBookmarkSalvagebehavior", "Found [" + Cache.Instance.AfterMissionSalvageBookmarks.Count() + "] salvage bookmarks ready to process.", Logging.White);
                    Statistics.Instance.StartedSalvaging = DateTime.UtcNow;     //this will be reset for each "run" between the station and the field if using <unloadLootAtStation>true</unloadLootAtStation>
                    Cache.Instance.NextSalvageTrip       = DateTime.UtcNow.AddMinutes(Time.Instance.DelayBetweenSalvagingSessions_minutes);
                }
                //we know we are connected here
                Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;

                Cache.Instance.OpenWrecks = true;
                if (Cache.Instance.InStation)
                {
                    if (_States.CurrentArmState == ArmState.Idle)
                    {
                        _States.CurrentArmState = ArmState.SwitchToSalvageShip;
                    }

                    Arm.ProcessState();
                }
                if (_States.CurrentArmState == ArmState.Done || Cache.Instance.InSpace)
                {
                    _States.CurrentArmState = ArmState.Idle;

                    if (_afterMissionSalvageBookmarks == null || Cache.Instance.InStation)
                    {
                        _afterMissionSalvageBookmarks = Cache.Instance.AfterMissionSalvageBookmarks.OrderBy(b => b.CreatedOn).ToList();
                    }

                    _afterMissionSalvageBookmarks = _afterMissionSalvageBookmarks.OrderBy(b => b.CreatedOn).ToList();
                    if (DateTime.UtcNow < Cache.Instance.LastAccelerationGateDetected.AddSeconds(10))     //long enough that the timer should expire if we have to warp even small distances to the next bm
                    {
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                        Cache.Instance.NextSalvageTrip = DateTime.UtcNow.AddMinutes(Time.Instance.DelayBetweenSalvagingSessions_minutes);
                        return;

                        //Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvager", "There is a gate on grid with us: deferring processing any bookmarks within CloseRangeScan because those are likely behind this gate and might have NPCs still there", Logging.White);
                        //_afterMissionSalvageBookmarks = new List<DirectBookmark>(_afterMissionSalvageBookmarks.Where(b => Cache.Instance.DistanceFromMe(b.X ?? 0, b.Y ?? 0, b.Z ?? 0) > (int)Distance.DirectionalScannerCloseRange)).OrderBy(b => b.CreatedOn).ToList();

                        //int i = 1;
                        //Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvager", "Listing bookmarks in: _afterMissionSalvageBookmarks, they should be all more than CloseRangeScan [" + Distance.DirectionalScannerCloseRange + "] away.", Logging.Red);
                        //foreach (var bm in _afterMissionSalvageBookmarks)
                        //{
                        //    Logging.Log("", "[" + i + "] BM Name: [" + bm.Title + "]" + "] Distance: [" + Cache.Instance.DistanceFromMe(bm.X ?? 0, bm.Y ?? 0, bm.Z ?? 0) + "]", Logging.Red);
                        //    i++;
                        //}

                        //if (_afterMissionSalvageBookmarks.Any())
                        //{
                        //    Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvager", "_afterMissionSalvageBookmarks contains [" + _afterMissionSalvageBookmarks.Count() + "] bookmarks", Logging.White);
                        //}
                        //else
                        //{
                        //    Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvager", "_afterMissionSalvageBookmarks contains [ Zero ] bookmarks", Logging.White);
                        //    Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvager", "AfterMissionSalvageBookmarks (including BMs we cant process yet) contains [" + Cache.Instance.AfterMissionSalvageBookmarks + "]", Logging.White);
                        //}
                    }

                    DirectBookmark bookmark = _afterMissionSalvageBookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault();

                    if (bookmark == null)
                    {
                        _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                        Cache.Instance.NextSalvageTrip = DateTime.UtcNow.AddMinutes(Time.Instance.DelayBetweenSalvagingSessions_minutes);
                        return;
                    }
                    Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvager", "Salvaging at first oldest bookmarks created on: " + bookmark.CreatedOn.ToString(), Logging.White);

                    List <DirectBookmark> bookmarksInLocal = new List <DirectBookmark>(_afterMissionSalvageBookmarks.Where(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId).
                                                                                       OrderBy(b => b.CreatedOn));
                    DirectBookmark localBookmark = bookmarksInLocal.FirstOrDefault();
                    if (localBookmark != null)
                    {
                        Traveler.Destination = new BookmarkDestination(localBookmark);
                    }
                    else
                    {
                        Traveler.Destination = new BookmarkDestination(bookmark);
                    }
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoSalvageBookmark;

                    //we know we are connected here
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.LastInWarp      = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth;
                    return;
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.GotoSalvageBookmark:
                Traveler.ProcessState();
                if (Cache.Instance.GateInGrid())
                {
                    //Logging.Log("DedicatedBookmarkSalvagerBehavior", "GotoSalvageBookmark: We found gate in salvage bookmark. Going back to Base", Logging.White);
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "GotoSalvageBookmark: We found gate in salvage bookmark. Skipping this bookmark.", Logging.White);
                    Cache.Instance.LastAccelerationGateDetected = DateTime.UtcNow;

                    //we know we are connected here
                    Cache.Instance.LastKnownGoodConnectedTime             = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance                        = Cache.Instance.DirectEve.Me.Wealth;
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.BeginAfterMissionSalvaging;
                    Traveler.Destination           = null;
                    Cache.Instance.NextSalvageTrip = DateTime.UtcNow.AddMinutes(Time.Instance.DelayBetweenSalvagingSessions_minutes);
                    return;
                }

                if (_States.CurrentTravelerState == TravelerState.AtDestination)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "GotoSalvageBookmark: Gate not found, we can start salvaging", Logging.White);

                    //we know we are connected here
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;
                    Cache.Instance.LastInWarp = DateTime.UtcNow;

                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Salvage;
                    Traveler.Destination = null;
                    return;
                }

                if (Settings.Instance.DebugStates)
                {
                    Logging.Log("Traveler.State is ", _States.CurrentTravelerState.ToString(), Logging.White);
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.Salvage:
                if (Settings.Instance.DebugSalvage)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "salvage::: attempting to open cargo hold", Logging.White);
                }
                if (Cache.Instance.CurrentShipsCargo == null)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "salvage:: if (Cache.Instance.CurrentShipsCargo == null)", Logging.Teal);
                    return;
                }

                if (Settings.Instance.DebugSalvage)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "salvage::: done opening cargo hold", Logging.White);
                }
                Cache.Instance.SalvageAll = true;
                Cache.Instance.OpenWrecks = true;
                Cache.Instance.CurrentlyShouldBeSalvaging = true;

                const int distanceToCheck = (int)Distances.OnGridWithMe;

                // is there any NPCs within distanceToCheck?
                EntityCache deadlyNPC = Cache.Instance.EntitiesOnGrid.Where(t => t.Distance < distanceToCheck && !t.IsEntityIShouldLeaveAlone && !t.IsContainer && t.IsNpc && t.CategoryId == (int)CategoryID.Entity && !t.IsLargeCollidable).OrderBy(t => t.Distance).FirstOrDefault();

                if (deadlyNPC != null)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior.Salvage", "Npc name:[" + deadlyNPC.Name + "] with groupId:[" + deadlyNPC.GroupId + "].", Logging.White);

                    // found NPCs that will likely kill out fragile salvage boat!

                    DirectBookmark bookmark = Cache.Instance.AfterMissionSalvageBookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault();
                    if (bookmark != null)
                    {
                        Cache.Instance.DeleteBookmarksOnGrid("DedicatedBookmarkSalvageBehavior");
                        return;
                    }

                    Statistics.Instance.FinishedSalvaging = DateTime.UtcNow;
                    Cache.Instance.NextSalvageTrip        = DateTime.UtcNow;
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                    return;
                }

                if (Cache.Instance.CurrentShipsCargo.IsValid && (Cache.Instance.CurrentShipsCargo.Capacity - Cache.Instance.CurrentShipsCargo.UsedCapacity) < Settings.Instance.ReserveCargoCapacity + 10)
                {
                    Logging.Log("DedicatedBookmarkSalvageBehavior.Salvage", "We are full, go to base to unload", Logging.White);
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                    break;
                }
                else if (Cache.Instance.CurrentShipsCargo.IsValid)
                {
                    if (Settings.Instance.DebugSalvage)
                    {
                        Logging.Log("DedicatedSalvager", "CurrentCapacity [" + Cache.Instance.CurrentShipsCargo.Capacity + "] UsedCapacity [" + Cache.Instance.CurrentShipsCargo.UsedCapacity + "][" + Settings.Instance.ReserveCargoCapacity + "]", Logging.Debug);
                    }
                }

                if (!Cache.Instance.UnlootedContainers.Any())
                {
                    if (!Cache.Instance.DeleteBookmarksOnGrid("DedicatedBookmarkSalvageBehavior"))
                    {
                        return;
                    }
                    // this can eventually be moved to somewhere else like unloadloot BUT...
                    // that will mean keeping track of bookmarks we delete and such in this local list.
                    _afterMissionSalvageBookmarks = Cache.Instance.AfterMissionSalvageBookmarks.OrderBy(b => b.CreatedOn).ToList();

                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.CheckBookmarkAge;
                    return;
                }

                if (DateTime.UtcNow > Cache.Instance.LastInWarp.AddMinutes(20))
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "It has been over 20 min since we were last in warp. Assuming something went wrong: setting GoToBase", Logging.Orange);
                    _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.GotoBase;
                    return;
                }

                if (Settings.Instance.DebugSalvage)
                {
                    Logging.Log("DedicatedBookmarkSalvagerBehavior", "salvage: we have more wrecks to salvage", Logging.White);
                }
                //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
                {
                    ApplySalvageSettings();
                }
                break;

            case DedicatedBookmarkSalvagerBehaviorState.Default:
                _States.CurrentDedicatedBookmarkSalvagerBehaviorState = DedicatedBookmarkSalvagerBehaviorState.Idle;
                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;
            }
        }
示例#3
0
        public void ProcessState()
        {
            // Invalid settings, quit while we're ahead
            if (!ValidSettings)
            {
                if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.ValidateSettings_seconds) //default is a 15 second interval
                {
                    Logging.Log("CombatHelperBehavior", "Invalid Settings: Running ValidateCombatMissionSettings();", Logging.Orange);
                    ValidateCombatMissionSettings();
                    LastAction = DateTime.UtcNow;
                }
                return;
            }

            if (Settings.Instance.FinishWhenNotSafe && (_States.CurrentCombatHelperBehaviorState != CombatHelperBehaviorState.GotoNearestStation /*|| State!=QuestorState.GotoBase*/))
            {
                //need to remove spam
                if (Cache.Instance.InSpace && !Cache.Instance.LocalSafe(Settings.Instance.LocalBadStandingPilotsToTolerate, Settings.Instance.LocalBadStandingLevelToConsiderBad))
                {
                    EntityCache station = null;
                    if (Cache.Instance.Stations != null && Cache.Instance.Stations.Any())
                    {
                        station = Cache.Instance.Stations.OrderBy(x => x.Distance).FirstOrDefault();
                    }

                    if (station != null)
                    {
                        Logging.Log("Local not safe", "Station found. Going to nearest station", Logging.White);
                        _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoNearestStation;
                    }
                    else
                    {
                        Logging.Log("Local not safe", "Station not found. Going back to base", Logging.White);
                        _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase;
                    }
                    Cache.Instance.StopBot = true;
                }
            }

            if (Cache.Instance.SessionState == "Quitting")
            {
                BeginClosingQuestor();
            }

            if (Cache.Instance.GotoBaseNow)
            {
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase;
            }

            if ((DateTime.UtcNow.Subtract(Cache.Instance.QuestorStarted_DateTime).TotalSeconds > 10) && (DateTime.UtcNow.Subtract(Cache.Instance.QuestorStarted_DateTime).TotalSeconds < 60))
            {
                if (Cache.Instance.QuestorJustStarted)
                {
                    Cache.Instance.QuestorJustStarted = false;
                    Cache.Instance.SessionState       = "Starting Up";

                    // write session log
                    Statistics.WriteSessionLogStarting();
                }
            }

            //
            // Panic always runs, not just in space
            //
            DebugPerformanceClearandStartTimer();
            _panic.ProcessState();
            DebugPerformanceStopandDisplayTimer("Panic.ProcessState");
            if (_States.CurrentPanicState == PanicState.Panic || _States.CurrentPanicState == PanicState.Panicking)
            {
                // If Panic is in panic state, questor is in panic States.CurrentCombatHelperBehaviorState :)
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Panic;

                DebugCombatHelperBehaviorStates();
                if (PanicStateReset)
                {
                    _States.CurrentPanicState = PanicState.Normal;
                    PanicStateReset           = false;
                }
            }
            else if (_States.CurrentPanicState == PanicState.Resume)
            {
                // Reset panic state
                _States.CurrentPanicState = PanicState.Normal;

                // Sit Idle and wait for orders.
                _States.CurrentTravelerState             = TravelerState.Idle;
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle;

                DebugCombatHelperBehaviorStates();
            }
            DebugPanicstates();

            //
            // the slave processstate is meant to override any CombatHelper behavior (it is after all meant to help the master kill things)
            //
            //_slave.ProcessState();
            //
            // done with slave process state
            //

            //Logging.Log("test");
            switch (_States.CurrentCombatHelperBehaviorState)
            {
            case CombatHelperBehaviorState.Idle:

                if (Cache.Instance.StopBot)
                {
                    //
                    // this is used by the 'local is safe' routines - standings checks - at the moment is stops questor for the rest of the session.
                    //
                    if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle)
                    {
                        Logging.Log("CombatHelperBehavior", "DebugIdle: StopBot [" + Cache.Instance.StopBot + "]", Logging.White);
                    }
                    return;
                }

                if (Cache.Instance.InSpace)
                {
                    if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle)
                    {
                        Logging.Log("CombatHelperBehavior", "DebugIdle: InSpace [" + Cache.Instance.InSpace + "]", Logging.White);
                    }

                    // Questor does not handle in space starts very well, head back to base to try again
                    Logging.Log("CombatHelperBehavior", "Started questor while in space, heading back to base in 15 seconds", Logging.White);
                    LastAction = DateTime.UtcNow;
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.DelayedGotoBase;
                    break;
                }

                if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(10))
                {
                    if (Settings.Instance.DebugAutoStart || Settings.Instance.DebugIdle)
                    {
                        Logging.Log("CombatHelperBehavior", "DebugIdle: Cache.Instance.LastInSpace [" + Cache.Instance.LastInSpace.Subtract(DateTime.UtcNow).TotalSeconds + "] sec ago, waiting until we have been docked for 10+ seconds", Logging.White);
                    }
                    return;
                }

                _States.CurrentArmState        = ArmState.Idle;
                _States.CurrentDroneState      = DroneState.Idle;
                _States.CurrentSalvageState    = SalvageState.Idle;
                _States.CurrentTravelerState   = TravelerState.Idle;
                _States.CurrentUnloadLootState = UnloadLootState.Idle;
                _States.CurrentTravelerState   = TravelerState.Idle;

                Logging.Log("CombatHelperBehavior", "Started questor in Combat Helper mode", Logging.White);
                LastAction = DateTime.UtcNow;
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper;
                break;

            case CombatHelperBehaviorState.DelayedGotoBase:
                if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.DelayedGotoBase_seconds)
                {
                    break;
                }

                Logging.Log("CombatHelperBehavior", "Heading back to base", Logging.White);
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase;
                break;

            case CombatHelperBehaviorState.Arm:
                //
                // only used when someone manually selects the arm state.
                //
                if (_States.CurrentArmState == ArmState.Idle)
                {
                    Logging.Log("Arm", "Begin", Logging.White);
                    _States.CurrentArmState = ArmState.Begin;

                    // Load right ammo based on mission
                    Arm.AmmoToLoad.Clear();
                    Arm.LoadSpecificAmmo(new[] { Cache.Instance.MissionDamageType });
                }

                Arm.ProcessState();

                if (Settings.Instance.DebugStates)
                {
                    Logging.Log("Arm.State", "is" + _States.CurrentArmState, Logging.White);
                }

                if (_States.CurrentArmState == ArmState.NotEnoughAmmo)
                {
                    // we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime
                    // we may be out of drones/ammo but disconnecting/reconnecting will not fix that so update the timestamp
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;
                    Logging.Log("Arm", "Armstate.NotEnoughAmmo", Logging.Orange);
                    _States.CurrentArmState = ArmState.Idle;
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error;
                }

                if (_States.CurrentArmState == ArmState.NotEnoughDrones)
                {
                    // we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime
                    // we may be out of drones/ammo but disconnecting/reconnecting will not fix that so update the timestamp
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;
                    Logging.Log("Arm", "Armstate.NotEnoughDrones", Logging.Orange);
                    _States.CurrentArmState = ArmState.Idle;
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error;
                }

                if (_States.CurrentArmState == ArmState.Done)
                {
                    //we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;
                    _States.CurrentArmState   = ArmState.Idle;
                    _States.CurrentDroneState = DroneState.WaitingForTargets;
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle;
                }
                break;

            case CombatHelperBehaviorState.CombatHelper:
                if (Cache.Instance.InSpace)
                {
                    DebugPerformanceClearandStartTimer();
                    Combat.ProcessState();
                    DebugPerformanceStopandDisplayTimer("Combat.ProcessState");

                    if (Settings.Instance.DebugStates)
                    {
                        Logging.Log("Combat.State is", _States.CurrentCombatState.ToString(), Logging.White);
                    }

                    DebugPerformanceClearandStartTimer();
                    Drones.ProcessState();
                    DebugPerformanceStopandDisplayTimer("Drones.ProcessState");

                    if (Settings.Instance.DebugStates)
                    {
                        Logging.Log("Drones.State is", _States.CurrentDroneState.ToString(), Logging.White);
                    }

                    DebugPerformanceClearandStartTimer();
                    Salvage.ProcessState();
                    DebugPerformanceStopandDisplayTimer("Salvage.ProcessState");

                    if (Settings.Instance.DebugStates)
                    {
                        Logging.Log("Salvage.State is", _States.CurrentSalvageState.ToString(), Logging.White);
                    }

                    // If we are out of ammo, return to base (do we want to do this with combat helper?!)
                    if (_States.CurrentCombatState == CombatState.OutOfAmmo)
                    {
                        Logging.Log("Combat", "Out of Ammo!", Logging.Orange);
                        _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.GotoBase;

                        // Clear looted containers
                        Cache.Instance.LootedContainers.Clear();
                    }
                }
                break;

            case CombatHelperBehaviorState.Salvage:
                if (!Cache.Instance.InSpace)
                {
                    return;
                }

                if (Cache.Instance.CurrentShipsCargo == null)
                {
                    return;
                }
                Cache.Instance.SalvageAll = true;
                if (Settings.Instance.SpeedTank || !Settings.Instance.SpeedTank)
                {
                    Cache.Instance.OpenWrecks = true;
                }

                if (Settings.Instance.UnloadLootAtStation && Cache.Instance.CurrentShipsCargo.IsValid && (Cache.Instance.CurrentShipsCargo.Capacity - Cache.Instance.CurrentShipsCargo.UsedCapacity) < 100)
                {
                    Logging.Log("CombatMissionsBehavior.Salvage", "We are full, go to base to unload", Logging.White);
                    _States.CurrentCombatMissionBehaviorState = CombatMissionsBehaviorState.GotoBase;
                    break;
                }

                if (!Cache.Instance.UnlootedContainers.Any())
                {
                    return;
                }

                //we __cannot ever__ approach in salvage.cs so this section _is_ needed.
                Salvage.MoveIntoRangeOfWrecks();
                try
                {
                    // Overwrite settings, as the 'normal' settings do not apply
                    Salvage.MaximumWreckTargets  = Cache.Instance.MaxLockedTargets;
                    Salvage.ReserveCargoCapacity = 80;
                    Salvage.LootEverything       = true;
                    Salvage.ProcessState();

                    //Logging.Log("number of max cache ship: " + Cache.Instance.ActiveShip.MaxLockedTargets);
                    //Logging.Log("number of max cache me: " + Cache.Instance.DirectEve.Me.MaxLockedTargets);
                    //Logging.Log("number of max math.min: " + _salvage.MaximumWreckTargets);
                }
                finally
                {
                    ApplyCombatHelperSettings();
                }
                break;

            case CombatHelperBehaviorState.GotoBase:
                if (Settings.Instance.DebugGotobase)
                {
                    Logging.Log("CombatHelperBehavior", "GotoBase: AvoidBumpingThings()", Logging.White);
                }

                if (Settings.Instance.AvoidBumpingThings)
                {
                    NavigateOnGrid.AvoidBumpingThings(Cache.Instance.BigObjects.FirstOrDefault(), "CombatHelperBehaviorState.GotoBase");
                }

                if (Settings.Instance.DebugGotobase)
                {
                    Logging.Log("CombatHelperBehavior", "GotoBase: Traveler.TravelHome()", Logging.White);
                }

                Traveler.TravelHome("CombatHelperBehavior.TravelHome");

                if (_States.CurrentTravelerState == TravelerState.AtDestination && DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(5))     // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10)
                {
                    if (Settings.Instance.DebugGotobase)
                    {
                        Logging.Log("CombatHelperBehavior", "GotoBase: We are at destination", Logging.White);
                    }
                    Cache.Instance.GotoBaseNow = false;     //we are there - turn off the 'forced' gotobase
                    Cache.Instance.Mission     = Cache.Instance.GetAgentMission(AgentID, false);

                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.UnloadLoot;

                    Traveler.Destination = null;
                }
                break;

            case CombatHelperBehaviorState.UnloadLoot:
                if (_States.CurrentUnloadLootState == UnloadLootState.Idle)
                {
                    Logging.Log("CombatHelperBehavior", "UnloadLoot: Begin", Logging.White);
                    _States.CurrentUnloadLootState = UnloadLootState.Begin;
                }

                _unloadLoot.ProcessState();

                if (Settings.Instance.DebugStates)
                {
                    Logging.Log("CombatHelperBehavior", "UnloadLoot.State is " + _States.CurrentUnloadLootState, Logging.White);
                }

                if (_States.CurrentUnloadLootState == UnloadLootState.Done)
                {
                    Cache.Instance.LootAlreadyUnloaded = true;
                    _States.CurrentUnloadLootState     = UnloadLootState.Idle;
                    Cache.Instance.Mission             = Cache.Instance.GetAgentMission(AgentID, false);
                    if (_States.CurrentCombatState == CombatState.OutOfAmmo)     // on mission
                    {
                        Logging.Log("CombatHelperBehavior.UnloadLoot", "We are out of ammo", Logging.Orange);
                        _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Arm;
                        return;
                    }

                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Arm;
                    Logging.Log("CombatHelperBehavior.Unloadloot", "CharacterMode: [" + Settings.Instance.CharacterMode + "], AfterMissionSalvaging: [" + Settings.Instance.AfterMissionSalvaging + "], CombatHelperBehaviorState: [" + _States.CurrentCombatHelperBehaviorState + "]", Logging.White);
                    Statistics.Instance.FinishedMission = DateTime.UtcNow;
                    return;
                }
                break;

            case CombatHelperBehaviorState.WarpOutStation:
                DirectBookmark warpOutBookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.UndockBookmarkPrefix ?? "").OrderByDescending(b => b.CreatedOn).FirstOrDefault(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId);

                //DirectBookmark _bookmark = Cache.Instance.BookmarksByLabel(Settings.Instance.bookmarkWarpOut + "-" + Cache.Instance.CurrentAgent ?? "").OrderBy(b => b.CreatedOn).FirstOrDefault();
                long solarid = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;

                if (warpOutBookmark == null)
                {
                    Logging.Log("BackgroundBehavior.WarpOut", "No Bookmark", Logging.White);
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper;
                }
                else if (warpOutBookmark.LocationId == solarid)
                {
                    if (Traveler.Destination == null)
                    {
                        Logging.Log("BackgroundBehavior.WarpOut", "Warp at " + warpOutBookmark.Title, Logging.White);
                        Traveler.Destination           = new BookmarkDestination(warpOutBookmark);
                        Cache.Instance.DoNotBreakInvul = true;
                    }

                    Traveler.ProcessState();
                    if (_States.CurrentTravelerState == TravelerState.AtDestination)
                    {
                        Logging.Log("BackgroundBehavior.WarpOut", "Safe!", Logging.White);
                        Cache.Instance.DoNotBreakInvul           = false;
                        _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper;
                        Traveler.Destination = null;
                    }
                }
                else
                {
                    Logging.Log("BackgroundBehavior.WarpOut", "No Bookmark in System", Logging.Orange);
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.CombatHelper;
                }

                break;

            case CombatHelperBehaviorState.Traveler:
                if (Settings.Instance.SpeedTank)
                {
                    Cache.Instance.OpenWrecks = false;
                }
                List <int> destination = Cache.Instance.DirectEve.Navigation.GetDestinationPath();
                if (destination == null || destination.Count == 0)
                {
                    // happens if autopilot is not set and this QuestorState is chosen manually
                    // this also happens when we get to destination (!?)
                    Logging.Log("CombatHelperBehavior.Traveler", "No destination?", Logging.White);
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error;
                }
                else if (destination.Count == 1 && destination.FirstOrDefault() == 0)
                {
                    destination[0] = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;
                }

                if (destination != null && (Traveler.Destination == null || Traveler.Destination.SolarSystemId != destination.Last()))
                {
                    IEnumerable <DirectBookmark> bookmarks = Cache.Instance.AllBookmarks.Where(b => b.LocationId == destination.Last()).ToList();
                    if (bookmarks.FirstOrDefault() != null && bookmarks.Any())
                    {
                        Traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).FirstOrDefault());
                    }
                    else
                    {
                        Logging.Log("CombatHelperBehavior.Traveler", "Destination: [" + Cache.Instance.DirectEve.Navigation.GetLocation(destination.Last()).Name + "]", Logging.White);
                        Traveler.Destination = new SolarSystemDestination(destination.Last());
                    }
                }
                else
                {
                    Traveler.ProcessState();

                    //we also assume you are connected during a manual set of questor into travel mode (safe assumption considering someone is at the kb)
                    Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                    Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;

                    if (_States.CurrentTravelerState == TravelerState.AtDestination)
                    {
                        if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Error)
                        {
                            Logging.Log("CombatHelperBehavior.Traveler", "an error has occurred", Logging.White);
                            _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error;
                        }
                        else if (Cache.Instance.InSpace)
                        {
                            Logging.Log("CombatHelperBehavior.Traveler", "Arrived at destination (in space, Questor stopped)", Logging.White);
                            _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error;
                        }
                        else
                        {
                            Logging.Log("CombatHelperBehavior.Traveler", "Arrived at destination", Logging.White);
                            _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle;
                            return;
                        }
                    }
                }
                break;

            case CombatHelperBehaviorState.GotoNearestStation:
                if (!Cache.Instance.InSpace || Cache.Instance.InWarp)
                {
                    return;
                }
                EntityCache station = null;
                if (Cache.Instance.Stations != null && Cache.Instance.Stations.Any())
                {
                    station = Cache.Instance.Stations.OrderBy(x => x.Distance).FirstOrDefault();
                }

                if (station != null)
                {
                    if (station.Distance > (int)Distances.WarptoDistance)
                    {
                        if (station.WarpTo())
                        {
                            Logging.Log("CombatHelperBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White);
                            _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle;
                        }
                    }
                    else
                    {
                        if (station.Distance < 1900)
                        {
                            if (station.Dock())
                            {
                                Logging.Log("CombatHelperBehavior.GotoNearestStation", "[" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White);
                            }
                        }
                        else
                        {
                            if (Cache.Instance.NextApproachAction < DateTime.UtcNow && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != station.Id))
                            {
                                Logging.Log("CombatHelperBehavior.GotoNearestStation", "Approaching [" + station.Name + "] which is [" + Math.Round(station.Distance / 1000, 0) + "k away]", Logging.White);
                                station.Approach();
                            }
                        }
                    }
                }
                else
                {
                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Error;     //should we goto idle here?
                }
                break;

            case CombatHelperBehaviorState.LogCombatTargets:
                //combat targets
                //List<EntityCache> combatentitiesInList =  Cache.Instance.Entities.Where(t => t.IsNpc && !t.IsBadIdea && t.CategoryId == (int)CategoryID.Entity && !t.IsContainer && t.Distance < Cache.Instance.MaxRange && !Cache.Instance.IgnoreTargets.Contains(t.Name.Trim())).ToList();
                List <EntityCache> combatentitiesInList = Cache.Instance.EntitiesOnGrid.Where(t => t.IsNpc && !t.IsBadIdea && t.CategoryId == (int)CategoryID.Entity && !t.IsContainer).ToList();
                Statistics.EntityStatistics(combatentitiesInList);
                Cache.Instance.Paused = true;
                break;

            case CombatHelperBehaviorState.LogDroneTargets:
                //drone targets
                List <EntityCache> droneentitiesInList = Cache.Instance.EntitiesOnGrid.Where(e => e.IsNpc && !e.IsBadIdea && e.CategoryId == (int)CategoryID.Entity && !e.IsContainer && !e.IsSentry && !e.IsLargeCollidable).ToList();
                Statistics.EntityStatistics(droneentitiesInList);
                Cache.Instance.Paused = true;
                break;

            case CombatHelperBehaviorState.LogStationEntities:
                //stations
                List <EntityCache> stationsInList = Cache.Instance.Entities.Where(e => !e.IsSentry && e.GroupId == (int)Group.Station).ToList();
                Statistics.EntityStatistics(stationsInList);
                Cache.Instance.Paused = true;
                break;

            case CombatHelperBehaviorState.LogStargateEntities:
                //stargates
                List <EntityCache> stargatesInList = Cache.Instance.Entities.Where(e => !e.IsSentry && e.GroupId == (int)Group.Stargate).ToList();
                Statistics.EntityStatistics(stargatesInList);
                Cache.Instance.Paused = true;
                break;

            case CombatHelperBehaviorState.LogAsteroidBelts:
                //Asteroid Belts
                List <EntityCache> asteroidbeltsInList = Cache.Instance.Entities.Where(e => !e.IsSentry && e.GroupId == (int)Group.AsteroidBelt).ToList();
                Statistics.EntityStatistics(asteroidbeltsInList);
                Cache.Instance.Paused = true;
                break;

            case CombatHelperBehaviorState.Default:
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle;
                break;
            }
        }