Inheritance: AiData_General
        internal static void Execute(object msg, User user)
        {
            Msg_CR_OperateMode modeMsg = msg as Msg_CR_OperateMode;

            if (null == modeMsg)
            {
                return;
            }
            EntityInfo userInfo = user.Info;

            if (null == userInfo)
            {
                return;
            }

            AiStateInfo   aiInfo = userInfo.GetAiStateInfo();
            AiData_Leader data   = aiInfo.AiDatas.GetData <AiData_Leader>();

            if (null == data)
            {
                data = new AiData_Leader();
                aiInfo.AiDatas.AddData(data);
            }
            data.IsAutoOperate = modeMsg.isauto;
        }
        internal static void Execute(object msg, User user)
        {
            Msg_CR_Skill use_skill = msg as Msg_CR_Skill;

            if (null == use_skill)
            {
                return;
            }
            EntityInfo userObj = user.Info;

            if (null == userObj)
            {
                LogSys.Log(LOG_TYPE.DEBUG, "UseSkillHandler, charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name);
                return;
            }
            Scene scene = user.OwnRoom.ActiveScene;

            if (null != scene)
            {
                EntityInfo obj = scene.GetEntityById(use_skill.role_id);
                if (null != obj)
                {
                    AiStateInfo aiInfo = obj.GetAiStateInfo();
                    if (use_skill.target_id > 0)
                    {
                        aiInfo.Target = use_skill.target_id;
                    }
                    else if (use_skill.target_dir > 0)
                    {
                        float dir = ProtoHelper.DecodeFloat(use_skill.target_dir);
                        obj.GetMovementStateInfo().SetFaceDir(dir);
                        aiInfo.Target = 0;
                    }
                    if (aiInfo.AiLogic == (int)AiStateLogicId.Entity_Leader)
                    {
                        AiData_Leader data = aiInfo.AiDatas.GetData <AiData_Leader>();
                        if (null == data)
                        {
                            data = new AiData_Leader();
                            aiInfo.AiDatas.AddData(data);
                        }
                        data.ManualSkillId = use_skill.skill_id;
                    }
                    else
                    {
                        AiData_General data = aiInfo.AiDatas.GetData <AiData_General>();
                        if (null == data)
                        {
                            data = new AiData_General();
                            aiInfo.AiDatas.AddData(data);
                        }
                        data.ManualSkillId = use_skill.skill_id;
                    }
                    aiInfo.ChangeToState((int)AiStateId.SkillCommand);
                }
            }
        }
        public bool CastSkill(int objId, int skillId)
        {
            bool       ret = false;
            EntityInfo obj = GetEntityById(objId);

            if (null != obj)
            {
                SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(skillId);
                if (null != skillInfo)
                {
                    if (obj.Energy >= obj.GetActualProperty().EnergyMax)
                    {
                        if (!skillInfo.IsInCd(TimeUtility.GetLocalMilliseconds()))
                        {
                            int targetId = 0;
                            if (null != SelectedTarget)
                            {
                                targetId = SelectedTarget.TargetId;
                            }
                            if (IsRoomScene)
                            {
                                Network.NetworkSystem.Instance.SyncPlayerSkill(obj, skillId, targetId, obj.GetMovementStateInfo().GetFaceDir());
                            }
                            else
                            {
                                AiStateInfo aiInfo = obj.GetAiStateInfo();
                                aiInfo.Target = targetId;
                                if (aiInfo.AiLogic == (int)AiStateLogicId.Entity_Leader)
                                {
                                    AiData_Leader data = aiInfo.AiDatas.GetData <AiData_Leader>();
                                    if (null == data)
                                    {
                                        data = new AiData_Leader();
                                        aiInfo.AiDatas.AddData(data);
                                    }
                                    data.ManualSkillId = skillId;
                                }
                                else
                                {
                                    AiData_General data = aiInfo.AiDatas.GetData <AiData_General>();
                                    if (null == data)
                                    {
                                        data = new AiData_General();
                                        aiInfo.AiDatas.AddData(data);
                                    }
                                    data.ManualSkillId = skillId;
                                }
                                aiInfo.ChangeToState((int)AiStateId.SkillCommand);
                            }
                            ret = true;
                        }
                    }
                }
            }
            return(ret);
        }
        private AiData_Leader GetAiData(EntityInfo entity)
        {
            AiData_Leader data = entity.GetAiStateInfo().AiDatas.GetData <AiData_Leader>();

            if (null == data)
            {
                data = new AiData_Leader();
                entity.GetAiStateInfo().AiDatas.AddData(data);
            }
            return(data);
        }
        private int GetFormationId(EntityInfo leader)
        {
            int ret = 0;

            if (null != leader)
            {
                AiData_Leader data = leader.GetAiStateInfo().AiDatas.GetData <AiData_Leader>();
                if (null != data)
                {
                    ret = data.FormationId;
                }
            }
            return(ret);
        }
        private bool IsAutoOperate(EntityInfo leader)
        {
            bool ret = false;

            if (null != leader)
            {
                AiData_Leader data = leader.GetAiStateInfo().AiDatas.GetData <AiData_Leader>();
                if (null != data)
                {
                    ret = data.IsAutoOperate;
                }
            }
            return(ret);
        }
 public bool CastSkill(int objId, int skillId)
 {
     bool ret = false;
     EntityInfo obj = GetEntityById(objId);
     if (null != obj) {
         SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(skillId);
         if (null != skillInfo) {
             if (obj.Energy >= obj.GetActualProperty().EnergyMax) {
                 if (!skillInfo.IsInCd(TimeUtility.GetLocalMilliseconds())) {
                     int targetId = 0;
                     if (null != SelectedTarget) {
                         targetId = SelectedTarget.TargetId;
                     }
                     if (IsRoomScene) {
                         Network.NetworkSystem.Instance.SyncPlayerSkill(obj, skillId, targetId, obj.GetMovementStateInfo().GetFaceDir());
                     } else {
                         AiStateInfo aiInfo = obj.GetAiStateInfo();
                         aiInfo.Target = targetId;
                         if (aiInfo.AiLogic == (int)AiStateLogicId.Entity_Leader) {
                             AiData_Leader data = aiInfo.AiDatas.GetData<AiData_Leader>();
                             if (null == data) {
                                 data = new AiData_Leader();
                                 aiInfo.AiDatas.AddData(data);
                             }
                             data.ManualSkillId = skillId;
                         } else {
                             AiData_General data = aiInfo.AiDatas.GetData<AiData_General>();
                             if (null == data) {
                                 data = new AiData_General();
                                 aiInfo.AiDatas.AddData(data);
                             }
                             data.ManualSkillId = skillId;
                         }
                         aiInfo.ChangeToState((int)AiStateId.SkillCommand);
                     }
                     ret = true;
                 }
             }
         }
     }
     return ret;
 }
        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);
            }
        }
        public void SetOperateType(bool bAuto)
        {
            int        leaderID = ClientModule.Instance.LeaderID;
            EntityInfo obj      = GetEntityById(leaderID);

            if (null != obj)
            {
                if (IsRoomScene)
                {
                    Network.NetworkSystem.Instance.SyncOperateMode(bAuto);
                }
                else
                {
                    AiStateInfo   aiInfo = obj.GetAiStateInfo();
                    AiData_Leader data   = aiInfo.AiDatas.GetData <AiData_Leader>();
                    if (null == data)
                    {
                        data = new AiData_Leader();
                        aiInfo.AiDatas.AddData(data);
                    }
                    data.IsAutoOperate = bAuto;
                }
            }
        }
 public void SetOperateType(bool bAuto)
 {
     int leaderID = ClientModule.Instance.LeaderID;
     EntityInfo obj = GetEntityById(leaderID);
     if (null != obj) {
         if (IsRoomScene) {
             Network.NetworkSystem.Instance.SyncOperateMode(bAuto);
         } else {
             AiStateInfo aiInfo = obj.GetAiStateInfo();
             AiData_Leader data = aiInfo.AiDatas.GetData<AiData_Leader>();
             if (null == data) {
                 data = new AiData_Leader();
                 aiInfo.AiDatas.AddData(data);
             }
             data.IsAutoOperate = bAuto;
         }
     }
 }
 internal static void Execute(object msg, User user)
 {
     Msg_CR_Skill use_skill = msg as Msg_CR_Skill;
     if (null == use_skill)
         return;
     EntityInfo userObj = user.Info;
     if (null == userObj) {
         LogSys.Log(LOG_TYPE.DEBUG, "UseSkillHandler, charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name);
         return;
     }
     Scene scene = user.OwnRoom.ActiveScene;
     if (null != scene) {
         EntityInfo obj = scene.GetEntityById(use_skill.role_id);
         if (null != obj) {
             AiStateInfo aiInfo = obj.GetAiStateInfo();
             if (use_skill.target_id > 0) {
                 aiInfo.Target = use_skill.target_id;
             } else if (use_skill.target_dir > 0) {
                 float dir = ProtoHelper.DecodeFloat(use_skill.target_dir);
                 obj.GetMovementStateInfo().SetFaceDir(dir);
                 aiInfo.Target = 0;
             }
             if (aiInfo.AiLogic == (int)AiStateLogicId.Entity_Leader) {
                 AiData_Leader data = aiInfo.AiDatas.GetData<AiData_Leader>();
                 if (null == data) {
                     data = new AiData_Leader();
                     aiInfo.AiDatas.AddData(data);
                 }
                 data.ManualSkillId = use_skill.skill_id;
             } else {
                 AiData_General data = aiInfo.AiDatas.GetData<AiData_General>();
                 if (null == data) {
                     data = new AiData_General();
                     aiInfo.AiDatas.AddData(data);
                 }
                 data.ManualSkillId = use_skill.skill_id;
             }
             aiInfo.ChangeToState((int)AiStateId.SkillCommand);
         }
     }
 }
        internal static void Execute(object msg, User user)
        {
            Msg_CR_OperateMode modeMsg = msg as Msg_CR_OperateMode;
            if (null == modeMsg) return;
            EntityInfo userInfo = user.Info;
            if (null == userInfo) return;

            AiStateInfo aiInfo = userInfo.GetAiStateInfo();
            AiData_Leader data = aiInfo.AiDatas.GetData<AiData_Leader>();
            if (null == data) {
                data = new AiData_Leader();
                aiInfo.AiDatas.AddData(data);
            }
            data.IsAutoOperate = modeMsg.isauto;
        }
 private AiData_Leader GetAiData(EntityInfo entity)
 {
     AiData_Leader data = entity.GetAiStateInfo().AiDatas.GetData<AiData_Leader>();
     if (null == data) {
         data = new AiData_Leader();
         entity.GetAiStateInfo().AiDatas.AddData(data);
     }
     return data;
 }
        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);
        }