Exemplo n.º 1
0
    private EntityMonster FindClosedTarget()
    {
        List <EntityMonster> lst = BattleMgr.GetEntityMonsters();

        if (lst == null || lst.Count == 0)
        {
            return(null);
        }

        Vector3       self          = GetPos();
        EntityMonster targetMonster = null;
        float         dis           = 0;

        for (int i = 0; i < lst.Count; i++)
        {
            Vector3 target = lst[i].GetPos();
            if (i == 0)
            {
                dis           = Vector3.Distance(self, target);
                targetMonster = lst[0];
            }
            else
            {
                float calcDis = Vector3.Distance(self, target);
                if (dis > calcDis)
                {
                    dis           = calcDis;
                    targetMonster = lst[i];
                }
            }
        }
        return(targetMonster);
    }