public bool Move( Direction dir, int speed, int clientSpeed, bool message )
{
Map map = Map;
if ( map == null || Deleted || CheckDecay() )
return false;
if ( m_Anchored )
{
if ( message && m_TillerMan != null )
m_TillerMan.Say( 501419 ); // Ar, the anchor is down sir!
return false;
}
int rx = 0, ry = 0;
Direction d = (Direction)(((int)m_Facing + (int)dir) & 0x7);
Movement.Movement.Offset( d, ref rx, ref ry );
for ( int i = 1; i <= speed; ++i )
{
if ( !CanFit( new Point3D( X + (i * rx), Y + (i * ry), Z ), Map, ItemID ) )
{
if ( i == 1 )
{
if ( message && m_TillerMan != null )
m_TillerMan.Say( 501424 ); // Ar, we've stopped sir.
return false;
}
speed = i - 1;
break;
}
}
int xOffset = speed*rx;
int yOffset = speed*ry;
int newX = X + xOffset;
int newY = Y + yOffset;
Rectangle2D[] wrap = GetWrapFor();
for ( int i = 0; i < wrap.Length; ++i )
{
Rectangle2D rect = wrap[i];
if ( rect.Contains( new Point2D( X, Y ) ) && !rect.Contains( new Point2D( newX, newY ) ) )
{
if ( newX < rect.X )
newX = rect.X + rect.Width - 1;
else if ( newX >= rect.X + rect.Width )
newX = rect.X;
if ( newY < rect.Y )
newY = rect.Y + rect.Height - 1;
else if ( newY >= rect.Y + rect.Height )
newY = rect.Y;
for ( int j = 1; j <= speed; ++j )
{
if ( !CanFit( new Point3D( newX + (j * rx), newY + (j * ry), Z ), Map, ItemID ) )
{
if ( message && m_TillerMan != null )
m_TillerMan.Say( 501424 ); // Ar, we've stopped sir.
return false;
}
}
xOffset = newX - X;
yOffset = newY - Y;
}
}
if ( !NewBoatMovement || Math.Abs( xOffset ) > 1 || Math.Abs( yOffset ) > 1 )
{
Teleport( xOffset, yOffset, 0 );
}
else
{
List<IEntity> toMove = GetMovingEntities();
SafeAdd( m_TillerMan, toMove );
SafeAdd( m_Hold, toMove );
SafeAdd( m_PPlank, toMove );
SafeAdd( m_SPlank, toMove );
// Packet must be sent before actual locations are changed
foreach ( NetState ns in Map.GetClientsInRange( Location, GetMaxUpdateRange() ) )
{
Mobile m = ns.Mobile;
if ( ns.HighSeas && m.CanSee( this ) && m.InRange( Location, GetUpdateRange( m ) ) )
ns.Send( new MoveBoatHS( m, this, d, clientSpeed, toMove, xOffset, yOffset ) );
}
foreach ( IEntity e in toMove )
{
if ( e is Item )
{
Item item = (Item)e;
item.NoMoveHS = true;
if ( !( item is TillerMan || item is Hold || item is Plank ) )
item.Location = new Point3D( item.X + xOffset, item.Y + yOffset, item.Z );
}
else if ( e is Mobile )
{
Mobile m = (Mobile)e;
m.NoMoveHS = true;
m.Location = new Point3D( m.X + xOffset, m.Y + yOffset, m.Z );
}
}
NoMoveHS = true;
Location = new Point3D( X + xOffset, Y + yOffset, Z );
foreach ( IEntity e in toMove )
{
if ( e is Item )
((Item)e).NoMoveHS = false;
else if ( e is Mobile )
((Mobile)e).NoMoveHS = false;
}
NoMoveHS = false;
}
return true;
}