コード例 #1
0
        //Initialises a new drone object in the world
        private void CreateDrone()
        {
            var update = _droneLogic.AddDrone();

            if (!update.Value)
            {
                return;
            }
            var model = Content.Load <Model>("Models/Drones/drone", ContentManagerLoaderSettings.Default);
            var drone = new Entity(new Vector3(update.Key.Route.First().XPosition, update.Key.Route.First().YPosition,
                                               update.Key.Route.First().ZPosition), update.Key.Name);

            drone.Components.Add(new ModelComponent(model));
            drone.Transform.Scale = new Vector3(update.Key.Scale.XPosition, update.Key.Scale.YPosition,
                                                update.Key.Scale.ZPosition);
            drone.Transform.Rotation = Quaternion.Identity;
            update.Key.Route.RemoveAt(0);
            Speeds.Add(update.Key.Id, update.Key.Speed);
            _waypointIndexes.Add(update.Key.Id, 0);
            if (Drones.IsNullOrEmpty())
            {
                Drones = new Dictionary <int, Entity>();
            }
            Drones.Add(update.Key.Id, drone);
            DistanceTravelled.Add(update.Key.Id, 0);
            TotalDroneCount++;
            _routes.Add(update.Key.Id, update.Key.Route.Select(x => new Vector3(x.XPosition, x.YPosition, x.ZPosition)).ToList());
            SceneSystem.SceneInstance.RootScene.Entities.Add(drone);
        }
コード例 #2
0
        private void RunSimulation()
        {
            CordenatorTask = Task.Run(async() => {
                for (; ;)
                {
                    Cordinator();
                    RefreshViews();
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            });

            RechargeStationTask = Task.Run(async() => {
                for (; ;)
                {
                    Drones.Where(d => d.State == DroneState.Recharging).ToList().ForEach((drone) => {
                        if (drone.Battery < 100)
                        {
                            drone.Battery += 1;
                        }
                        else
                        {
                            drone.State = DroneState.Waiting;
                        }
                    });
                    RefreshViews();
                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                }
            });
        }
コード例 #3
0
 private void Cordinator()
 {
     Positions.OrderByDescending(p => p.Position.ThreatLevel).ToList().ForEach((position) => {
         if (position.ActiveDrone != null && position.ActiveDrone.Battery <= 10)
         {
             var drone            = position.ActiveDrone;
             drone.State          = DroneState.Recharging;
             position.ActiveDrone = null;
         }
         else if (position.ActiveDrone == null && Drones.Where(d => d.State == DroneState.Waiting).Count() != 0)
         {
             var drone            = Drones.Where(d => d.State == DroneState.Waiting).FirstOrDefault();
             drone.State          = DroneState.OnGarde;
             position.ActiveDrone = drone;
         }
         else if (position.ActiveDrone == null && Drones.Where(d => d.State == DroneState.Waiting).Count() == 0)
         {
             var found = Positions.Where(p => p.ActiveDrone != null && p.Position.ThreatLevel < position.Position.ThreatLevel)
                         .OrderBy(p => p.Position.ThreatLevel).FirstOrDefault();
             if (found != null)
             {
                 var newDrone         = found.ActiveDrone;
                 found.ActiveDrone    = null;
                 position.ActiveDrone = newDrone;
             }
         }
         else if (position.ActiveDrone != null && position.ActiveDrone.Battery > 10)
         {
             position.ActiveDrone.Battery -= (int)Math.Round(position.Position.ThreatLevel * 0.1);
         }
     });
 }
コード例 #4
0
ファイル: MapController.cs プロジェクト: sojanml/eX-Portal
        public ActionResult FlightData([Bind(Prefix = "ID")] int FlightID = 0, int IsLive = 0)
        {
            if (!exLogic.User.hasAccess("FLIGHT.MAP"))
            {
                return(RedirectToAction("NoAccess", "Home"));
            }
            ViewBag.FlightID = FlightID;
            Drones thisDrone = new Drones();

            ViewBag.AllowedLocation = thisDrone.getAllowedLocation(FlightID);
            ViewBag.DroneID         = thisDrone.DroneID;

            if (thisDrone.isLiveFlight(FlightID) || IsLive == 1)
            {
                ViewBag.IsLive    = true;
                ViewBag.PlayerURL = thisDrone.getLiveURL(FlightID);
                ViewBag.Title     = "Flight Map (Live)";
            }
            else
            {
                ViewBag.IsLive       = false;
                ViewBag.Title        = "Flight Map (Replay)";
                ViewBag.VideoStartAt = thisDrone.getVideoStartDate(FlightID);
                ViewBag.PlayerURL    = thisDrone.getPlayListURL(FlightID);
            }
            //if (IsLive == 1) IsLive = ViewBag.IsLive = true;
            if (!exLogic.User.hasAccess("FLIGHT.VIDEOS"))
            {
                ViewBag.PlayerURL    = String.Empty;
                ViewBag.VideoStartAt = String.Empty;
            }
            return(View(thisDrone));
        }
コード例 #5
0
ファイル: MapController.cs プロジェクト: sojanml/eX-Portal
        public JsonResult GeoTag([Bind(Prefix = "ID")]  int FlightID)
        {
            if (!exLogic.User.hasAccess("FLIGHT.MAP"))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            ExponentPortalEntities db = new ExponentPortalEntities();
            var thisDrone             = new Drones();
            var DroneName             = thisDrone.getDroneNameForFlight(FlightID);
            var Records = (
                from n in db.DroneDocuments
                where n.DocumentType == "Geo Tag" &&
                n.FlightID == FlightID
                select new GeoTagReport {
                ID = n.ID,
                DocumentName = n.DocumentName,
                FlightID = FlightID,
                Altitude = n.Altitude,
                DroneName = DroneName,
                Latitude = n.Latitude,
                Longitude = n.Longitude,
                UpLoadedDate = n.UploadedDate
            }
                ).ToList();

            return(Json(Records, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
ファイル: Questor.cs プロジェクト: vega87/questor
        public Questor()
        {
            _lastPulse = DateTime.MinValue;

            _random = new Random();

            _salvage = new Salvage();
            _defense = new Defense();
            _combat = new Combat();
            _traveler = new Traveler();
            _unloadLoot = new UnloadLoot();
            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _missionController = new MissionController();
            _drones = new Drones();
            _panic = new Panic();
            _storyline = new Storyline();

            Settings.Instance.SettingsLoaded += SettingsLoaded;

            // State fixed on ExecuteMission
            State = QuestorState.Idle;

            _directEve = new DirectEve();
            Cache.Instance.DirectEve = _directEve;

            _directEve.OnFrame += OnFrame;
        }
コード例 #7
0
        public FighterCarrier(Texture2D texture, Vector2 location, SpriteBatch spriteBatch, Texture2D droneTexture)
            : base(texture, location, spriteBatch)
        {
            //UseCenterAsOrigin = true;

            //Init drones
            Drones.Add(new Drone(droneTexture, location, spriteBatch, this)
            {
                DroneState = CoreTypes.DroneState.Stowed
            });
            Drones[0].Rotation.Radians = MathHelper.Pi;

            Drones.Add(new Drone(droneTexture, location, spriteBatch, this)
            {
                DroneState = CoreTypes.DroneState.Stowed
            });
            Drones[1].Rotation.Radians = MathHelper.TwoPi;

            BulletTexture     = GameContent.GameAssets.Images.Ships.Bullets[ShipType.FighterCarrier, ShipTier.Tier1];
            DelayBetweenShots = TimeSpan.FromMilliseconds(100);
            DamagePerShot     = 2;
            _initHealth       = 100;
            MovementSpeed     = Vector2.One;
            this.TierChanged += new EventHandler(FighterCarrier_TierChanged);
            DamagePerShot     = 2;
            this.PlayerType   = PlayerType.Ally;
        }
コード例 #8
0
ファイル: Questor.cs プロジェクト: dineshkummarc/Questor
        public Questor(frmMain form1)
        {
            m_Parent   = form1;
            _lastPulse = DateTime.MinValue;

            _random = new Random();

            _salvage          = new Salvage();
            _defense          = new Defense();
            _combat           = new Combat();
            _traveler         = new Traveler();
            _unloadLoot       = new UnloadLoot();
            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _missionController = new MissionController();
            _drones            = new Drones();
            _panic             = new Panic();
            _storyline         = new Storyline();

            Settings.Instance.SettingsLoaded += SettingsLoaded;

            // State fixed on ExecuteMission
            State = QuestorState.Idle;

            _directEve = new DirectEve();
            Cache.Instance.DirectEve = _directEve;

            Cache.Instance.StopTimeSpecified = Program.stopTimeSpecified;

            _directEve.OnFrame += OnFrame;
        }
コード例 #9
0
 public ActionResult FlightDataVideo(int ID = 0) {
   //to get the url of the video
   Drones thisDrone = new Drones();
   string sql = "select VideoURL from DroneFlightVideo where videoId=" + ID;
   string videourl = Util.getDBVal(sql);
   ViewBag.PlayerURL = videourl; //thisDrone.getLiveURL(ID);
   return View();
 }
コード例 #10
0
 //Update drone positions and initialises them
 public override async void Update()
 {
     CreateDrone();
     if (!Drones.IsNullOrEmpty())
     {
         await NavigateDrones();
     }
     CheckTimeToExit();
 }
コード例 #11
0
    public void AddDrone(Vector3 position)
    {
        GameObject Clone = Instantiate(newDrone, position, ourDrone.rotation);

        Clone.name = "DroneObject" + droneNumber.ToString();
        Drones.drones.Add(Clone);
        Drones.DroneAdded(dronesPanelGrid, dronesPrefab, iconTransform, icon, PopUp, PopUpRenderTexture);
        droneNumber++;
        Clone.transform.SetParent(transform);
    }
コード例 #12
0
 public DateTime?GetStartTime()
 {
     return(Drones.SelectMany(
                drone => drone.GetValidInstructions()
                ).OrderBy(
                i => i.EndAt
                ).Select(
                i => i.EndAt
                ).FirstOrDefault());
 }
コード例 #13
0
 private void AddDroneCommand_Executed()
 {
     Drones.Add(
         new DroneViewModel(
             new Drone()
     {
         Name = "Drone " + Drones.Count(), Battery = 100
     }
             )
         );
     RefreshViews();
 }
コード例 #14
0
    public ActionResult PlayVideo([Bind(Prefix = "ID")]int id = 0) {
      ViewBag.Title = "Flight Data";
      ViewBag.VideoID = id;
      Drones thisDrone = new Drones();
      ViewBag.AllowedLocation = thisDrone.getAllowedLocation(id);
      ViewBag.DroneID = thisDrone.DroneID;
      //ViewBag.VideoURL = thisDrone.getVideoURL(id);
      //ViewBag.PlayerURL = thisDrone.getPlayerURL(id);

      return View();

    }
コード例 #15
0
        private void CalculateDamage(Ship ship)
        {
            double damage = 0;

            foreach (var weapon in Weapons.GroupBy(x => x))
            {
                int weaponCount = weapon.Count();
                damage             += weapon.Key.FromWeapons().Damage *weaponCount;
                LaserEquippedCount += weaponCount;
            }

            foreach (double amount in ship.Boosts.Where(x => x.Type == BoosterType.DAMAGE).Select(x => x.Amount))
            {
                damage *= amount;
            }

            bool isFullDroneDesign = Drones.GroupBy(x => x.StatsDesignID).Count() == 1;

            foreach (var dronePair in Drones)
            {
                double inner_damage = 0;
                foreach (var weapon in dronePair.WeaponItems.GroupBy(x => x))
                {
                    int weaponCount = weapon.Count();
                    inner_damage       += weapon.Key.FromWeapons().Damage *weaponCount;
                    LaserEquippedCount += weaponCount;
                }
                inner_damage *= dronePair.DroneID.FromDrones().DamageBoost;

                if (dronePair.StatsDesignID != DroneDesign.NONE.ID)
                {
                    DroneDesign design = dronePair.StatsDesignID.FromDroneDesigns();
                    if (isFullDroneDesign)
                    {
                        foreach (double amount in design.Full.Where(x => x.Type == BoosterType.DAMAGE).Select(x => x.Amount))
                        {
                            inner_damage *= amount;
                        }
                    }
                    else
                    {
                        foreach (double amount in design.Single.Where(x => x.Type == BoosterType.DAMAGE).Select(x => x.Amount))
                        {
                            inner_damage *= amount;
                        }
                    }
                }

                damage += inner_damage;
            }

            Damage = (int)damage;
        }
コード例 #16
0
 private void SetDrones(int count)
 {
     Drones.Clear();
     for (int i = 0; i < count; i++)
     {
         Drone drone = new Drone()
         {
             Name = "Drone " + i, Battery = 100
         };
         DroneViewModel DroneVM = new DroneViewModel(drone);
         Drones.Add(DroneVM);
     }
 }
コード例 #17
0
 private IEnumerable <Unload> GetAllUnloadInstruction()
 {
     return(Drones.SelectMany(
                drone => drone.GetValidInstructions()
                .Where(
                    i => i.GetType() == typeof(Unload)
                    ).Select(
                    i => (i as Unload)
                    )
                ).OrderBy(
                u => u.EndAt
                ));
 }
コード例 #18
0
ファイル: DroneFactory.cs プロジェクト: shep22/Runling_Client
        private DroneStateManager AddDroneData(GameObject drone)
        {
            do
            {
                _lastId++;
            } while (Drones.ContainsKey(_lastId));

            var droneData = drone.AddComponent <DroneStateManager>();

            droneData.Initialize(_lastId, this);
            Drones[_lastId] = droneData;
            return(droneData);
        }
コード例 #19
0
        public GenericCombatStoryline()
        {
            _neededAmmo = new List <Ammo>();

            _agentInteraction = new AgentInteraction();
            _arm               = new Arm();
            _traveler          = new Traveler();
            _combat            = new Combat();
            _drones            = new Drones();
            _salvage           = new Salvage();
            _missionController = new MissionController();

            Settings.Instance.SettingsLoaded += ApplySettings;
        }
コード例 #20
0
        public GenericCombatStoryline()
        {
            _neededAmmo = new List<Ammo>();

            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _traveler = new Traveler();
            _combat = new Combat();
            _drones = new Drones();
            _salvage = new Salvage();
            _missionController = new MissionController();

            Settings.Instance.SettingsLoaded += ApplySettings;
        }
コード例 #21
0
        public GenericCombatStoryline()
        {
            _neededAmmo = new List<Ammo>();

            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _combat = new Combat();
            _drones = new Drones();
            _salvage = new Salvage();
            _statistics = new Statistics();
            _combatMissionCtrl = new CombatMissionCtrl();

            Settings.Instance.SettingsLoaded += ApplySettings;
        }
コード例 #22
0
ファイル: AddDrone.cs プロジェクト: Sevin556/drone_vstool
    public void addDrone(Transform position)
    {
        Vector3 newPosition = position.position;

        GameObject Clone = Instantiate(newDrone, newPosition, ourDrone.rotation);

        Clone.name = "DroneObject" + droneNumber.ToString();
        //DroneList.drones.Add(Clone);ß
        //DisplayDrones.dronesList.Add(Clone);
        Drones.drones.Add(new Drone(Clone, new DroneFlightData()));
        Drones.DroneAdded(tarfetTransform, dronesPrefab, iconTransform, icon, PopUp, RenderTexture);
        Debug.Log(Clone.name + "added");
        droneNumber++;
        //Clone.GetComponent("DroneController").enabled = false;
    }
コード例 #23
0
    public void AddDrone(DroneFlightData flightData)
    {
        Mapbox.Utils.Vector2d mapboxPosition = new Mapbox.Utils.Vector2d(flightData.Latitude, flightData.Longitude);
        Vector3 position3d = MapController.Instance.Map.GeoToWorldPosition(mapboxPosition, false);

        //float groundAltitude = MapController.Instance.Map.QueryElevationInUnityUnitsAt(MapController.Instance.Map.WorldToGeoPosition(position3d));
        position3d.y = (float)flightData.Altitude;

        GameObject Clone = Instantiate(newDrone, position3d, ourDrone.rotation);

        Clone.name = "DroneObject" + droneNumber.ToString();
        Drones.drones.Add(new Drone(Clone, flightData));
        Drones.DroneAdded(dronesPanelGrid, dronesPrefab, iconTransform, icon, PopUp, PopUpRenderTexture);
        droneNumber++;
        Clone.transform.SetParent(transform);
    }
コード例 #24
0
        //Loops through each drone to update their position and remove them from the world if necessary
        private async Task NavigateDrones()
        {
            var toRemove = new List <int>();

            foreach (var drone in Drones.ToList())
            {
                toRemove.Add(await NavigateToNexPoint(drone));
            }
            foreach (var key in toRemove.Where(x => x != 0))
            {
                var drone = Drones.ContainsKey(key) ? Drones[key] : null;
                SceneSystem.SceneInstance.RootScene.Entities.Remove(drone);
                Drones.Remove(key);
                DistanceTravelled.Remove(key);
                _routes.Remove(key);
                _waypointIndexes.Remove(key);
                Speeds.Remove(key);
                DroneLogic.SetDroneNotLive(key);
            }
        }
コード例 #25
0
 public IEnumerable <ResourceQuantity> GetStoredResourcesAt(DateTime time)
 {
     return(Drones.SelectMany(
                drone => drone.GetValidInstructions()
                .Where(
                    i => i.IsFinishedAt(time) && i.GetType() == typeof(Unload)
                    ).Select(
                    i => (i as Unload).Resource
                    )
                ).GroupBy(
                rq => rq.Resource
                ).Select(
                rqGroup => new ResourceQuantity()
     {
         Resource = rqGroup.Key,
         Quantity = rqGroup.Sum(
             rq => rq.Quantity
             )
     }
                ));
 }
コード例 #26
0
        private void CalculateHitpoints(Ship ship)
        {
            double maxHP = ship.Hitpoints;

            foreach (double amount in ship.Boosts.Where(x => x.Type == BoosterType.HITPOINTS).Select(x => x.Amount))
            {
                maxHP *= amount;
            }

            bool isFullDroneDesign = Drones.GroupBy(x => x.StatsDesignID).Count() == 1;

            if (isFullDroneDesign)
            {
                maxHP *= Math.Max(1, Drones.First().StatsDesignID.FromDroneDesigns().Full.Where(x => x.Type == BoosterType.HITPOINTS).Sum(x => x.Amount));
            }
            else
            {
                maxHP *= Math.Max(1, Drones.Sum(x => x.StatsDesignID.FromDroneDesigns().Single.Where(y => y.Type == BoosterType.HITPOINTS).Sum(y => y.Amount)));
            }

            MaxHitpoints = (int)maxHP;
        }
コード例 #27
0
        private void CheckAvailableShields(IGameLogger logger, int accountId, VaultView vault, Ship ship)
        {
            if (Shields == null)
            {
                Shields = new List <int>();
            }

            var tempShieldsGroup = Shields.Union(Drones.SelectMany(x => x.ShieldItems)).GroupBy(x => x).ToList();

            foreach (var grouping in tempShieldsGroup)
            {
                if (!vault.Shields.ContainsKey(grouping.Key))
                {
                    logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with equipped shields id:{grouping.Key} which are not owned!");
                    Shields.RemoveAll(x => x == grouping.Key);
                }
                else if (grouping.Count() > vault.Shields[grouping.Key])
                {
                    int diff = grouping.Count() - vault.Shields[grouping.Key];

                    Shields.RemoveAll(x => x == grouping.Key && diff-- > 0);
                    foreach (var drone in Drones)
                    {
                        if (diff <= 0)
                        {
                            break;
                        }

                        drone.ShieldItems.RemoveAll(x => x == grouping.Key && diff-- > 0);
                    }

                    if (diff != 0)
                    {
                        logger.LogWarning($"Check for player {accountId} on hangar with ship {ship.ID} resulted with a problematic difference of {diff} (shield check)");
                    }
                }
            }
        }
コード例 #28
0
 private void TravelToAgentsStation()
 {
     try
     {
         StationDestination baseDestination = Traveler.Destination as StationDestination;
         if (baseDestination == null || baseDestination.StationId != Cache.Instance.Agent.StationId)
         {
             Traveler.Destination = new StationDestination(Cache.Instance.Agent.SolarSystemId,
                                                           Cache.Instance.Agent.StationId,
                                                           Cache.Instance.DirectEve.GetLocationName(
                                                               Cache.Instance.Agent.StationId));
         }
     }
     catch (Exception ex)
     {
         Logging.Log("DebugHangarsBehavior", "TravelToAgentsStation: Exception caught: [" + ex.Message + "]", Logging.Red);
         return;
     }
     if (Cache.Instance.InSpace)
     {
         if (!Cache.Instance.ActiveShip.Entity.IsCloaked || (Cache.Instance.LastSessionChange.AddSeconds(60) > DateTime.UtcNow))
         {
             Combat.ProcessState();
             Drones.ProcessState(); //do we really want to use drones here?
         }
     }
     if (Cache.Instance.InSpace && !Cache.Instance.TargetedBy.Any(t => t.IsWarpScramblingMe))
     {
         Cache.Instance.IsMissionPocketDone = true; //tells drones.cs that we can pull drones
         //Logging.Log("CombatmissionBehavior","TravelToAgentStation: not pointed",Logging.White);
     }
     Traveler.ProcessState();
     if (Settings.Instance.DebugStates)
     {
         Logging.Log("Traveler.State", "is " + _States.CurrentTravelerState, Logging.White);
     }
 }
コード例 #29
0
ファイル: Traveler.cs プロジェクト: Grafalck/Questor
 public Traveler()
 {
     _lastPulse = DateTime.MinValue;
     _combat = new Combat();
     _drones = new Drones();
 }
コード例 #30
0
ファイル: Questor.cs プロジェクト: ahaw/Questor
        public Questor(frmMain form1)
        {
            m_Parent = form1;
            _lastPulse = DateTime.MinValue;

            _random = new Random();

            //_debugmodule = new DebugModule();

            //_scoop = new Scoop();
            _salvage = new Salvage();
            _defense = new Defense();
            _localwatch = new LocalWatch();
            _scanInteraction = new ScanInteraction();
            _combat = new Combat();
            _traveler = new Traveler();
            _unloadLoot = new UnloadLoot();
            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _courier = new CourierMission();
            _switch = new SwitchShip();
            _missionController = new MissionController();
            _drones = new Drones();
            _panic = new Panic();
            _storyline = new Storyline();

            Settings.Instance.SettingsLoaded += SettingsLoaded;

            // State fixed on ExecuteMission
            State = QuestorState.Idle;

            _directEve = new DirectEve();
            Cache.Instance.DirectEve = _directEve;

            Cache.Instance.StopTimeSpecified = Program.stopTimeSpecified;
            Cache.Instance.MaxRuntime = Program.maxRuntime;
            Cache.Instance.StopTime = Program._stopTime;
            _questorStarted = DateTime.Now;

            _directEve.OnFrame += OnFrame;
        }
コード例 #31
0
        public void ProcessState()
        {
            // Invalid settings, quit while we're ahead
            if (!ValidSettings)
            {
                if (DateTime.UtcNow.Subtract(LastAction).TotalSeconds < Time.Instance.ValidateSettings_seconds) //default is a 15 second interval
                {
                    Logging.Log("CombatHelperBehavior", "Invalid Settings: Running ValidateCombatMissionSettings();", Logging.Orange);
                    ValidateCombatMissionSettings();
                    LastAction = DateTime.UtcNow;
                }
                return;
            }

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

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

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

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

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

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

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

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

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

                DebugCombatHelperBehaviorStates();
            }
            DebugPanicstates();

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

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

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

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

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

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

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

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

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

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

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

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

                Arm.ProcessState();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Traveler.TravelHome("CombatHelperBehavior.TravelHome");

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

                    _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.UnloadLoot;

                    Traveler.Destination = null;
                }
                break;

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

                _unloadLoot.ProcessState();

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

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

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

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

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

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

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

                break;

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

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

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

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

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

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

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

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

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

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

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

            case CombatHelperBehaviorState.Default:
                _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.Idle;
                break;
            }
        }
コード例 #32
0
 //Checks if a collision has occurd
 private static bool CheckCollision(Vector3 position, int id)
 {
     return(Drones.Any(x => Vector3.NearEqual(x.Value.Transform.Position, position, x.Value.Transform.Scale) &&
                       x.Key != id));
 }
コード例 #33
0
ファイル: MiningBehavior.cs プロジェクト: seb1707/Questor
        public void ProcessState()
        {
            if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < Time.Instance.QuestorPulse_milliseconds) //default: 1500ms
            {
                return;
            }

            _lastPulse = DateTime.UtcNow;

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

            if (Cache.Instance.GotoBaseNow)
            {
                _States.CurrentMiningState = MiningState.GotoBase;
            }

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

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

            _panic.ProcessState();

            if (_States.CurrentPanicState == PanicState.Panic || _States.CurrentPanicState == PanicState.Panicking)
            {
                // If Panic is in panic state, questor is in panic States.CurrentCombatMissionBehaviorState :)
                _States.CurrentMiningState = MiningState.Panic;

                if (PanicStateReset)
                {
                    _States.CurrentPanicState = PanicState.Normal;
                    PanicStateReset           = false;
                }
            }
            else if (_States.CurrentPanicState == PanicState.Resume)
            {
                // Reset panic state
                _States.CurrentPanicState    = PanicState.Normal;
                _States.CurrentTravelerState = TravelerState.Idle;
                _States.CurrentMiningState   = MiningState.GotoBelt;
            }

            if (Settings.Instance.DebugMiningBehavior)
            {
                Logging.Log("MiningBehavior", "Pre-switch", Logging.White);
            }

            switch (_States.CurrentMiningState)
            {
            case MiningState.Default:
            case MiningState.Idle:
                _States.CurrentMiningState = MiningState.Cleanup;
                break;

            case MiningState.Cleanup:
                if (Cache.Instance.LootAlreadyUnloaded == false)
                {
                    _States.CurrentMiningState = MiningState.GotoBase;
                    break;
                }

                Cleanup.CheckEVEStatus();
                _States.CurrentMiningState = MiningState.Arm;
                break;

            case MiningState.GotoBase:
                DirectBookmark miningHome = Cache.Instance.BookmarksByLabel("Mining Home").FirstOrDefault();

                //Cache.Instance.DirectEve.Navigation.GetDestinationPath
                Traveler.TravelToMiningHomeBookmark(miningHome, "Mining go to base");

                if (_States.CurrentTravelerState == TravelerState.AtDestination)     // || DateTime.UtcNow.Subtract(Cache.Instance.EnteredCloseQuestor_DateTime).TotalMinutes > 10)
                {
                    if (Settings.Instance.DebugGotobase)
                    {
                        Logging.Log("MiningBehavior", "GotoBase: We are at destination", Logging.White);
                    }
                    Cache.Instance.GotoBaseNow = false;     //we are there - turn off the 'forced' gotobase
                    _States.CurrentMiningState = MiningState.UnloadLoot;
                    Traveler.Destination       = null;
                }
                break;

            case MiningState.UnloadLoot:

                //
                // this state should never be reached in space. if we are in space and in this state we should switch to gotobase
                //
                if (Cache.Instance.InSpace)
                {
                    Logging.Log(_States.CurrentCombatMissionBehaviorState.ToString(), "We are in space, how did we get set to this state while in space? Changing state to: GotoBase", Logging.White);
                    _States.CurrentMiningState = MiningState.GotoBase;
                }

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

                _unloadLoot.ProcessState();

                if (_States.CurrentUnloadLootState == UnloadLootState.Done)
                {
                    Cache.Instance.LootAlreadyUnloaded = true;
                    _States.CurrentUnloadLootState     = UnloadLootState.Idle;

                    if (_States.CurrentCombatState == CombatState.OutOfAmmo)
                    {
                        Logging.Log("MiningBehavior.UnloadLoot", "We are out of ammo", Logging.Orange);
                        _States.CurrentMiningState = MiningState.Idle;
                        return;
                    }

                    _States.CurrentMiningState  = MiningState.Idle;
                    _States.CurrentQuestorState = QuestorState.Idle;
                    Logging.Log("MiningBehavior.Unloadloot", "CharacterMode: [" + Settings.Instance.CharacterMode + "], AfterMissionSalvaging: [" + Settings.Instance.AfterMissionSalvaging + "], MiningState: [" + _States.CurrentMiningState + "]", Logging.White);
                    return;
                }
                break;

            case MiningState.Start:
                Cache.Instance.OpenWrecks  = false;
                _States.CurrentMiningState = MiningState.Arm;
                DirectBookmark asteroidShortcut = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault();

                if (asteroidShortcut != null)
                {
                    asteroidShortcut.Delete();
                }
                break;

            case MiningState.Arm:

                //
                // this state should never be reached in space. if we are in space and in this state we should switch to gotobase
                //
                if (Cache.Instance.InSpace)
                {
                    Logging.Log(_States.CurrentMiningState.ToString(), "We are in space, how did we get set to this state while in space? Changing state to: GotoBase", Logging.White);
                    _States.CurrentMiningState = MiningState.GotoBase;
                }

                if (_States.CurrentArmState == ArmState.Idle)
                {
                    Logging.Log("Arm", "Begin", Logging.White);
                    _States.CurrentArmState = ArmState.Begin;

                    // Load ammo... this "fixes" the problem I experienced with not reloading after second arm phase. The quantity was getting set to 0.
                    Arm.AmmoToLoad.Clear();
                    Arm.AmmoToLoad.Add(Settings.Instance.Ammo.FirstOrDefault());

                    //FIXME: bad hack - this should be fixed differently / elsewhere
                    Ammo FirstAmmoToLoad = Arm.AmmoToLoad.FirstOrDefault();
                    if (FirstAmmoToLoad != null && FirstAmmoToLoad.Quantity == 0)
                    {
                        FirstAmmoToLoad.Quantity = 333;
                    }
                }

                Arm.ProcessState();

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

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

                if (_States.CurrentArmState == ArmState.Done)
                {
                    if (DateTime.UtcNow > Cache.Instance.LastInSpace.AddSeconds(45))     //do not try to leave the station until you have been docked for at least 45seconds! (this gives some overhead to load the station env + session change timer)
                    {
                        //we know we are connected if we were able to arm the ship - update the lastknownGoodConnectedTime
                        Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow;
                        Cache.Instance.MyWalletBalance            = Cache.Instance.DirectEve.Me.Wealth;
                        _States.CurrentArmState   = ArmState.Idle;
                        _States.CurrentDroneState = DroneState.WaitingForTargets;


                        //exit the station
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdExitStation);

                        //set up a wait of 10 seconds so the undock can complete
                        _lastPulse = DateTime.UtcNow.AddSeconds(10);
                        _States.CurrentMiningState = MiningState.GotoBelt;
                    }
                }
                break;

            case MiningState.GotoBelt:
                if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < Time.Instance.QuestorPulse_milliseconds * 2)
                {
                    return;
                }

                if (Cache.Instance.InWarp || (!Cache.Instance.InSpace && !Cache.Instance.InStation))
                {
                    return;
                }

                //
                // this should goto a mining system bookmark (one of possibly many)
                // then goto the 1st belt. This would allow for mining in systems without stations
                //
                Logging.Log("MiningBehavior", "Setting Destination to 1st Asteroid belt.", Logging.White);

                DirectBookmark asteroidShortcutGTB = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault();

                if (asteroidShortcutGTB != null)
                {
                    if (Cache.Instance.EntityById(_currentBelt.Id).Distance < 65000)
                    {
                        _States.CurrentMiningState = MiningState.Mine;
                        Traveler.Destination       = null;
                    }
                    else
                    {
                        asteroidShortcutGTB.WarpTo();
                        _lastPulse = DateTime.UtcNow;
                    }
                    break;
                }

                IEnumerable <EntityCache> belts = Cache.Instance.Entities.Where(i => i.GroupId == (int)Group.AsteroidBelt && !i.Name.ToLower().Contains("ice") && !EmptyBelts.Contains(i.Id));
                EntityCache belt = belts.OrderBy(x => x.Distance).FirstOrDefault();
                _currentBelt = belt;

                //Traveler.Destination = new MissionBookmarkDestination(belt);

                if (belt != null)
                {
                    if (belt.Distance < 35000)
                    {
                        _States.CurrentMiningState = MiningState.Mine;
                        Traveler.Destination       = null;
                    }
                    else
                    {
                        if (belt.WarpTo())
                        {
                            _lastPulse = DateTime.UtcNow;
                        }
                    }
                    break;
                }

                _States.CurrentMiningState = MiningState.GotoBase;
                Logging.Log("MiningBehavior", "Could not find a suitable Asteroid belt.", Logging.White);
                Settings.Instance.AutoStart = false;
                break;

            case MiningState.Mine:

                IEnumerable <EntityCache> _asteroidsOnGrid  = Cache.Instance.EntitiesOnGrid.Where(i => i.Distance < (int)Distances.OnGridWithMe && i.CategoryId == (int)CategoryID.Asteroid).OrderBy(i => i.Distance);
                IEnumerable <EntityCache> _asteroidsInRange = _asteroidsOnGrid.Where(i => i.Distance < 65000).ToList();
                EntityCache asteroid = null;

                if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Kernite))
                {
                    asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Kernite).OrderBy(i => i.Distance).FirstOrDefault();
                }

                if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Plagioclase))
                {
                    asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Plagioclase).OrderBy(i => i.Distance).FirstOrDefault();
                }

                if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Pyroxeres))
                {
                    asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Pyroxeres).OrderBy(i => i.Distance).FirstOrDefault();
                }

                if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Scordite))
                {
                    asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Scordite).OrderBy(i => i.Distance).FirstOrDefault();
                }

                if (asteroid == null && _asteroidsInRange.Any(i => i.GroupId == (int)Group.Veldspar))
                {
                    asteroid = _asteroidsInRange.Where(i => i.GroupId == (int)Group.Veldspar).OrderBy(i => i.Distance).FirstOrDefault();
                }


                if (asteroid == null)
                {
                    EmptyBelts.Add(_currentBelt.Id);
                    DirectBookmark asteroidShortcutBM2 = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault();

                    if (asteroidShortcutBM2 != null)
                    {
                        asteroidShortcutBM2.Delete();
                    }

                    Logging.Log("MiningBehavior", "Could not find a suitable Asteroid to mine in this belt.", Logging.White);
                    _States.CurrentMiningState = MiningState.GotoBelt;
                    break;
                }

                Logging.Log("Mining: [", "Target Rock is [" + asteroid.Name + "][" + Math.Round(asteroid.Distance / 1000, 0) + "k] ID [" + asteroid.MaskedId + "] GroupID [" + asteroid.GroupId + "]", Logging.White);
                _targetAsteroidID = asteroid.Id;
                _targetAsteroid.Approach();
                _States.CurrentMiningState = MiningState.MineAsteroid;
                break;

            case MiningState.MineAsteroid:
                if (Cache.Instance.EntityById(_targetAsteroidID) == null)
                {
                    Logging.Log("Mining: [", "Target Rock [" + Cache.Instance.MaskedID(_targetAsteroidID) + "] has been depleted. Searching for another target.", Logging.White);
                    _States.CurrentMiningState = MiningState.Mine;
                    return;
                }
                _targetAsteroid = Cache.Instance.EntityById(_targetAsteroidID);
                Combat.ProcessState();
                Drones.ProcessState();

                // If we are out of ammo, return to base, Arm should then grab the right ammo / crystals / drones
                if (_States.CurrentCombatState == CombatState.OutOfAmmo)
                {
                    Logging.Log("Combat", "Out of Ammo!", Logging.Orange);
                    _States.CurrentMiningState = MiningState.GotoBase;
                }

                //check if we're full

                //
                // we really ought to be checking for and using the OreHold if needed, not directly using the cargohold ffs!
                //
                if (Cache.Instance.CurrentShipsCargo == null)
                {
                    return;
                }

                if (Cache.Instance.CurrentShipsCargo.IsValid && (Cache.Instance.CurrentShipsCargo.UsedCapacity >= Cache.Instance.CurrentShipsCargo.Capacity * .9) && Cache.Instance.CurrentShipsCargo.Capacity > 0)
                {
                    if (_States.CurrentDroneState == DroneState.WaitingForTargets)
                    {
                        Logging.Log("Miner:MineAsteroid", "We are full, go to base to unload. Capacity is: " + Cache.Instance.CurrentShipsCargo.Capacity + ", Used: " + Cache.Instance.CurrentShipsCargo.UsedCapacity, Logging.White);
                        _States.CurrentMiningState = MiningState.GotoBase;
                        break;
                    }

                    if (_States.CurrentDroneState == DroneState.WaitingForTargets)
                    {
                        Logging.Log("Miner:MineAsteroid", "We are full, but drones are busy. Drone state: " + _States.CurrentDroneState.ToString(), Logging.White);
                    }
                }

                //
                // do we need to make sure the rock is in targeting range? rats that damp, frigates with crap skills?, wormhole effects...
                //
                if (_targetAsteroid.Distance < 10000)
                {
                    if (_targetAsteroid.Distance < 9400)
                    {
                        if (_asteroidBookmarkForID != _targetAsteroid.Id)
                        {
                            DirectBookmark asteroidShortcutBM = Cache.Instance.BookmarksByLabel("Asteroid Location").FirstOrDefault();

                            if (asteroidShortcutBM != null)
                            {
                                asteroidShortcutBM.UpdateBookmark("Asteroid Location", "Mining Shortcut");
                            }
                            else
                            {
                                Cache.Instance.DirectEve.BookmarkCurrentLocation("Asteroid Location", "Mining Shortcut", null);
                            }

                            _asteroidBookmarkForID = _targetAsteroid.Id;
                        }
                    }

                    if (Cache.Instance.Targeting.Contains(_targetAsteroid))
                    {
                        if (Settings.Instance.DebugMiningBehavior)
                        {
                            Logging.Log("Miner:MineAsteroid", "Targeting asteroid.", Logging.White);
                        }
                        return;
                        //wait
                    }

                    if (Cache.Instance.Targets.Contains(_targetAsteroid))
                    {
                        if (Settings.Instance.DebugMiningBehavior)
                        {
                            Logging.Log("Miner:MineAsteroid", "Asteroid Targeted.", Logging.White);
                        }
                        //if(!_targetAsteroid.IsActiveTarget) _targetAsteroid.MakeActiveTarget();
                        List <ModuleCache> miningTools = Cache.Instance.Modules.Where(m => MiningToolGroupIDs.Contains(m.GroupId)).ToList();

                        _minerNumber = 0;
                        foreach (ModuleCache miningTool in miningTools)
                        {
                            if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(miningTool.ItemId))
                            {
                                if (Cache.Instance.LastActivatedTimeStamp[miningTool.ItemId].AddSeconds(3) > DateTime.UtcNow)
                                {
                                    continue;
                                }
                            }

                            _minerNumber++;

                            // Are we on the right target?
                            if (miningTool.IsActive)
                            {
                                if (miningTool.TargetId != _targetAsteroid.Id)
                                {
                                    if (miningTool.Click())
                                    {
                                        return;
                                    }

                                    return;
                                }
                                continue;
                            }

                            // Are we deactivating?
                            if (miningTool.IsDeactivating)
                            {
                                continue;
                            }

                            if (miningTool.Activate(_targetAsteroid))
                            {
                                //only activate one module per cycle
                                Logging.Log("Mining", "Activating mining tool [" + _minerNumber + "] on [" + _targetAsteroid.Name + "][" + Cache.Instance.MaskedID(_targetAsteroid.Id) + "][" + Math.Round(_targetAsteroid.Distance / 1000, 0) + "k away]", Logging.Teal);
                                return;
                            }

                            continue;
                        }

                        return;
                    }     //mine

                    //asteroid is not targeted
                    if (Settings.Instance.DebugMiningBehavior)
                    {
                        Logging.Log("Miner:MineAsteroid", "Asteroid not yet targeted.", Logging.White);
                    }
                    if (DateTime.UtcNow < Cache.Instance.NextTargetAction)     //if we just did something wait a fraction of a second
                    {
                        return;
                    }

                    if (Cache.Instance.MaxLockedTargets == 0)
                    {
                        if (!_isJammed)
                        {
                            Logging.Log("Mining", "We are jammed and can't target anything", Logging.Orange);
                        }

                        _isJammed = true;
                        return;
                    }

                    if (_isJammed)
                    {
                        // Clear targeting list as it does not apply
                        Cache.Instance.TargetingIDs.Clear();
                        Logging.Log("Mining", "We are no longer jammed, ReTargeting", Logging.Teal);
                    }
                    _isJammed = false;

                    _targetAsteroid.LockTarget("Mining.targetAsteroid");
                    Cache.Instance.NextTargetAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.TargetDelay_milliseconds);
                    return;
                }     //check 10K distance

                //
                // not inside 10k
                //
                if (Settings.Instance.DebugMiningBehavior)
                {
                    Logging.Log("Miner:MineAsteroid", "Debug: Distance to Target [" + Math.Round(_targetAsteroid.Distance / 1000, 2) + "] > 10K.] Id [" + _targetAsteroid.Id + "] TargetingMe [" + Combat.TargetingMe.Count() + "]", Logging.White);
                }
                //this isn't working because Cache.Instance.Approaching.TargetValue always seems to return null. This will negatively impact combat since it won't orbit. Might want to check CombatState instead.
                if (Cache.Instance.IsApproaching(_targetAsteroidID) && !Cache.Instance.TargetedBy.Any())
                {
                    //
                    // this will only approach every 15 sec
                    //
                    _targetAsteroid.Approach();
                }


                break;
            } //ends MiningState switch
        }     //ends ProcessState method
コード例 #34
0
        /// <summary>
        ///   Do a mini-questor here (goto mission, execute mission, goto base)
        /// </summary>
        /// <returns></returns>
        public StorylineState ExecuteMission(Storyline storyline)
        {
            switch (_state)
            {
            case GenericCombatStorylineState.WarpOutStation:
                DirectBookmark warpOutBookMark = Cache.Instance.BookmarksByLabel(Settings.Instance.UndockBookmarkPrefix ?? "").OrderByDescending(b => b.CreatedOn).FirstOrDefault(b => b.LocationId == Cache.Instance.DirectEve.Session.SolarSystemId);
                long           solarid         = Cache.Instance.DirectEve.Session.SolarSystemId ?? -1;

                if (warpOutBookMark == null)
                {
                    Logging.Log("GenericCombatStoryline.WarpOut", "No Bookmark", Logging.Orange);
                    _state = GenericCombatStorylineState.GotoMission;
                    break;
                }

                if (warpOutBookMark.LocationId == solarid)
                {
                    if (Traveler.Destination == null)
                    {
                        Logging.Log("GenericCombatStoryline.WarpOut", "Warp at " + warpOutBookMark.Title, Logging.White);
                        Traveler.Destination           = new BookmarkDestination(warpOutBookMark);
                        Cache.Instance.DoNotBreakInvul = true;
                    }

                    Traveler.ProcessState();
                    if (_States.CurrentTravelerState == TravelerState.AtDestination)
                    {
                        Logging.Log("GenericCombatStoryline.WarpOut", "Safe!", Logging.White);
                        Cache.Instance.DoNotBreakInvul = false;
                        _state = GenericCombatStorylineState.GotoMission;
                        Traveler.Destination = null;
                        break;
                    }

                    break;
                }

                Logging.Log("GenericCombatStoryline.WarpOut", "No Bookmark in System", Logging.White);
                _state = GenericCombatStorylineState.GotoMission;
                break;

            case GenericCombatStorylineState.GotoMission:
                MissionBookmarkDestination missionDestination = Traveler.Destination as MissionBookmarkDestination;
                //
                // if we have no destination yet... OR if missionDestination.AgentId != storyline.CurrentStorylineAgentId
                //
                //if (missionDestination != null) Logging.Log("GenericCombatStoryline: missionDestination.AgentId [" + missionDestination.AgentId + "] " + "and storyline.CurrentStorylineAgentId [" + storyline.CurrentStorylineAgentId + "]");
                //if (missionDestination == null) Logging.Log("GenericCombatStoryline: missionDestination.AgentId [ NULL ] " + "and storyline.CurrentStorylineAgentId [" + storyline.CurrentStorylineAgentId + "]");
                if (missionDestination == null || missionDestination.AgentId != Cache.Instance.CurrentStorylineAgentId)     // We assume that this will always work "correctly" (tm)
                {
                    string nameOfBookmark = "";
                    if (Settings.Instance.EveServerName == "Tranquility")
                    {
                        nameOfBookmark = "Encounter";
                    }
                    if (Settings.Instance.EveServerName == "Serenity")
                    {
                        nameOfBookmark = "遭遇战";
                    }
                    if (nameOfBookmark == "")
                    {
                        nameOfBookmark = "Encounter";
                    }
                    Logging.Log("GenericCombatStoryline", "Setting Destination to 1st bookmark from AgentID: [" + Cache.Instance.CurrentStorylineAgentId + "] with [" + nameOfBookmark + "] in the title", Logging.White);
                    Traveler.Destination = new MissionBookmarkDestination(Cache.Instance.GetMissionBookmark(Cache.Instance.CurrentStorylineAgentId, nameOfBookmark));
                }

                if (Cache.Instance.PotentialCombatTargets.Any())
                {
                    Logging.Log("GenericCombatStoryline", "Priority targets found while traveling, engaging!", Logging.White);
                    Combat.ProcessState();
                }

                Traveler.ProcessState();
                if (_States.CurrentTravelerState == TravelerState.AtDestination)
                {
                    _state = GenericCombatStorylineState.ExecuteMission;

                    //_States.CurrentCombatState = CombatState.CheckTargets;
                    Traveler.Destination = null;
                }
                break;

            case GenericCombatStorylineState.ExecuteMission:
                Combat.ProcessState();
                Drones.ProcessState();
                Salvage.ProcessState();
                _combatMissionCtrl.ProcessState();

                // If we are out of ammo, return to base, the mission will fail to complete and the bot will reload the ship
                // and try the mission again
                if (_States.CurrentCombatState == CombatState.OutOfAmmo)
                {
                    // Clear looted containers
                    Cache.Instance.LootedContainers.Clear();

                    Logging.Log("GenericCombatStoryline", "Out of Ammo!", Logging.Orange);
                    return(StorylineState.ReturnToAgent);
                }

                if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Done)
                {
                    // Clear looted containers
                    Cache.Instance.LootedContainers.Clear();
                    return(StorylineState.ReturnToAgent);
                }

                // If in error state, just go home and stop the bot
                if (_States.CurrentCombatMissionCtrlState == CombatMissionCtrlState.Error)
                {
                    // Clear looted containers
                    Cache.Instance.LootedContainers.Clear();

                    Logging.Log("MissionController", "Error", Logging.Red);
                    return(StorylineState.ReturnToAgent);
                }
                break;
            }

            return(StorylineState.ExecuteMission);
        }
コード例 #35
0
        public Ship(XElement ship)
            : base(ship)
        {
            this._crew              = new ObservableCollection <CMember>();
            this._tradeQueue        = new ObservableCollection <XElement>();
            this._constructionWares = new ObservableCollection <XElement>();
            this._drones            = new ObservableCollection <XElement>();

            if (ship.Attribute("name") == null)
            {
                EntityValueConverter conv = new EntityValueConverter();
                XAttribute           name = new XAttribute("name", conv.Convert(ship.Attribute("macro").Value, null, null, null));
                ship.Add(name);
            }

            IEnumerable <XElement> crewquery =
                from crew in this.Data.Descendants().Elements("component")
                where (string)crew.Attribute("class") == "npc"
                select crew;

            foreach (XElement person in crewquery)
            {
                Crew.Add(new CMember(person));
            }

            foreach (XElement trade in this.Data.Elements("trade").Elements("shopping").Elements("trade"))
            {
                TradeQueue.Add(trade);
            }

            IEnumerable <XElement> buildmodulesQuery =
                from buildmodules in this.Data.Descendants().Elements("connection")
                where (string)buildmodules.Attribute("macro") == "connection_buildmodule01"
                select buildmodules;

            IEnumerable <XElement> constructionWaresQuery =
                from wares in buildmodulesQuery.Descendants <XElement>().Elements("resources").Elements("ware")
                select wares;

            foreach (XElement ware in constructionWaresQuery)
            {
                ConstructionWares.Add(ware);
            }

            foreach (XElement drone in this.Data.Elements("ammunition").Elements("available").Elements("item"))
            {
                Drones.Add(drone);
            }


            IEnumerable <XElement> cargoList =
                from cargo in this.Data.Descendants().Elements("component")
                where (string)cargo.Attribute("class") == "storage" & (string)cargo.Attribute("macro") != "unit_player_ship_storage_macro"
                select cargo;

            foreach (XElement cargoType in cargoList)
            {
                string cargoTypeName = cargoType.Attribute("macro").Value;
                switch (cargoTypeName)
                {
                case "storage_ship_l_bulk_01_macro":
                case "storage_ship_m_bulk_01_macro":
                case "storage_ship_l_bulk_02_macro":
                case "storage_ship_l_bulk_03_macro":
                case "storage_ship_l_bulk_04_macro":
                case "storage_ship_xl_bulk_01_macro":
                    BulkCargo = cargoType;
                    break;

                case "storage_ship_l_container_01_macro":
                case "storage_ship_l_container_02_macro":
                case "storage_ship_m_container_01_macro":
                case "storage_ship_xl_container_01_macro":
                    ContainerCargo = cargoType;
                    break;

                case "storage_ship_l_energy_01_macro":
                case "storage_ship_l_energy_02_macro":
                case "storage_ship_xl_energy_01_macro":
                case "storage_ship_m_energy_01_macro":
                    EnergyCargo = cargoType;
                    break;

                case "storage_ship_l_fuel_01_macro":
                case "storage_ship_xl_fuel_01_macro":
                    FuelCargo = cargoType;
                    break;

                case "storage_ship_l_liquid_01_macro":
                case "storage_ship_l_liquid_02_macro":
                case "storage_ship_l_liquid_03_macro":
                case "storage_ship_xl_liquid_01_macro":
                case "storage_ship_m_liquid_01_macro":
                    LiquidCargo = cargoType;
                    break;

                case "storage_ship_xl_universal_01_macro":
                case "storage_ship_xs_universal_01_macro":
                case "storage_temp_huge_macro":
                    UniversalCargo = cargoType;
                    break;
                }
            }

            Gravidar = this.Data.Element("gravidar");

            LoadDetails();
        }