Exemplo n.º 1
0
        public string BuildCalendarMailBody()
        {
            var  now  = Time.UnixTimeToDateTime(Date);
            uint time = Convert.ToUInt32(((now.Year - 1900) - 100) << 24 | (now.Month - 1) << 20 | (now.Day - 1) << 14 | (int)now.DayOfWeek << 11 | now.Hour << 6 | now.Minute);

            return(time.ToString());
        }
Exemplo n.º 2
0
        public bool ReGenerate()
        {
            if (m_weatherChances == null)
            {
                m_type  = WeatherType.Fine;
                m_grade = 0.0f;
                return(false);
            }

            /// Weather statistics:
            // 30% - no change
            // 30% - weather gets better (if not fine) or change weather type
            // 30% - weather worsens (if not fine)
            // 10% - radical change (if not fine)
            uint u = RandomHelper.URand(0, 99);

            if (u < 30)
            {
                return(false);
            }

            // remember old values
            WeatherType old_type  = m_type;
            float       old_grade = m_grade;

            long gtime  = Global.WorldMgr.GetGameTime();
            var  ltime  = Time.UnixTimeToDateTime(gtime).ToLocalTime();
            uint season = (uint)((ltime.DayOfYear - 78 + 365) / 91) % 4;

            string[] seasonName = { "spring", "summer", "fall", "winter" };

            Log.outError(LogFilter.Server, "Generating a change in {0} weather for zone {1}.", seasonName[season], m_zone);

            if ((u < 60) && (m_grade < 0.33333334f))                // Get fair
            {
                m_type  = WeatherType.Fine;
                m_grade = 0.0f;
            }

            if ((u < 60) && (m_type != WeatherType.Fine))          // Get better
            {
                m_grade -= 0.33333334f;
                return(true);
            }

            if ((u < 90) && (m_type != WeatherType.Fine))          // Get worse
            {
                m_grade += 0.33333334f;
                return(true);
            }

            if (m_type != WeatherType.Fine)
            {
                /// Radical change:
                // if light . heavy
                // if medium . change weather type
                // if heavy . 50% light, 50% change weather type

                if (m_grade < 0.33333334f)
                {
                    m_grade = 0.9999f;                              // go nuts
                    return(true);
                }
                else
                {
                    if (m_grade > 0.6666667f)
                    {
                        // Severe change, but how severe?
                        uint rnd = RandomHelper.URand(0, 99);
                        if (rnd < 50)
                        {
                            m_grade -= 0.6666667f;
                            return(true);
                        }
                    }
                    m_type  = WeatherType.Fine;                    // clear up
                    m_grade = 0;
                }
            }

            // At this point, only weather that isn't doing anything remains but that have weather data
            uint chance1 = m_weatherChances.data[season].rainChance;
            uint chance2 = chance1 + m_weatherChances.data[season].snowChance;
            uint chance3 = chance2 + m_weatherChances.data[season].stormChance;
            uint rn      = RandomHelper.URand(1, 100);

            if (rn <= chance1)
            {
                m_type = WeatherType.Rain;
            }
            else if (rn <= chance2)
            {
                m_type = WeatherType.Snow;
            }
            else if (rn <= chance3)
            {
                m_type = WeatherType.Storm;
            }
            else
            {
                m_type = WeatherType.Fine;
            }

            // New weather statistics (if not fine):
            // 85% light
            // 7% medium
            // 7% heavy
            // If fine 100% sun (no fog)

            if (m_type == WeatherType.Fine)
            {
                m_grade = 0.0f;
            }
            else if (u < 90)
            {
                m_grade = (float)RandomHelper.NextDouble() * 0.3333f;
            }
            else
            {
                // Severe change, but how severe?
                rn = RandomHelper.URand(0, 99);
                if (rn < 50)
                {
                    m_grade = (float)RandomHelper.NextDouble() * 0.3333f + 0.3334f;
                }
                else
                {
                    m_grade = (float)RandomHelper.NextDouble() * 0.3333f + 0.6667f;
                }
            }

            // return true only in case weather changes
            return(m_type != old_type || m_grade != old_grade);
        }