//GS
public virtual bool ShouldRun()
{
if ( m_Mobile.AllowedStealthSteps > 0 )
return false;
return m_Mobile.CanRun;
}
public virtual bool WalkMobileRange(Mobile m, int iWantDist)
{
bool bRun = ShouldRun();
return WalkMobileRange(m, 1, bRun, iWantDist, iWantDist);
}
public virtual bool WalkMobileRange(Mobile m, int iWantDistMin, int iWantDistMax)
{
bool bRun = ShouldRun();
return WalkMobileRange(m, 1, bRun, iWantDistMin, iWantDistMax);
}
public virtual bool WalkMobileRange(Mobile m, bool bRun, int iWantDistMin, int iWantDistMax)
{
return WalkMobileRange(m, 1, bRun, iWantDistMin, iWantDistMax);
}
public virtual bool WalkMobileRange(Mobile f, int iSteps, bool bRun, int iWantDistMin, int iWantDistMax)
{
BaseCreature m = m_Mobile as BaseCreature;
if (m.Deleted)
return false;
if ( f == null || f.Deleted || !f.Alive || f.Map != m.Map )
return false;
int iOldDist = (int)m.GetDistanceToSqrt(f);
// Already where I want to be
if ( iOldDist >= iWantDistMin && iOldDist <= iWantDistMax )
{
CheckTurn(f);
return true;
}
// I'm either too close or too far
// I'm unable to move!
if ( BlockingMove() || m.DisallowAllMoves)
{
CheckTurn(f);
return false;
}
// Walk to my target
for (int i = 0; i < iSteps; i++)
{
// Get the current distance
int iCurrDist = (int)m.GetDistanceToSqrt(f);
if (iCurrDist < iWantDistMin || iCurrDist > iWantDistMax)
{
bool needCloser = (iCurrDist > iWantDistMax);
if (needCloser && m_Path != null && m_Path.Goal == f)
{
if (m_Path.Follow(bRun, 1))
m_Path = null;
}
else
{
Direction dirTo;
if (needCloser)
dirTo = m.GetDirectionTo(f);
else
dirTo = f.GetDirectionTo(m);
// Add the run flag
if (bRun)
dirTo = dirTo | Direction.Running;
if (!DoMove(dirTo, true))
{
if (needCloser)
{
m_Path = new PathFollower(m, f);
m_Path.Mover = new MoveMethod(DoMoveImpl);
if (m_Path.Follow(bRun, 1))
m_Path = null;
}
else
{
m.Direction = m.GetDirectionTo(f);
m_Path = null;
}
}
else
{
m_Path = null;
}
}
}
}
// Am I where I want to be now?
int iNewDist = (int)m.GetDistanceToSqrt(f);
if (iNewDist >= iWantDistMin && iNewDist <= iWantDistMax)
return true;
return false;
}
public virtual void CheckTurn( Mobile f )
{
BaseCreature m = m_Mobile as BaseCreature;
if ( f == null )
return;
if ( Core.TickCount <= m.LastMoveTime + 1000 )
return;
if ( Core.TickCount <= NextTurn )
return;
Direction d = m.GetDirectionTo(f);
if ( d != m.Direction && (BlockingMove() || m.DisallowAllMoves || Core.TickCount >= m.LastMoveTime + 2000) )
{
NextTurn = Core.TickCount + 1000;
m.Direction = d;
}
else if ( Core.TickCount < m.LastMoveTime + 2000 )
{
d = (Direction)((int)d + Utility.RandomList(-1, +1));
Timer.DelayCall(TimeSpan.FromMilliseconds(1), new TimerStateCallback(Turn), f);
NextTurn = Core.TickCount + 1000;
m.Direction = d;
}
}
public virtual void Turn(object o)
{
BaseCreature m = m_Mobile as BaseCreature;
if ( m == null || m.Deleted || !m.Alive || m.Map == null || m.Map == Map.Internal )
return;
Mobile f = o as Mobile;
if ( f == null || f.Deleted || !f.Alive || f.Map == null || f.Map == Map.Internal )
return;
if ( m.Map != f.Map )
return;
m.Direction = m.GetDirectionTo(f);
}
public virtual bool BlockingMove()
{
if ( m_Mobile.Spell == null || !m_Mobile.Spell.IsCasting || m_Mobile.Target != null )
return false;
if ( m_Mobile.Spell != null && m_Mobile.Spell.IsCasting )
return true;
return false;
}