Example #1
0
        protected virtual NPC TargetDecider(ManagerHelper mH)
        {
            if (mH.GetGametype() is Survival)
            {
                NPC   closest         = null;
                float closestDistance = float.PositiveInfinity;

                foreach (var suicide in mH.GetNPCManager().GetAllies(NPC.AffliationTypes.black))
                {
                    if (NPCManager.IsNPCInRadius(suicide, GetOriginPosition(), sight) &&
                        NPCManager.IsNPCInDirection(suicide, GetOriginPosition(), rotation, vision, mH))
                    {
                        float distanceToSuicide = PathHelper.DistanceSquared(GetOriginPosition(), suicide.GetOriginPosition());

                        if (distanceToSuicide < closestDistance)
                        {
                            closestDistance = distanceToSuicide;
                            closest         = suicide;
                        }
                    }
                }

                return(closest);
            }
            else
            {
                NPC   closest         = null;
                float closestDistance = float.PositiveInfinity;

                foreach (var agent in mH.GetNPCManager().GetNPCs())
                {
                    if (agent.GetAffiliation() != affiliation &&
                        NPCManager.IsNPCInRadius(agent, GetOriginPosition(), sight) &&
                        NPCManager.IsNPCInDirection(agent, GetOriginPosition(), rotation, vision, mH))
                    {
                        float distanceToAgent = PathHelper.DistanceSquared(GetOriginPosition(), agent.GetOriginPosition());

                        if (distanceToAgent < closestDistance)
                        {
                            closestDistance = distanceToAgent;
                            closest         = agent;
                        }
                    }
                }

                return(closest);
            }
        }
Example #2
0
        protected override NPC TargetDecider(ManagerHelper mH)
        {
            NPC   bestEnemy    = null;
            float bestDistance = float.PositiveInfinity;

            foreach (var agent in mH.GetNPCManager().GetNPCs())
            {
                if (agent.GetAffiliation() != affiliation &&
                    NPCManager.IsNPCInRadius(agent, GetOriginPosition(), sight) &&
                    NPCManager.IsNPCInDirection(agent, GetOriginPosition(), rotation, vision, mH))
                {
                    float distanceToEnemy = PathHelper.DistanceSquared(GetOriginPosition(), agent.GetOriginPosition());

                    if (distanceToEnemy < bestDistance)
                    {
                        bestDistance = distanceToEnemy;
                        bestEnemy    = agent;
                    }
                }
            }


            return(bestEnemy);
        }