public static Packets.Packet_33_Weather GetUpdatedWeather()
            {
                Packets.Packet_33_Weather OutWeather = new Packets.Packet_33_Weather(_Weather);
                if (!AdvancedWeatherOptions._Weather_Variable)
                {
                    return(OutWeather);
                }
                OutWeather.WindX = _WindX;
                OutWeather.WindY = _WindY;
                OutWeather.WindZ = _WindZ;
                OutWeather.Fog   = _Fog__;

                //Get the baseline weather
                float BASEWINDX = _Weather.WindX;
                float BASEWINDY = _Weather.WindY;
                float BASEWINDZ = _Weather.WindZ;
                float BASEFOG__ = _Weather.Fog;

                //find the minimum weather limit
                float MINWINDX = BASEWINDX - ((BASEWINDX - 0) * (_Weather_Variance_Limit / (float)100));
                float MINWINDY = BASEWINDY - ((BASEWINDY - 0) * (_Weather_Variance_Limit / (float)100));
                float MINWINDZ = BASEWINDZ - ((BASEWINDZ - 0) * (_Weather_Variance_Limit / (float)100));
                float MINFOG__ = BASEFOG__ - ((BASEFOG__ - 0) * (_Weather_Variance_Limit / (float)100));

                //find the maximum weather limit
                float MAXWINDX = BASEWINDX + ((BASEWINDX - 0) * (_Weather_Variance_Limit / (float)100));
                float MAXWINDY = BASEWINDY + ((BASEWINDY - 0) * (_Weather_Variance_Limit / (float)100));
                float MAXWINDZ = BASEWINDZ + ((BASEWINDZ - 0) * (_Weather_Variance_Limit / (float)100));
                float MAXFOG__ = BASEFOG__ + ((BASEFOG__ - 0) * (_Weather_Variance_Limit / (float)100));

                //shouldn't need any of this crap...

                /*
                 * if (BASEWINDX < MINWINDX) BASEWINDX = MINWINDX;
                 * if (BASEWINDY < MINWINDY) BASEWINDY = MINWINDY;
                 * if (BASEWINDZ < MINWINDZ) BASEWINDZ = MINWINDZ;
                 * if (BASEFOG__ < MINFOG__) BASEFOG__ = MINFOG__;
                 *
                 * if (BASEWINDX > MAXWINDX) BASEWINDX = MAXWINDX;
                 * if (BASEWINDY > MAXWINDY) BASEWINDY = MAXWINDY;
                 * if (BASEWINDZ > MAXWINDZ) BASEWINDZ = MAXWINDZ;
                 * if (BASEFOG__ > MAXFOG__) BASEFOG__ = MAXFOG__;
                 */

                if (MINFOG__ < 0)
                {
                    MINFOG__ = 0;
                }
                if (MAXFOG__ > 20000)
                {
                    MAXFOG__ = 20000;
                }

                Random RandomGenerator = new Random();

                //adjust the rate of change for the weather.

                //LIMITER * ([VALUE+([BASE-VALUE]/2)]/[BASE/(BASE*VARIANCELIMIT)]) ~= 0.00 +/- ACCEPTABLE VARIANCE.
                //LIMITER * ([VALUE+([BASE-VALUE]/2)]/[BASE/(BASE*VARIANCELIMIT)]) ~= 0.00 +/- ACCEPTABLE VARIANCE.
                //LIMITER * ([VALUE+([BASE-VALUE]/2)]/[(BASE*VARIANCELIMIT)/BASE]) ~= 0.00 +/- ACCEPTABLE VARIANCE.
                //4000 * 3750
                //((-3000 * 100),
                //
                //RATIO GETS STEEPER AS THE VALUES GET FURTHER AWAY FROM CENTER. IT'S LIKE A BALL IN A PARABOLA! :D
                float Limiter;

                if (_Weather_Variance_Limit == 0)
                {
                    Limiter = 1;
                }
                else
                {
                    Limiter = (_Weather_Variance_Limit / (float)100);
                }
                try
                {
                    if (BASEWINDX != 0)
                    {
                        _WindX_DUDX1 += (_WindX_DUDX1_MAX / 60 / 10) * ((RandomGenerator.Next(-10000, 10000) / (float)10000) + (((float)BASEWINDX - _WindX) / ((float)BASEWINDX * Limiter)) / 2);
                    }
                    if (BASEWINDY != 0)
                    {
                        _WindY_DUDX1 += (_WindY_DUDX1_MAX / 60 / 10) * ((RandomGenerator.Next(-10000, 10000) / (float)10000) + (((float)BASEWINDY - _WindY) / ((float)BASEWINDY * Limiter)) / 2);
                    }
                    if (BASEWINDZ != 0)
                    {
                        _WindZ_DUDX1 += (_WindZ_DUDX1_MAX / 60 / 10) * ((RandomGenerator.Next(-10000, 10000) / (float)10000) + (((float)BASEWINDZ - _WindZ) / ((float)BASEWINDZ * Limiter)) / 2);
                    }
                    if (BASEFOG__ != 0)
                    {
                        _Fog___DUDX1 += (_Fog___DUDX1_MAX / 60 / 10) * ((RandomGenerator.Next(-10000, 10000) / (float)10000) + (((float)BASEFOG__ - _Fog__) / ((float)BASEFOG__ * Limiter)) / 2);
                    }
                }
                catch
                {
                }

                //limit the rates of change to the minimum.
                if (_WindX_DUDX1 < -_WindX_DUDX1_MAX / 60 / 10)
                {
                    _WindX_DUDX1 = -_WindX_DUDX1_MAX / 60 / 10;
                }
                if (_WindY_DUDX1 < -_WindY_DUDX1_MAX / 60 / 10)
                {
                    _WindY_DUDX1 = -_WindY_DUDX1_MAX / 60 / 10;
                }
                if (_WindZ_DUDX1 < -_WindZ_DUDX1_MAX / 60 / 10)
                {
                    _WindZ_DUDX1 = -_WindZ_DUDX1_MAX / 60 / 10;
                }
                if (_Fog___DUDX1 < -_Fog___DUDX1_MAX / 60 / 10)
                {
                    _Fog___DUDX1 = -_Fog___DUDX1_MAX / 60 / 10;
                }

                //limit the rates of change to the maximum.
                if (_WindX_DUDX1 > _WindX_DUDX1_MAX / 60 / 10)
                {
                    _WindX_DUDX1 = _WindX_DUDX1_MAX / 60 / 10;
                }
                if (_WindY_DUDX1 > _WindY_DUDX1_MAX / 60 / 10)
                {
                    _WindY_DUDX1 = _WindY_DUDX1_MAX / 60 / 10;
                }
                if (_WindZ_DUDX1 > _WindZ_DUDX1_MAX / 60 / 10)
                {
                    _WindZ_DUDX1 = _WindZ_DUDX1_MAX / 60 / 10;
                }
                if (_Fog___DUDX1 > _Fog___DUDX1_MAX / 60 / 10)
                {
                    _Fog___DUDX1 = _Fog___DUDX1_MAX / 60 / 10;
                }

                //add the rate of change to the current weather.
                _WindX += _WindX_DUDX1;
                _WindY += _WindY_DUDX1;
                _WindZ += _WindZ_DUDX1;
                _Fog__ += _Fog___DUDX1;

                //limit the weather by the minimums.
                if (_WindX < MINWINDX)
                {
                    _WindX = MINWINDX;
                }
                if (_WindY < MINWINDY)
                {
                    _WindY = MINWINDY;
                }
                if (_WindZ < MINWINDZ)
                {
                    _WindZ = MINWINDZ;
                }
                if (_Fog__ < MINFOG__)
                {
                    _Fog__ = MINFOG__;
                }

                //limit the weather by the maximums.
                if (_WindX > MAXWINDX)
                {
                    _WindX = MAXWINDX;
                }
                if (_WindY > MAXWINDY)
                {
                    _WindY = MAXWINDY;
                }
                if (_WindZ > MAXWINDZ)
                {
                    _WindZ = MAXWINDZ;
                }
                if (_Fog__ > MAXFOG__)
                {
                    _Fog__ = MAXFOG__;
                }

                //prepare for turbulence
                float OutWindX = _WindX;
                float OutWindY = _WindY;
                float OutWindZ = _WindZ;
                float OutFog__ = _Fog__;

                OutWindX *= (RandomGenerator.Next(-_Turbulence, _Turbulence) / (float)100) + 1;
                OutWindY *= (RandomGenerator.Next(-_Turbulence, _Turbulence) / (float)100) + 1;
                OutWindZ *= (RandomGenerator.Next(-_Turbulence, _Turbulence) / (float)100) + 1;
                //OutFog__ *= (RandomGenerator.Next(-Turbulence, Turbulence) / (float)100) + 1;

                OutWeather.WindX = OutWindX;
                OutWeather.WindY = OutWindY;
                OutWeather.WindZ = OutWindZ;
                OutWeather.Fog   = OutFog__;

                return(OutWeather);
            }
        public static bool UpdateTimeOfDay()
        {
            while ((DateTime.Now - AdvancedWeatherOptions._LastDayNightCycleRestart).TotalMinutes > AdvancedWeatherOptions._DayNightCycleLength & AdvancedWeatherOptions._DayNightCycleLength > 0)
            {
                AdvancedWeatherOptions._LastDayNightCycleRestart += new TimeSpan(0, AdvancedWeatherOptions._DayNightCycleLength, 0);
            }
            CurrentTick = GetServerTimeTicks();
            if (AdvancedWeatherOptions._DayNightCycleLength <= 0)
            {
                CurrentTick = PreviousTick;
                //return false;
            }

            //These packets ultimately sent to the clients.
            Packets.Packet_49_SkyColor SkyColorUpdate = new Packets.Packet_49_SkyColor(Settings.Weather.Advanced.SkyColor);
            Packets.Packet_48_FogColor FogColorUpdate = new Packets.Packet_48_FogColor(Settings.Weather.Advanced.FogColor);

            Colors.XRGBColor BlendedSkyColor = Settings.Weather.Advanced.SkyColor;
            Colors.XRGBColor BlendedFogColor = Settings.Weather.Advanced.FogColor;
            #region TimeOfDayBlending
            //Night 1
            if (CurrentTick < 6000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.NightSkyColor;
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor;
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            //Dawn 1
            if (CurrentTick >= 6000 && CurrentTick < 7000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.NightSkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DawnSkyColor, (CurrentTick - 6000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DawnHorizonColor, (CurrentTick - 6000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            //Dawn 2
            if (CurrentTick >= 7000 && CurrentTick < 8000)
            {
                if (PreviousTick < 7000)
                {
                    Weather = new Packets.Packet_33_Weather(_Weather)
                    {
                        Lighting = 0
                    };                                                                  //Set To Day
                    Clients.AllClients.SendPacket(Weather);
                }
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DawnSkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(new Colors.XRGBColor(255, 255, 255), (CurrentTick - 7000) / 1000d);
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DaySkyColor, (CurrentTick - 7000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DawnHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(new Colors.XRGBColor(255, 255, 255), (CurrentTick - 7000) / 1000d);
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DayHorizonColor, (CurrentTick - 7000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
            }
            //Day
            if (CurrentTick >= 8000 && CurrentTick < 18000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DaySkyColor;
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DayHorizonColor;
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
            }
            //Dusk 1
            if (CurrentTick >= 18000 && CurrentTick < 19000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DaySkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DuskSkyColor, (CurrentTick - 18000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DayHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.DuskHorizonColor, (CurrentTick - 18000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
            }
            //Dusk 2
            if (CurrentTick >= 19000 && CurrentTick < 20000)
            {
                if (PreviousTick < 19000)
                {
                    Weather = new Packets.Packet_33_Weather(_Weather)
                    {
                        Lighting = 65537
                    };                                                                      //Set To Night
                    Clients.AllClients.SendPacket(Weather);
                }
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.DuskSkyColor;
                BlendedSkyColor      = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NightSkyColor, (CurrentTick - 19000) / 1000d);
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.DuskHorizonColor;
                BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor, (CurrentTick - 19000) / 1000d);
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            //Night 2
            if (CurrentTick >= 20000)
            {
                BlendedSkyColor      = Settings.Weather.Advanced.EnvironmentColors.NightSkyColor;
                SkyColorUpdate.Color = SkyColorUpdate.Color.AlphaBlend(BlendedSkyColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);

                BlendedFogColor      = Settings.Weather.Advanced.EnvironmentColors.NightHorizonColor;
                FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(BlendedFogColor, Settings.Weather.Advanced.EnvironmentColors.OverallBlendFactor);
                //FogColorUpdate.Color = FogColorUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightHorizonColorChangeFactor);
            }
            #endregion

            #region Fog Distance Blending
            BlendedFogColor      = FogColorUpdate.Color;
            BlendedFogColor      = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.WhiteFogColor, 1 - (OpenYS.Weather.Fog / 20000));
            FogColorUpdate.Color = BlendedFogColor;
            #endregion

            foreach (Client ThisClient in Clients.LoggedIn)
            {
                #region Altitude Blending
                //Now filter the sky and fog based on altitude.
                Packets.Packet_48_FogColor ThisClientFogUpdate = FogColorUpdate;
                Packets.Packet_49_SkyColor ThisClientSkyUpdate = SkyColorUpdate;

                Vehicle ThisVehicle = ThisClient.Vehicle;
                if (ThisVehicle != Vehicles.NoVehicle)
                {
                    if (ThisVehicle.PosY >= Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters) //Above 100,000ft
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereSkyColor, 1.0);
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereHorizonColor, 1.0);
                        //ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - NightFogFilter);
                    }
                    if (ThisVehicle.PosY >= Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters && ThisVehicle.PosY < Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters) //Roughly 40,000ft to 100,000ft
                    {
                        BlendedSkyColor           = ThisClientSkyUpdate.Color;
                        BlendedSkyColor           = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.MaxAltitudeSkyColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters));  //fade to the sky color.
                        BlendedSkyColor           = BlendedSkyColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereSkyColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters)); //fade to the noatmosphere color.
                        ThisClientSkyUpdate.Color = BlendedSkyColor;

                        BlendedFogColor           = ThisClientFogUpdate.Color;
                        BlendedFogColor           = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.MaxAltitudeHorizonColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters));  //fade to the Fog color.
                        BlendedFogColor           = BlendedFogColor.AlphaBlend(Settings.Weather.Advanced.EnvironmentColors.NoAtmosphereHorizonColor, (ThisVehicle.PosY - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) / (Settings.Weather.Advanced.AtmosphericFading.MaximumAltitudeInMeters - Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters)); //fade to the noatmosphere color.
                        ThisClientFogUpdate.Color = BlendedFogColor;
                        //ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Utilities.RGBColor(0, 0, 0), 1 - NightFogFilter);
                    }
                    if (ThisVehicle.PosY < Settings.Weather.Advanced.AtmosphericFading.MinimumAltitudeInMeters) //Less then 40,000 ft.
                    {
                        //Do nothing.
                    }
                    #region SetNightColors
                    if (CurrentTick < 6000 | CurrentTick >= 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor);                                            //7000 = 0, 6000 = 1
                    }
                    if (CurrentTick >= 6000 & CurrentTick < 7000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 6000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 7000 & CurrentTick < 8000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 7000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 18000 & CurrentTick < 19000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 18000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 19000 & CurrentTick < 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 19000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    #endregion
                }
                else
                {
                    #region SetNightColors
                    if (CurrentTick < 6000 | CurrentTick >= 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), 1 - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor);                                            //7000 = 0, 6000 = 1
                    }
                    if (CurrentTick >= 6000 & CurrentTick < 7000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 6000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 7000 & CurrentTick < 8000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (1.0d - ((CurrentTick - 7000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 18000 & CurrentTick < 19000)
                    {
                        ThisClientSkyUpdate.Color = ThisClientSkyUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 18000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    if (CurrentTick >= 19000 & CurrentTick < 20000)
                    {
                        ThisClientFogUpdate.Color = ThisClientFogUpdate.Color.AlphaBlend(new Colors.XRGBColor(0, 0, 0), (((CurrentTick - 19000d) / 1000d)) * (1.0d - Settings.Weather.Advanced.EnvironmentColors.NightColorFactor));
                    }
                    #endregion
                }
                #endregion

                #region Set Definied Colors
                if (ThisClient.Version > 20110207)
                {
                    if (!Settings.Weather.Advanced.EnableSkyColor)
                    {
                        ThisClient.SendPacket(ThisClientSkyUpdate);
                    }
                    if (!Settings.Weather.Advanced.EnableFogColor)
                    {
                        ThisClient.SendPacket(ThisClientFogUpdate);
                    }
                }
                #endregion
            }
            PreviousTick = CurrentTick;
            return(true);
        }
        public static bool DayNightCycler()
        {
            try
            {
                if (AdvancedWeatherOptions._DayNightCycleLength <= 0)
                {
                    return(false);
                }

                //Synchronise the time.
                if (Weather.Lighting <= 65536)
                {
                    //Set time to 1200J
                    AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now - new TimeSpan(0, 0, (int)((float)AdvancedWeatherOptions._DayNightCycleLength / 2 * 60)); //mid day is half a day AFTER midnight! adjust the start day time accordingly!
                }
                else
                {
                    //Set time to 0000J
                    AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now; //mid day is half a day AFTER midnight! adjust the start day time accordingly!
                }

                while (!Environment.TerminateSignal.WaitOne(0))
                {
                    if (AdvancedWeatherOptions._DayNightCycleLength <= 0)
                    {
                        return(false);
                    }
                    Thread.Sleep((int)((((AdvancedWeatherOptions._DayNightCycleLength / (float)4)) * 1000 * 60) - 3000)); //sleep to 0600 or 1800.
                    if (AdvancedWeatherOptions._DayNightCycleLength != 0)
                    {
                        if (_Weather.Lighting >= 65537)
                        {
                            Clients.AllClients.SendMessage("&6The sun is about to rise...");
                            Thread.Sleep(3000);
                            Clients.AllClients.SendMessage("&6The sun rises...");
                            Weather = new Packets.Packet_33_Weather(_Weather)
                            {
                                Lighting = 0
                            };
                            Clients.AllClients.SendPacket(Weather);
                            Thread.Sleep((int)(((AdvancedWeatherOptions._DayNightCycleLength / (float)4)) * 1000 * 60)); //sleep to 1200
                        }
                        else
                        {
                            Clients.AllClients.SendMessage("&5The sun is about to set...");
                            Thread.Sleep(3000);
                            Clients.AllClients.SendMessage("&5The sun sets...");
                            Weather = new Packets.Packet_33_Weather(_Weather)
                            {
                                Lighting = 65537
                            };
                            Clients.AllClients.SendPacket(Weather);
                            Thread.Sleep((int)(((AdvancedWeatherOptions._DayNightCycleLength / (float)4)) * 1000 * 60)); //sleep until 0000
                            AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException)
                {
                    return(false);
                }
                else
                {
                    Log.Error(e);
                    Console.TerminateConsole(e);
                    return(false);
                }
            }
            return(true);
        }
        public static bool MicroTick()
        {
            #region DoWeather
            if (AdvancedWeatherOptions._Weather_Variable)
            {
                Packets.Packet_33_Weather TempWeather = AdvancedWeatherOptions.GetUpdatedWeather();
                TempWeather.Control_BlackOut       = false;
                TempWeather.Control_Collisions     = false;
                TempWeather.Control_LandEverywhere = false;
                Clients.AllClients.SendPacket(TempWeather);
            }
            #endregion
            #region DoHeartbeatMonitor
            Clients.DoHeartbeatMonitor();
            #endregion
            #region DoOnTickUpdateEvent
            lock (Events_OnMicroTickUpdate)
            {
                foreach (OnMicroTickUpdateEvent ThisMethod in Events_OnMicroTickUpdate)
                {
                    ThisMethod();
                }
            }
            #endregion

            #region CountThreads
            Thread[] _ThreadsArray;
            lock (Threads.List) _ThreadsArray = Threads.List.ToArray();
            foreach (Thread ThisThread in _ThreadsArray)
            {
                if (!ThisThread.IsAlive)
                {
                    //Log.Error("Thread killed as part of maintenance: " + ThisThread.Name);
                    Threads.List.RemoveAll(x => x == ThisThread);
                }
            }
            #endregion
            #region ManageVehicles
            Vehicle[] _VehiclesArray;
            lock (Vehicles.List) _VehiclesArray = Vehicles.List.ToArray();
            foreach (Vehicle ThisVehicle in _VehiclesArray)
            {
                if (Clients.Flying.Where(x => x.Vehicle == ThisVehicle).Count() < 1
                    & !ThisVehicle.IsVirtualVehicle)
                {
                    Vehicles.List.RemoveAll(x => x == ThisVehicle);
                    Packets.Packet_13_RemoveAirplane RemoveAirplane = new Packets.Packet_13_RemoveAirplane(ThisVehicle.ID);
                    foreach (Client OtherClient in Clients.AllClients)
                    {
                        Packets.Packet_06_Acknowledgement AcknowledgeLeave = new Packets.Packet_06_Acknowledgement(2, RemoveAirplane.ID);
                        //OtherClient.SendPacketGetPacket(RemoveAirplane, AcknowledgeLeave);
                        OtherClient.SendPacket(RemoveAirplane);
                    }
                    Console.WriteLine("&3Found a lost Vehicle... Cleaned it up!");
                    continue;
                }
                if (ThisVehicle.Invincible)
                {
                    Clients.LoggedIn.SendPacket(new Packets.Packet_30_AirCommand(ThisVehicle.ID, "STRENGTH", "255"));
                }
            }
            #endregion
            return(true);
        }