public static void TargetResponse( NetState state, PacketReader pvSrc )
{
int type = pvSrc.ReadByte();
int targetID = pvSrc.ReadInt32();
int flags = pvSrc.ReadByte();
Serial serial = pvSrc.ReadInt32();
int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
int graphic = pvSrc.ReadUInt16();
if ( targetID == unchecked( (int) 0xDEADBEEF ) )
return;
Mobile from = state.Mobile;
Target t = from.Target;
if ( t != null )
{
TargetProfile prof = TargetProfile.Acquire( t.GetType() );
if ( prof != null ) {
prof.Start();
}
try {
if ( x == -1 && y == -1 && !serial.IsValid )
{
// User pressed escape
t.Cancel( from, TargetCancelType.Canceled );
}
else if ( Target.TargetIDValidation && t.TargetID != targetID )
{
// Sanity, prevent fake target
return;
}
else
{
object toTarget;
if ( type == 1 )
{
if ( graphic == 0 )
{
toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
}
else
{
Map map = from.Map;
if ( map == null || map == Map.Internal )
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
else
{
StaticTile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );
bool valid = false;
if ( state.HighSeas ) {
ItemData id = TileData.ItemTable[graphic&TileData.MaxItemValue];
if ( id.Surface ) {
z -= id.Height;
}
}
for ( int i = 0; !valid && i < tiles.Length; ++i )
{
if ( tiles[i].Z == z && tiles[i].ID == graphic )
valid = true;
}
if ( !valid )
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
else
{
toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
}
}
}
}
else if ( serial.IsMobile )
{
toTarget = World.FindMobile( serial );
}
else if ( serial.IsItem )
{
toTarget = World.FindItem( serial );
}
else
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
t.Invoke( from, toTarget );
}
} finally {
if ( prof != null ) {
prof.Finish();
}
}
}
}