public static bool NearestEnemy(EntityAlive theEntity, List <Entity> NearbyEnemies) { if (NearbyEnemies.Count == 0) { return(false); } // Finds the closet block we matched with. EntityAlive closeEnemy = null; float minDist = Mathf.Infinity; Vector3 currentPos = theEntity.position; foreach (EntityAlive enemy in NearbyEnemies) { float dist = Vector3.Distance(enemy.position, currentPos); DisplayLog(" Entity: " + enemy.EntityName + "'s distance is: " + dist); if (dist < minDist) { closeEnemy = enemy; minDist = dist; } } if (closeEnemy != null) { DisplayLog(" Closes Enemy: " + closeEnemy.ToString()); theEntity.SetRevengeTarget(closeEnemy); return(true); } return(false); }
public static bool CanExecuteTask(int EntityID, EntityUtilities.Orders order) { EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; 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) { DisplayLog("My Current Order is Follow"); if (Distance < 2) { if (myEntity.moveHelper != null) { 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); }