public virtual bool DoOrderGuard()
{
if (m_Mobile.IsDeadPet)
return true;
Mobile controlMaster = m_Mobile.ControlMaster;
if (controlMaster == null || controlMaster.Deleted)
return true;
Mobile combatant = m_Mobile.Combatant;
List<AggressorInfo> aggressors = controlMaster.Aggressors;
if (aggressors.Count > 0)
{
for (int i = 0; i < aggressors.Count; ++i)
{
AggressorInfo info = aggressors[i];
Mobile attacker = info.Attacker;
if (attacker != null && !attacker.Deleted && attacker.GetDistanceToSqrt(m_Mobile) <= m_Mobile.RangePerception)
{
if (combatant == null || attacker.GetDistanceToSqrt(controlMaster) < combatant.GetDistanceToSqrt(controlMaster))
combatant = attacker;
}
}
if (combatant != null)
m_Mobile.DebugSay("Crap, my master has been attacked! I will attack one of those bastards!");
}
if (combatant != null && combatant != m_Mobile && combatant != m_Mobile.ControlMaster && !combatant.Deleted && combatant.Alive && !combatant.IsDeadBondedPet && m_Mobile.CanSee(combatant) && m_Mobile.CanBeHarmful(combatant, false) && combatant.Map == m_Mobile.Map)
{
m_Mobile.DebugSay("Guarding from target...");
m_Mobile.Combatant = combatant;
m_Mobile.FocusMob = combatant;
Action = ActionType.Combat;
/*
* We need to call Think() here or spell casting monsters will not use
* spells when guarding because their target is never processed.
*/
Think();
}
else
{
m_Mobile.DebugSay("Nothing to guard from");
m_Mobile.Warmode = false;
WalkMobileRange(controlMaster, 1, false, 0, 1);
}
return true;
}