private void ProcessTarget( Target targ )
{
bool isDispel = ( targ is DispelSpell.InternalTarget );
bool isParalyze = ( targ is ParalyzeSpell.InternalTarget );
bool isTeleport = ( targ is TeleportSpell.InternalTarget );
bool teleportAway = false;
Mobile toTarget;
if ( isDispel )
{
toTarget = FindDispelTarget( false );
if ( !SmartAI && toTarget != null )
RunTo( toTarget );
else if ( toTarget != null && m_Mobile.InRange( toTarget, 10 ) )
RunFrom( toTarget );
}
else if ( SmartAI && (isParalyze || isTeleport) )
{
toTarget = FindDispelTarget( true );
if ( toTarget == null )
{
toTarget = m_Mobile.Combatant;
if ( toTarget != null )
RunTo( toTarget );
}
else if ( m_Mobile.InRange( toTarget, 10 ) )
{
RunFrom( toTarget );
teleportAway = true;
}
else
{
teleportAway = true;
}
}
else
{
toTarget = m_Mobile.Combatant;
if ( toTarget != null )
RunTo( toTarget );
}
if ( (targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null )
{
if ( (targ.Range == -1 || m_Mobile.InRange( toTarget, targ.Range )) && m_Mobile.CanSee( toTarget ) && m_Mobile.InLOS( toTarget ) )
{
targ.Invoke( m_Mobile, toTarget );
}
else if ( isDispel )
{
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
}
}
else if ( (targ.Flags & TargetFlags.Beneficial) != 0 )
{
targ.Invoke( m_Mobile, m_Mobile );
}
else if ( isTeleport && toTarget != null )
{
Map map = m_Mobile.Map;
if ( map == null )
{
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
return;
}
int px, py;
if ( teleportAway )
{
int rx = m_Mobile.X - toTarget.X;
int ry = m_Mobile.Y - toTarget.Y;
double d = m_Mobile.GetDistanceToSqrt( toTarget );
px = toTarget.X + (int)(rx * (10 / d));
py = toTarget.Y + (int)(ry * (10 / d));
}
else
{
px = toTarget.X;
py = toTarget.Y;
}
for ( int i = 0; i < m_Offsets.Length; i += 2 )
{
int x = m_Offsets[i], y = m_Offsets[i + 1];
Point3D p = new Point3D( px + x, py + y, 0 );
LandTarget lt = new LandTarget( p, map );
if ( (targ.Range == -1 || m_Mobile.InRange( p, targ.Range )) && m_Mobile.InLOS( lt ) && map.CanSpawnMobile( px + x, py + y, lt.Z ) && !SpellHelper.CheckMulti( p, map ) )
{
targ.Invoke( m_Mobile, lt );
return;
}
}
int teleRange = targ.Range;
if ( teleRange < 0 )
teleRange = 12;
for ( int i = 0; i < 10; ++i )
{
Point3D randomPoint = new Point3D( m_Mobile.X - teleRange + Utility.Random( teleRange * 2 + 1 ), m_Mobile.Y - teleRange + Utility.Random( teleRange * 2 + 1 ), 0 );
LandTarget lt = new LandTarget( randomPoint, map );
if ( m_Mobile.InLOS( lt ) && map.CanSpawnMobile( lt.X, lt.Y, lt.Z ) && !SpellHelper.CheckMulti( randomPoint, map ) )
{
targ.Invoke( m_Mobile, new LandTarget( randomPoint, map ) );
return;
}
}
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
}
else
{
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
}
}