Пример #1
0
        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;
            }
        }
Пример #2
0
        public void ProcessState()
        {
            if (!Cache.Instance.InStation)
            {
                return;
            }

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

            if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(20)) // we wait 20 seconds after we last thought we were in space before trying to do anything in station
            {
                return;
            }

            string defaultFitting = Settings.Instance.DefaultFitting.FittingName;

            switch (_States.CurrentSwitchShipState)
            {
            case SwitchShipState.Idle:
                break;

            case SwitchShipState.Done:
                break;

            case SwitchShipState.Begin:
                _States.CurrentSwitchShipState = SwitchShipState.OpenShipHangar;
                break;

            case SwitchShipState.OpenShipHangar:

                // Is the ship hangar open?
                if (!Cache.Instance.OpenShipsHangar("SwitchShip"))
                {
                    break;
                }

                Logging.Log("SwitchShip", "Activating combat ship", Logging.White);

                _States.CurrentSwitchShipState = SwitchShipState.ActivateCombatShip;

                break;

            case SwitchShipState.ActivateCombatShip:
                string shipName = Settings.Instance.CombatShipName.ToLower();

                if (Cache.Instance.ActiveShip == null || (!string.IsNullOrEmpty(shipName) && Cache.Instance.ActiveShip.GivenName.ToLower() != shipName))
                {
                    if (DateTime.UtcNow.Subtract(_lastSwitchShipAction).TotalSeconds > Time.Instance.SwitchShipsDelay_seconds)
                    {
                        if (!Cache.Instance.OpenShipsHangar("SwitchShip"))
                        {
                            break;
                        }

                        if (Cache.Instance.ShipHangar != null)
                        {
                            List <DirectItem> ships = Cache.Instance.ShipHangar.Items;
                            if (ships != null && ships.Any())
                            {
                                foreach (DirectItem ship in ships.Where(ship => ship.GivenName != null && ship.GivenName.ToLower() == shipName))
                                {
                                    Logging.Log("SwitchShip", "Making [" + ship.GivenName + "] active", Logging.White);
                                    ship.ActivateShip();
                                    Logging.Log("SwitchShip", "Activated", Logging.White);
                                    _lastSwitchShipAction = DateTime.UtcNow;
                                    return;
                                }
                            }
                        }
                    }
                }

                _States.CurrentSwitchShipState = Settings.Instance.UseFittingManager ? SwitchShipState.OpenFittingWindow : SwitchShipState.Cleanup;

                break;

            case SwitchShipState.OpenFittingWindow:

                //let's check first if we need to change fitting at all
                Logging.Log("SwitchShip", "Fitting: " + defaultFitting + " - currentFit: " + Cache.Instance.CurrentFit, Logging.White);
                if (defaultFitting.Equals(Cache.Instance.CurrentFit))
                {
                    Logging.Log("SwitchShip", "Current fit is correct - no change necessary", Logging.White);
                    _States.CurrentSwitchShipState = SwitchShipState.Done;
                }
                else
                {
                    Cache.Instance.DirectEve.OpenFitingManager();
                    _States.CurrentSwitchShipState = SwitchShipState.WaitForFittingWindow;
                }
                break;

            case SwitchShipState.WaitForFittingWindow:

                DirectFittingManagerWindow fittingMgr = Cache.Instance.Windows.OfType <DirectFittingManagerWindow>().FirstOrDefault();

                //open it again ?
                if (fittingMgr == null)
                {
                    Logging.Log("SwitchShip", "Opening fitting manager", Logging.White);
                    Cache.Instance.DirectEve.OpenFitingManager();
                }

                //check if it's ready
                else if (fittingMgr.IsReady)
                {
                    _States.CurrentSwitchShipState = SwitchShipState.ChoseFitting;
                }
                break;

            case SwitchShipState.ChoseFitting:
                fittingMgr = Cache.Instance.Windows.OfType <DirectFittingManagerWindow>().FirstOrDefault();
                if (fittingMgr != null)
                {
                    Logging.Log("SwitchShip", "Looking for fitting " + defaultFitting, Logging.White);

                    foreach (DirectFitting fitting in fittingMgr.Fittings)
                    {
                        //ok found it
                        DirectActiveShip ship = Cache.Instance.ActiveShip;
                        if (defaultFitting.ToLower().Equals(fitting.Name.ToLower()) &&
                            fitting.ShipTypeId == ship.TypeId)
                        {
                            Logging.Log("SwitchShip", "Found fitting " + fitting.Name, Logging.White);

                            //switch to the requested fitting for the current mission
                            fitting.Fit();
                            _lastSwitchShipAction          = DateTime.UtcNow;
                            Cache.Instance.CurrentFit      = fitting.Name;
                            _States.CurrentSwitchShipState = SwitchShipState.WaitForFitting;
                            break;
                        }
                    }
                }
                _States.CurrentSwitchShipState = SwitchShipState.Done;
                if (fittingMgr != null)
                {
                    fittingMgr.Close();
                }
                break;

            case SwitchShipState.WaitForFitting:

                //let's wait 10 seconds
                if (DateTime.UtcNow.Subtract(_lastSwitchShipAction).TotalMilliseconds > Time.Instance.FittingWindowLoadFittingDelay_seconds &&
                    Cache.Instance.DirectEve.GetLockedItems().Count == 0)
                {
                    //we should be done fitting, proceed to the next state
                    _States.CurrentSwitchShipState = SwitchShipState.Done;
                    fittingMgr = Cache.Instance.Windows.OfType <DirectFittingManagerWindow>().FirstOrDefault();
                    if (fittingMgr != null)
                    {
                        fittingMgr.Close();
                    }
                    Logging.Log("SwitchShip", "Done fitting", Logging.White);
                }
                else
                {
                    Logging.Log("SwitchShip", "Waiting for fitting. time elapsed = " + DateTime.UtcNow.Subtract(_lastSwitchShipAction).TotalMilliseconds + " locked items = " + Cache.Instance.DirectEve.GetLockedItems().Count, Logging.White);
                }
                break;

            case SwitchShipState.NotEnoughAmmo:
                Logging.Log("SwitchShip", "Out of Ammo, checking a solution ...", Logging.White);
                break;

            case SwitchShipState.Cleanup:
                if (!Cleanup.CloseInventoryWindows())
                {
                    break;
                }
                _States.CurrentSwitchShipState = SwitchShipState.Done;
                break;
            }
        }