Beispiel #1
0
        public void SendConnectToInstance(ConnectToSerial serial)
        {
            var instanceAddress = Global.WorldMgr.GetRealm().GetAddressForClient(System.Net.IPAddress.Parse(GetRemoteAddress()));

            instanceAddress.Port = WorldConfig.GetIntValue(WorldCfg.PortInstance);

            _instanceConnectKey.AccountId      = GetAccountId();
            _instanceConnectKey.connectionType = ConnectionType.Instance;
            _instanceConnectKey.Key            = RandomHelper.URand(0, 0x7FFFFFFF);

            ConnectTo connectTo = new ConnectTo();

            connectTo.Key           = _instanceConnectKey.Raw;
            connectTo.Serial        = serial;
            connectTo.Payload.Where = instanceAddress;
            connectTo.Con           = (byte)ConnectionType.Instance;

            SendPacket(connectTo);
        }
Beispiel #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);
        }
Beispiel #3
0
        public void SpawnObject(ActivePoolData spawns, uint limit, ulong triggerFrom)
        {
            if (typeof(T).Name == "Quest")
            {
                SpawnQuestObject(spawns, limit, triggerFrom);
                return;
            }

            int count = (int)(limit - spawns.GetActiveObjectCount(poolId));

            // If triggered from some object respawn this object is still marked as spawned
            // and also counted into m_SpawnedPoolAmount so we need increase count to be
            // spawned by 1
            if (triggerFrom != 0)
            {
                ++count;
            }

            // This will try to spawn the rest of pool, not guaranteed
            if (count > 0)
            {
                List <PoolObject> rolledObjects = new List <PoolObject>();

                // roll objects to be spawned
                if (!ExplicitlyChanced.Empty())
                {
                    while (count != 0 && ExplicitlyChanced.Count > rolledObjects.Count)
                    {
                        --count;
                        float roll = (float)RandomHelper.randChance();

                        foreach (PoolObject obj in ExplicitlyChanced)
                        {
                            roll -= obj.chance;
                            // Triggering object is marked as spawned at this time and can be also rolled (respawn case)
                            // so this need explicit check for this case
                            if (roll < 0 && (obj.guid == triggerFrom || !spawns.IsActiveObject <T>(obj.guid)))
                            {
                                rolledObjects.Add(obj);
                                break;
                            }
                        }
                    }
                }
                else if (!EqualChanced.Empty())
                {
                    rolledObjects = EqualChanced;

                    for (var i = 0; i < rolledObjects.Count; ++i)
                    {
                        var obj = rolledObjects[i];
                        // remove most of the active objects so there is higher chance inactive ones are spawned
                        if (spawns.IsActiveObject <T>(obj.guid) && RandomHelper.URand(1, 4) != 1)
                        {
                            rolledObjects.Remove(obj);
                        }
                    }

                    rolledObjects.RandomResize((uint)count);
                }

                // try to spawn rolled objects
                foreach (PoolObject obj in rolledObjects)
                {
                    if (spawns.IsActiveObject <T>(obj.guid))
                    {
                        continue;
                    }

                    if (obj.guid == triggerFrom)
                    {
                        ReSpawn1Object(obj);
                        triggerFrom = 0;
                    }
                    else
                    {
                        spawns.ActivateObject <T>(obj.guid, poolId);
                        Spawn1Object(obj);
                    }
                }
            }

            // One spawn one despawn no count increase
            if (triggerFrom != 0)
            {
                DespawnObject(spawns, triggerFrom);
            }
        }