Server.Multis.BaseBoat.CanFit C# (CSharp) Méthode

CanFit() public méthode

public CanFit ( Server.Point3D p, Server.Map map, int itemID ) : bool
p Server.Point3D
map Server.Map
itemID int
Résultat bool
		public bool CanFit( Point3D p, Map map, int itemID )
		{
			if ( map == null || map == Map.Internal || Deleted || CheckDecay() )
				return false;

			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;

					for ( int i = 0; i < tiles.Length; ++i )
					{
						StaticTile tile = tiles[i];
						bool isWater = ( 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 is BaseMulti || item.ItemID > TileData.MaxItemValue || 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;
		}

Usage Example

Exemple #1
0
        public void RemoveBoat(BaseBoat boat)
        {
            if (boat == null)
                return;

            //First, we'll try and put the boat in the cooresponding location where it warped in
            if (boat.Map != null && boat.Map != Map.Internal && m_Altar != null && m_Altar.WarpRegion != null)
            {
                Map map = boat.Map;
                Rectangle2D rec = m_Altar.WarpRegion.Bounds;

                int x = boat.X - m_Bounds.X;
                int y = boat.Y - m_Bounds.Y;
                int z = map.GetAverageZ(x, y);

                Point3D ePnt = new Point3D(rec.X + x, rec.Y + y, -5);

                int offsetX = ePnt.X - boat.X;
                int offsetY = ePnt.Y - boat.Y;
                int offsetZ = map.GetAverageZ(ePnt.X, ePnt.Y) - boat.Z;

                if (boat.CanFit(ePnt, this.Map, boat.ItemID))
                {
                    boat.Teleport(offsetX, offsetY, offsetZ);

                    //int z = this.Map.GetAverageZ(boat.X, boat.Y);
                    if (boat.Z != -5)
                        boat.Z = -5;

                    if (boat.TillerMan != null)
                        boat.TillerManSay(501425); //Ar, turbulent water!
                    return;
                }
            }

            //Plan B, lets kick to some random location who-knows-where
            for (int i = 0; i < 25; i++)
            {
                Rectangle2D rec = CorgulAltar.BoatKickLocation;
                Point3D ePnt = CorgulAltar.GetRandomPoint(rec, Map);

                int offsetX = ePnt.X - boat.X;
                int offsetY = ePnt.Y - boat.Y;
                int offsetZ = ePnt.Z - boat.Z;

                if (boat.CanFit(ePnt, this.Map, boat.ItemID))
                {
                    boat.Teleport(offsetX, offsetY, -5);
                    boat.SendMessageToAllOnBoard("A rough patch of sea has disoriented the crew!");

                    //int z = this.Map.GetAverageZ(boat.X, boat.Y);
                    if (boat.Z != -5)
                        boat.Z = -5;

                    if (boat.TillerMan != null)
                        boat.TillerManSay(501425); //Ar, turbulent water!
                    break;
                }
            }
        }
All Usage Examples Of Server.Multis.BaseBoat::CanFit