Ejemplo n.º 1
0
        public float GetMinHeight(float x, float y)
        {
            if (_minHeightPlanes == null)
            {
                return(-500.0f);
            }

            GridCoord gridCoord = GridDefines.ComputeGridCoord(x, y);

            int doubleGridX = (int)(Math.Floor(-(x - MapConst.MapHalfSize) / MapConst.CenterGridOffset));
            int doubleGridY = (int)(Math.Floor(-(y - MapConst.MapHalfSize) / MapConst.CenterGridOffset));

            float gx = x - ((int)gridCoord.X_coord - MapConst.CenterGridId + 1) * MapConst.SizeofGrids;
            float gy = y - ((int)gridCoord.Y_coord - MapConst.CenterGridId + 1) * MapConst.SizeofGrids;

            uint quarterIndex = 0;

            if (Convert.ToBoolean(doubleGridY & 1))
            {
                if (Convert.ToBoolean(doubleGridX & 1))
                {
                    quarterIndex = 4 + (gx <= gy ? 1 : 0u);
                }
                else
                {
                    quarterIndex = (2 + ((-MapConst.SizeofGrids - gx) > gy ? 1u : 0));
                }
            }
            else if (Convert.ToBoolean(doubleGridX & 1))
            {
                quarterIndex = 6 + ((-MapConst.SizeofGrids - gx) <= gy ? 1u : 0);
            }
            else
            {
                quarterIndex = gx > gy ? 1u : 0;
            }


            Ray ray = new Ray(new Vector3(gx, gy, 0.0f), Vector3.ZAxis);

            return(ray.intersection(_minHeightPlanes[quarterIndex]).Z);
        }
Ejemplo n.º 2
0
        void LoadHelper <T>(SortedSet <ulong> guid_set, CellCoord cell, ref uint count, Map map) where T : WorldObject, new()
        {
            foreach (var guid in guid_set)
            {
                T obj = new T();
                // Don't spawn at all if there's a respawn time
                if ((obj.IsTypeId(TypeId.Unit) && map.GetCreatureRespawnTime(guid) == 0) || (obj.IsTypeId(TypeId.GameObject) && map.GetGORespawnTime(guid) == 0))
                {
                    //TC_LOG_INFO("misc", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
                    if (obj.IsTypeId(TypeId.Unit))
                    {
                        CreatureData cdata = Global.ObjectMgr.GetCreatureData(guid);
                        Cypher.Assert(cdata != null, $"Tried to load creature with spawnId {guid}, but no such creature exists.");

                        SpawnGroupTemplateData group = cdata.spawnGroupData;
                        // If creature in manual spawn group, don't spawn here, unless group is already active.
                        if (!group.flags.HasAnyFlag(SpawnGroupFlags.System))
                        {
                            if (!map.IsSpawnGroupActive(group.groupId))
                            {
                                obj.Dispose();
                                continue;
                            }
                        }

                        // If script is blocking spawn, don't spawn but queue for a re-check in a little bit
                        if (!group.flags.HasFlag(SpawnGroupFlags.CompatibilityMode) && !Global.ScriptMgr.CanSpawn(guid, cdata.Id, cdata, map))
                        {
                            map.SaveRespawnTime(SpawnObjectType.Creature, guid, cdata.Id, Time.UnixTime + RandomHelper.URand(4, 7), map.GetZoneId(PhasingHandler.EmptyPhaseShift, cdata.spawnPoint), GridDefines.ComputeGridCoord(cdata.spawnPoint.GetPositionX(), cdata.spawnPoint.GetPositionY()).GetId(), false);
                            obj.Dispose();
                            continue;
                        }
                    }
                    else if (obj.IsTypeId(TypeId.GameObject))
                    {
                        // If gameobject in manual spawn group, don't spawn here, unless group is already active.
                        GameObjectData godata = Global.ObjectMgr.GetGameObjectData(guid);
                        Cypher.Assert(godata != null, $"Tried to load gameobject with spawnId {guid}, but no such object exists.");

                        if (!godata.spawnGroupData.flags.HasAnyFlag(SpawnGroupFlags.System))
                        {
                            if (!map.IsSpawnGroupActive(godata.spawnGroupData.groupId))
                            {
                                obj.Dispose();
                                continue;
                            }
                        }
                    }

                    if (!obj.LoadFromDB(guid, map, false, false))
                    {
                        obj.Dispose();
                        continue;
                    }
                    AddObjectHelper(cell, ref count, map, obj);
                }
                else
                {
                    obj.Dispose();
                }
            }
        }