public static bool CanExecuteTask(int EntityID, EntityUtilities.Orders order) { EntityAliveSDX myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAliveSDX; if (myEntity) { if (GetCurrentOrder(EntityID) != order) { // DisplayLog("CanExecuteTask(): Current Order does not match passed in Order: " + GetCurrentOrder(EntityID)); return(false); } Entity leader = EntityUtilities.GetLeader(EntityID); float Distance = 0f; if (leader) { Distance = myEntity.GetDistance(leader); } // If we have an attack or revenge target, don't execute task if (myEntity.GetAttackTarget() != null && myEntity.GetAttackTarget().IsAlive()) { // If we have a leader and they are far away, abandon the fight and go after your leader. if (Distance > 20) { //DisplayLog("CanExecuteTask(): I have an Attack Target but my Leader is too far away."); myEntity.SetAttackTarget(null, 0); return(true); } // I have an attack target, so don't keep doing your current task //DisplayLog("CanExecuteTask(): I have an Attack Target: " + myEntity.GetAttackTarget().ToString() ); return(false); } if (myEntity.GetRevengeTarget() != null && myEntity.GetRevengeTarget().IsAlive()) { if (Distance > 20) { // DisplayLog("CanExecuteTask(): I have a Revenge Target, but my leader is too far way."); myEntity.SetRevengeTarget(null); return(true); } // DisplayLog("CanExecuteTask(): I have a Revenge Target: " + myEntity.GetRevengeTarget().ToString()); return(false); } if (GetCurrentOrder(EntityID) == Orders.Follow) { if (Distance < 2) { myEntity.moveHelper.Stop(); // DisplayLog(" Too Close to leader. Moving to Look Vector"); myEntity.moveHelper.SetMoveTo((leader as EntityAlive).GetLookVector(), false); return(false); } } return(true); } return(true); }