Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
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);
            }
        }