Пример #1
0
        private IEveInvChildWindow GetStationItemsChildWindow()
        {
            var methodName = "GetStationItemsChildWindow";

            LogTrace(methodName);

            var inventoryWindow = _eveWindowProvider.GetInventoryWindow();

            if (LavishScriptObject.IsNullOrInvalid(inventoryWindow))
            {
                return(null);
            }

            var childWindow = inventoryWindow.GetChildWindow(StealthBot.MeCache.StationId, "StationItems");

            if (LavishScriptObject.IsNullOrInvalid(childWindow))
            {
                LogMessage(methodName, LogSeverityTypes.Debug, "Error: Child window for ID {0}, Name StationItems was null or invalid.", StealthBot.MeCache.StationId);
                return(null);
            }

            return(childWindow);
        }
Пример #2
0
        public IEveInvChildWindow GetChildWindow()
        {
            var methodName = "GetChildWindow";

            LogTrace(methodName);

            var inventoryWindow = _eveWindowProvider.GetInventoryWindow();

            if (LavishScriptObject.IsNullOrInvalid(inventoryWindow))
            {
                LogMessage(methodName, LogSeverityTypes.Debug, "Error: Inventory window was null.");
                return(null);
            }

            var eveInvChildWindow = inventoryWindow.GetChildWindow(CurrentContainer.ID);

            if (eveInvChildWindow == null)
            {
                LogMessage(methodName, LogSeverityTypes.Debug, "Error: Child inventory window for ID {0} was null.", CurrentContainer.ID);
                return(null);
            }

            return(eveInvChildWindow);
        }
Пример #3
0
 public IEveInvWindow GetInventoryWindow()
 {
     return(_eveWindowProvider.GetInventoryWindow());
 }
Пример #4
0
        private void ProcessCourierState()
        {
            var methodName = "ProcessCourierState";

            LogTrace(methodName);

            switch (_courierState)
            {
            case CourierMissionStates.MoveToStart:
                var isAtMissionStartBookmark = Core.StealthBot.MissionCache.IsAtMissionStartBookmark(ActiveMission);
                if (isAtMissionStartBookmark)
                {
                    _courierState = CourierMissionStates.LoadCourierCargo;
                    goto case CourierMissionStates.LoadCourierCargo;
                }

                MoveToMissionStart();
                break;

            case CourierMissionStates.LoadCourierCargo:
                if (!Core.StealthBot.Station.IsStationHangarActive)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Making station hangar active.");
                    Core.StealthBot.Station.MakeStationHangarActive();
                    return;
                }

                var missionItem = Core.StealthBot.MeCache.HangarItems.FirstOrDefault(
                    item => item.TypeID == ActiveMission.TypeId);

                if (missionItem == null)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Mission item not found in station hangar; moving to mission end.");
                    _courierState = CourierMissionStates.MoveToEnd;
                    goto case CourierMissionStates.MoveToEnd;
                }

                //If I have space for cargo
                var freeCargoCapacity = Core.StealthBot.MeCache.Ship.CargoCapacity - Core.StealthBot.MeCache.Ship.UsedCargoCapacity;
                if (freeCargoCapacity >= missionItem.Volume)
                {
                    //If another trip is required...
                    var requiredCapacity = Core.StealthBot.MeCache.HangarItems.Where(
                        item => item.TypeID == ActiveMission.TypeId).Sum(
                        item => item.Volume * item.Quantity);

                    if (requiredCapacity > freeCargoCapacity)
                    {
                        LogMessage(methodName, LogSeverityTypes.Standard, "Cargohold has {0} m^3 free and {1} m^3 is needed for the (remaining) mission items - another trip is required.",
                                   freeCargoCapacity, requiredCapacity);
                        _anotherTripRequired = true;
                    }
                    else
                    {
                        _anotherTripRequired = false;
                    }

                    var fitAllItems = false;
                    LogMessage(methodName, LogSeverityTypes.Standard, "Moving mission items from hangar to cargo.");
                    Core.StealthBot.Ship.TransferItemFromHangarToCargo(ActiveMission.TypeId, out fitAllItems);
                    _courierState = CourierMissionStates.MoveToEnd;
                }
                break;

            case CourierMissionStates.MoveToEnd:
                var isAtMissionEndBookmark = Core.StealthBot.MissionCache.IsAtMissionEndBookmark(ActiveMission);
                if (isAtMissionEndBookmark)
                {
                    _courierState = CourierMissionStates.UnloadCourierCargo;
                    goto case CourierMissionStates.UnloadCourierCargo;
                }

                MoveToMissionEnd();
                break;

            case CourierMissionStates.UnloadCourierCargo:
                if (!Core.StealthBot.Ship.IsCargoHoldActive)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Making ship cargohold active.");
                    Core.StealthBot.Ship.MakeCargoHoldActive();
                    return;
                }

                LogMessage(methodName, LogSeverityTypes.Standard, "Transfering non-charge items to station hangar.");
                Core.StealthBot.Ship.TransferCargoHoldToStationExcludingCategoryIds((int)CategoryIDs.Charge);
                _courierState = CourierMissionStates.StackCargo;
                break;

            case CourierMissionStates.StackCargo:
                if (!Core.StealthBot.Station.IsStationHangarActive)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Making station hangar active.");
                    Core.StealthBot.Station.MakeStationHangarActive();
                    return;
                }

                LogMessage(methodName, LogSeverityTypes.Standard, "Stacking station hangar.");
                var eveWindow = _eveWindowProvider.GetInventoryWindow();
                eveWindow.StackAll();

                if (_anotherTripRequired)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Another trip was required, mission not yet complete.");
                    _courierState = CourierMissionStates.MoveToStart;
                    goto case CourierMissionStates.MoveToStart;
                }

                _courierState       = CourierMissionStates.Idle;
                _missionRunnerState = MissionRunnerStates.TurnInMission;
                break;
            }
        }
Пример #5
0
        private bool ProcessLoot(Action action)
        {
            var methodName = "ProcessLoot";

            LogTrace(methodName, "Action: {0}", action.Name);

            if (StealthBot.Movement.IsMoving)
            {
                return(false);
            }

            //Get a list of entities of matching groupID
            var possibleTargetEntities = StealthBot.EntityProvider.EntityWrappers.Where(entity => !_lootCanBlacklist.Contains(entity.ID) &&
                                                                                        (entity.HaveLootRights || entity.GroupID == (int)GroupIDs.SpawnContainer));

            //If we don't have a specific target...
            if (action.TargetName == string.Empty)
            {
                possibleTargetEntities = possibleTargetEntities.Where(entity => entity.GroupID == action.GroupId);

                if (!possibleTargetEntities.Any())
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Could not find any cans on grid, error. Dequeueing action.");
                    return(true);
                }

                //If a "near wreck" option is defined...
                if (action.NearWreck != string.Empty)
                {
                    //Get the specified wreck...
                    var wreckEntity = StealthBot.EntityProvider.EntityWrappers.FirstOrDefault(x => x.Name.Contains(action.NearWreck, StringComparison.InvariantCultureIgnoreCase));

                    //If we found no result we have issues.
                    if (wreckEntity == null)
                    {
                        LogMessage(methodName, LogSeverityTypes.Standard, "Could not find wreck/can matching NearWreck \"{0}\", error. Dequeueing action.",
                                   action.NearWreck);
                        return(true);
                    }

                    //Sort the cans by distance to the wreck, ascending.
                    possibleTargetEntities = possibleTargetEntities.OrderBy(
                        x => Distance(wreckEntity.X, wreckEntity.Y, wreckEntity.Z, x.X, x.Y, x.Z));
                }
            }

            //Get the first match
            IEntityWrapper targetEntity;

            if (action.TargetName == string.Empty)
            {
                targetEntity = possibleTargetEntities.FirstOrDefault();

                if (targetEntity == null)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Could not find any non-blacklisted cans on grid, error. Dequeueing action.");
                    return(true);
                }
            }
            else
            {
                //This is excepting due to a null name. No easy way to figure out which entity it is either.
                targetEntity = possibleTargetEntities.FirstOrDefault(
                    x => x.Name != null && x.Name.Contains(action.TargetName) &&
                    ((action.GroupId == 0 && (x.GroupID == (int)GroupIDs.CargoContainer || x.GroupID == (int)GroupIDs.SpawnContainer || x.GroupID == (int)GroupIDs.Wreck)) ||
                     (action.GroupId > 0 && x.GroupID == action.GroupId)));
                if (targetEntity == null)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard,
                               "Could not find wreck/can matching name \"{0}\", error. Dequeueing action.",
                               action.TargetName);
                    return(true);
                }
            }

            //If we're too far, approach.
            if (targetEntity.Distance > (int)Ranges.LootActivate)
            {
                LogMessage(methodName, LogSeverityTypes.Standard, "Moving to target wreck/can \"{0}\" ({1}) for looting.",
                           targetEntity.Name, targetEntity.ID);
                var destination = new Destination(DestinationTypes.Entity, targetEntity.ID)
                {
                    Distance = (int)Ranges.LootActivate
                };
                StealthBot.Movement.QueueDestination(destination);
            }
            else
            {
                var inventoryWindow = _eveWindowProvider.GetInventoryWindow();

                //If there's no loot window for it, open one
                var childWindow = inventoryWindow.GetChildWindow(targetEntity.ID);
                if (LavishScriptObject.IsNullOrInvalid(childWindow))
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Opening cargo of target wreck/can \"{0}\" ({1}).",
                               targetEntity.Name, targetEntity.ID);
                    targetEntity.Open();
                    return(false);
                }

                if (inventoryWindow.ActiveChild.ItemId != targetEntity.ID)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Making target wreck/can \"{0}\" ({1}) loot window active.",
                               targetEntity.Name, targetEntity.ID);
                    childWindow.MakeActive();
                    return(false);
                }

                //Get all items, try to move them to cargo.
                var cargo = targetEntity.ToEntity.GetCargo();

                //If there are no items in the cargo, wait a few seconds
                if (cargo.Count == 0)
                {
                    if (_lootTimeouts-- <= 0)
                    {
                        //reset teh loot timeout and dequeue action
                        _lootTimeouts = MaxLootTimeouts;

                        LogMessage(methodName, LogSeverityTypes.Standard, "Did not find any cargo in can \"{0}\" ({1}) after 3 pulses, blacklisting and trying another...",
                                   targetEntity.Name, targetEntity.ID);
                        if (!_lootCanBlacklist.Contains(targetEntity.ID))
                        {
                            _lootCanBlacklist.Add(targetEntity.ID);
                        }
                    }
                    else
                    {
                        LogMessage(methodName, LogSeverityTypes.Standard, "No items found in target wreck/can, waiting a pulse...");
                        StealthBot.ModuleManager.DelayPulseByHighestTime(1);
                    }
                }
                else
                {
                    //If the required item / volume are defined just look for them.
                    var typeId = -1;

                    if (StealthBot.MissionRunner.ActiveMission.TypeId > -1)
                    {
                        typeId = StealthBot.MissionRunner.ActiveMission.TypeId;
                    }

                    List <IItem> itemQueryResults;

                    //First, check against the specified item name.
                    if (action.ItemName != string.Empty)
                    {
                        itemQueryResults = cargo
                                           .Where(item => item.Name.Contains(action.ItemName, StringComparison.InvariantCultureIgnoreCase))
                                           .ToList();

                        //If we got a match, move it to cargo.
                        if (itemQueryResults.Count > 0)
                        {
                            foreach (var item in itemQueryResults)
                            {
                                LogMessage(methodName, LogSeverityTypes.Standard, "Attempting to move item \"{0}\" matching item name \"{1}\" from target wreck/can \"{2}\" ({3}) to our ship.",
                                           item.Name, action.ItemName, targetEntity.Name, targetEntity.ID);
                                item.MoveTo(StealthBot.MeCache.Ship.Id, ToDestinationNames.CargoHold.ToString());
                            }

                            //We were able to find the item we needed for this action; we're done here.
                            LogMessage(methodName, LogSeverityTypes.Standard, "Found action target item and looted it; dequeueing action.");
                            return(true);
                        }
                    }
                    //Next, check if it matches the typeID for the mission.
                    else if (typeId >= 0)
                    {
                        itemQueryResults = cargo
                                           .Where(item => item.TypeID == typeId)
                                           .ToList();

                        //If we have results, move them to cargo.
                        if (itemQueryResults.Count > 0)
                        {
                            foreach (var item in itemQueryResults)
                            {
                                LogMessage(methodName, LogSeverityTypes.Standard, "Attempting to move item \"{0}\" matching required type ID {1} from target wreck/can \"{2}\" ({3}) to our ship.",
                                           item.Name, typeId, targetEntity.Name, targetEntity.ID);
                                item.MoveTo(StealthBot.MeCache.Ship.Id, ToDestinationNames.CargoHold.ToString());
                            }

                            //We were able to find the item we needed for the mission; we're done here.
                            LogMessage(methodName, LogSeverityTypes.Standard, "Found mission objective item and looted it; dequeueing action.");
                            return(true);
                        }
                    }
                    //otherwise, it means target name was defined for this can/wreck. Just loot and be done with it.
                    else
                    {
                        itemQueryResults = cargo
                                           .OrderByDescending(item => item.Volume * item.Quantity)
                                           .ToList();

                        //If we got a match, move it to cargo.
                        if (itemQueryResults.Count > 0)
                        {
                            foreach (var item in itemQueryResults)
                            {
                                LogMessage(methodName, LogSeverityTypes.Standard, "Attempting to move item \"{0}\" from target wreck/can \"{1}\" ({2}) to our ship.",
                                           item.Name, targetEntity.Name, targetEntity.ID);
                                item.MoveTo(StealthBot.MeCache.Ship.Id, ToDestinationNames.CargoHold.ToString());
                            }

                            //We were able to find the item we needed for this action; we're done here.
                            LogMessage(methodName, LogSeverityTypes.Standard, "Found and looted name-specified Loot target \"{0}\" ({1}); dequeueing action.",
                                       targetEntity.Name, targetEntity.ID);
                            return(true);
                        }
                    }

                    if (!_lootCanBlacklist.Contains(targetEntity.ID))
                    {
                        //If we got here, we didn't find the item, so blacklist the can and try another.
                        LogMessage(methodName, LogSeverityTypes.Standard, "Did not find item with typeID {0} or ItemName \"{1}\" in can \"{2}\" ({3}), blacklisting and trying another...",
                                   typeId, action.ItemName, targetEntity.Name, targetEntity.ID);
                        _lootCanBlacklist.Add(targetEntity.ID);
                    }
                }
            }

            return(false);
        }
Пример #6
0
        public IEveInvWindow GetInventoryWindow()
        {
            var inventoryWindow = _eveWindowProvider.GetInventoryWindow();

            return(LavishScriptObject.IsNullOrInvalid(inventoryWindow) ? null : inventoryWindow);
        }