GetAiStateInfo() public method

public GetAiStateInfo ( ) : AiStateInfo
return AiStateInfo
        public static Msg_RC_CreateNpc BuildCreateNpcMessage(EntityInfo npc, int rate = -1)
        {
            Msg_RC_CreateNpc bder = new Msg_RC_CreateNpc();

            bder.npc_id  = npc.GetId();
            bder.unit_id = npc.GetUnitId();
            ScriptRuntime.Vector3         pos    = npc.GetMovementStateInfo().GetPosition3D();
            GameFrameworkMessage.Position pos_bd = new GameFrameworkMessage.Position();
            pos_bd.x            = (float)pos.X;
            pos_bd.z            = (float)pos.Z;
            bder.cur_pos        = pos_bd;
            bder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir();
            bder.link_id        = npc.GetTableId();
            bder.camp_id        = npc.GetCampId();
            if (npc.OwnerId > 0)
            {
                bder.owner_id = npc.OwnerId;
            }
            if (npc.GetAiStateInfo().LeaderId > 0)
            {
                bder.leader_id = npc.GetAiStateInfo().LeaderId;
            }
            User user = npc.CustomData as User;

            if (null != user)
            {
                bder.key = user.GetKey();
            }
            bder.level = npc.Level;

            return(bder);
        }
        internal static Msg_RC_CreateNpc BuildCreateNpcMessage(EntityInfo npc, int rate = -1)
        {
            Msg_RC_CreateNpc bder = new Msg_RC_CreateNpc();
            bder.npc_id = npc.GetId();
            bder.unit_id = npc.GetUnitId();
            ScriptRuntime.Vector3 pos = npc.GetMovementStateInfo().GetPosition3D();
            GameFrameworkMessage.Position pos_bd = new GameFrameworkMessage.Position();
            pos_bd.x = (float)pos.X;
            pos_bd.z = (float)pos.Z;
            bder.cur_pos = pos_bd;
            bder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir();
            bder.link_id = npc.GetLinkId();
            bder.camp_id = npc.GetCampId();
            if (npc.OwnerId > 0) {
                bder.owner_id = npc.OwnerId;
            }
            if (npc.GetAiStateInfo().LeaderID > 0) {
                bder.leader_id = npc.GetAiStateInfo().LeaderID;
            }
            User user = npc.CustomData as User;
            if (null != user) {
                bder.key = user.GetKey();
            }
            bder.level = npc.GetLevel();

            return bder;
        }
 private AiData_General GetAiData(EntityInfo entity)
 {
     AiData_General data = entity.GetAiStateInfo().AiDatas.GetData<AiData_General>();
     if (null == data) {
         data = new AiData_General();
         entity.GetAiStateInfo().AiDatas.AddData(data);
     }
     return data;
 }
        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 AiData_General GetAiData(EntityInfo entity)
        {
            AiData_General data = entity.GetAiStateInfo().AiDatas.GetData <AiData_General>();

            if (null == data)
            {
                data = new AiData_General();
                entity.GetAiStateInfo().AiDatas.AddData(data);
            }
            return(data);
        }
        private void GoHomeHandler(EntityInfo entity, long deltaTime)
        {
            AiStateInfo info = entity.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > c_IntervalTime)
            {
                info.Time = 0;
                AiData_General data = GetAiData(entity);
                if (null != data)
                {
                    Vector3 targetPos            = info.HomePos;
                    ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D();
                    float powDistToHome          = Geometry.DistanceSquare(srcPos, info.HomePos);
                    if (powDistToHome <= 1)
                    {
                        NotifyAiStopPursue(entity);
                        ChangeToState(entity, (int)AiStateId.Idle);
                    }
                    else
                    {
                        NotifyAiPursue(entity, targetPos);
                    }
                }
            }
        }
        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;
        }
        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 (!skillInfo.IsInCd(TimeUtility.GetLocalMilliseconds()))
                    {
                        int targetId = 0;
                        if (null != SelectedTarget)
                        {
                            targetId = SelectedTarget.TargetId;
                        }
                        if (!IsBattleState)
                        {
                            Network.NetworkSystem.Instance.SyncPlayerSkill(obj, skillId, targetId, obj.GetMovementStateInfo().GetFaceDir());
                        }
                        else
                        {
                            AiStateInfo aiInfo = obj.GetAiStateInfo();
                            aiInfo.Target = targetId;
                            GfxSkillSystem.Instance.StartSkill(objId, skillInfo.ConfigData, 0);
                        }
                        ret = true;
                    }
                }
            }
            return(ret);
        }
Esempio n. 9
0
        public GfxSkillSenderInfo BuildSkillInfo(int objId, TableConfig.Skill configData, int seq)
        {
            GfxSkillSenderInfo ret  = null;
            EntityViewModel    view = GetEntityViewById(objId);

            if (null != view && null != view.Actor && null != view.Entity && null != configData)
            {
                EntityInfo entity   = view.Entity;
                int        targetId = 0;
                if (configData.type == (int)SkillOrImpactType.Skill)
                {
                    targetId = entity.GetAiStateInfo().Target;
                }
                else
                {
                    ImpactInfo impactInfo = entity.GetSkillStateInfo().GetImpactInfoBySeq(seq);
                    if (null != impactInfo)
                    {
                        targetId = impactInfo.ImpactSenderId;
                    }
                }
                UnityEngine.GameObject targetObj = GetGameObject(targetId);
                if (null != targetObj)
                {
                    ret = new GfxSkillSenderInfo(configData, seq, objId, view.Actor, targetId, targetObj);
                }
                else
                {
                    ret = new GfxSkillSenderInfo(configData, seq, objId, view.Actor);
                }
            }
            return(ret);
        }
        public void SetLockTarget(int targetId)
        {
            int oldTargetId = 0;

            if (null != m_SelectedTarget)
            {
                oldTargetId = m_SelectedTarget.TargetId;
            }
            OnSelectedTargetChange(oldTargetId, targetId);
            EntityInfo target = GetEntityById(targetId);

            if (null != target)
            {
                m_SelectedTarget = new LockTargetInfo {
                    Target = target, TargetId = targetId
                };
                EntityInfo leader = GetEntityById(LeaderId);
                if (null != leader)
                {
                    AiStateInfo aiInfo = leader.GetAiStateInfo();
                    if (null != SelectedTarget)
                    {
                        aiInfo.Target = SelectedTarget.TargetId;
                    }
                }
            }
            else
            {
                m_SelectedTarget = null;
            }
        }
Esempio n. 11
0
 private void TickNpc(EntityInfo entity, long delta)
 {
     IAiStateLogic logic = AiLogicManager.Instance.GetNpcStateLogic(entity.GetAiStateInfo().AiLogic);
     if (null != logic) {
         logic.Execute(entity, delta);
     }
 }
Esempio n. 12
0
        internal GfxSkillSenderInfo BuildSkillInfo(int objId, TableConfig.Skill configData, int seq, Scene scene)
        {
            GfxSkillSenderInfo ret    = null;
            EntityInfo         entity = m_Scene.EntityManager.GetEntityInfo(objId);

            if (null != entity && null != configData)
            {
                int targetId = 0;
                if (configData.type == (int)SkillOrImpactType.Skill)
                {
                    targetId = entity.GetAiStateInfo().Target;
                }
                else
                {
                    ImpactInfo impactInfo = entity.GetSkillStateInfo().GetImpactInfoBySeq(seq);
                    if (null != impactInfo)
                    {
                        targetId = impactInfo.ImpactSenderId;
                    }
                }
                EntityInfo targetObj = m_Scene.EntityManager.GetEntityInfo(targetId);
                if (null != targetObj)
                {
                    ret = new GfxSkillSenderInfo(configData, seq, objId, entity, targetId, targetObj, scene);
                }
                else
                {
                    ret = new GfxSkillSenderInfo(configData, seq, objId, entity, scene);
                }
            }
            return(ret);
        }
 protected override void OnStateLogicInit(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time = 0;
     info.HomePos = entity.GetMovementStateInfo().GetPosition3D();
     info.Target = 0;
 }
        protected override void OnStateLogicInit(EntityInfo entity, long deltaTime)
        {
            AiStateInfo info = entity.GetAiStateInfo();

            info.Time    = 0;
            info.HomePos = entity.GetMovementStateInfo().GetPosition3D();
            info.Target  = 0;
        }
 private void DslLogicHandler(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     if (null != info.AiStoryInstanceInfo) {
         long curTime = TimeUtility.GetLocalMilliseconds();
         info.AiStoryInstanceInfo.m_StoryInstance.Tick(curTime);
     }
 }
Esempio n. 16
0
        private void TickNpc(EntityInfo entity, long delta)
        {
            IAiStateLogic logic = AiLogicManager.Instance.GetNpcStateLogic(entity.GetAiStateInfo().AiLogic);

            if (null != logic)
            {
                logic.Execute(entity, delta);
            }
        }
        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);
                }
            }
        }
 private void IdleHandler(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time += deltaTime;
     if (info.Time > 100) {
         info.Time = 0;
         ChangeToState(entity, (int)AiStateId.DslLogic);
     }
 }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated()) {
                return;
            }

            AiStateInfo info = npc.GetAiStateInfo();
            Vector3 targetPos = info.HomePos;
            ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
            float distSqrToHome = Geometry.DistanceSquare(srcPos, info.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), true);
            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) //视野范围内找到可攻击目标
            {
                NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
                return;
            }

            currSkInfo.SetCurSkillInfo(0);
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.GoHome);
        }
        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 DslLogicHandler(EntityInfo entity, long deltaTime)
        {
            AiStateInfo info = entity.GetAiStateInfo();

            if (null != info.AiStoryInstanceInfo)
            {
                long curTime = TimeUtility.GetLocalMilliseconds();
                info.AiStoryInstanceInfo.m_StoryInstance.Tick(curTime);
            }
        }
        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);
        }
        private void IdleHandler(EntityInfo entity, long deltaTime)
        {
            AiStateInfo info = entity.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                ChangeToState(entity, (int)AiStateId.DslLogic);
            }
        }
        private void DetachAiLogic(EntityInfo npc)
        {
            var aiStateInfo = npc.GetAiStateInfo();
            var aiStoryInfo = aiStateInfo.AiStoryInstanceInfo;

            if (null != aiStoryInfo)
            {
                aiStoryInfo.Recycle();
                aiStateInfo.AiStoryInstanceInfo = null;
            }
        }
 protected override bool OnStateLogicCheck(EntityInfo entity, long deltaTime)
 {
     if (entity.IsDead()) {
         if (entity.GetAiStateInfo().CurState != (int)AiStateId.Idle) {
             NotifyAiStopPursue(entity);
             ChangeToState(entity, (int)AiStateId.Idle);
         }
         return false;
     }
     return true;
 }
        private void OnAiDestroy(EntityInfo npc)
        {
            m_EntitiesForAi.Remove(npc);
            var aiStateInfo = npc.GetAiStateInfo();
            var aiStoryInfo = aiStateInfo.AiStoryInstanceInfo;

            if (null != aiStoryInfo)
            {
                aiStoryInfo.Recycle();
                aiStateInfo.AiStoryInstanceInfo = null;
            }
        }
 protected override bool OnStateLogicCheck(EntityInfo entity, long deltaTime)
 {
     if (entity.IsDead())
     {
         if (entity.GetAiStateInfo().CurState != (int)AiStateId.Idle)
         {
             NotifyAiStopPursue(entity);
             ChangeToState(entity, (int)AiStateId.Idle);
         }
         return(false);
     }
     return(true);
 }
        private bool IsLeaderDead(EntityInfo entity)
        {
            bool           ret    = true;
            AiStateInfo    info   = entity.GetAiStateInfo();
            AiData_General data   = GetAiData(entity);
            EntityInfo     leader = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.LeaderID);

            if (null != leader)
            {
                ret = leader.IsDead();
            }
            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);
        }
        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);
        }
        internal static Msg_RC_NpcSkill BuildNpcSkillMessage(EntityInfo obj, int skillId)
        {
            MovementStateInfo msi = obj.GetMovementStateInfo();
            ScriptRuntime.Vector3 pos = msi.GetPosition3D();

            Msg_RC_NpcSkill msg = new Msg_RC_NpcSkill();
            msg.npc_id = obj.GetId();
            msg.skill_id = skillId;
            msg.stand_pos = ProtoHelper.EncodePosition2D(pos.X, pos.Z);
            msg.face_direction = ProtoHelper.EncodeFloat(msi.GetFaceDir());
            msg.target_id = obj.GetAiStateInfo().Target;

            return msg;
        }
 private void OnAiInitDslLogic(EntityInfo entity)
 {
     AiStateInfo aiInfo = entity.GetAiStateInfo();
     if (aiInfo.AiParam.Length >= 2) {
         string storyId = aiInfo.AiParam[0];
         string storyFile = aiInfo.AiParam[1];
         if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile)) {
             aiInfo.AiStoryInstanceInfo = GfxStorySystem.Instance.NewAiStoryInstance(storyId, string.Empty, storyFile);
             if (null != aiInfo.AiStoryInstanceInfo) {
                 aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", entity.GetId());
                 aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start();
             }
         }
     }
 }
 protected override bool OnStateLogicCheck(EntityInfo entity, long deltaTime)
 {
     if (entity.IsDead()) {
         if (entity.GetAiStateInfo().CurState != (int)AiStateId.Idle) {
             NotifyAiStopPursue(entity);
             ChangeToState(entity, (int)AiStateId.Idle);
         }
         return false;
     }
     if (IsLeaderDead(entity)) {
         entity.SetHp(Operate_Type.OT_Absolute, 0);
         return false;
     }
     return true;
 }
        public static Msg_RC_NpcSkill BuildNpcSkillMessage(EntityInfo obj, int skillId)
        {
            MovementStateInfo msi = obj.GetMovementStateInfo();

            ScriptRuntime.Vector3 pos = msi.GetPosition3D();

            Msg_RC_NpcSkill msg = new Msg_RC_NpcSkill();

            msg.npc_id         = obj.GetId();
            msg.skill_id       = skillId;
            msg.stand_pos      = ToPosition(pos.X, pos.Z);
            msg.face_direction = msi.GetFaceDir();
            msg.target_id      = obj.GetAiStateInfo().Target;

            return(msg);
        }
        public 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();
        }
 protected override bool OnStateLogicCheck(EntityInfo entity, long deltaTime)
 {
     if (entity.IsDead())
     {
         if (entity.GetAiStateInfo().CurState != (int)AiStateId.Idle)
         {
             NotifyAiStopPursue(entity);
             ChangeToState(entity, (int)AiStateId.Idle);
         }
         return(false);
     }
     if (IsLeaderDead(entity))
     {
         entity.SetHp(Operate_Type.OT_Absolute, 0);
         return(false);
     }
     return(true);
 }
        private void AttachAiLogic(EntityInfo npc)
        {
            AiStateInfo aiInfo    = npc.GetAiStateInfo();
            string      storyId   = aiInfo.AiLogic;
            string      storyFile = aiInfo.AiParam[0];

            if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile))
            {
                aiInfo.HomePos = npc.GetMovementStateInfo().GetPosition3D();
                aiInfo.ChangeToState((int)PredefinedAiStateId.Idle);
                aiInfo.AiStoryInstanceInfo = GfxStorySystem.Instance.NewAiStoryInstance(storyId, string.Empty, storyFile);
                if (null != aiInfo.AiStoryInstanceInfo)
                {
                    aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", npc.GetId());
                    aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start();
                }
            }
        }
        internal static void DoMoveCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(entity);

            if (null == data)
            {
                return;
            }

            if (!data.IsFinish)
            {
                if (WayPointArrived(entity, data))
                {
                    Vector3 targetPos = new Vector3();
                    MoveToNext(entity, data, ref targetPos);
                    if (!data.IsFinish)
                    {
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                }
                else
                {
                    AiStateInfo info = entity.GetAiStateInfo();
                    info.Time += deltaTime;
                    if (info.Time > 500)
                    {
                        info.Time = 0;
                        Vector3 targetPos = data.WayPoints[data.Index];
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                }
            }

            //判断是否状态结束并执行相应处理
            if (data.IsFinish)
            {
                logic.AiSendStoryMessage(entity, "npc_arrived:" + entity.GetUnitId(), entity.GetId());
                logic.AiSendStoryMessage(entity, "obj_arrived", entity.GetId());
                logic.NotifyAiStopPursue(entity);
                logic.ChangeToState(entity, (int)AiStateId.Idle);
            }
        }
        private void OnAiInitDslLogic(EntityInfo entity)
        {
            AiStateInfo aiInfo = entity.GetAiStateInfo();

            if (aiInfo.AiParam.Length >= 2)
            {
                string storyId   = aiInfo.AiParam[0];
                string storyFile = aiInfo.AiParam[1];
                if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile))
                {
                    aiInfo.AiStoryInstanceInfo = GfxStorySystem.Instance.NewAiStoryInstance(storyId, string.Empty, storyFile);
                    if (null != aiInfo.AiStoryInstanceInfo)
                    {
                        aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", entity.GetId());
                        aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start();
                    }
                }
            }
        }
        private static void DoMoveCommandState(EntityInfo npc, long deltaTime)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(npc);

            if (null == data)
            {
                return;
            }

            if (!data.IsFinish)
            {
                if (WayPointArrived(npc, data))
                {
                    ScriptRuntime.Vector3 targetPos = new ScriptRuntime.Vector3();
                    MoveToNext(npc, data, ref targetPos);
                    if (!data.IsFinish)
                    {
                        AiPursue(npc, targetPos);
                    }
                }
                else
                {
                    ScriptRuntime.Vector3 targetPos = data.WayPoints[data.Index];
                    AiPursue(npc, targetPos);
                }
            }

            //判断是否状态结束并执行相应处理
            if (data.IsFinish)
            {
                Scene scene = npc.SceneContext.CustomData as Scene;
                if (null != scene)
                {
                    scene.StorySystem.SendMessage("npcarrived:" + npc.GetUnitId(), npc.GetId());
                    scene.StorySystem.SendMessage("objarrived", npc.GetId());
                }
                AiStopPursue(npc);
                npc.GetAiStateInfo().ChangeToState((int)PredefinedAiStateId.Idle);
            }
        }
 internal static void DoSkillCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic, int skillId)
 {
     if (entity.GetMovementStateInfo().IsMoving)
     {
         logic.NotifyAiStopPursue(entity);
     }
     if (skillId > 0)
     {
         AiStateInfo aiInfo    = entity.GetAiStateInfo();
         SkillInfo   skillInfo = entity.GetSkillStateInfo().GetSkillInfoById(skillId);
         if (null != skillInfo)
         {
             if (aiInfo.Target <= 0)
             {
                 EntityInfo info;
                 if (skillInfo.ConfigData.targetType == (int)SkillTargetType.Enemy || skillInfo.ConfigData.targetType == (int)SkillTargetType.RandEnemy)
                 {
                     info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY);
                 }
                 else
                 {
                     info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_FRIEND);
                 }
                 if (null != info)
                 {
                     aiInfo.Target = info.GetId();
                 }
             }
             if (aiInfo.Target > 0)
             {
                 logic.NotifyAiSkill(entity, skillId);
             }
         }
     }
     else if (!entity.GetSkillStateInfo().IsSkillActivated())
     {
         logic.AiSendStoryMessage(entity, "npc_skill_finish:" + entity.GetUnitId(), entity.GetId());
         logic.AiSendStoryMessage(entity, "obj_skill_finish", entity.GetId());
         logic.ChangeToState(entity, (int)AiStateId.Idle);
     }
 }
        internal static void DoPursuitCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic)
        {
            AiStateInfo info = entity.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 200)
            {
                EntityInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.Target);
                if (null != target)
                {
                    float   minDist              = entity.GetRadius() + target.GetRadius();
                    float   dist                 = (float)entity.GetActualProperty().AttackRange + minDist;
                    float   distGoHome           = entity.GohomeRange;
                    Vector3 targetPos            = target.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D();
                    float dir = Geometry.GetYRadian(new Vector2(targetPos.X, targetPos.Z), new Vector2(srcPos.X, srcPos.Z));
                    targetPos.X += (float)(minDist * Math.Sin(dir));
                    targetPos.Z += (float)(minDist * Math.Cos(dir));
                    float powDist = Geometry.DistanceSquare(srcPos, targetPos);
                    if (powDist < dist * dist)
                    {
                        logic.AiSendStoryMessage(entity, "npc_pursuit_finish:" + entity.GetUnitId(), entity.GetId());
                        logic.AiSendStoryMessage(entity, "obj_pursuit_finish", entity.GetId());
                        logic.NotifyAiStopPursue(entity);
                        logic.ChangeToState(entity, (int)AiStateId.Idle);
                    }
                    else
                    {
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                }
                else
                {
                    logic.AiSendStoryMessage(entity, "npc_pursuit_exit:" + entity.GetUnitId(), entity.GetId());
                    logic.AiSendStoryMessage(entity, "obj_pursuit_exit", entity.GetId());
                    logic.NotifyAiStopPursue(entity);
                    logic.ChangeToState(entity, (int)AiStateId.Idle);
                }
            }
        }
 private void GoHomeHandler(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time += deltaTime;
     if (info.Time > c_IntervalTime) {
         info.Time = 0;
         AiData_General data = GetAiData(entity);
         if (null != data) {
             Vector3 targetPos = info.HomePos;
             ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D();
             float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
             if (powDistToHome <= 1) {
                 NotifyAiStopPursue(entity);
                 ChangeToState(entity, (int)AiStateId.Idle);
             } else {
                 NotifyAiPursue(entity, targetPos);
             }
         }
     }
 }
 internal static void DoPursuitCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time += deltaTime;
     if (info.Time > 200) {
         EntityInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.Target);
         if (null != target) {
             float minDist = entity.GetRadius() + target.GetRadius();
             float dist = (float)entity.GetActualProperty().AttackRange + minDist;
             float distGoHome = entity.GohomeRange;
             Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
             ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D();
             float dir = Geometry.GetYRadian(new Vector2(targetPos.X, targetPos.Z), new Vector2(srcPos.X, srcPos.Z));
             targetPos.X += (float)(minDist * Math.Sin(dir));
             targetPos.Z += (float)(minDist * Math.Cos(dir));
             float powDist = Geometry.DistanceSquare(srcPos, targetPos);
             if (powDist < dist * dist) {
                 logic.AiSendStoryMessage(entity, "npc_pursuit_finish:" + entity.GetUnitId(), entity.GetId());
                 logic.AiSendStoryMessage(entity, "obj_pursuit_finish", entity.GetId());
                 logic.NotifyAiStopPursue(entity);
                 logic.ChangeToState(entity, (int)AiStateId.Idle);
             } else {
                 logic.NotifyAiPursue(entity, targetPos);
             }
         } else {
             logic.AiSendStoryMessage(entity, "npc_pursuit_exit:" + entity.GetUnitId(), entity.GetId());
             logic.AiSendStoryMessage(entity, "obj_pursuit_exit", entity.GetId());
             logic.NotifyAiStopPursue(entity);
             logic.ChangeToState(entity, (int)AiStateId.Idle);
         }
     }
 }
Esempio n. 45
0
 public void PopState(EntityInfo entity)
 {
     entity.GetAiStateInfo().PopState();
 }
 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 bool IsLeaderDead(EntityInfo entity)
 {
     bool ret = true;
     AiStateInfo info = entity.GetAiStateInfo();
     AiData_General data = GetAiData(entity);
     EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.LeaderID);
     if (null != leader) {
         ret = leader.IsDead();
     }
     return ret;
 }
Esempio n. 48
0
 public void PushState(EntityInfo entity, int state)
 {
     entity.GetAiStateInfo().PushState(state);
 }
Esempio n. 49
0
 public void Execute(EntityInfo entity, long deltaTime)
 {
     if (entity.IsUnderControl()) {
         return;
     }
     if (entity.GetAIEnable()) {
         AiStateInfo npcAi = entity.GetAiStateInfo();
         if (!npcAi.IsInited) {
             OnStateLogicInit(entity, deltaTime);
             npcAi.IsInited = true;
         }
         int curState = npcAi.CurState;
         if (curState > (int)AiStateId.Invalid && curState < (int)AiStateId.MaxNum) {
             AiStateHandler handler;
             if (m_Handlers.TryGetValue(curState, out handler)) {
                 if (OnStateLogicCheck(entity, deltaTime) && null != handler) {
                     handler(entity, deltaTime);
                 }
             } else {
                 LogSystem.Error("Illegal ai state: " + curState + " entity:" + entity.GetId());
             }
         } else {
             ChangeToState(entity, (int)AiStateId.Idle);
         }
     }
 }
Esempio n. 50
0
 public void ChangeToState(EntityInfo entity, int state)
 {
     entity.GetAiStateInfo().ChangeToState(state);
 }
 internal static void DoSkillCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic, int skillId)
 {
     if (entity.GetMovementStateInfo().IsMoving) {
         logic.NotifyAiStopPursue(entity);
     }
     if (skillId > 0) {
         AiStateInfo aiInfo = entity.GetAiStateInfo();
         SkillInfo skillInfo = entity.GetSkillStateInfo().GetSkillInfoById(skillId);
         if (null != skillInfo) {
             if (aiInfo.Target <= 0) {
                 EntityInfo info;
                 if (skillInfo.ConfigData.targetType == (int)SkillTargetType.Enemy || skillInfo.ConfigData.targetType == (int)SkillTargetType.RandEnemy) {
                     info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY);
                 } else {
                     info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_FRIEND);
                 }
                 if (null != info) {
                     aiInfo.Target = info.GetId();
                 }
             }
             if (aiInfo.Target > 0) {
                 logic.NotifyAiSkill(entity, skillId);
             }
         }
     } else if(!entity.GetSkillStateInfo().IsSkillActivated()) {
         logic.AiSendStoryMessage(entity, "npc_skill_finish:" + entity.GetUnitId(), entity.GetId());
         logic.AiSendStoryMessage(entity, "obj_skill_finish", entity.GetId());
         logic.ChangeToState(entity, (int)AiStateId.Idle);
     }
 }
 private static AiData_ForPatrolCommand GetAiDataForPatrolCommand(EntityInfo entity)
 {
     AiData_ForPatrolCommand data = entity.GetAiStateInfo().AiDatas.GetData<AiData_ForPatrolCommand>();
     return data;
 }
 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;
 }
 internal static void DoPatrolCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time += deltaTime;
     if (info.Time > 100) {
         info.Time = 0;
         EntityInfo target = null;
         if (info.IsExternalTarget) {
             target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(entity, info.Target);
             if (null == target) {
                 target = AiLogicUtility.GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY);
                 if (null != target)
                     info.Target = target.GetId();
             }
         } else {
             target = AiLogicUtility.GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY);
             if (null != target)
                 info.Target = target.GetId();
         }
         if (null != target) {
             logic.AiSendStoryMessage(entity, "obj_patrol_exit", entity.GetId());
             logic.AiSendStoryMessage(entity, string.Format("npc_patrol_exit:{0}", entity.GetUnitId()), entity.GetId());
             logic.ChangeToState(entity, (int)AiStateId.Idle);
         } else {
             AiData_ForPatrolCommand data = GetAiDataForPatrolCommand(entity);
             if (null != data) {
                 ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D();
                 if (data.PatrolPath.HavePathPoint && !data.PatrolPath.IsReached(srcPos)) {
                     logic.NotifyAiPursue(entity, data.PatrolPath.CurPathPoint);
                 } else {
                     data.PatrolPath.UseNextPathPoint();
                     if (data.PatrolPath.HavePathPoint) {
                         logic.NotifyAiPursue(entity, data.PatrolPath.CurPathPoint);
                     } else {
                         if (data.IsLoopPatrol) {
                             logic.AiSendStoryMessage(entity, "obj_patrol_restart", entity.GetId());
                             logic.AiSendStoryMessage(entity, string.Format("npc_patrol_restart:{0}", entity.GetUnitId()), entity.GetId());
                             data.PatrolPath.Restart();
                         } else {
                             logic.AiSendStoryMessage(entity, "obj_patrol_finish", entity.GetId());
                             logic.AiSendStoryMessage(entity, string.Format("npc_patrol_finish:{0}", entity.GetUnitId()), entity.GetId());
                             logic.NotifyAiStopPursue(entity);
                             logic.ChangeToState(entity, (int)AiStateId.Idle);
                         }
                     }
                 }
                 info.HomePos = entity.GetMovementStateInfo().GetPosition3D();
             } else {
                 logic.NotifyAiStopPursue(entity);
                 logic.ChangeToState(entity, (int)AiStateId.Idle);
             }
         }
     }
 }
        internal static void DoMoveCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic)
        {
            //执行状态处理
            AiData_ForMoveCommand data = GetAiDataForMoveCommand(entity);
            if (null == data) return;

            if (!data.IsFinish) {
                if (WayPointArrived(entity, data)) {
                    Vector3 targetPos = new Vector3();
                    MoveToNext(entity, data, ref targetPos);
                    if (!data.IsFinish) {
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                } else {
                    AiStateInfo info = entity.GetAiStateInfo();
                    info.Time += deltaTime;
                    if (info.Time > 500) {
                        info.Time = 0;
                        Vector3 targetPos = data.WayPoints[data.Index];
                        logic.NotifyAiPursue(entity, targetPos);
                    }
                }
            }

            //判断是否状态结束并执行相应处理
            if (data.IsFinish) {
                logic.AiSendStoryMessage(entity, "npc_arrived:" + entity.GetUnitId(), entity.GetId());
                logic.AiSendStoryMessage(entity, "obj_arrived", entity.GetId());
                logic.NotifyAiStopPursue(entity);
                logic.ChangeToState(entity, (int)AiStateId.Idle);
            }
        }
 private void GoHomeHandler(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time += deltaTime;
     if (info.Time > c_IntervalTime) {
         info.Time = 0;
         AiData_General data = GetAiData(entity);
         if (null != data) {
             EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.LeaderID);
             if (null != leader) {
                 float minDist = entity.GetRadius() + leader.GetRadius();
                 Vector3 targetPos = GetHomePos(entity.GetMovementStateInfo().FormationIndex, leader);
                 ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D();
                 float powDistToHome = Geometry.DistanceSquare(srcPos, targetPos);
                 if (powDistToHome <= (minDist + 1) * (minDist + 1)) {
                     NotifyAiStopPursue(entity);
                     ChangeToState(entity, (int)AiStateId.Idle);
                 } else {
                     NotifyAiPursue(entity, targetPos);
                 }
             } else {
                 NotifyAiStopPursue(entity);
                 ChangeToState(entity, (int)AiStateId.Idle);
             }
         }
     }
 }
 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;
 }