Beispiel #1
0
        public static bool ChangeArmState(ArmState armStateToSet, bool waitAMomentbeforeNextAction = false, string LogMessage = null)
        {
            try
            {
                //
                // if _ArmStateToSet matches also do this stuff...
                //
                switch (armStateToSet)
                {
                    case ArmState.OpenShipHangar:
                        _States.CurrentCombatState = CombatState.Idle;
                        break;

                    case ArmState.NotEnoughAmmo:
                        if (LogMessage != null) Logging.Log(_States.CurrentArmState.ToString(), LogMessage, Logging.Red);
                        QuestorCache.Instance.Paused = true;
                        _States.CurrentCombatState = CombatState.Idle;
                        break;
                }
            }
            catch (Exception ex)
            {
                Logging.Log(_States.CurrentArmState.ToString(), "Exception [" + ex + "]", Logging.Red);
                return false;
            }

            try
            {
                Arm.ClearDataBetweenStates();
                if (_States.CurrentArmState != armStateToSet)
                {
                    _States.CurrentArmState = armStateToSet;
                    if (waitAMomentbeforeNextAction) _lastArmAction = DateTime.UtcNow;
                    else Arm.ProcessState();
                }

                return true;
            }
            catch (Exception ex)
            {
                Logging.Log(_States.CurrentArmState.ToString(), "Exception [" + ex + "]", Logging.Red);
                return false;
            }
        }
Beispiel #2
0
        private void SetArmState(ArmState newstate)
        {
            if(_state != newstate)
            {
                // Trace("smg: arm: {0} -> {1}", _state, newstate);
                _state = newstate;

                if(_state == ArmState.modify)
                {
                    ClearCalculations();
                }
            }
        }
Beispiel #3
0
        public void ProcessState()
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();
            var droneBay = Cache.Instance.DirectEve.GetShipsDroneBay();
            var itemHangar = Cache.Instance.DirectEve.GetItemHangar();
            var shipHangar = Cache.Instance.DirectEve.GetShipHangar();

            DirectContainer corpHangar = null;
            if (!string.IsNullOrEmpty(Settings.Instance.AmmoHangar))
                corpHangar = Cache.Instance.DirectEve.GetCorporationHangar(Settings.Instance.AmmoHangar);

            // Select the correct ammo hangar
            var ammoHangar = corpHangar ?? itemHangar;
            switch (State)
            {
                case ArmState.Idle:

                    break;
                case ArmState.Done:
                    break;

                case ArmState.Begin:
                    //DefaultFittingChecked = false; //flag to check for the correct default fitting before using the fitting manager
                    //DefaultFittingFound = true; //Did we find the default fitting?
                    Cache.Instance.ArmLoadedCache = false;
                    TryMissionShip = true;  // Used in the event we can't find the ship specified in the missionfittings
                    UseMissionShip = false; // Were we successful in activating the mission specific ship?
                    State = ArmState.OpenShipHangar;
                    break;

                case ArmState.OpenShipHangar:
                case ArmState.SwitchToSalvageShip:
                    // Is the ship hangar open?
                    if (shipHangar.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenShipHangar);
                        break;
                    }

                    if (!shipHangar.IsReady)
                        break;

                    if (State == ArmState.OpenShipHangar)
                    {
                        Logging.Log("Arm: Activating combat ship");
                        State = ArmState.ActivateCombatShip;
                    }
                    else
                    {
                        Logging.Log("Arm: Activating salvage ship");
                        State = ArmState.ActivateSalvageShip;
                    }
                    break;

                case ArmState.ActivateCombatShip:
                case ArmState.ActivateSalvageShip:
                    var shipName = State == ArmState.ActivateCombatShip
                                       ? Settings.Instance.CombatShipName.ToLower()
                                       : Settings.Instance.SalvageShipName.ToLower();

                    if (!Cache.Instance.ArmLoadedCache)
                    {
                        _missionItemMoved = false;
                        Cache.Instance.RefreshMissionItems(AgentId);
                        Cache.Instance.ArmLoadedCache = true;
                    }

                    // If we've got a mission-specific ship defined, switch to it
                    if ((State == ArmState.ActivateCombatShip) && !(Cache.Instance.MissionShip == "" || Cache.Instance.MissionShip == null) && TryMissionShip)
                        shipName = Cache.Instance.MissionShip.ToLower();

                    if (Settings.Instance.CombatShipName.ToLower() == shipName) // if the mission specific ship is our default combat ship, no need to do anything special
                        TryMissionShip = false;

                    if ((!string.IsNullOrEmpty(shipName) && Cache.Instance.DirectEve.ActiveShip.GivenName.ToLower() != shipName))
                    {
                        if (DateTime.Now.Subtract(_lastAction).TotalSeconds > 15)
                        {
                            var ships = Cache.Instance.DirectEve.GetShipHangar().Items;
                            foreach (var ship in ships.Where(ship => ship.GivenName.ToLower() == shipName))
                            {
                                Logging.Log("Arm: Making [" + ship.GivenName + "] active");

                                ship.ActivateShip();
                                _lastAction = DateTime.Now;
                                if (TryMissionShip)
                                    UseMissionShip = true;
                                return;
                            }

                            if (TryMissionShip && !UseMissionShip)
                            {
                                Logging.Log("Arm: Unable to find the ship specified in the missionfitting.  Using default combat ship and default fitting.");
                                TryMissionShip = false;
                                Cache.Instance.Fitting = Cache.Instance.DefaultFitting;
                                return;
                            }

                            State = ArmState.NotEnoughAmmo;
                            Logging.Log("Arm: Found the following ships:");
                            foreach (var ship in ships)
                                Logging.Log("Arm: [" + ship.GivenName + "]");
                            Logging.Log("Arm: Could not find [" + shipName + "] ship!");
                            return;
                        }
                        return;
                    }
                    else if (TryMissionShip)
                        UseMissionShip = true;

                    if (State == ArmState.ActivateSalvageShip)
                    {
                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                        return;
                    }

                    //_missionItemMoved = false;
                    //Cache.Instance.RefreshMissionItems(AgentId);
                    if (AmmoToLoad.Count == 0 && string.IsNullOrEmpty(Cache.Instance.BringMissionItem))
                    {
                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                    }
                    else
                    {
                        Logging.Log("Arm: Opening item hangar");
                        State = ArmState.OpenItemHangar;
                    }
                    break;

                case ArmState.OpenItemHangar:
                    // Is the hangar open?
                    if (itemHangar.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenHangarFloor);
                        break;
                    }

                    if (!itemHangar.IsReady)
                        break;

                    if (corpHangar != null)
                    {
                        Logging.Log("Arm: Opening corporation hangar");
                        State = ArmState.OpenCorpHangar;
                    }
                    else
                    {
                        Logging.Log("Arm: Opening ship's cargo");
                        State = ArmState.OpenCargo;
                    }
                    break;

                case ArmState.OpenCorpHangar:
                    // Is the hangar open?
                    if (corpHangar != null)
                    {
                        if (corpHangar.Window == null)
                        {
                            // No, command it to open
                            Cache.Instance.DirectEve.OpenCorporationHangar();
                            break;
                        }

                        if (!corpHangar.IsReady)
                            break;
                    }

                    Logging.Log("Arm: Opening ship's cargo");
                    State = ArmState.OpenCargo;
                    break;

                case ArmState.OpenCargo:
                    // Is cargo open?
                    if (cargo.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip);
                        break;
                    }

                    if (!cargo.IsReady)
                        break;

                    if (Settings.Instance.UseDrones && Settings.Instance.DroneTypeId > 0)
                    {
                        Logging.Log("Arm: Opening ship's drone bay");
                        State = ArmState.OpenDroneBay;
                    }
                    else if ((Settings.Instance.FittingsDefined && DefaultFittingFound) && !(UseMissionShip && !(Cache.Instance.ChangeMissionShipFittings)))
                    {
                        Logging.Log("Arm: Fitting");
                        State = ArmState.OpenFittingWindow;
                    }
                    else
                        State = ArmState.MoveItems;
                    break;

                case ArmState.OpenFittingWindow:
                    //let's check first if we need to change fitting at all
                    Logging.Log("Arm: Fitting: " + Cache.Instance.Fitting + " - currentFit: " + Cache.Instance.currentFit);
                    if (Cache.Instance.Fitting.Equals(Cache.Instance.currentFit))
                    {
                        Logging.Log("Arm: Current fit is correct - no change necessary");
                        State = ArmState.MoveItems;
                    }
                    else
                    {
                        Cache.Instance.DirectEve.OpenFitingManager();
                        State = ArmState.WaitForFittingWindow;
                    }
                    break;
                case ArmState.WaitForFittingWindow:

                    var fittingMgr = Cache.Instance.DirectEve.Windows.OfType<DirectFittingManagerWindow>().FirstOrDefault();
                    //open it again ?
                    if (fittingMgr == null)
                    {
                        Logging.Log("Arm: Opening fitting manager");
                        Cache.Instance.DirectEve.OpenFitingManager();
                    }
                    //check if it's ready
                    else if (fittingMgr.IsReady)
                    {
                        State = ArmState.ChoseFitting;
                    }
                    break;
                case ArmState.ChoseFitting:
                    fittingMgr = Cache.Instance.DirectEve.Windows.OfType<DirectFittingManagerWindow>().FirstOrDefault();
                    bool found = false;
                    if (!DefaultFittingChecked)
                    {
                        DefaultFittingChecked = true;
                        Logging.Log("Arm: Looking for Default Fitting " + Cache.Instance.DefaultFitting);
                        foreach (var fitting in fittingMgr.Fittings)
                        {
                            //ok found it
                            if (Cache.Instance.DefaultFitting.ToLower().Equals(fitting.Name.ToLower()))
                            {
                                found = true;
                                Logging.Log("Arm: Found Default Fitting " + fitting.Name);
                            }
                        }
                        if (!found)
                        {
                            Logging.Log("Arm: Error! Couldn't find Default Fitting.  Disabling fitting manager.");
                            DefaultFittingFound = false;
                            Settings.Instance.FittingsDefined = false;
                            State = ArmState.MoveItems;
                            break;
                        }
                        found = false;
                    }
                    Logging.Log("Arm: Looking for fitting " + Cache.Instance.Fitting);
                    foreach (var fitting in fittingMgr.Fittings)
                    {
                        //ok found it
                        var ship = Cache.Instance.DirectEve.ActiveShip;
                        if (Cache.Instance.Fitting.ToLower().Equals(fitting.Name.ToLower()) && fitting.ShipTypeId == ship.TypeId)
                        {
                            Logging.Log("Arm: Found fitting " + fitting.Name);
                            //switch to the requested fitting for the current mission
                            fitting.Fit();
                            _lastAction = DateTime.Now;
                            Cache.Instance.currentFit = fitting.Name;
                            State = ArmState.WaitForFitting;
                            found = true;
                            break;
                        }

                    }
                    //if we didn't find it, we'll set currentfit to default
                    //this should provide backwards compatibility without trying to fit always
                    if (!found)
                    {
                        if (UseMissionShip)
                        {
                            Logging.Log("Arm: Couldn't find fitting for this ship typeid.  Using current fitting.");
                            State = ArmState.MoveItems;
                            break;
                        }
                        else
                        {
                            Logging.Log("Arm: Couldn't find fitting - switching to default");
                            Cache.Instance.Fitting = Cache.Instance.DefaultFitting;
                            break;
                        }
                    }
                    State = ArmState.MoveItems;
                    fittingMgr.Close();
                    break;

                case ArmState.WaitForFitting:
                    //let's wait 10 seconds
                    if (DateTime.Now.Subtract(_lastAction).TotalMilliseconds > 10000 &&
                        Cache.Instance.DirectEve.GetLockedItems().Count == 0)
                    {
                        //we should be done fitting, proceed to the next state
                        State = ArmState.MoveItems;
                        fittingMgr = Cache.Instance.DirectEve.Windows.OfType<DirectFittingManagerWindow>().FirstOrDefault();
                        fittingMgr.Close();
                        Logging.Log("Arm: Done fitting");
                    }
                    else Logging.Log("Arm: Waiting for fitting. time elapsed = " + DateTime.Now.Subtract(_lastAction).TotalMilliseconds + " locked items = " + Cache.Instance.DirectEve.GetLockedItems().Count);
                    break;

                case ArmState.OpenDroneBay:
                    // Is cargo open?
                    if (droneBay.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenDroneBayOfActiveShip);
                        break;
                    }

                    if (!droneBay.IsReady)
                        break;

                    Logging.Log("Arm: Moving drones");
                    State = ArmState.MoveDrones;
                    break;

                case ArmState.MoveDrones:
                    var drone = ammoHangar.Items.FirstOrDefault(i => i.TypeId == Settings.Instance.DroneTypeId);
                    if (drone == null || drone.Stacksize < 1)
                    {
                        Logging.Log("Arm: Out of drones");
                        State = ArmState.NotEnoughAmmo;
                        break;
                    }

                    var neededDrones = Math.Floor((droneBay.Capacity - droneBay.UsedCapacity)/drone.Volume);
                    Logging.Log("neededDrones: " + neededDrones);
                    if (neededDrones == 0 && ((Settings.Instance.FittingsDefined && DefaultFittingFound) && !(UseMissionShip && !(Cache.Instance.ChangeMissionShipFittings))))
                    {
                        Logging.Log("Arm: Fitting");
                        State = ArmState.OpenFittingWindow;
                        break;
                    }
                    else if (neededDrones == 0)
                    {
                        State = ArmState.MoveItems;
                        break;
                    }

                    // Move needed drones
                    droneBay.Add(drone, (int)Math.Min(neededDrones, drone.Stacksize));
                    break;

                case ArmState.MoveItems:
                    var bringItem = Cache.Instance.BringMissionItem;
                    if (string.IsNullOrEmpty(bringItem))
                        _missionItemMoved = true;

                    if (!_missionItemMoved)
                    {
                        var missionItem = (corpHangar ?? itemHangar).Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);
                        if (missionItem == null)
                            missionItem = itemHangar.Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);

                        if (missionItem != null)
                        {
                            Logging.Log("Arm: Moving [" + missionItem.TypeName + "]");

                            cargo.Add(missionItem, 1);
                            _missionItemMoved = true;
                            break;
                        }
                    }

                    var itemMoved = false;
                    if (Cache.Instance.missionAmmo.Count() != 0)
                    {
                        AmmoToLoad = new List<Ammo>(Cache.Instance.missionAmmo);

                    }
                    foreach (var item in ammoHangar.Items.OrderBy(i => i.Quantity))
                    {
                        if (item.ItemId <= 0)
                            continue;

                        var ammo = AmmoToLoad.FirstOrDefault(a => a.TypeId == item.TypeId);
                        if (ammo == null)
                            continue;

                        Logging.Log("Arm: Moving [" + item.TypeName + "]");

                        var moveQuantity = Math.Min(item.Quantity, ammo.Quantity);
                        moveQuantity = Math.Max(moveQuantity, 1);
                        cargo.Add(item, moveQuantity);

                        ammo.Quantity -= moveQuantity;
                        if (ammo.Quantity <= 0)
                        {
                            Cache.Instance.missionAmmo.RemoveAll(a => a.TypeId == item.TypeId);
                            AmmoToLoad.RemoveAll(a => a.TypeId == item.TypeId);
                        }
                        itemMoved = true;
                        break;
                    }

                    if (AmmoToLoad.Count == 0 && _missionItemMoved)
                    {
                        _lastAction = DateTime.Now;

                        Logging.Log("Arm: Waiting for items");
                        State = ArmState.WaitForItems;
                    }
                    else if (!itemMoved)
                    {
                        if (AmmoToLoad.Count > 0)
                            foreach (var ammo in AmmoToLoad)
                                Logging.Log("Arm: Missing ammo with TypeId [" + ammo.TypeId + "]");

                        if (!_missionItemMoved)
                            Logging.Log("Arm: Missing mission item [" + bringItem + "]");

                        State = ArmState.NotEnoughAmmo;
                    }
                    break;

                case ArmState.WaitForItems:
                    // Wait 5 seconds after moving
                    if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 5)
                        break;

                    if (cargo.Items.Count == 0)
                        break;

                    if (Cache.Instance.DirectEve.GetLockedItems().Count == 0)
                    {
                        // Close the drone bay, its not required in space.
                        if (droneBay.IsReady)
                            droneBay.Window.Close();

                        Logging.Log("Arm: Done");

                        //reload the ammo setting for combat
                        try
                        {
                            var mission = Cache.Instance.DirectEve.AgentMissions.FirstOrDefault(m => m.AgentId == AgentId);
                            if (mission == null)
                                return;

                            var missionName = Cache.Instance.FilterPath(mission.Name);
                            var missionXmlPath = Path.Combine(Settings.Instance.MissionsPath, missionName + ".xml");
                            var missionXml = XDocument.Load(missionXmlPath);
                            Cache.Instance.missionAmmo = new List<Ammo>();
                            var ammoTypes = missionXml.Root.Element("missionammo");
                            if (ammoTypes != null)
                                foreach (var ammo in ammoTypes.Elements("ammo"))
                                    Cache.Instance.missionAmmo.Add(new Ammo(ammo));
                        }
                        catch (Exception e)
                        {
                            Cache.Instance.missionAmmo = new List<Ammo>();
                        }

                        State = ArmState.Done;
                        break;
                    }

                    // Note, there's no unlock here as we *always* want our ammo!
                    break;
            }
        }
Beispiel #4
0
        public void ProcessState()
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();
            var droneBay = Cache.Instance.DirectEve.GetShipsDroneBay();
            var itemHangar = Cache.Instance.DirectEve.GetItemHangar();
            var shipHangar = Cache.Instance.DirectEve.GetShipHangar();

            DirectContainer corpHangar = null;
            if (!string.IsNullOrEmpty(Settings.Instance.AmmoHangar))
                corpHangar = Cache.Instance.DirectEve.GetCorporationHangar(Settings.Instance.AmmoHangar);

            // Select the correct ammo hangar
            var ammoHangar = corpHangar ?? itemHangar;
            switch (State)
            {
                case ArmState.Idle:
                case ArmState.Done:
                    break;

                case ArmState.Begin:
                    State = ArmState.OpenShipHangar;
                    break;

                case ArmState.OpenShipHangar:
                case ArmState.SwitchToSalvageShip:
                    // Is the ship hangar open?
                    if (shipHangar.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenShipHangar);
                        break;
                    }

                    if (!shipHangar.IsReady)
                        break;

                    if (State == ArmState.OpenShipHangar)
                    {
                        Logging.Log("Arm: Activating combat ship");
                        State = ArmState.ActivateCombatShip;
                    }
                    else
                    {
                        Logging.Log("Arm: Activating salvage ship");
                        State = ArmState.ActivateSalvageShip;
                    }
                    break;

                case ArmState.ActivateCombatShip:
                case ArmState.ActivateSalvageShip:
                    var shipName = State == ArmState.ActivateCombatShip
                                       ? Settings.Instance.CombatShipName
                                       : Settings.Instance.SalvageShipName;

                    if (!string.IsNullOrEmpty(shipName) && Cache.Instance.DirectEve.ActiveShip.GivenName != shipName)
                    {
                        if (DateTime.Now.Subtract(_lastAction).TotalSeconds > 15)
                        {
                            var ships = Cache.Instance.DirectEve.GetShipHangar().Items;
                            foreach (var ship in ships.Where(ship => ship.GivenName == shipName))
                            {
                                Logging.Log("Arm: Making [" + ship.GivenName + "] active");

                                ship.ActivateShip();
                                _lastAction = DateTime.Now;
                                return;
                            }

                            State = ArmState.NotEnoughAmmo;
                            Logging.Log("Arm: Found the following ships:");
                            foreach (var ship in ships)
                                Logging.Log("Arm: [" + ship.GivenName + "]");
                            Logging.Log("Arm: Could not find [" + shipName + "] ship!");
                            return;
                        }
                        return;
                    }

                    if (State == ArmState.ActivateSalvageShip)
                    {
                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                        return;
                    }

                    _missionItemMoved = false;
                    Cache.Instance.RefreshMissionItems(AgentId);
                    if (AmmoToLoad.Count == 0 && string.IsNullOrEmpty(Cache.Instance.BringMissionItem))
                    {
                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                    }
                    else
                    {
                        Logging.Log("Arm: Opening item hangar");
                        State = ArmState.OpenItemHangar;
                    }
                    break;

                case ArmState.OpenItemHangar:
                    // Is the hangar open?
                    if (itemHangar.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenHangarFloor);
                        break;
                    }

                    if (!itemHangar.IsReady)
                        break;

                    if (corpHangar != null)
                    {
                        Logging.Log("Arm: Opening corporation hangar");
                        State = ArmState.OpenCorpHangar;
                    }
                    else
                    {
                        Logging.Log("Arm: Opening ship's cargo");
                        State = ArmState.OpenCargo;
                    }
                    break;

                case ArmState.OpenCorpHangar:
                    // Is the hangar open?
                    if (corpHangar != null)
                    {
                        if (corpHangar.Window == null)
                        {
                            // No, command it to open
                            Cache.Instance.DirectEve.OpenCorporationHangar();
                            break;
                        }

                        if (!corpHangar.IsReady)
                            break;
                    }

                    Logging.Log("Arm: Opening ship's cargo");
                    State = ArmState.OpenCargo;
                    break;

                case ArmState.OpenCargo:
                    // Is cargo open?
                    if (cargo.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip);
                        break;
                    }

                    if (!cargo.IsReady)
                        break;

                    if (Settings.Instance.UseDrones && Settings.Instance.DroneTypeId > 0)
                    {
                        Logging.Log("Arm: Opening ship's drone bay");
                        State = ArmState.OpenDroneBay;
                    }
                    else
                    {
                        Logging.Log("Arm: Moving items");
                        State = ArmState.MoveItems;
                    }
                    break;

                case ArmState.OpenDroneBay:
                    // Is cargo open?
                    if (droneBay.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenDroneBayOfActiveShip);
                        break;
                    }

                    if (!droneBay.IsReady)
                        break;

                    Logging.Log("Arm: Moving drones");
                    State = ArmState.MoveDrones;
                    break;

                case ArmState.MoveDrones:
                    var drone = ammoHangar.Items.FirstOrDefault(i => i.TypeId == Settings.Instance.DroneTypeId);
                    if (drone == null || !drone.Stacksize.HasValue)
                    {
                        Logging.Log("Arm: Out of drones");
                        State = ArmState.NotEnoughAmmo;
                        break;
                    }

                    var neededDrones = Math.Floor((droneBay.Capacity - droneBay.UsedCapacity)/drone.Volume);
                    if (neededDrones == 0)
                    {
                        Logging.Log("Arm: Moving items");
                        State = ArmState.MoveItems;
                        break;
                    }

                    // Move needed drones
                    droneBay.Add(drone, (int)Math.Min(neededDrones, drone.Stacksize.Value));
                    break;

                case ArmState.MoveItems:
                    var bringItem = Cache.Instance.BringMissionItem;
                    if (string.IsNullOrEmpty(bringItem))
                        _missionItemMoved = true;

                    if (!_missionItemMoved)
                    {
                        var missionItem = (corpHangar ?? itemHangar).Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);
                        if (missionItem == null)
                            missionItem = itemHangar.Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);

                        if (missionItem != null)
                        {
                            Logging.Log("Arm: Moving [" + missionItem.TypeName + "]");

                            cargo.Add(missionItem, 1);
                            _missionItemMoved = true;
                            break;
                        }
                    }

                    var itemMoved = false;
                    foreach (var item in ammoHangar.Items.OrderBy(i => i.Quantity))
                    {
                        if (item.ItemId <= 0)
                            continue;

                        var ammo = AmmoToLoad.FirstOrDefault(a => a.TypeId == item.TypeId);
                        if (ammo == null)
                            continue;

                        Logging.Log("Arm: Moving [" + item.TypeName + "]");

                        var moveQuantity = Math.Min(item.Quantity, ammo.Quantity);
                        moveQuantity = Math.Max(moveQuantity, 1);
                        cargo.Add(item, moveQuantity);

                        ammo.Quantity -= moveQuantity;
                        if (ammo.Quantity <= 0)
                            AmmoToLoad.RemoveAll(a => a.TypeId == item.TypeId);

                        itemMoved = true;
                        break;
                    }

                    if (AmmoToLoad.Count == 0 && _missionItemMoved)
                    {
                        _lastAction = DateTime.Now;

                        Logging.Log("Arm: Waiting for items");
                        State = ArmState.WaitForItems;
                    }
                    else if (!itemMoved)
                    {
                        if (AmmoToLoad.Count > 0)
                            foreach (var ammo in AmmoToLoad)
                                Logging.Log("Arm: Missing ammo with TypeId [" + ammo.TypeId + "]");

                        if (!_missionItemMoved)
                            Logging.Log("Arm: Missing mission item [" + bringItem + "]");

                        State = ArmState.NotEnoughAmmo;
                    }
                    break;

                case ArmState.WaitForItems:
                    // Wait 5 seconds after moving
                    if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 5)
                        break;

                    if (cargo.Items.Count == 0)
                        break;

                    if (Cache.Instance.DirectEve.GetLockedItems().Count == 0)
                    {
                        // Close the drone bay, its not required in space.
                        if (droneBay.IsReady)
                            droneBay.Window.Close();

                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                        break;
                    }

                    // Note, there's no unlock here as we *always* want our ammo!
                    break;
            }
        }
Beispiel #5
0
        public void ProcessState()
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();
            var droneBay = Cache.Instance.DirectEve.GetShipsDroneBay();
            var itemHangar = Cache.Instance.DirectEve.GetItemHangar();
            var shipHangar = Cache.Instance.DirectEve.GetShipHangar();

            DirectContainer corpHangar = null;
            if (!string.IsNullOrEmpty(Settings.Instance.AmmoHangar))
                corpHangar = Cache.Instance.DirectEve.GetCorporationHangar(Settings.Instance.AmmoHangar);

            // Select the correct ammo hangar
            var ammoHangar = corpHangar ?? itemHangar;
            switch (State)
            {
                case ArmState.Idle:
                case ArmState.Done:
                    break;

                case ArmState.Begin:
                    State = ArmState.OpenShipHangar;
                    break;

                case ArmState.OpenShipHangar:
                case ArmState.SwitchToSalvageShip:
                    // Is the ship hangar open?
                    if (shipHangar.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenShipHangar);
                        break;
                    }

                    if (!shipHangar.IsReady)
                        break;

                    if (State == ArmState.OpenShipHangar)
                    {
                        Logging.Log("Arm: Activating combat ship");
                        State = ArmState.ActivateCombatShip;
                    }
                    else
                    {
                        Logging.Log("Arm: Activating salvage ship");
                        State = ArmState.ActivateSalvageShip;
                    }
                    break;

                case ArmState.ActivateCombatShip:
                case ArmState.ActivateSalvageShip:
                    var shipName = State == ArmState.ActivateCombatShip
                                       ? Settings.Instance.CombatShipName
                                       : Settings.Instance.SalvageShipName;

                    if (!string.IsNullOrEmpty(shipName) && Cache.Instance.DirectEve.ActiveShip.GivenName != shipName)
                    {
                        if (DateTime.Now.Subtract(_lastAction).TotalSeconds > 15)
                        {
                            var ships = Cache.Instance.DirectEve.GetShipHangar().Items;
                            foreach (var ship in ships.Where(ship => ship.GivenName == shipName))
                            {
                                Logging.Log("Arm: Making [" + ship.GivenName + "] active");

                                ship.ActivateShip();
                                _lastAction = DateTime.Now;
                                return;
                            }

                            State = ArmState.NotEnoughAmmo;
                            Logging.Log("Arm: Found the following ships:");
                            foreach (var ship in ships)
                                Logging.Log("Arm: [" + ship.GivenName + "]");
                            Logging.Log("Arm: Could not find [" + shipName + "] ship!");
                            return;
                        }
                        return;
                    }

                    if (State == ArmState.ActivateSalvageShip)
                    {
                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                        return;
                    }

                    _missionItemMoved = false;
                    Cache.Instance.RefreshMissionItems(AgentId);
                    if (AmmoToLoad.Count == 0 && string.IsNullOrEmpty(Cache.Instance.BringMissionItem))
                    {
                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                    }
                    else
                    {
                        Logging.Log("Arm: Opening item hangar");
                        State = ArmState.OpenItemHangar;
                    }
                    break;

                case ArmState.OpenItemHangar:
                    // Is the hangar open?
                    if (itemHangar.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenHangarFloor);
                        break;
                    }

                    if (!itemHangar.IsReady)
                        break;

                    if (corpHangar != null)
                    {
                        Logging.Log("Arm: Opening corporation hangar");
                        State = ArmState.OpenCorpHangar;
                    }
                    else
                    {
                        Logging.Log("Arm: Opening ship's cargo");
                        State = ArmState.OpenCargo;
                    }
                    break;

                case ArmState.OpenCorpHangar:
                    // Is the hangar open?
                    if (corpHangar != null)
                    {
                        if (corpHangar.Window == null)
                        {
                            // No, command it to open
                            Cache.Instance.DirectEve.OpenCorporationHangar();
                            break;
                        }

                        if (!corpHangar.IsReady)
                            break;
                    }

                    Logging.Log("Arm: Opening ship's cargo");
                    State = ArmState.OpenCargo;
                    break;

                case ArmState.OpenCargo:
                    // Is cargo open?
                    if (cargo.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip);
                        break;
                    }

                    if (!cargo.IsReady)
                        break;

                    if (Settings.Instance.UseDrones && Settings.Instance.DroneTypeId > 0)
                    {
                        Logging.Log("Arm: Opening ship's drone bay");
                        State = ArmState.OpenDroneBay;
                    }
                    else
                    {
                        Logging.Log("Arm: Fitting");
                        State = ArmState.OpenFittingWindow;
                    }
                    break;

                case ArmState.OpenFittingWindow:
                    //let's check first if we need to change fitting at all

                    if (Cache.Instance.Fitting.Equals(Cache.Instance.currentFit))
                    {
                        Logging.Log("Arm: Current fit is correct - no change necessary");
                        State = ArmState.MoveItems;
                    }
                    else
                    {
                        Cache.Instance.DirectEve.OpenFitingManager();
                        State = ArmState.WaitForFittingWindow;
                    }
                    break;
                case ArmState.WaitForFittingWindow:

                    var fittingMgr = Cache.Instance.DirectEve.Windows.OfType<DirectFittingManagerWindow>().FirstOrDefault();
                    //open it again ?
                    if (fittingMgr == null)
                    {
                        Logging.Log("Arm: Opening fitting manager");
                        Cache.Instance.DirectEve.OpenFitingManager();
                    }
                    //check if it's ready
                    else if (fittingMgr.IsReady)
                    {
                        State = ArmState.ChoseFitting;
                    }
                    break;
                case ArmState.ChoseFitting:
                    fittingMgr = Cache.Instance.DirectEve.Windows.OfType<DirectFittingManagerWindow>().FirstOrDefault();
                    bool found = false;
                    Logging.Log("Arm: Looking for fitting " + Cache.Instance.Fitting);
                    foreach (var fitting in fittingMgr.Fittings)
                    {
                        //ok found it
                        if (Cache.Instance.Fitting.Equals(fitting.Name))
                        {
                            Logging.Log("Arm: Found fitting " + fitting.Name);
                            //switch to the requested fitting for the current mission
                            fitting.Fit();
                            _lastAction = DateTime.Now;
                            Cache.Instance.currentFit = fitting.Name;
                            State = ArmState.WaitForFitting;
                            found = true;
                        }

                    }
                    //if we didn't find it, we'll set currentfit to default
                    //this should provide backwards compatibility without trying to fit always
                    if (!found)
                    {
                        Logging.Log("Arm: Couldn't find fitting - switching to default");
                        Cache.Instance.Fitting = Cache.Instance.DefaultFitting;
                        break;
                    }
                    State = ArmState.MoveItems;
                    fittingMgr.Close();
                    break;

                case ArmState.WaitForFitting:
                    //let's wait 10 seconds
                    if (DateTime.Now.Subtract(_lastAction).TotalMilliseconds > 10000 &&
                        Cache.Instance.DirectEve.GetLockedItems().Count == 0)
                    {
                        //we should be done fitting, proceed to the next state
                        State = ArmState.MoveItems;
                        fittingMgr = Cache.Instance.DirectEve.Windows.OfType<DirectFittingManagerWindow>().FirstOrDefault();
                        fittingMgr.Close();
                        Logging.Log("Arm: Done fitting");
                    }
                    else Logging.Log("Arm: Waiting for fitting. time elapsed = " + DateTime.Now.Subtract(_lastAction).TotalMilliseconds + " locked items = " + Cache.Instance.DirectEve.GetLockedItems().Count);
                    break;

                case ArmState.OpenDroneBay:
                    // Is cargo open?
                    if (droneBay.Window == null)
                    {
                        // No, command it to open
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenDroneBayOfActiveShip);
                        break;
                    }

                    if (!droneBay.IsReady)
                        break;

                    Logging.Log("Arm: Moving drones");
                    State = ArmState.MoveDrones;
                    break;

                case ArmState.MoveDrones:
                    var drone = ammoHangar.Items.FirstOrDefault(i => i.TypeId == Settings.Instance.DroneTypeId);
                    if (drone == null || drone.Stacksize < 1)
                    {
                        Logging.Log("Arm: Out of drones");
                        State = ArmState.NotEnoughAmmo;
                        break;
                    }

                    var neededDrones = Math.Floor((droneBay.Capacity - droneBay.UsedCapacity)/drone.Volume);
                    if (neededDrones == 0)
                    {
                        Logging.Log("Arm: Fitting");
                        State = ArmState.OpenFittingWindow;
                        break;
                    }

                    // Move needed drones
                    droneBay.Add(drone, (int)Math.Min(neededDrones, drone.Stacksize));
                    break;

                case ArmState.MoveItems:
                    var bringItem = Cache.Instance.BringMissionItem;
                    if (string.IsNullOrEmpty(bringItem))
                        _missionItemMoved = true;

                    if (!_missionItemMoved)
                    {
                        var missionItem = (corpHangar ?? itemHangar).Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);
                        if (missionItem == null)
                            missionItem = itemHangar.Items.FirstOrDefault(i => (i.TypeName ?? string.Empty).ToLower() == bringItem);

                        if (missionItem != null)
                        {
                            Logging.Log("Arm: Moving [" + missionItem.TypeName + "]");

                            cargo.Add(missionItem, 1);
                            _missionItemMoved = true;
                            break;
                        }
                    }

                    var itemMoved = false;
                    foreach (var item in ammoHangar.Items.OrderBy(i => i.Quantity))
                    {
                        if (item.ItemId <= 0)
                            continue;

                        var ammo = AmmoToLoad.FirstOrDefault(a => a.TypeId == item.TypeId);
                        if (ammo == null)
                            continue;

                        Logging.Log("Arm: Moving [" + item.TypeName + "]");

                        var moveQuantity = Math.Min(item.Quantity, ammo.Quantity);
                        moveQuantity = Math.Max(moveQuantity, 1);
                        cargo.Add(item, moveQuantity);

                        ammo.Quantity -= moveQuantity;
                        if (ammo.Quantity <= 0)
                            AmmoToLoad.RemoveAll(a => a.TypeId == item.TypeId);

                        itemMoved = true;
                        break;
                    }

                    if (AmmoToLoad.Count == 0 && _missionItemMoved)
                    {
                        _lastAction = DateTime.Now;

                        Logging.Log("Arm: Waiting for items");
                        State = ArmState.WaitForItems;
                    }
                    else if (!itemMoved)
                    {
                        if (AmmoToLoad.Count > 0)
                            foreach (var ammo in AmmoToLoad)
                                Logging.Log("Arm: Missing ammo with TypeId [" + ammo.TypeId + "]");

                        if (!_missionItemMoved)
                            Logging.Log("Arm: Missing mission item [" + bringItem + "]");

                        State = ArmState.NotEnoughAmmo;
                    }
                    break;

                case ArmState.WaitForItems:
                    // Wait 5 seconds after moving
                    if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 5)
                        break;

                    if (cargo.Items.Count == 0)
                        break;

                    if (Cache.Instance.DirectEve.GetLockedItems().Count == 0)
                    {
                        // Close the drone bay, its not required in space.
                        if (droneBay.IsReady)
                            droneBay.Window.Close();

                        Logging.Log("Arm: Done");
                        State = ArmState.Done;
                        break;
                    }

                    // Note, there's no unlock here as we *always* want our ammo!
                    break;
            }
        }
Beispiel #6
0
        private static bool WaitForLockedItems(ArmState _armStateToSwitchTo)
        {
            try
            {
                while (Math.Abs(DateTime.UtcNow.Subtract(_lastArmAction).TotalSeconds) > 5)
                {
                    break;
                }

                //if (Cache.Instance.EveCom.GetLockedItems().Count != 0)
                //{
                //    if (Math.Abs(DateTime.UtcNow.Subtract(_lastArmAction).TotalSeconds) > 15)
                //    {
                //        Logging.Log(WeAreInThisStateForLogs(), "Moving Ammo timed out, clearing item locks", Logging.Orange);
                //        //Cache.Instance.EveCom.UnlockItems();
                //        _lastArmAction = DateTime.UtcNow.AddSeconds(-1);
                //        return false;
                //    }
                //
                //    if (Logging.DebugUnloadLoot) Logging.Log(WeAreInThisStateForLogs(), "Waiting for Locks to clear. GetLockedItems().Count [" + Cache.Instance.EveCom.GetLockedItems().Count + "]", Logging.Teal);
                //    return false;
                //}

                _lastArmAction = DateTime.UtcNow.AddSeconds(-1);
                Logging.Log(WeAreInThisStateForLogs(), "Done", Logging.White);
                _itemsAreBeingMoved = false;
                ChangeArmState(_armStateToSwitchTo);
                return true;
            }
            catch (Exception ex)
            {
                Logging.Log(_States.CurrentArmState.ToString(), "Exception [" + ex + "]", Logging.Debug);
                return false;
            }
        }
Beispiel #7
0
        private static bool MoveItemsToCargo(string moveItemTypeName,int totalMoveItemQuantity, ArmState stateToChangeToWhenDoneMoving, ArmState stateWeWereCalledFrom, bool optional = false)
        {
            try
            {

                if (string.IsNullOrEmpty(moveItemTypeName))
                {
                    ChangeArmState(stateToChangeToWhenDoneMoving);
                    return false;
                }

                if (_itemsAreBeingMoved)
                {
                    if (!WaitForLockedItems(stateWeWereCalledFrom)) return false;
                    return true;
                }

                if (!LookForItem(moveItemTypeName, QuestorCache.Instance.CurrentShipsCargo)) return false;

                if (_weHaveThisManyOfThoseItemsInCargo + _weHaveThisManyOfThoseItemsInItemHangar + _weHaveThisManyOfThoseItemsInAmmoHangar + _weHaveThisManyOfThoseItemsInLootHangar < totalMoveItemQuantity)
                {
                    if (optional)
                    {
                        ChangeArmState(stateToChangeToWhenDoneMoving);
                        return true;
                    }

                    Logging.Log(WeAreInThisStateForLogs(), "ItemHangar has: [" + _weHaveThisManyOfThoseItemsInItemHangar + "] AmmoHangar has: [" + _weHaveThisManyOfThoseItemsInAmmoHangar + "] LootHangar has: [" + _weHaveThisManyOfThoseItemsInLootHangar + "] [" + moveItemTypeName + "] we need [" + totalMoveItemQuantity + "] units)", Logging.Red);
                    _itemsAreBeingMoved = false;
                    QuestorCache.Instance.Paused = true;
                    ChangeArmState(ArmState.NotEnoughAmmo);
                    return true;
                }

                //
                // check the local cargo for items and subtract the items in the cargo from the quantity we still need to move to our cargohold
                //
                if (_cargoItems.Any())
                {
                    _itemsLeftToMoveQuantity = totalMoveItemQuantity;
                    foreach (EveCom.Item moveItemInCargo in _cargoItems)
                    {
                        _itemsLeftToMoveQuantity -= moveItemInCargo.Stacksize;
                        if (_itemsLeftToMoveQuantity <= 0)
                        {
                            ChangeArmState(stateToChangeToWhenDoneMoving);
                            return true;
                        }

                        continue;
                    }
                }

                if (_lootHangarItem != null && !string.IsNullOrEmpty(_lootHangarItem.Type.ToString(CultureInfo.InvariantCulture)))
                {
                    if (_lootHangarItem.ID == "0" || _lootHangarItem.Volume == 0.00 || _lootHangarItem.Quantity == 0)
                    {
                        return false;
                    }

                    int moveItemQuantity = Math.Min(_lootHangarItem.Stacksize, _itemsLeftToMoveQuantity);
                    moveItemQuantity = Math.Max(moveItemQuantity, 1);
                    _itemsLeftToMoveQuantity = _itemsLeftToMoveQuantity - moveItemQuantity;
                    Logging.Log(WeAreInThisStateForLogs(), "Moving Item [" + _lootHangarItem.Type + "] from Loothangar to CargoHold: We have [" + _itemsLeftToMoveQuantity + "] more item(s) to move after this", Logging.White);
                    QuestorCache.Instance.CurrentShipsCargo.Add(_lootHangarItem, moveItemQuantity);
                    _itemsAreBeingMoved = true;
                    _lastArmAction = DateTime.UtcNow;
                    return false;
                }

                if (_itemHangarItem != null && !string.IsNullOrEmpty(_itemHangarItem.Type.ToString(CultureInfo.InvariantCulture)))
                {
                    if (_itemHangarItem.ID == "0" || _itemHangarItem.Volume == 0.00 || _itemHangarItem.Quantity == 0)
                    {
                        return false;
                    }

                    int moveItemQuantity = Math.Min(_itemHangarItem.Stacksize, _itemsLeftToMoveQuantity);
                    moveItemQuantity = Math.Max(moveItemQuantity, 1);
                    _itemsLeftToMoveQuantity = _itemsLeftToMoveQuantity - moveItemQuantity;
                    Logging.Log(WeAreInThisStateForLogs(), "Moving Item [" + _itemHangarItem.Type + "] from ItemHangar to CargoHold: We have [" + _itemsLeftToMoveQuantity + "] more item(s) to move after this", Logging.White);
                    QuestorCache.Instance.CurrentShipsCargo.Add(_itemHangarItem, moveItemQuantity);
                    _itemsAreBeingMoved = true;
                    _lastArmAction = DateTime.UtcNow;
                    return false;
                }

                if (_ammoHangarItem != null && !string.IsNullOrEmpty(_ammoHangarItem.Type.ToString(CultureInfo.InvariantCulture)))
                {
                    if (_ammoHangarItem.ID == "0" || _ammoHangarItem.Volume == 0.00 || _ammoHangarItem.Quantity == 0)
                    {
                        return false;
                    }

                    int moveItemQuantity = Math.Min(_ammoHangarItem.Stacksize, _itemsLeftToMoveQuantity);
                    moveItemQuantity = Math.Max(moveItemQuantity, 1);
                    _itemsLeftToMoveQuantity = _itemsLeftToMoveQuantity - moveItemQuantity;
                    Logging.Log(WeAreInThisStateForLogs(), "Moving Item [" + _ammoHangarItem.Type + "] from AmmoHangar to CargoHold: We have [" + _itemsLeftToMoveQuantity + "] more item(s) to move after this", Logging.White);
                    QuestorCache.Instance.CurrentShipsCargo.Add(_ammoHangarItem, moveItemQuantity);
                    _itemsAreBeingMoved = true;
                    _lastArmAction = DateTime.UtcNow;
                    return false;
                }

                _itemsAreBeingMoved = false;
                return true;
            }
            catch (Exception ex)
            {
                Logging.Log(WeAreInThisStateForLogs(), "Exception [" + ex + "]", Logging.Debug);
                return false;
            }
        }
Beispiel #8
0
        private static bool MoveDronesToDroneBay(string moveItemTypeName, ArmState stateToChangeToWhenDoneMoving, ArmState stateWeWereCalledFrom, bool optional = false)
        {
            try
            {
                if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "(re)Entering MoveDronesToDroneBay", Logging.Debug);
                //
                // we assume useDrones is true if we got this far already.
                //

                if (string.IsNullOrEmpty(moveItemTypeName))
                {
                    if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "if (string.IsNullOrEmpty(MoveItemTypeName))", Logging.Debug);
                    ChangeArmState(stateToChangeToWhenDoneMoving);
                    return false;
                }

                if (_itemsAreBeingMoved)
                {
                    if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "if (ItemsAreBeingMoved)", Logging.Debug);
                    if (!WaitForLockedItems(stateWeWereCalledFrom)) return false;
                    return true;
                }

                if (QuestorCache.Instance.ItemHangar == null)
                {
                    if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "if (Cache.Instance.ItemHangar == null)", Logging.Debug);
                    return false;
                }

                if (Drones.DroneBay == null)
                {
                    if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "if (Drones.DroneBay == null)", Logging.Debug);
                    return false;
                }

                if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "if (Drones.DroneBay != null)", Logging.Debug);

                //This wasnt getting instanciated in Drones.cs so moved here. This is the only place that currently uses it
                EveComFramework.Data.DroneType MyDroneType = EveComFramework.Data.DroneType.All.FirstOrDefault(i => i.ID == Drones.DroneTypeId);
                if ((int)Drones.DroneBay.MaxCapacity == 0 && _droneBayRetries <= 2)
                {
                    _droneBayRetries++;
                    Logging.Log("Arm.MoveDronesToDroneBay", "Dronebay: not yet ready. Capacity [" + Drones.DroneBay.MaxCapacity + "] UsedCapacity [" + Drones.DroneBay.UsedCapacity + "]", Logging.White);
                    Time.Instance.NextArmAction = DateTime.UtcNow.AddSeconds(2);
                    return false;
                }

                if (!LookForItem(moveItemTypeName, Drones.DroneBay))
                {
                    if (Logging.DebugArm) Logging.Log("Arm.MoveDronesToDroneBay", "if (!LookForItem(MoveItemTypeName, Drones.DroneBay))", Logging.Debug);
                    return false;
                }

                Logging.Log("Arm.MoveDronesToDroneBay", "Dronebay details: Capacity [" + Drones.DroneBay.MaxCapacity + "] UsedCapacity [" + Drones.DroneBay.UsedCapacity + "]", Logging.White);
                if ((int)Drones.DroneBay.MaxCapacity == (int)Drones.DroneBay.UsedCapacity)
                {
                    Logging.Log("Arm.MoveDronesToDroneBay", "Dronebay is Full. No need to move any more drones.", Logging.White);
                    ChangeArmState(stateToChangeToWhenDoneMoving);
                    return false;
                }

                int neededDrones = 0;
                if (MyDroneType != null)
                {
                    neededDrones = (int)Math.Floor((Drones.DroneBay.MaxCapacity - Drones.DroneBay.UsedCapacity) / MyDroneType.Volume);
                    Logging.Log("Arm.MoveDronesToDroneBay", "neededDrones: [" + neededDrones + "]", Logging.White);
                }

                if ((int)neededDrones == 0)
                {
                    Logging.Log("Arm.MoveDronesToDroneBay", "MoveItems", Logging.White);
                    ChangeArmState(ArmState.MoveBringItems);
                    return false;
                }

                if (_weHaveThisManyOfThoseItemsInCargo + _weHaveThisManyOfThoseItemsInItemHangar + _weHaveThisManyOfThoseItemsInAmmoHangar + _weHaveThisManyOfThoseItemsInLootHangar < neededDrones)
                {
                    Logging.Log("Arm.MoveDronesToDroneBay", "ItemHangar has: [" + _weHaveThisManyOfThoseItemsInItemHangar + "] AmmoHangar has: [" + _weHaveThisManyOfThoseItemsInAmmoHangar + "] LootHangar has: [" + _weHaveThisManyOfThoseItemsInLootHangar + "] [" + moveItemTypeName + "] we need [" + neededDrones + "] drones to fill the DroneBay)", Logging.Red);
                    _itemsAreBeingMoved = false;
                    QuestorCache.Instance.Paused = true;
                    ChangeArmState(ArmState.NotEnoughDrones);
                    return true;
                }

                //
                // check the drone bay so we can determine how many drones we need to move
                //
                if (Drones.DroneBay.Items.Any())
                {
                    _itemsLeftToMoveQuantity = neededDrones;
                    foreach (EveCom.Item moveItemInCargo in _cargoItems)
                    {
                        _itemsLeftToMoveQuantity -= moveItemInCargo.Stacksize;
                        if (_itemsLeftToMoveQuantity <= 0)
                        {
                            ChangeArmState(stateToChangeToWhenDoneMoving);
                            return true;
                        }

                        continue;
                    }
                }

                if (_lootHangarItem != null && !string.IsNullOrEmpty(_lootHangarItem.Type.ToString(CultureInfo.InvariantCulture)))
                {
                    if (_lootHangarItem.ID == "0" || _lootHangarItem.Volume == 0.00 || _lootHangarItem.Quantity == 0)
                    {
                        return false;
                    }

                    int moveDroneQuantity = Math.Min(_lootHangarItem.Stacksize, _itemsLeftToMoveQuantity);
                    moveDroneQuantity = Math.Max(moveDroneQuantity, 1);
                    _itemsLeftToMoveQuantity = _itemsLeftToMoveQuantity - moveDroneQuantity;
                    Logging.Log("Arm.MoveDronesToDroneBay", "Moving Item [" + _lootHangarItem.Type + "] from LootHangar to DroneBay: We have [" + _itemsLeftToMoveQuantity + "] more item(s) to move after this", Logging.White);
                    Drones.DroneBay.Add(_lootHangarItem, moveDroneQuantity);
                    _itemsAreBeingMoved = true;
                    _lastArmAction = DateTime.UtcNow;
                    return false;
                }

                if (_itemHangarItem != null && !string.IsNullOrEmpty(_itemHangarItem.Type.ToString(CultureInfo.InvariantCulture)))
                {
                    if (_itemHangarItem.ID == "0" || _itemHangarItem.Volume == 0.00 || _itemHangarItem.Quantity == 0)
                    {
                        return false;
                    }

                    int moveDroneQuantity = Math.Min(_itemHangarItem.Stacksize, _itemsLeftToMoveQuantity);
                    moveDroneQuantity = Math.Max(moveDroneQuantity, 1);
                    _itemsLeftToMoveQuantity = _itemsLeftToMoveQuantity - moveDroneQuantity;
                    Logging.Log("Arm.MoveDronesToDroneBay", "Moving Item [" + _itemHangarItem.Type + "] from ItemHangar to DroneBay: We have [" + _itemsLeftToMoveQuantity + "] more item(s) to move after this", Logging.White);
                    Drones.DroneBay.Add(_itemHangarItem, moveDroneQuantity);
                    _itemsAreBeingMoved = true;
                    _lastArmAction = DateTime.UtcNow;
                    return false;
                }

                if (_ammoHangarItem != null && !string.IsNullOrEmpty(_ammoHangarItem.Type.ToString(CultureInfo.InvariantCulture)))
                {
                    if (_ammoHangarItem.ID == "0" || _ammoHangarItem.Volume == 0.00 || _ammoHangarItem.Quantity == 0)
                    {
                        return false;
                    }

                    int moveDroneQuantity = Math.Min(_ammoHangarItem.Stacksize, _itemsLeftToMoveQuantity);
                    moveDroneQuantity = Math.Max(moveDroneQuantity, 1);
                    _itemsLeftToMoveQuantity = _itemsLeftToMoveQuantity - moveDroneQuantity;
                    Logging.Log("Arm.MoveDronesToDroneBay", "Moving Item [" + _ammoHangarItem.Type + "] from AmmoHangar to DroneBay: We have [" + _itemsLeftToMoveQuantity + "] more item(s) to move after this", Logging.White);
                    Drones.DroneBay.Add(_ammoHangarItem, moveDroneQuantity);
                    _itemsAreBeingMoved = true;
                    _lastArmAction = DateTime.UtcNow;
                    return false;
                }

                return true;
            }
            catch (Exception ex)
            {
                Logging.Log("Arm.MoveDronesToDroneBay", "Exception [" + ex + "]", Logging.Red);
                return false;
            }
        }