NpcFindCanUseSkill() static private method

static private NpcFindCanUseSkill ( EntityInfo npc, AiData_General aidata, bool includeManualSkill ) : SkillInfo
npc EntityInfo
aidata AiData_General
includeManualSkill bool
return SkillInfo
        private void IdleHandler(EntityInfo npc, long deltaTime)
        {
            AiData_Leader aiData = GetAiData(npc);
            SkillInfo     skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, aiData, aiData.IsAutoOperate);

            if (skInfo == null)
            {
                return;
            }
            CharacterRelation relation =
                (skInfo.TargetType == SkillTargetType.Friend ||
                 skInfo.TargetType == SkillTargetType.RandFriend) ?
                CharacterRelation.RELATION_FRIEND :
                CharacterRelation.RELATION_ENEMY;

            EntityInfo attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, aiData.IsAutoOperate ? npc.ViewRange : skInfo.Distance, relation);

            if (attackTarget != null)
            {
                ChangeToState(npc, (int)AiStateId.Combat);
            }
        }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }

            AiStateInfo info          = npc.GetAiStateInfo();
            EntityInfo  leader        = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.LeaderID);
            bool        isAutoOperate = IsAutoOperate(leader);

            ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
            Vector3 homePos = Vector3.Zero;

            if (null != leader)
            {
                GetHomePos(npc.GetMovementStateInfo().FormationIndex, leader);
            }
            float distSqrToHome = Geometry.DistanceSquare(srcPos, homePos);

            if (distSqrToHome > npc.GohomeRange * npc.GohomeRange)
            {
                NotifyAiStopPursue(npc);
                ChangeToState(npc, (int)AiStateId.GoHome);
                return;
            }

            ///
            EntityInfo     attackTarget = null;
            SkillStateInfo currSkInfo   = npc.GetSkillStateInfo();
            ///找到可以使用的技能
            SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), isAutoOperate);

            NotifyAiSelectSkill(npc, skInfo);
            if (skInfo == null)
            {
                //没有可以使用的技能就切换到Idle状态
                ChangeToState(npc, (int)AiStateId.Idle);
                return;
            }

            CharacterRelation relation =
                (skInfo.TargetType == SkillTargetType.Friend ||
                 skInfo.TargetType == SkillTargetType.RandFriend) ?
                CharacterRelation.RELATION_FRIEND :
                CharacterRelation.RELATION_ENEMY;

            attackTarget = AiLogicUtility.GetNearstTargetHelper(
                npc, skInfo.Distance, relation);

            if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标
            {
                info.Target = attackTarget.GetId();
                NotifyAiStopPursue(npc);
                NotifyAiSkill(npc, skInfo.SkillId); //攻击目标
                return;
            }
            attackTarget = AiLogicUtility.GetNearstTargetHelper(
                npc, npc.ViewRange, relation);
            if (attackTarget != null && isAutoOperate)                                    //视野范围内找到可攻击目标
            {
                NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
                return;
            }

            currSkInfo.SetCurSkillInfo(0);
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.GoHome);
        }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            AiStateInfo   aiInfo = npc.GetAiStateInfo();
            AiData_Leader aiData = GetAiData(npc);

            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            ///
            SkillStateInfo currSkInfo = npc.GetSkillStateInfo();
            ///找到可以使用的技能
            SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), aiData.IsAutoOperate);

            NotifyAiSelectSkill(npc, skInfo);
            if (skInfo == null)
            {
                //没有可以使用的技能就切换到Idle状态
                ChangeToState(npc, (int)AiStateId.Idle);
                return;
            }

            CharacterRelation relation =
                (skInfo.TargetType == SkillTargetType.Friend ||
                 skInfo.TargetType == SkillTargetType.RandFriend) ?
                CharacterRelation.RELATION_FRIEND :
                CharacterRelation.RELATION_ENEMY;
            EntityInfo attackTarget = AiLogicUtility.GetNearstAttackerHelper(npc, relation, aiData);

            if (null != attackTarget)
            {
                NotifyAiTarget(npc, attackTarget);
                if (Geometry.DistanceSquare(npc.GetMovementStateInfo().GetPosition3D(), attackTarget.GetMovementStateInfo().GetPosition3D()) < skInfo.Distance * skInfo.Distance)
                {
                    aiInfo.Target = attackTarget.GetId();
                    NotifyAiStopPursue(npc);
                    NotifyAiSkill(npc, skInfo.SkillId);
                    return;
                }
            }
            attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, skInfo.Distance, relation);
            if (attackTarget != null && null != skInfo)   //攻击范围内找到可攻击目标
            {
                NotifyAiTarget(npc, attackTarget);
                aiInfo.Target = attackTarget.GetId();
                NotifyAiStopPursue(npc);
                NotifyAiSkill(npc, skInfo.SkillId); //攻击目标
                return;
            }
            if (aiData.IsAutoOperate)
            {
                attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, npc.ViewRange, relation);
                if (attackTarget != null && null != skInfo)   //视野内找到可攻击目标
                {
                    NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D());
                    return;
                }
            }

            ///退出战斗模式清理一下手动技能
            currSkInfo.SetCurSkillInfo(0);
            aiData.ManualSkillId = 0;
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.Idle);
        }