Exemplo n.º 1
0
 private ArrayList GetListForSector( Sector sector )
 {
     switch ( m_Type )
     {
         case SectorEnumeratorType.Clients: return sector.Clients;
         case SectorEnumeratorType.Mobiles: return sector.Mobiles;
         case SectorEnumeratorType.Items:   return sector.Items;
         default: throw new Exception( "Invalid SectorEnumeratorType" );
     }
 }
Exemplo n.º 2
0
        public void AddMulti( Item item, Sector start, Sector end )
        {
            if ( this == Map.Internal )
                return;

            for ( int x = start.X; x <= end.X; ++x )
                for ( int y = start.Y; y <= end.Y; ++y )
                    InternalGetSector( x, y ).OnMultiEnter( item );
        }
Exemplo n.º 3
0
            private MultiTileEnumerator( Sector sector, Point2D loc )
            {
                m_List = sector.Multis;
                m_Location = loc;

                Reset();
            }
Exemplo n.º 4
0
            public static MultiTileEnumerator Instantiate( Sector sector, Point2D loc )
            {
                MultiTileEnumerator e;

                if ( m_InstancePool.Count > 0 )
                {
                    e = (MultiTileEnumerator)m_InstancePool.Dequeue();

                    e.m_List = sector.Multis;
                    e.m_Location = loc;

                    e.Reset();
                }
                else
                {
                    e = new MultiTileEnumerator( sector, loc );
                }

                return e;
            }
Exemplo n.º 5
0
        private Sector InternalGetSector( int x, int y )
        {
            if ( x >= 0 && x < m_SectorsWidth && y >= 0 && y < m_SectorsHeight )
            {
                Sector[] xSectors = m_Sectors[x];

                if ( xSectors == null )
                    m_Sectors[x] = xSectors = new Sector[m_SectorsHeight];

                Sector sec = xSectors[y];

                if ( sec == null )
                    xSectors[y] = sec = new Sector( x, y, this );

                return sec;
            }
            else
            {
                return m_InvalidSector;
            }
        }
Exemplo n.º 6
0
        private bool PlayersInRange( Sector sect, int range )
        {
            for (int x=sect.X - range;x<=sect.X + range;++x)
            {
                for (int y=sect.Y - range;y<=sect.Y + range;++y)
                {
                    Sector check = GetRealSector( x, y );
                    if ( check != m_InvalidSector && check.Players.Count > 0 )
                        return true;
                }
            }

            return false;
        }
Exemplo n.º 7
0
 public static bool Contains(this Sector s, Point3D p)
 {
     return(s.RegionRects.Contains(p));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the highest surface that is lower than <paramref name="p"/>.
        /// </summary>
        /// <param name="p">The reference point.</param>
        /// <returns>A surface <typeparamref name="Tile"/> or <typeparamref name="Item"/>.</returns>
        public object GetTopSurface(Point3D p)
        {
            if (this == Map.Internal)
            {
                return(null);
            }

            object surface  = null;
            int    surfaceZ = int.MinValue;


            Tile lt = Tiles.GetLandTile(p.X, p.Y);

            if (!lt.Ignored)
            {
                int avgZ = GetAverageZ(p.X, p.Y);

                if (avgZ <= p.Z)
                {
                    surface  = lt;
                    surfaceZ = avgZ;

                    if (surfaceZ == p.Z)
                    {
                        return(surface);
                    }
                }
            }


            Tile[] staticTiles = Tiles.GetStaticTiles(p.X, p.Y, true);

            for (int i = 0; i < staticTiles.Length; i++)
            {
                Tile     tile = staticTiles[i];
                ItemData id   = TileData.ItemTable[tile.ID & TileData.MaxItemValue];

                if (id.Surface || (id.Flags & TileFlag.Wet) != 0)
                {
                    int tileZ = tile.Z + id.CalcHeight;

                    if (tileZ > surfaceZ && tileZ <= p.Z)
                    {
                        surface  = tile;
                        surfaceZ = tileZ;

                        if (surfaceZ == p.Z)
                        {
                            return(surface);
                        }
                    }
                }
            }


            Sector sector = GetSector(p.X, p.Y);

            for (int i = 0; i < sector.Items.Count; i++)
            {
                Item item = sector.Items[i];

                if (!(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue && item.AtWorldPoint(p.X, p.Y) && !item.Movable)
                {
                    ItemData id = item.ItemData;

                    if (id.Surface || (id.Flags & TileFlag.Wet) != 0)
                    {
                        int itemZ = item.Z + id.CalcHeight;

                        if (itemZ > surfaceZ && itemZ <= p.Z)
                        {
                            surface  = item;
                            surfaceZ = itemZ;

                            if (surfaceZ == p.Z)
                            {
                                return(surface);
                            }
                        }
                    }
                }
            }


            return(surface);
        }
Exemplo n.º 9
0
        private static bool CanFit(Map map, int x, int y, int z)
        {
            bool hasSurface = false;

            LandTile lt = map.Tiles.GetLandTile(x, y);
            int      lowZ = 0, avgZ = 0, topZ = 0;

            map.GetAverageZ(x, y, ref lowZ, ref avgZ, ref topZ);
            TileFlag landFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags;

            if ((landFlags & TileFlag.Impassable) != 0 && topZ > z && (z + 16) > lowZ)
            {
                return(false);
            }
            else if ((landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored)
            {
                hasSurface = true;
            }

            StaticTile[] staticTiles = map.Tiles.GetStaticTiles(x, y);

            bool surface, impassable;

            for (int i = 0; i < staticTiles.Length; ++i)
            {
                if (IsDisplayCase(staticTiles[i].ID))
                {
                    continue;
                }

                ItemData id = TileData.ItemTable[staticTiles[i].ID & TileData.MaxItemValue];

                surface    = id.Surface;
                impassable = id.Impassable;

                if ((surface || impassable) && (staticTiles[i].Z + id.CalcHeight) > z && (z + 16) > staticTiles[i].Z)
                {
                    return(false);
                }
                else if (surface && !impassable && z == (staticTiles[i].Z + id.CalcHeight))
                {
                    hasSurface = true;
                }
            }

            Sector      sector = map.GetSector(x, y);
            List <Item> items  = sector.Items;

            for (int i = 0; i < items.Count; ++i)
            {
                Item item = items[i];

                if (item.AtWorldPoint(x, y))
                {
                    ItemData id = item.ItemData;
                    surface    = id.Surface;
                    impassable = id.Impassable;

                    if ((surface || impassable) && (item.Z + id.CalcHeight) > z && (z + 16) > item.Z)
                    {
                        return(false);
                    }
                    else if (surface && !impassable && z == (item.Z + id.CalcHeight))
                    {
                        hasSurface = true;
                    }
                }
            }

            return(hasSurface);
        }
Exemplo n.º 10
0
 public static bool Contains(this Sector s, Point3D p, Map m)
 {
     return(s.Owner == m && Contains(s, p));
 }
Exemplo n.º 11
0
			private Dictionary<Server.Serial, object>.ValueCollection GetListForSector(Sector sector)
			{
				switch (m_Type)
				{
					case SectorEnumeratorType.Clients: return sector.Clients.Values;
					case SectorEnumeratorType.Mobiles: return sector.Mobiles.Values;
					case SectorEnumeratorType.Items: return sector.Items.Values;
					default: throw new Exception("Invalid SectorEnumeratorType");
				}
			}
Exemplo n.º 12
0
			private MultiTileEnumerator(Sector sector, Point2D loc)
			{
				m_ListManager = new ListManager(sector.Multis.Values);
				//m_List = sector.Multis;
				m_Location = loc;

				Reset();
			}
Exemplo n.º 13
0
        public void Register()
        {
            if (m_Registered)
            {
                return;
            }

            OnRegister();

            m_Registered = true;

            if (m_Parent != null)
            {
                m_Parent.m_Children.Add(this);
                m_Parent.OnChildAdded(this);
            }

            m_Regions.Add(this);

            m_Map.RegisterRegion(this);

            m_IndexedName = IndexedRegionName.NotIndexed;

            if (m_Name != null)
            {
                IndexedRegionName temp;

                if (m_NameToIndexLookup.TryGetValue(m_Name, out temp))
                {
                    m_IndexedName = temp;
                }
            }

            List <Sector> sectors = new List <Sector>();

            for (int i = 0; i < m_Area.Length; i++)
            {
                Rectangle3D rect = m_Area[i];

                Point2D start = m_Map.Bound(new Point2D(rect.Start));
                Point2D end   = m_Map.Bound(new Point2D(rect.End));

                Sector startSector = m_Map.GetSector(start);
                Sector endSector   = m_Map.GetSector(end);

                for (int x = startSector.X; x <= endSector.X; x++)
                {
                    for (int y = startSector.Y; y <= endSector.Y; y++)
                    {
                        Sector sector = m_Map.GetRealSector(x, y);

                        sector.OnEnter(this, rect);

                        if (!sectors.Contains(sector))
                        {
                            sectors.Add(sector);
                        }
                    }
                }
            }

            m_Sectors = sectors.ToArray();
        }
Exemplo n.º 14
0
		private static void RemoveFromSectorTable( Sector s, XmlSpawner spawner )
		{
			if( s == null || s.Owner == null || s.Owner == Map.Internal || GlobalSectorTable[s.Owner.MapID] == null ) return;

			// find the sector
			if( GlobalSectorTable[s.Owner.MapID].Contains( s ) )
			{
				ArrayList spawnerlist = (ArrayList)GlobalSectorTable[s.Owner.MapID][s];
				if( spawnerlist.Contains( spawner ) )
				{
					spawnerlist.Remove( spawner );
				}
			}
		}
Exemplo n.º 15
0
        public Map( int mapID, int mapIndex, int fileIndex, int width, int height, int season, string name, MapRules rules )
        {
            m_MapID = mapID;
            m_MapIndex = mapIndex;
            m_FileIndex = fileIndex;
            m_Width = width;
            m_Height = height;
            m_Season = season;
            m_Name = name;
            m_Rules = rules;
            m_Regions = new ArrayList();

            //m_Tiles = new TileMatrix( fileIndex, width, height );

            m_InvalidSector = new Sector( 0, 0, this );

            m_SectorsWidth = width >> SectorShift;
            m_SectorsHeight = height >> SectorShift;

            m_Sectors = new Sector[m_SectorsWidth][];
        }
Exemplo n.º 16
0
		/*
		public override void OnSectorDeactivate()
		{
			sectorIsActive = false;
			base.OnSectorDeactivate();
		}

		public override void OnSectorActivate()
		{
			sectorIsActive = true;

			base.OnSectorActivate();

			// perform the smart respawning
			if(SmartSpawning && IsInactivated && UseSectorActivate)
			{
				SmartRespawn();
			}

		}
		*/

		public bool InActivationRange( Sector s1, Sector s2 )
		{
			// check to see if the sectors are within +- 2 of one another
			if( s1 == null || s2 == null ) return false;

			return (Math.Abs( s1.X - s2.X ) < 3 && Math.Abs( s1.Y - s2.Y ) < 3);
		}
Exemplo n.º 17
0
        public bool CanFit(int x, int y, int z, int height, bool checkBlocksFit, bool checkMobiles, bool requireSurface)
        {
            if (this == Map.Internal)
            {
                return(false);
            }

            if (x < 0 || y < 0 || x >= m_Width || y >= m_Height)
            {
                return(false);
            }

            bool hasSurface = false;

            Tile lt = Tiles.GetLandTile(x, y);
            int  lowZ = 0, avgZ = 0, topZ = 0;

            GetAverageZ(x, y, ref lowZ, ref avgZ, ref topZ);
            TileFlag landFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags;

            if ((landFlags & TileFlag.Impassable) != 0 && avgZ > z && (z + height) > lowZ)
            {
                return(false);
            }
            else if ((landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored)
            {
                hasSurface = true;
            }

            Tile[] staticTiles = Tiles.GetStaticTiles(x, y, true);

            bool surface, impassable;

            for (int i = 0; i < staticTiles.Length; ++i)
            {
                ItemData id = TileData.ItemTable[staticTiles[i].ID & TileData.MaxItemValue];
                surface    = id.Surface;
                impassable = id.Impassable;

                if ((surface || impassable) && (staticTiles[i].Z + id.CalcHeight) > z && (z + height) > staticTiles[i].Z)
                {
                    return(false);
                }
                else if (surface && !impassable && z == (staticTiles[i].Z + id.CalcHeight))
                {
                    hasSurface = true;
                }
            }

            Sector        sector = GetSector(x, y);
            List <Item>   items  = sector.Items;
            List <Mobile> mobs   = sector.Mobiles;

            for (int i = 0; i < items.Count; ++i)
            {
                Item item = items[i];

                if (!(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue && item.AtWorldPoint(x, y))
                {
                    ItemData id = item.ItemData;
                    surface    = id.Surface;
                    impassable = id.Impassable;

                    if ((surface || impassable || (checkBlocksFit && item.BlocksFit)) && (item.Z + id.CalcHeight) > z && (z + height) > item.Z)
                    {
                        return(false);
                    }
                    else if (surface && !impassable && !item.Movable && z == (item.Z + id.CalcHeight))
                    {
                        hasSurface = true;
                    }
                }
            }

            if (checkMobiles)
            {
                for (int i = 0; i < mobs.Count; ++i)
                {
                    Mobile m = mobs[i];

                    if (m.Location.X == x && m.Location.Y == y && m.Alive && (m.AccessLevel == AccessLevel.Player || !m.Hidden))
                    {
                        if ((m.Z + 16) > z && (z + height) > m.Z)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(!requireSurface || hasSurface);
        }