Exemplo n.º 1
0
        public int AIPlayergetNearestPlayerTarget(coAIPlayer npc)
        {
            if (!console.isObject(npc))
            {
                return(-1);
            }

            if ((npc["CurrentTarget"] != "") && (npc["CurrentTarget"] != "-1"))
            {
                if (npc["CurrentTarget"].isObject())
                {
                    if (((coPlayer)npc["CurrentTarget"]).getState() != "Dead")
                    {
                        return(npc["CurrentTarget"].AsInt());
                    }
                }
            }


            coSimSet MobSearchGroup;

            if (npc["aiteam"] == "1")
            {
                MobSearchGroup = "MobSearchGroup_2";
            }
            else
            {
                MobSearchGroup = "MobSearchGroup_1";
            }

            coSimSet MobSearchGroupResult = "MobSearchGroupResult";

            if (!MobSearchGroupResult.isObject())
            {
                MobSearchGroupResult = new Torque_Class_Helper("SimSet", "MobSearchGroupResult").Create();
            }

            npc.AISearchSimSet(180, 50, MobSearchGroup, MobSearchGroupResult);


            int   closesttarget = -1;
            float closestdist   = 51;

            for (uint i = 0; i < MobSearchGroupResult.getCount(); i++)
            {
                coPlayer target = MobSearchGroupResult.getObject(i);
                if (!target.isObject())
                {
                    continue;
                }
                if (target.getState() == "Dead")
                {
                    continue;
                }
                float dist = AIPlayergetTargetDistance(npc, target);
                if (dist >= closestdist)
                {
                    continue;
                }
                closestdist   = dist;
                closesttarget = target;
            }
            MobSearchGroupResult.clear();

            npc["CurrentTarget"] = closesttarget.AsString();

            return(closesttarget);
        }