예제 #1
0
        /// <summary>
        /// This routine handles the asteroid track status between clients
        /// </summary>
        private void CheckAsteroidsStatus()
        {
            if (!Enabled)
            {
                return;
            }

            //Check for changes to tracking
            foreach (var asteroid in GetCurrentAsteroids().Where(asteroid => asteroid.state != Vessel.State.DEAD))
            {
                if (!ServerAsteroidTrackStatus.ContainsKey(asteroid.id.ToString()))
                {
                    ServerAsteroidTrackStatus.Add(asteroid.id.ToString(), asteroid.DiscoveryInfo.trackingStatus.Value);
                }
                else
                {
                    if (asteroid.DiscoveryInfo.trackingStatus.Value != ServerAsteroidTrackStatus[asteroid.id.ToString()])
                    {
                        LunaLog.Log($"[LMP]: Sending changed asteroid, new state: {asteroid.DiscoveryInfo.trackingStatus.Value}!");
                        ServerAsteroidTrackStatus[asteroid.id.ToString()] = asteroid.DiscoveryInfo.trackingStatus.Value;
                        SystemsContainer.Get <VesselProtoSystem>().MessageSender.SendVesselMessage(asteroid, true);
                    }
                }
            }
        }
예제 #2
0
        protected override void OnDisabled()
        {
            base.OnDisabled();
            GameEvents.onAsteroidSpawned.Remove(AsteroidEventHandler.OnAsteroidSpawned);

            ServerAsteroids.Clear();
            ServerAsteroidTrackStatus.Clear();
        }
예제 #3
0
        public override void OnDisabled()
        {
            base.OnDisabled();
            GameEvents.onAsteroidSpawned.Remove(AsteroidEventHandler.OnAsteroidSpawned);
            GameEvents.onGameSceneLoadRequested.Remove(AsteroidEventHandler.OnGameSceneLoadRequested);

            ServerAsteroids.Clear();
            ServerAsteroidTrackStatus.Clear();
        }
예제 #4
0
 /// <summary>
 /// Registers the server asteroid - Prevents LMP from deleting it.
 /// </summary>
 /// <param name="asteroidId">Asteroid to register</param>
 public void RegisterServerAsteroid(string asteroidId)
 {
     if (!ServerAsteroids.Contains(asteroidId))
     {
         ServerAsteroids.Add(asteroidId);
     }
     //This will ignore Status changes so we don't resend the asteroid.
     if (ServerAsteroidTrackStatus.ContainsKey(asteroidId))
     {
         ServerAsteroidTrackStatus.Remove(asteroidId);
     }
 }
예제 #5
0
        /// <summary>
        /// This coroutine tries to ackquire the asteroid lock. If we have it spawn the needed asteroids.
        /// It also handles the asteroid track status between clients
        /// </summary>
        /// <returns></returns>
        private IEnumerator CheckAsteroids()
        {
            //TODO: Surround with try catch as other coroutines
            var seconds = new WaitForSeconds(AsteroidCheckInterval);

            while (true)
            {
                if (!Enabled)
                {
                    break;
                }

                //Try to acquire the asteroid-spawning lock if nobody else has it.
                if (!LockSystem.Singleton.LockExists("asteroid"))
                {
                    LockSystem.Singleton.AcquireLock("asteroid");
                }

                //We have the spawn lock, lets do stuff.
                if (LockSystem.Singleton.LockIsOurs("asteroid") && WarpSystem.Singleton.CurrentSubspace == 0 &&
                    Time.timeSinceLevelLoad > 1f && MainSystem.Singleton.GameRunning)
                {
                    var beforeSpawn      = GetAsteroidCount();
                    var asteroidsToSpawn = SettingsSystem.ServerSettings.MaxNumberOfAsteroids - beforeSpawn;
                    for (var asteroidsSpawned = 0; asteroidsSpawned < asteroidsToSpawn; asteroidsSpawned++)
                    {
                        Debug.Log($"[LMP]: Spawning asteroid, have {beforeSpawn + asteroidsSpawned}, need {SettingsSystem.ServerSettings.MaxNumberOfAsteroids}");
                        ScenarioController.SpawnAsteroid();
                        yield return(null); //Resume on next frame
                    }
                }

                //Check for changes to tracking
                foreach (var asteroid in GetCurrentAsteroids().Where(asteroid => asteroid.state != Vessel.State.DEAD))
                {
                    if (!ServerAsteroidTrackStatus.ContainsKey(asteroid.id.ToString()))
                    {
                        ServerAsteroidTrackStatus.Add(asteroid.id.ToString(), asteroid.DiscoveryInfo.trackingStatus.Value);
                    }
                    else
                    {
                        if (asteroid.DiscoveryInfo.trackingStatus.Value != ServerAsteroidTrackStatus[asteroid.id.ToString()])
                        {
                            Debug.Log($"[LMP]: Sending changed asteroid, new state: {asteroid.DiscoveryInfo.trackingStatus.Value}!");
                            ServerAsteroidTrackStatus[asteroid.id.ToString()] = asteroid.DiscoveryInfo.trackingStatus.Value;
                            VesselProtoSystem.Singleton.MessageSender.SendVesselMessage(asteroid);
                        }
                    }
                }

                yield return(seconds);
            }
        }
예제 #6
0
 protected override void OnDisabled()
 {
     base.OnDisabled();
     ServerAsteroids.Clear();
     ServerAsteroidTrackStatus.Clear();
 }