Ejemplo n.º 1
0
        private const int Range = 5;// No house may be placed within 5 tiles of the treasure
        public TreasureRegion(int x, int y, Map map)
            : base(null, map, Region.DefaultPriority, new Rectangle2D(x - Range, y - Range, 1 + (Range * 2), 1 + (Range * 2)))
        {
            this.GoLocation = new Point3D(x, y, map.GetAverageZ(x, y));

            this.Register();
        }
Ejemplo n.º 2
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;
        }
		private const int Range = 5; // No house may be placed within 5 tiles of the treasure

		public TreasureRegion( int x, int y, Map map ): base( "", "DynRegion", map )
		{
			Priority = Region.TownPriority;
			LoadFromXml = false;

			Coords = new ArrayList();
			Coords.Add( new Rectangle2D( x - Range, y - Range, 1 + (Range * 2), 1 + (Range * 2) ) );

			GoLocation = new Point3D( x, y, map.GetAverageZ( x, y ) );
		}
Ejemplo n.º 4
0
        public static void ShowRectBounds( Rectangle2D r, Map m )
        {
            if( m == Map.Internal || m == null )
                return;

            Point3D p1 = new Point3D( r.X, r.Y - 1, 0 );	//So we dont' need to create a new one each point
            Point3D p2 = new Point3D( r.X, r.Y + r.Height - 1, 0 );	//So we dont' need to create a new one each point

            Effects.SendLocationEffect( new Point3D( r.X -1, r.Y - 1, m.GetAverageZ( r.X, r.Y -1 ) ) , m, 251, 75, 1, 1151, 3 );	//Top Corner	//Testing color

            for( int x = r.X; x <= ( r.X + r.Width -1 ); x++ )
            {
                p1.X = x;
                p2.X = x;

                p1.Z = m.GetAverageZ( p1.X, p1.Y );
                p2.Z = m.GetAverageZ( p2.X, p2.Y );

                Effects.SendLocationEffect( p1, m, 249, 75, 1, 1151, 3 );	//North bound
                Effects.SendLocationEffect( p2, m, 249, 75, 1, 1151, 3 );	//South bound
            }

            p1 = new Point3D( r.X -1 , r.Y -1 , 0 );
            p2 = new Point3D( r.X + r.Width - 1, r.Y, 0 );

            for( int y = r.Y; y <= ( r.Y + r.Height -1 ); y++ )
            {
                p1.Y = y;
                p2.Y = y;

                p1.Z = m.GetAverageZ( p1.X, p1.Y );
                p2.Z = m.GetAverageZ( p2.X, p2.Y );

                Effects.SendLocationEffect( p1, m, 250, 75, 1, 1151, 3 );	//West Bound
                Effects.SendLocationEffect( p2, m, 250, 75, 1, 1151, 3 );	//East Bound
            }
        }
Ejemplo n.º 5
0
        public static int GetSpawnerZ( int x, int y, Map map )
        {
            int z = map.GetAverageZ( x, y );

            if ( map.CanFit( x, y, z, 16, false, false ) )
                return z;

            for ( int i = 1; i <= 20; ++i )
            {
                if ( map.CanFit( x, y, z + i, 16, false, false ) )
                    return z + i;

                if ( map.CanFit( x, y, z - i, 16, false, false ) )
                    return z - i;
            }

            return z;
        }
Ejemplo n.º 6
0
        public static object GetTopSurface(this Map map, Point3D p, bool multis)
        {
            if (map == Map.Internal)
            {
                return(null);
            }

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

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

            if (!lt.Ignored && TileData.LandTable[lt.ID].Name != "NoName")
            {
                var avgZ = map.GetAverageZ(p.X, p.Y);

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

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

            var staticTiles = map.Tiles.GetStaticTiles(p.X, p.Y, multis);

            ItemData id;
            int      tileZ;

            foreach (var tile in staticTiles)
            {
                id = TileData.ItemTable[tile.ID & TileData.MaxItemValue];

                if (!id.Surface && (id.Flags & TileFlag.Wet) == 0)
                {
                    continue;
                }

                tileZ = tile.Z + id.CalcHeight;

                if (tileZ <= surfaceZ || tileZ > p.Z)
                {
                    continue;
                }

                surface  = tile;
                surfaceZ = tileZ;

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

            var sector = map.GetSector(p.X, p.Y);

            int itemZ;

            var items =
                sector.Items.Where(
                    o => o.ItemID <= TileData.MaxItemValue && !o.Movable && !(o is BaseMulti) && o.AtWorldPoint(p.X, p.Y));

            foreach (var item in items)
            {
                id = item.ItemData;

                if (!id.Surface && (id.Flags & TileFlag.Wet) == 0)
                {
                    continue;
                }

                itemZ = item.Z + id.CalcHeight;

                if (itemZ <= surfaceZ || itemZ > p.Z)
                {
                    continue;
                }

                surface  = item;
                surfaceZ = itemZ;

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

            return(surface);
        }
Ejemplo n.º 7
0
		public static BaseCreature Spawn( int level, Point3D p, Map map, Mobile target, bool guardian )
		{
			if ( map == null )
				return null;

			BaseCreature c = Spawn( level, p, guardian );

			if ( c != null )
			{
				bool spawned = false;

				for ( int i = 0; !spawned && i < 10; ++i )
				{
					int x = p.X - 3 + Utility.Random( 7 );
					int y = p.Y - 3 + Utility.Random( 7 );

					if ( map.CanSpawnMobile( x, y, p.Z ) )
					{
						c.MoveToWorld( new Point3D( x, y, p.Z ), map );
						spawned = true;
					}
					else
					{
						int z = map.GetAverageZ( x, y );

						if ( map.CanSpawnMobile( x, y, z ) )
						{
							c.MoveToWorld( new Point3D( x, y, z ), map );
							spawned = true;
						}
					}
				}

				if ( !spawned )
				{
					c.Delete();
					return null;
				}

				if ( target != null )
					c.Combatant = target;

				return c;
			}

			return null;
		}
Ejemplo n.º 8
0
        //25JUL2008 Lord_Greywolf fix for bad X *** START ***
        //        protected void Spawn( Point2D p, Map map, BaseCreature spawn )
        //        {
        //            if ( map == null )
        //            {
        //                spawn.Delete();
        //                return;
        //            }

        //            int x = p.X, y = p.Y;

        ////			for ( int j = 0; j < 5; ++j )
        ////			{
        ////				int tx = p.X - 2 + Utility.Random( 5 );
        ////				int ty = p.Y - 2 + Utility.Random( 5 );
        ////			}

        //            spawn.MoveToWorld( new Point3D( x, y, 0 ), map );
        //            spawn.PackItem( new TreasureMessageChest() );
        //}
        protected void Spawn(Point2D p, Map map, BaseCreature spawn)
        {
            if (map == null) { spawn.Delete(); return; }

            int x = p.X, y = p.Y;

            if (map.CanSpawnMobile(x, y, 0))
            {
                spawn.MoveToWorld(new Point3D(x, y, 0), map);
            }
            else
            {
                int z = map.GetAverageZ(x, y);
                if (map.CanSpawnMobile(x, y, z))
                {
                    spawn.MoveToWorld(new Point3D(x, y, z), map);
                }
                else if (map.CanSpawnMobile(x, y, z + 10))
                {
                    spawn.MoveToWorld(new Point3D(x, y, z + 10), map);
                }
                else if (map.CanSpawnMobile(x + 1, y + 1, z))
                {
                    spawn.MoveToWorld(new Point3D(x + 1, y + 1, z), map);
                }
                else if (map.CanSpawnMobile(x + 1, y + 1, z + 10))
                {
                    spawn.MoveToWorld(new Point3D(x + 1, y + 1, z + 10), map);
                }
                else
                {
                    spawn.MoveToWorld(new Point3D(x - 1, y - 1, 100), map);
                }
            }
            spawn.PackItem(new TreasureMessageChest(Utility.RandomMinMax((((m_Level - 1) * 400) + 100), (((m_Level - 1) * 400) + 500))));
        }
Ejemplo n.º 9
0
		/// <summary>
		///     Gets a Point3D collection representing all locations between 'start' and 'end', including 'start' and 'end', on the given 'map'.
		/// </summary>
		public static Point3D[] GetLine3D(this IPoint3D start, IPoint3D end, Map map, bool avgZ = true)
		{
			var path = new List<Point3D>();

			Geometry.Line2D(ToPoint3D(start), ToPoint3D(end), map, (p, m) => path.Add(p));

			var arr = path.OrderBy(p => GetDistance(start, p)).ToArray();

			arr.SetAll(
				(i, p) =>
				{
					p.Z = avgZ ? map.GetAverageZ(p.X, p.Y) : start.Z + (int)Math.Floor((end.Z - start.Z) * (i / (double)path.Count));
					return p;
				});

			path.Free(true);

			return arr;
		}
Ejemplo n.º 10
0
        public static Point3D GetSpawnPosition(Point3D from, Map map, int range)
        {
            if (map == null)
                return from;

            for (int i = 0; i < 10; i++)
            {
                int x = from.X + Utility.Random(range);
                int y = from.Y + Utility.Random(range);
                int z = map.GetAverageZ(x, y);

                if (Utility.RandomBool())
                    x *= -1;

                if (Utility.RandomBool())
                    y *= -1;

                Point3D p = new Point3D(x, y, from.Z);

                if (map.CanSpawnMobile(p) && map.LineOfSight(from, p))
                    return p;

                p = new Point3D(x, y, z);

                if (map.CanSpawnMobile(p) && map.LineOfSight(from, p))
                    return p;
            }

            return from;
        }
Ejemplo n.º 11
0
		/// <summary>
		///     Gets a Point3D collection representing all locations between 'start' and 'end', including 'start' and 'end', on the given 'map'.
		/// </summary>
		public static Point3D[] GetLine3D(this IPoint3D start, IPoint3D end, Map map, bool avgZ = true)
		{
			var path2d = GetLine2D(start, end, map);
			var path3d = new Point3D[path2d.Length];

			if (avgZ)
			{
				path3d.SetAll(i => path2d[i].ToPoint3D(map.GetAverageZ(path2d[i].X, path2d[i].Y)));
			}
			else
			{
				path3d.SetAll(i => path2d[i].ToPoint3D(start.Z + (int)Math.Floor((end.Z - start.Z) * (i / (double)path2d.Length))));
			}

			return path3d;
		}
Ejemplo n.º 12
0
        private const int Range = 5;         // No house may be placed within 5 tiles of the treasure

        public TreasureRegion(int x, int y, Map map) : base(null, map, Region.DefaultPriority, new Rectangle2D(x - Range, y - Range, 1 + Range * 2, 1 + Range * 2))
        {
            GoLocation = new Point3D(x, y, map.GetAverageZ(x, y));

            Register();
        }
Ejemplo n.º 13
0
        public Region(XmlElement xml, Map map, Region parent)
        {
            Map     = map;
            Parent  = parent;
            Dynamic = false;

            if (Parent == null)
            {
                ChildLevel = 0;
                m_Priority = DefaultPriority;
            }
            else
            {
                ChildLevel = Parent.ChildLevel + 1;
                m_Priority = Parent.Priority;
            }

            ReadString(xml, "name", ref m_Name, false);

            if (parent == null)
            {
                ReadInt32(xml, "priority", ref m_Priority, false);
            }


            int minZ = MinZ;
            int maxZ = MaxZ;

            XmlElement zrange = xml["zrange"];

            ReadInt32(zrange, "min", ref minZ, false);
            ReadInt32(zrange, "max", ref maxZ, false);


            List <Rectangle3D> area = new List <Rectangle3D>();

            foreach (XmlElement xmlRect in xml.SelectNodes("rect"))
            {
                Rectangle3D rect = new Rectangle3D();
                if (ReadRectangle3D(xmlRect, minZ, maxZ, ref rect))
                {
                    area.Add(rect);
                }
            }

            Area = area.ToArray();

            if (Area.Length == 0)
            {
                log.Warning("Empty area for region '{0}'", this);
            }


            if (!ReadPoint3D(xml["go"], map, ref m_GoLocation, false) && Area.Length > 0)
            {
                Point3D start = Area[0].Start;
                Point3D end   = Area[0].End;

                int x = start.X + (end.X - start.X) / 2;
                int y = start.Y + (end.Y - start.Y) / 2;

                m_GoLocation = new Point3D(x, y, Map.GetAverageZ(x, y));
            }


            object oMusic = this.DefaultMusic;

            ReadEnum(xml["music"], "name", typeof(MusicName), ref oMusic, false);

            Music = (MusicName)oMusic;

            if (xml.Attributes["CannotDrop"] != null)
            {
                XmlAttribute attr = xml.Attributes["CannotDrop"];
                this.CannotDrop = Convert.ToBoolean(attr.Value);
            }
        }
Ejemplo n.º 14
0
		//Main spawn generation function called from any item that needs to generate treasure type spawn.
		public static void Spawn( int level, Point3D p, Map map, Mobile target, bool IsThemed, ChestThemeType theme, bool guardian, bool guardian2)
		{
			//bool guardian is designator for if theme type has special spawn mechanics and thus does not spawn its highest mobs at random
			//guardian2 is second flag indicateing to spawn highest mob.
			if ( map == null )
				return;
			BaseCreature c = null;
			if(guardian == false) c = Spawn( level, IsThemed, theme, guardian ); 
			if(guardian == true && guardian2 == false) c = Spawn( level, IsThemed, theme, true ); 
			if(guardian == true && guardian2 == true) c = SpawnHighestMob(theme);
			if ( c != null )
			{
				c.Home = p;
				c.RangeHome = 8;

				bool spawned = false;

				for ( int i = 0; !spawned && i < 10; ++i )
				{
					int x = p.X - 3 + Utility.Random( 7 );
					int y = p.Y - 3 + Utility.Random( 7 );

					if ( map.CanSpawnMobile( x, y, p.Z ) )
					{
						c.MoveToWorld( new Point3D( x, y, p.Z ), map );
						spawned = true;
					}
					else
					{
						int z = map.GetAverageZ( x, y );

						if ( map.CanSpawnMobile( x, y, z ) )
						{
							c.MoveToWorld( new Point3D( x, y, z ), map );
							spawned = true;
						}
					}
				}

				if ( !spawned )
					c.Delete();
				else if ( target != null )
					c.Combatant = target;
			}
		}
Ejemplo n.º 15
0
        private bool ValidateLocation(Point3D p, Map map)
        {
            if (!TreasureMap.ValidateLocation(p.X, p.Y, map))
                return false;

            for (int x = p.X - 1; x <= p.X + 1; x++)
            {
                for (int y = p.Y - 1; y <= p.Y + 1; y++)
                {
                    if(TreasureMap.ValidateLocation(x, y, map))
                    {
                        int z = map.GetAverageZ(x, y);
                        IPooledEnumerable eable = map.GetItemsInRange(new Point3D(x, y, z), 0);
                        foreach (Item item in eable)
                        {
                            ItemData id = TileData.ItemTable[item.ItemID & TileData.MaxItemValue];

                            if (item.Z + id.CalcHeight >= z)
                            {
                                eable.Free();
                                return false;
                            }
                        }
                        eable.Free();

                        return true;
                    }
                }
            }

            return false;
        }
Ejemplo n.º 16
0
        public Region(XmlElement xml, Map map, Region parent)
        {
            m_Map     = map;
            m_Parent  = parent;
            m_Dynamic = false;

            if (m_Parent == null)
            {
                m_ChildLevel = 0;
                m_Priority   = DefaultPriority;
            }
            else
            {
                m_ChildLevel = m_Parent.ChildLevel + 1;
                m_Priority   = m_Parent.Priority;
            }

            ReadString(xml, "name", ref m_Name, false);

            if (parent == null)
            {
                ReadInt32(xml, "priority", ref m_Priority, false);
            }

            int minZ = MinZ;
            int maxZ = MaxZ;

            XmlElement zrange = xml["zrange"];

            ReadInt32(zrange, "min", ref minZ, false);
            ReadInt32(zrange, "max", ref maxZ, false);

            var area = new List <Rectangle3D>();

            foreach (XmlElement xmlRect in xml.SelectNodes("rect"))
            {
                var rect = new Rectangle3D();
                if (ReadRectangle3D(xmlRect, minZ, maxZ, ref rect))
                {
                    area.Add(rect);
                }
            }

            m_Area = area.ToArray();

            if (m_Area.Length == 0)
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.WriteLine("Empty area for region '{0}'", this);
                Utility.PopColor();
            }

            if (!ReadPoint3D(xml["go"], map, ref m_GoLocation, false) && m_Area.Length > 0)
            {
                Point3D start = m_Area[0].Start;
                Point3D end   = m_Area[0].End;

                int x = start.X + (end.X - start.X) / 2;
                int y = start.Y + (end.Y - start.Y) / 2;

                m_GoLocation = new Point3D(x, y, m_Map.GetAverageZ(x, y));
            }

            MusicName music = DefaultMusic;

            ReadEnum(xml["music"], "name", ref music, false);

            Music = music;
        }
Ejemplo n.º 17
0
        public static Point2D GetRandomLocation( Map map )
        {
            for ( int i = 0; i < 30; ++i )
            {
                int tx = 0, ty = 0;

                if ( map == Map.Trammel || map == Map.Felucca )
                {
                    tx = Utility.RandomMinMax( 0, 4080 );
                    ty = Utility.RandomMinMax( 0, 5100 );
                }
                else if ( map == Map.Ilshenar )
                {
                    tx = Utility.RandomMinMax( 220, 1770 );
                    ty = Utility.RandomMinMax( 200, 1415 );
                }
                else if ( map == Map.Malas )
                {
                    tx = Utility.RandomMinMax( 600, 2150 );
                    ty = Utility.RandomMinMax( 70, 1910 );
                }
                else if ( map == Map.Tokuno )
                {
                    tx = Utility.RandomMinMax( 90, 1410 );
                    ty = Utility.RandomMinMax( 20, 1400 );
                }
                else if ( map == Map.TerMur )
                {
                    tx = Utility.RandomMinMax( 300, 1220 );
                    ty = Utility.RandomMinMax( 2800, 4050 );
                }

                // First, check for land tile to be valid, for most efficiency
                if ( !IsValidLandTile( map, tx, ty ) )
                    continue;

                var loc = new Point3D( tx, ty, map.GetAverageZ( tx, ty ) );

                var region = Region.Find( loc, map );

                if ( region.IsPartOf<GuardedRegion>() || region.IsPartOf<DungeonRegion>() || region.IsPartOf<HouseRegion>() )
                    continue;

                if ( map.CanSpawnMobile( loc ) )
                    return new Point2D( tx, ty );
            }

            return Point2D.Zero;
        }
Ejemplo n.º 18
0
		public Region( XmlElement xml, Map map, Region parent )
		{
			m_Map = map;
			m_Parent = parent;
			m_Dynamic = false;

			if ( m_Parent == null )
			{
				m_ChildLevel = 0;
				m_Priority = DefaultPriority;
			}
			else
			{
				m_ChildLevel = m_Parent.ChildLevel + 1;
				m_Priority = m_Parent.Priority;
			}

			ReadString( xml, "name", ref m_Name, false );

			if ( parent == null )
				ReadInt32( xml, "priority", ref m_Priority, false );


			int minZ = MinZ;
			int maxZ = MaxZ;

			XmlElement zrange = xml["zrange"];
			ReadInt32( zrange, "min", ref minZ, false );
			ReadInt32( zrange, "max", ref maxZ, false );


			List<Rectangle3D> area = new List<Rectangle3D>();
			foreach ( XmlElement xmlRect in xml.SelectNodes( "rect" ) )
			{
				Rectangle3D rect = new Rectangle3D();
				if ( ReadRectangle3D( xmlRect, minZ, maxZ, ref rect ) )
					area.Add( rect );
			}

			m_Area = area.ToArray();

			if ( m_Area.Length == 0 )
				Console.WriteLine( "Empty area for region '{0}'", this );


			if ( !ReadPoint3D( xml["go"], map, ref m_GoLocation, false ) && m_Area.Length > 0 )
			{
				Point3D start = m_Area[0].Start;
				Point3D end = m_Area[0].End;

				int x = start.X + (end.X - start.X) / 2;
				int y = start.Y + (end.Y - start.Y) / 2;

				m_GoLocation = new Point3D( x, y, m_Map.GetAverageZ( x, y ) );
			}


			object oMusic = this.DefaultMusic;

			ReadEnum( xml["music"], "name", typeof( MusicName ), ref oMusic, false );

			m_Music = (MusicName) oMusic;
		}
Ejemplo n.º 19
0
        public static Point3D GetRandomPoint(Rectangle2D rec, Map map)
        {
            int x = Utility.Random(rec.X, rec.Width);
            int y = Utility.Random(rec.Y, rec.Height);
            int z = map.GetAverageZ(x, y);

            return new Point3D(x, y, z);
        }
Ejemplo n.º 20
0
        public Point3D GetValidPoint(BaseBoat boat, Map map, int distance)
        {
            if (boat == null || map == null || map == Map.Internal)
                return new Point3D(this.X + Utility.RandomMinMax(-1, 1), this.Y + Utility.RandomMinMax(-1, 1), this.Z);

            if (distance < 5) distance = 5;
            if (distance > 15) distance = 15;

            int x = boat.X;
            int y = boat.Y;
            int z = boat.Z;
            int size = boat is BritannianShip ? 4 : 3;

            int range = distance - size;
            if (range < 1) range = 1;

            switch (boat.Facing)
            {
                default:
                case Direction.South:
                case Direction.North:
                    x = Utility.RandomBool() ? Utility.RandomMinMax(x -= distance, x -= (distance - range)) : Utility.RandomMinMax(x += (distance - range), x += distance);
                    y = Utility.RandomMinMax(y - 8, y + 8);
                    z = map.GetAverageZ(x, y);
                    break;
                case Direction.East:
                case Direction.West:
                    x = Utility.RandomMinMax(x - 8, x + 8);
                    y = Utility.RandomBool() ? Utility.RandomMinMax(y -= distance, y -= (distance - range)) : Utility.RandomMinMax(y += (distance - range), y += distance);
                    z = map.GetAverageZ(x, y);
                    break;
            }
            return new Point3D(x, y, z);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
		static void HoverExploit(Map map, int x, int y)
		{
			try
			{
				Point3D location = new Point3D(x, y, 0);
				IPooledEnumerable eable = map.GetClientsInRange(location, 0);
				Tile[] tiles = map.Tiles.GetStaticTiles(x, y, true);
				foreach (NetState ns in eable)
				{
					if (ns == null || ns.Mobile == null) continue;
					Mobile m = ns.Mobile;
					if (map.CanSpawnMobile(m.Location, CanFitFlags.requireSurface) == false)
					{
						// Console.WriteLine("Bogus man!!");
						//int averageZ = map.GetAverageZ(m.Location.X, m.Location.Y);
						int averageZ = 0, topZ = 0, z = 0;
						map.GetAverageZ(m.Location.X, m.Location.Y, ref z, ref averageZ, ref topZ);
						while (m.Location.Z > averageZ && TileAtZ(tiles, m.Z) == false)
						{	// drop the player down a notch
							Point3D newLocation = new Point3D(m.Location);
							newLocation.Z--;
							m.MoveToWorld(newLocation, m.Map);
							if (map.CanSpawnMobile(m.Location, CanFitFlags.requireSurface) == true)
								break;
						}
					}
				}
				eable.Free();
			}
			catch (Exception ex) 
			{ 
				// adam: stop logging this to the exception file as it's polluting it.
				// we still need to fix it tho .. meh
				Console.WriteLine(ex.ToString());
				// EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); 
			}

			return;
		}
Ejemplo n.º 23
0
		public virtual Point3D GetSpawnPosition( ISpawnable spawned, Map map )
		{
			if ( map == null || map == Map.Internal )
				return Location;

			bool waterMob, waterOnlyMob;

			if ( spawned is Mobile )
			{
				Mobile mob = (Mobile)spawned;

				waterMob = mob.CanSwim;
				waterOnlyMob = ( mob.CanSwim && mob.CantWalk );
			}
			else
			{
				waterMob = false;
				waterOnlyMob = false;
			}

			// Try 10 times to find a Spawnable location.
			for ( int i = 0; i < 10; i++ )
			{
				int x = Location.X + (Utility.Random( (m_HomeRange * 2) + 1 ) - m_HomeRange);
				int y = Location.Y + (Utility.Random( (m_HomeRange * 2) + 1 ) - m_HomeRange);
				int z = Map.GetAverageZ( x, y );

				int mapZ = map.GetAverageZ( x, y );

				if ( waterMob )
				{
					if ( IsValidWater( map, x, y, this.Z ) )
						return new Point3D( x, y, this.Z );
					else if ( IsValidWater( map, x, y, mapZ ) )
						return new Point3D( x, y, mapZ );
				}

				if ( !waterOnlyMob )
				{
					if ( map.CanSpawnMobile( x, y, this.Z ) )
						return new Point3D( x, y, this.Z );
					else if ( map.CanSpawnMobile( x, y, mapZ ) )
						return new Point3D( x, y, mapZ );
				}
			}

			return this.Location;
		}
Ejemplo n.º 24
0
		private bool Check( Map map, Mobile m, List<Item> items, List<Mobile> mobiles, int x, int y, int startTop, int startZ, bool canSwim, bool cantWalk, out int newZ )
		{
			newZ = 0;

			StaticTile[] tiles = map.Tiles.GetStaticTiles( x, y, true );
			LandTile landTile = map.Tiles.GetLandTile( x, y );

			bool landBlocks = (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Impassable) != 0;
			bool considerLand = !landTile.Ignored;

			if ( landBlocks && canSwim && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) != 0 )	//Impassable, Can Swim, and Is water.  Don't block it.
				landBlocks = false;
			else if ( cantWalk && (TileData.LandTable[landTile.ID & TileData.MaxLandValue].Flags & TileFlag.Wet) == 0 )	//Can't walk and it's not water
				landBlocks = true;

			int landZ = 0, landCenter = 0, landTop = 0;

			map.GetAverageZ( x, y, ref landZ, ref landCenter, ref landTop );

			bool moveIsOk = false;

			int stepTop = startTop + StepHeight;
			int checkTop = startZ + PersonHeight;

			bool ignoreDoors = ( m_AlwaysIgnoreDoors || !m.Alive || m.Body.BodyID == 0x3DB || m.IsDeadBondedPet );
			bool ignoreSpellFields = m is PlayerMobile && map != Map.Felucca;

			#region Tiles
			for ( int i = 0; i < tiles.Length; ++i )
			{
				StaticTile tile = tiles[i];
				ItemData itemData = TileData.ItemTable[tile.ID & TileData.MaxItemValue];
				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) == TileFlag.Surface || (canSwim && (flags & TileFlag.Wet) != 0) ) // Surface && !Impassable
				{
					if ( cantWalk && (flags & TileFlag.Wet) == 0 )
						continue;

					int itemZ = tile.Z;
					int itemTop = itemZ;
					int ourZ = itemZ + itemData.CalcHeight;
					int ourTop = ourZ + PersonHeight;
					int testTop = checkTop;

					if ( moveIsOk )
					{
						int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

						if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
							continue;
					}

					if ( ourZ + PersonHeight > testTop )
						testTop = ourZ + PersonHeight;

					if ( !itemData.Bridge )
						itemTop += itemData.Height;

					if ( stepTop >= itemTop )
					{
						int landCheck = itemZ;

						if ( itemData.Height >= StepHeight )
							landCheck += StepHeight;
						else
							landCheck += itemData.Height;

						if ( considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ )
							continue;

						if ( IsOk( ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items ) )
						{
							newZ = ourZ;
							moveIsOk = true;
						}
					}
				}
			}
			#endregion

			#region Items
			for ( int i = 0; i < items.Count; ++i )
			{
				Item item = items[i];
				ItemData itemData = item.ItemData;
				TileFlag flags = itemData.Flags;

				if ( !item.Movable && ((flags & ImpassableSurface) == TileFlag.Surface || (m.CanSwim && (flags & TileFlag.Wet) != 0)) ) // Surface && !Impassable && !Movable
				{
					if ( cantWalk && (flags & TileFlag.Wet) == 0 )
						continue;

					int itemZ = item.Z;
					int itemTop = itemZ;
					int ourZ = itemZ + itemData.CalcHeight;
					int ourTop = ourZ + PersonHeight;
					int testTop = checkTop;

					if ( moveIsOk )
					{
						int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

						if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
							continue;
					}

					if ( ourZ + PersonHeight > testTop )
						testTop = ourZ + PersonHeight;

					if ( !itemData.Bridge )
						itemTop += itemData.Height;

					if ( stepTop >= itemTop )
					{
						int landCheck = itemZ;

						if ( itemData.Height >= StepHeight )
							landCheck += StepHeight;
						else
							landCheck += itemData.Height;

						if ( considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ )
							continue;

						if ( IsOk( ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items ) )
						{
							newZ = ourZ;
							moveIsOk = true;
						}
					}
				}
			}
			#endregion

			if ( considerLand && !landBlocks && stepTop >= landZ )
			{
				int ourZ = landCenter;
				int ourTop = ourZ + PersonHeight;
				int testTop = checkTop;

				if ( ourZ + PersonHeight > testTop )
					testTop = ourZ + PersonHeight;

				bool shouldCheck = true;

				if ( moveIsOk )
				{
					int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

					if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
						shouldCheck = false;
				}

				if ( shouldCheck && IsOk( ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items ) )
				{
					newZ = ourZ;
					moveIsOk = true;
				}
			}

			#region Mobiles
			if ( moveIsOk )
			{
				for ( int i = 0; moveIsOk && i < mobiles.Count; ++i )
				{
					Mobile mob = mobiles[i];

					if ( mob != m && ( mob.Z + 15 ) > newZ && ( newZ + 15 ) > mob.Z && !CanMoveOver( m, mob ) )
						moveIsOk = false;
				}
			}
			#endregion

			return moveIsOk;
		}
Ejemplo n.º 25
0
        public bool CanFit( Point3D p, Map map, int itemID )
        {
            if ( map == null || map == Map.Internal || Deleted || CheckDecay() )
                return false;

            MultiComponentList oldComponents = MultiData.GetComponents( ItemID );
            MultiComponentList newComponents = MultiData.GetComponents( itemID );

            for ( int x = 0; x < newComponents.Width; ++x )
            {
                for ( int y = 0; y < newComponents.Height; ++y )
                {
                    int tx = p.X + newComponents.Min.X + x;
                    int ty = p.Y + newComponents.Min.Y + y;

                    if ( newComponents.Tiles[x][y].Length == 0 || Contains( tx, ty ) )
                        continue;

                    LandTile landTile = map.Tiles.GetLandTile( tx, ty );
                    StaticTile[] tiles = map.Tiles.GetStaticTiles( tx, ty, true );

                    bool hasWater = false;

                    if ( landTile.Z == p.Z && ((landTile.ID >= 168 && landTile.ID <= 171) || (landTile.ID >= 310 && landTile.ID <= 311)) )
                        hasWater = true;

                    int z = p.Z;

                    int landZ = 0, landAvg = 0, landTop = 0;

                    map.GetAverageZ( tx, ty, ref landZ, ref landAvg, ref landTop );

                    //if ( !landTile.Ignored && top > landZ && landTop > z )
                    //	return false;

                    for ( int i = 0; i < tiles.Length; ++i )
                    {
                        StaticTile tile = tiles[i];
                        bool isWater = ( tile.ID >= 0x5796 && tile.ID <= 0x57B2 ) || ( tile.ID >= 0x1796 && tile.ID <= 0x17B2 );

                        if ( tile.Z == p.Z && isWater )
                            hasWater = true;
                        else if ( tile.Z >= p.Z && !isWater )
                            return false;
                    }

                    if ( !hasWater )
                        return false;
                }
            }

            IPooledEnumerable eable = map.GetItemsInBounds( new Rectangle2D( p.X + newComponents.Min.X, p.Y + newComponents.Min.Y, newComponents.Width, newComponents.Height ) );

            foreach ( Item item in eable )
            {
                if ( item.ItemID >= 0x4000 || item.Z < p.Z || !item.Visible )
                    continue;

                int x = item.X - p.X + newComponents.Min.X;
                int y = item.Y - p.Y + newComponents.Min.Y;

                if ( x >= 0 && x < newComponents.Width && y >= 0 && y < newComponents.Height && newComponents.Tiles[x][y].Length == 0 )
                    continue;
                else if ( Contains( item ) )
                    continue;

                eable.Free();
                return false;
            }

            eable.Free();

            return true;
        }
Ejemplo n.º 26
0
		public static bool FindValidSpawnLocation( Map map, ref Point3D p, bool surroundingsOnly )
		{
			if( map == null )	//sanity
				return false;

			if( !surroundingsOnly )
			{
				if( map.CanSpawnMobile( p ) )	//p's fine.
				{
					p = new Point3D( p );
					return true;
				}

				int z = map.GetAverageZ( p.X, p.Y );

				if( map.CanSpawnMobile( p.X, p.Y, z ) )
				{
					p = new Point3D( p.X, p.Y, z );
					return true;
				}
			}

			int offset = Utility.Random( 8 ) * 2;

			for( int i = 0; i < m_Offsets.Length; i += 2 )
			{
				int x = p.X + m_Offsets[(offset + i) % m_Offsets.Length];
				int y = p.Y + m_Offsets[(offset + i + 1) % m_Offsets.Length];

				if( map.CanSpawnMobile( x, y, p.Z ) )
				{
					p = new Point3D( x, y, p.Z );
					return true;
				}
				else
				{
					int z = map.GetAverageZ( x, y );

					if( map.CanSpawnMobile( x, y, z ) )
					{
						p = new Point3D( x, y, z );
						return true;
					}
				}
			}

			return false;
		}
Ejemplo n.º 27
0
		private bool Check( Map map, Mobile m, List<Item> items, int x, int y, int startTop, int startZ, bool canSwim, bool cantWalk, out int newZ )
		{
			newZ = 0;

			Tile[] tiles = map.Tiles.GetStaticTiles( x, y, true );
			Tile landTile = map.Tiles.GetLandTile( x, y );

			bool landBlocks = (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Impassable) != 0;
			bool considerLand = !landTile.Ignored;

			if ( landBlocks && canSwim && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) != 0 )	//Impassable, Can Swim, and Is water.  Don't block it.
				landBlocks = false;
			else if ( cantWalk && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) == 0 )	//Can't walk and it's not water
				landBlocks = true;

			int landZ = 0, landCenter = 0, landTop = 0;

			map.GetAverageZ( x, y, ref landZ, ref landCenter, ref landTop );

			bool moveIsOk = false;

			int stepTop = startTop + StepHeight;
			int checkTop = startZ + PersonHeight;

			bool ignoreDoors = ( m_AlwaysIgnoreDoors || !m.Alive || m.Body.BodyID == 0x3DB || m.IsDeadBondedPet );
			bool ignoreSpellFields = m is PlayerMobile && map != Map.Felucca;

			#region Tiles
			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile tile = tiles[i];

				#region SA
				ItemData itemData = TileData.ItemTable[(tile.ID-0x4000) & 0x7FFF];

				if ( m.Flying && ( itemData.Name == "hover over" ) )
				{
					newZ = tile.Z;
					return true;
				}
				else if ( m is StygianDragon && map == Map.TerMur )
				{
					if ( x >= 307 && x <= 354 && y >= 126 && y <= 192 )
					{
						if ( tile.Z > newZ )
							newZ = tile.Z;

						moveIsOk = true;
					}
					else if ( x >= 42 && x <= 89 )
					{
						if ( (y >= 333 && y <= 399) || (y >= 531 && y <= 597) || (y >= 739 && y <= 805) )
						{
							if ( tile.Z > newZ )
								newZ = tile.Z;

							moveIsOk = true;
						}
					}
				}
				#endregion

				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) == TileFlag.Surface || (canSwim && (flags & TileFlag.Wet) != 0) ) // Surface && !Impassable
				{
					if ( cantWalk && (flags & TileFlag.Wet) == 0 )
						continue;

					int itemZ = tile.Z;
					int itemTop = itemZ;
					int ourZ = itemZ + itemData.CalcHeight;
					int ourTop = ourZ + PersonHeight;
					int testTop = checkTop;

					if ( moveIsOk )
					{
						int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

						if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
							continue;
					}

					if ( ourZ + PersonHeight > testTop )
						testTop = ourZ + PersonHeight;

					if ( !itemData.Bridge )
						itemTop += itemData.Height;

					if ( stepTop >= itemTop )
					{
						int landCheck = itemZ;

						if ( itemData.Height >= StepHeight )
							landCheck += StepHeight;
						else
							landCheck += itemData.Height;

						if ( considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ )
							continue;

						if ( IsOk( ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items ) )
						{
							newZ = ourZ;
							moveIsOk = true;
						}
					}
				}
			}
			#endregion

			#region Items
			for ( int i = 0; i < items.Count; ++i )
			{
				Item item = items[i];
				ItemData itemData = item.ItemData;
				TileFlag flags = itemData.Flags;

				#region SA
				if ( m.Flying && ( itemData.Name == "hover over" ) )
				{
					newZ = item.Z;
					return true;
				}
				#endregion

				if ( !item.Movable && ((flags & ImpassableSurface) == TileFlag.Surface || (m.CanSwim && (flags & TileFlag.Wet) != 0)) ) // Surface && !Impassable && !Movable
				{
					if ( cantWalk && (flags & TileFlag.Wet) == 0 )
						continue;

					int itemZ = item.Z;
					int itemTop = itemZ;
					int ourZ = itemZ + itemData.CalcHeight;
					int ourTop = ourZ + PersonHeight;
					int testTop = checkTop;

					if ( moveIsOk )
					{
						int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

						if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
							continue;
					}

					if ( ourZ + PersonHeight > testTop )
						testTop = ourZ + PersonHeight;

					if ( !itemData.Bridge )
						itemTop += itemData.Height;

					if ( stepTop >= itemTop )
					{
						int landCheck = itemZ;

						if ( itemData.Height >= StepHeight )
							landCheck += StepHeight;
						else
							landCheck += itemData.Height;

						if ( considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ )
							continue;

						if ( IsOk( ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items ) )
						{
							newZ = ourZ;
							moveIsOk = true;
						}
					}
				}
			}

			#endregion

			if ( considerLand && !landBlocks && stepTop >= landZ )
			{
				int ourZ = landCenter;
				int ourTop = ourZ + PersonHeight;
				int testTop = checkTop;

				if ( ourZ + PersonHeight > testTop )
					testTop = ourZ + PersonHeight;

				bool shouldCheck = true;

				if ( moveIsOk )
				{
					int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

					if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
						shouldCheck = false;
				}

				if ( shouldCheck && IsOk( ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items ) )
				{
					newZ = ourZ;
					moveIsOk = true;
				}
			}

			return moveIsOk;
		}
Ejemplo n.º 28
0
        public static Point3D GetRandomSpawnPoint(this Rectangle2D rec, Map map)
        {
            if (map == null || map == Map.Internal)
                return Point3D.Zero;

            int x = Utility.RandomMinMax(rec.X, rec.X + rec.Width);
            int y = Utility.RandomMinMax(rec.Y, rec.Y + rec.Height);
            int z = map.GetAverageZ(x, y);

            return new Point3D(x, y, z);
        }
Ejemplo n.º 29
0
		private bool Check( Map map, Mobile m, ArrayList items, int x, int y, int startTop, int startZ, bool canSwim, bool cantWalk, out int newZ )
		{
			newZ = 0;

			Tile[] tiles = map.Tiles.GetStaticTiles( x, y, true );
			Tile landTile = map.Tiles.GetLandTile( x, y );

			bool landBlocks = (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Impassable) != 0;
			bool considerLand = !landTile.Ignored;

			if ( landBlocks && canSwim && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) != 0 )
				landBlocks = false;
			else if ( cantWalk && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) == 0 )
				landBlocks = true;

			int landZ = 0, landCenter = 0, landTop = 0;

			map.GetAverageZ( x, y, ref landZ, ref landCenter, ref landTop );

			bool moveIsOk = false;

			int stepTop = startTop + StepHeight;
			int checkTop = startZ + PersonHeight;

			bool ignoreDoors = ( m_AlwaysIgnoreDoors || !m.Alive || m.Body.BodyID == 0x3DB || m.IsDeadBondedPet );

			for ( int i = 0; i < tiles.Length; ++i )
			{
				Tile tile = tiles[i];
				ItemData itemData = TileData.ItemTable[tile.ID & 0x3FFF];
				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) == TileFlag.Surface || (canSwim && (flags & TileFlag.Wet) != 0) ) // Surface && !Impassable
				{
					if ( cantWalk && (flags & TileFlag.Wet) == 0 )
						continue;

					int itemZ = tile.Z;
					int itemTop = itemZ;
					int ourZ = itemZ + itemData.CalcHeight;
					int ourTop = ourZ + PersonHeight;
					int testTop = checkTop;

					if ( moveIsOk )
					{
						int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

						if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
							continue;
					}

					if ( ourZ + PersonHeight > testTop )
						testTop = ourZ + PersonHeight;

					if ( !itemData.Bridge )
						itemTop += itemData.Height;

					if ( stepTop >= itemTop )
					{
						int landCheck = itemZ;

						if ( itemData.Height >= StepHeight )
							landCheck += StepHeight;
						else
							landCheck += itemData.Height;

						if ( considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ )
							continue;

						if ( IsOk( ignoreDoors, ourZ, testTop, tiles, items ) )
						{
							newZ = ourZ;
							moveIsOk = true;
						}
					}
				}
			}

			for ( int i = 0; i < items.Count; ++i )
			{
				Item item = (Item)items[i];
				ItemData itemData = item.ItemData;//TileData.ItemTable[item.ItemID & 0x3FFF];
				TileFlag flags = itemData.Flags;

				if ( (flags & ImpassableSurface) == TileFlag.Surface || (m.CanSwim && (flags & TileFlag.Wet) != 0) ) // Surface && !Impassable
				{
					if ( cantWalk && (flags & TileFlag.Wet) == 0 )
						continue;

					int itemZ = item.Z;
					int itemTop = itemZ;
					int ourZ = itemZ + itemData.CalcHeight;
					int ourTop = ourZ + PersonHeight;
					int testTop = checkTop;

					if ( moveIsOk )
					{
						int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

						if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
							continue;
					}

					if ( ourZ + PersonHeight > testTop )
						testTop = ourZ + PersonHeight;

					if ( !itemData.Bridge )
						itemTop += itemData.Height;

					if ( stepTop >= itemTop )
					{
						int landCheck = itemZ;

						if ( itemData.Height >= StepHeight )
							landCheck += StepHeight;
						else
							landCheck += itemData.Height;

						if ( considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ )
							continue;

						if ( IsOk( ignoreDoors, ourZ, testTop, tiles, items ) )
						{
							newZ = ourZ;
							moveIsOk = true;
						}
					}
				}
			}

			if ( considerLand && !landBlocks && stepTop >= landZ )
			{
				int ourZ = landCenter;
				int ourTop = ourZ + PersonHeight;
				int testTop = checkTop;

				if ( ourZ + PersonHeight > testTop )
					testTop = ourZ + PersonHeight;

				bool shouldCheck = true;

				if ( moveIsOk )
				{
					int cmp = Math.Abs( ourZ - m.Z ) - Math.Abs( newZ - m.Z );

					if ( cmp > 0 || (cmp == 0 && ourZ > newZ) )
						shouldCheck = false;
				}

				if ( shouldCheck && IsOk( ignoreDoors, ourZ, testTop, tiles, items ) )
				{
					newZ = ourZ;
					moveIsOk = true;
				}
			}

			return moveIsOk;
		}
Ejemplo n.º 30
0
		public static BaseCreature Spawn( int level, Point3D p, Map map, Mobile target, bool guardian )
		{
			if ( map == null )
				return null;

			BaseCreature c = Spawn( level, p, guardian );



			if ( c != null )
			{
				bool spawned = false;

				for ( int i = 0; !spawned && i < 10; ++i )
				{
					int x = p.X - 3 + Utility.Random( 7 );
					int y = p.Y - 3 + Utility.Random( 7 );

					if ( map.CanSpawnMobile( x, y, p.Z ) )
					{
						c.MoveToWorld( new Point3D( x, y, p.Z ), map );

                        if (HalloweenEventController.Instance != null && HalloweenEventController.Halloween && HalloweenCorruption.CheckCorrupt(c, new Point3D(x, y, p.Z), map))
                            c.IsCorrupt = true;

                        if (!c.IsCorrupt && Paragon.CheckConvert(c, new Point3D(x, y, p.Z), map))
                            c.IsParagon = true;

						spawned = true;
					}
					else
					{
						int z = map.GetAverageZ( x, y );

						if ( map.CanSpawnMobile( x, y, z ) )
						{
							c.MoveToWorld( new Point3D( x, y, z ), map );
							spawned = true;

                            if (HalloweenEventController.Instance != null && HalloweenEventController.Halloween && HalloweenCorruption.CheckCorrupt(c, new Point3D(x, y, z), map))
                                c.IsCorrupt = true;

                            if (!c.IsCorrupt && Paragon.CheckConvert(c, new Point3D(x, y, z), map))
                                c.IsParagon = true;
						}
					}
				}

				if ( !spawned )
				{
					c.Delete();
					return null;
				}

				c.HomeMap = c.Map;

				if ( target != null )
					c.Combatant = target;

				return c;
			}

			return null;
		}
Ejemplo n.º 31
0
        public static Point3D GetRandomSpawnLocation( Point3D p, Map map )
        {
            for ( int i = 0; i < 10; ++i )
            {
                int x = p.X - 3 + Utility.Random( 7 );
                int y = p.Y - 3 + Utility.Random( 7 );

                if ( map.CanSpawnMobile( x, y, p.Z ) )
                {
                    return new Point3D( x, y, p.Z );
                }
                else
                {
                    int z = map.GetAverageZ( x, y );

                    if ( map.CanSpawnMobile( x, y, z ) )
                        return new Point3D( x, y, z );
                }
            }

            return Point3D.Zero;
        }
Ejemplo n.º 32
0
		private void GetStartZ( Mobile m, Map map, Point3D loc, ArrayList itemList, out int zLow, out int zTop )
		{
			int xCheck = loc.X, yCheck = loc.Y;

			Tile landTile = map.Tiles.GetLandTile( xCheck, yCheck );
			int landZ = 0, landCenter = 0, landTop = 0;
			bool landBlocks = (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Impassable) != 0;

			if ( landBlocks && m.CanSwim && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) != 0 )
				landBlocks = false;
			else if ( m.CantWalk && (TileData.LandTable[landTile.ID & 0x3FFF].Flags & TileFlag.Wet) == 0 )
				landBlocks = true;

			map.GetAverageZ( xCheck, yCheck, ref landZ, ref landCenter, ref landTop );

			bool considerLand = !landTile.Ignored;

			int zCenter = zLow = zTop = 0;
			bool isSet = false;

			if ( considerLand && !landBlocks && loc.Z >= landCenter )
			{
				zLow = landZ;
				zCenter = landCenter;

				if ( !isSet || landTop > zTop )
					zTop = landTop;

				isSet = true;
			}

			Tile[] staticTiles = map.Tiles.GetStaticTiles( xCheck, yCheck, true );

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

				int calcTop = (tile.Z + id.CalcHeight);

				if ( (!isSet || calcTop >= zCenter) && ( (id.Flags & TileFlag.Surface) != 0 || ( m.CanSwim && (id.Flags&TileFlag.Wet) != 0 ) ) && loc.Z >= calcTop )
				{
					if ( m.CantWalk && (id.Flags & TileFlag.Wet) == 0 )
						continue;

					zLow = tile.Z;
					zCenter = calcTop;

					int top = tile.Z + id.Height;

					if ( !isSet || top > zTop )
						zTop = top;

					isSet = true;
				}
			}

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

				ItemData id = item.ItemData;

				int calcTop = item.Z + id.CalcHeight;

				if ( (!isSet || calcTop >= zCenter) && ( (id.Flags & TileFlag.Surface) != 0 || ( m.CanSwim && (id.Flags&TileFlag.Wet) != 0 ) ) && loc.Z >= calcTop )
				{
					if ( m.CantWalk && (id.Flags & TileFlag.Wet) == 0 )
						continue;

					zLow = item.Z;
					zCenter = calcTop;

					int top = item.Z + id.Height;

					if ( !isSet || top > zTop )
						zTop = top;

					isSet = true;
				}
			}

			if ( !isSet )
				zLow = zTop = loc.Z;
			else if ( loc.Z > zTop )
				zTop = loc.Z;
		}
Ejemplo n.º 33
0
		public static IEnumerable<Point3D> PlotLine3D(this IPoint3D start, IPoint3D end, Map map, bool avgZ = true)
		{
			var dist = GetDistance(start, end);
			var dZ = end.Z - start.Z;

			return Line2D.Plot(start, end).Select(
				(p, i) =>
				{
					var z = start.Z;

					if (avgZ)
					{
						if (map != null)
						{
							z = map.GetAverageZ(p.X, p.Y);
						}
						else
						{
							z += (int)(dZ * (i / dist));
						}
					}

					return new Point3D(p, z);
				});
		}
Ejemplo n.º 34
0
		public static bool ReadPoint3D( XmlElement xml, Map map, ref Point3D value, bool mandatory )
		{
			int x = 0, y = 0, z = 0;

			bool xyOk = ReadInt32( xml, "x", ref x, mandatory ) & ReadInt32( xml, "y", ref y, mandatory );
			bool zOk = ReadInt32( xml, "z", ref z, mandatory && map == null );

			if ( xyOk && ( zOk || map != null ) )
			{
				if ( !zOk )
					z = map.GetAverageZ( x, y );

				value = new Point3D( x, y, z );
				return true;
			}

			return false;
		}
Ejemplo n.º 35
0
		public static Point3D GetSpawnPosition(Map map, Point3D location, int homeRange, bool forceZ, object o)
		{
			CanFitFlags flags = CanFitFlags.requireSurface;
			if (o is Mobile)
			{
				Mobile m = o as Mobile;
				if (m != null && m.CanSwim == true) flags |= CanFitFlags.canSwim;
				if (m != null && m.CantWalk == true) flags |= CanFitFlags.cantWalk;
			}

			if (map == null)
				return location;

			// Try 10 times to find a Spawnable location.
			for (int i = 0; i < 10; i++)
			{
				int x = location.X + (Utility.Random((homeRange * 2) + 1) - homeRange);
				int y = location.Y + (Utility.Random((homeRange * 2) + 1) - homeRange);
				int z = map.GetAverageZ(x, y);

				if (map.CanSpawnMobile(new Point2D(x, y), location.Z, flags))
					return new Point3D(x, y, location.Z);
				if (forceZ == false)
					if (map.CanSpawnMobile(new Point2D(x, y), z, flags))
						return new Point3D(x, y, z);
			}

			return location;
		}