示例#1
0
文件: Clock.cs 项目: K07H/The-Forest
 public void CopyPropertiesToNetwork()
 {
     if (BoltNetwork.isServer && CoopWeatherProxy.Instance)
     {
         IWeatherState state = CoopWeatherProxy.Instance.state;
         state.Temp = Clock.Temp;
         state.Day  = Clock.Day;
         if (CoopPeerStarter.DedicatedHost || (LocalPlayer.Inventory && LocalPlayer.Inventory.CurrentView != PlayerInventory.PlayerViews.Loading))
         {
             state.TimeOfDay = this.Atmos.TimeOfDay;
         }
         state.ElapsedGameTime = this.ElapsedGameTime;
         if (!Mathf.Approximately(state.CloudOvercastTarget, Scene.WeatherSystem.CloudOvercastTarget))
         {
             state.CloudOvercastTarget = Scene.WeatherSystem.CloudOvercastTarget;
         }
         if (!Mathf.Approximately(state.CloudOpacityScaleTarget, Scene.WeatherSystem.CloudOpacityScaleTarget))
         {
             state.CloudOpacityScaleTarget = Scene.WeatherSystem.CloudOpacityScaleTarget;
         }
         state.Raining          = Scene.WeatherSystem.Raining;
         state.RainLight        = Scene.RainTypes.RainLight.activeInHierarchy;
         state.RainMedium       = Scene.RainTypes.RainMedium.activeInHierarchy;
         state.RainHeavy        = Scene.RainTypes.RainHeavy.activeInHierarchy;
         state.Rainbow          = this.RainbowA.activeInHierarchy;
         state.RainbowIntensity = this.RainbowIntensity;
         state.NightTimeSfx     = this.NightTimeSfx.activeInHierarchy;
         state.DayTimeSfx       = this.DayTimeSfx.activeInHierarchy;
         state.Lightning        = Scene.WeatherSystem.ShouldDoLighting;
     }
 }
        /// <summary>
        /// Removes the given weather state from the zone, preventing the zone from applying it any further.
        /// If the zone is currently using the state, it will be removed but the state will not change until the weather frequency is triggered again.
        /// </summary>
        /// <param name="weatherState">State of the weather.</param>
        /// <returns>Returns an awaitable Task</returns>
        public Task RemoveWeatherState(IWeatherState weatherState)
        {
            if (weatherState == null || !this.weatherStates.Contains(weatherState))
            {
                return(Task.FromResult(0));
            }

            this.weatherStates.Remove(weatherState);
            return(Task.FromResult(0));
        }
        /// <summary>
        /// Called when the zones weather state has changed
        /// </summary>
        /// <param name="initialState">The state of the weather prior to the change occuring.</param>
        /// <param name="nextState">State of the zones weather now.</param>
        void OnWeatherChanged(IWeatherState initialState, IWeatherState nextState)
        {
            EventHandler <WeatherStateChangedEventArgs> handler = this.WeatherChanged;

            if (handler == null)
            {
                return;
            }

            handler(this, new WeatherStateChangedEventArgs(initialState, nextState));
        }
示例#4
0
        /// <summary>
        /// Called when the zones weather has changed.
        /// </summary>
        /// <param name="oldWeather">The old weather prior to the change taking place.</param>
        /// <param name="newWeather">The new weather once the change is completed.</param>
        protected virtual void OnWeatherChanged(IWeatherState oldWeather, IWeatherState newWeather)
        {
            EventHandler <WeatherStateChangedEventArgs> handler = this.WeatherChanged;

            if (handler == null)
            {
                return;
            }

            handler(this, new WeatherStateChangedEventArgs(oldWeather, newWeather));
        }
示例#5
0
        /// <summary>
        /// Setups the weather up.
        /// </summary>
        private void SetupWeather(IWeatherState state, EngineTimer <IWeatherState> timer)
        {
            // Set the current weather based on the probability of it changing.
            IWeatherState nextWeatherState = this.weatherStates.AnyOrDefaultFromWeight(weather => weather.OccurrenceProbability);

            if (nextWeatherState != this.CurrentWeather)
            {
                this.CurrentWeather = nextWeatherState;
                this.OnWeatherChanged(null, this.CurrentWeather);
            }
        }
        /// <summary>
        /// Sets up the weather condition in the zone by evaluating the available weather states
        /// and changing the state if needed.
        /// </summary>
        /// <param name="state">The current weather state.</param>
        /// <param name="timer">The zone timer that is responsible for updating the weather state.</param>
        void SetupWeather(IWeatherState state, EngineTimer <IWeatherState> timer)
        {
            IWeatherState nextState = this.weatherStates.AnyOrDefaultFromWeight(weather => weather.OccurrenceProbability);

            if (nextState == null)
            {
                return;
            }

            var initialState = this.CurrentWeather;

            this.CurrentWeather = nextState;

            this.OnWeatherChanged(initialState, nextState);
            timer.SetState(nextState);
        }
        /// <summary>
        /// Adds the given weather state to the zone, allowing it to have the weather defined applied to it.
        /// </summary>
        /// <param name="weatherState">State of the weather.</param>
        /// <returns>Returns an awaitable Task</returns>
        public Task AddWeatherState(IWeatherState weatherState)
        {
            if (weatherState == null)
            {
                throw new ArgumentNullException(nameof(weatherState), "You can not add a null weather state instance to a zone.");
            }
            else if (this.weatherStates.Contains(weatherState))
            {
                return(Task.FromResult(0));
            }
            else if (string.IsNullOrEmpty(weatherState.Name))
            {
                throw new InvalidWeatherStateException(weatherState, "You must provide the state with a name before adding it to a zone.");
            }
            else if (weatherState.OccurrenceProbability < 1)
            {
                throw new InvalidWeatherStateException(weatherState, "You must have an occurrence probability set higher than 1.");
            }

            this.weatherStates.Add(weatherState);

            return(Task.FromResult(0));
        }
示例#8
0
        /// <summary>
        /// Called when the zones weather state has changed
        /// </summary>
        /// <param name="initialState">The state of the weather prior to the change occuring.</param>
        /// <param name="nextState">State of the zones weather now.</param>
        void OnWeatherChanged(IWeatherState initialState, IWeatherState nextState)
        {
            EventHandler<WeatherStateChangedEventArgs> handler = this.WeatherChanged;
            if (handler == null)
            {
                return;
            }

            handler(this, new WeatherStateChangedEventArgs(initialState, nextState));
        }
示例#9
0
        /// <summary>
        /// Sets up the weather condition in the zone by evaluating the available weather states 
        /// and changing the state if needed.
        /// </summary>
        /// <param name="state">The current weather state.</param>
        /// <param name="timer">The zone timer that is responsible for updating the weather state.</param>
        void SetupWeather(IWeatherState state, EngineTimer<IWeatherState> timer)
        {
            IWeatherState nextState = this.weatherStates.AnyOrDefaultFromWeight(weather => weather.OccurrenceProbability);
            if (nextState == null)
            {
                return;
            }

            var initialState = this.CurrentWeather;
            this.CurrentWeather = nextState;

            this.OnWeatherChanged(initialState, nextState);
            timer.SetState(nextState);
        }
示例#10
0
        /// <summary>
        /// Removes the given weather state from the zone, preventing the zone from applying it any further.
        /// If the zone is currently using the state, it will be removed but the state will not change until the weather frequency is triggered again.
        /// </summary>
        /// <param name="weatherState">State of the weather.</param>
        /// <returns>Returns an awaitable Task</returns>
        public Task RemoveWeatherState(IWeatherState weatherState)
        {
            if (weatherState == null || !this.weatherStates.Contains(weatherState))
            {
                return Task.FromResult(0);
            }

            this.weatherStates.Remove(weatherState);
            return Task.FromResult(0);
        }
示例#11
0
        /// <summary>
        /// Adds the given weather state to the zone, allowing it to have the weather defined applied to it.
        /// </summary>
        /// <param name="weatherState">State of the weather.</param>
        /// <returns>Returns an awaitable Task</returns>
        public Task AddWeatherState(IWeatherState weatherState)
        {
            if (weatherState == null)
            {
                throw new ArgumentNullException(nameof(weatherState), "You can not add a null weather state instance to a zone.");
            }
            else if (this.weatherStates.Contains(weatherState))
            {
                return Task.FromResult(0);
            }
            else if (string.IsNullOrEmpty(weatherState.Name))
            {
                throw new InvalidWeatherStateException(weatherState, "You must provide the state with a name before adding it to a zone.");
            }
            else if (weatherState.OccurrenceProbability < 1)
            {
                throw new InvalidWeatherStateException(weatherState, "You must have an occurrence probability set higher than 1.");
            }

            this.weatherStates.Add(weatherState);

            return Task.FromResult(0);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InvalidWeatherStateException"/> class.
 /// </summary>
 /// <param name="state">The time period that is not valid.</param>
 /// <param name="message">The message.</param>
 public InvalidWeatherStateException(IWeatherState state, string message) : base(message)
 {
     this.Data.Add(state, message);
 }
示例#13
0
 /// <summary>
 /// Setups the weather up.
 /// </summary>
 private void SetupWeather(IWeatherState state, EngineTimer<IWeatherState> timer)
 {
     // Set the current weather based on the probability of it changing.
     IWeatherState nextWeatherState = this.weatherStates.AnyOrDefaultFromWeight(weather => weather.OccurrenceProbability);
     if (nextWeatherState != this.CurrentWeather)
     {
         this.CurrentWeather = nextWeatherState;
         this.OnWeatherChanged(null, this.CurrentWeather);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="WeatherStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="previousState">State of the previous.</param>
 /// <param name="newState">The new state.</param>
 public WeatherStateChangedEventArgs(IWeatherState previousState, IWeatherState newState)
 {
     this.PreviousState = previousState;
     this.CurrentState  = newState;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InvalidWeatherStateException"/> class.
 /// </summary>
 /// <param name="state">The time period that is not valid.</param>
 /// <param name="message">The message.</param>
 public InvalidWeatherStateException(IWeatherState state, string message) : base(message)
 {
     this.Data.Add(state, message);
 }
示例#16
0
        /// <summary>
        /// Called when the zones weather has changed.
        /// </summary>
        /// <param name="oldWeather">The old weather prior to the change taking place.</param>
        /// <param name="newWeather">The new weather once the change is completed.</param>
        protected virtual void OnWeatherChanged(IWeatherState oldWeather, IWeatherState newWeather)
        {
            EventHandler<WeatherStateChangedEventArgs> handler = this.WeatherChanged;
            if (handler == null)
            {
                return;
            }

            handler(this, new WeatherStateChangedEventArgs(oldWeather, newWeather));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WeatherStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="previousState">State of the previous.</param>
 /// <param name="newState">The new state.</param>
 public WeatherStateChangedEventArgs(IWeatherState previousState, IWeatherState newState)
 {
     this.PreviousState = previousState;
     this.CurrentState = newState;
 }