GetUnitId() public method

public GetUnitId ( ) : int
return int
        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);
        }
 private void OnCreateEntity(EntityInfo entity)
 {
     if (null != entity) {
     StorySystem.SendMessage("obj_created", entity.GetId());
     StorySystem.SendMessage(string.Format("npc_created:{0}", entity.GetUnitId()), entity.GetId());
     }
 }
        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;
        }
Exemplo n.º 4
0
        private void OnEntityKilled(EntityInfo ni)
        {
            int leftEnemyCt  = GetBattleNpcCount((int)CampIdEnum.Blue, CharacterRelation.RELATION_ENEMY);
            int leftFriendCt = GetBattleNpcCount((int)CampIdEnum.Blue);

            m_StorySystem.SendMessage("obj_killed", ni.GetId(), leftEnemyCt, leftFriendCt);
            m_StorySystem.SendMessage("npc_killed:" + ni.GetUnitId(), ni.GetId(), leftEnemyCt, leftFriendCt);
        }
Exemplo n.º 5
0
 private void OnCreateEntity(EntityInfo entity)
 {
     if (null != entity)
     {
         StorySystem.SendMessage("obj_created", entity.GetId());
         StorySystem.SendMessage(string.Format("npc_created:{0}", entity.GetUnitId()), entity.GetId());
     }
 }
Exemplo n.º 6
0
 public void NotifyAiMeetEnemy(EntityInfo entity)
 {
     if (null != OnAiMeetEnemy)
     {
         OnAiMeetEnemy(entity);
     }
     AiSendStoryMessage(entity, "obj_meet_enemy", entity.GetId());
     AiSendStoryMessage(entity, "npc_meet_enemy:" + entity.GetUnitId(), entity.GetId());
 }
        public int ObjId2UnitId(int actorId)
        {
            int        id     = 0;
            EntityInfo entity = GetEntityById(actorId);

            if (null != entity)
            {
                id = entity.GetUnitId();
            }
            return(id);
        }
Exemplo n.º 8
0
        private void OnCreateEntity(EntityInfo entity)
        {
            if (null != entity)
            {
                GfxStorySystem.Instance.SendMessage("obj_created", entity.GetId());
                GfxStorySystem.Instance.SendMessage(string.Format("npc_created:{0}", entity.GetUnitId()), entity.GetId());

                bool isGreen = CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation(entity.GetCampId(), CampId);
                Utility.EventSystem.Publish("ui_add_actor", "ui", entity.GetId(), isGreen, entity.ConfigData);
            }
        }
Exemplo n.º 9
0
        private void OnEntityKilled(EntityInfo ni)
        {
            if (ni.GetMovementStateInfo().IsMoving)
            {
                ni.GetMovementStateInfo().IsMoving = false;
            }
            int leftEnemyCt  = GetBattleNpcCount(CampId, CharacterRelation.RELATION_ENEMY);
            int leftFriendCt = GetBattleNpcCount(CampId);

            GfxStorySystem.Instance.SendMessage("obj_killed", ni.GetId(), leftEnemyCt, leftFriendCt);
            GfxStorySystem.Instance.SendMessage("npc_killed:" + ni.GetUnitId(), ni.GetId(), leftEnemyCt, leftFriendCt);
        }
Exemplo n.º 10
0
        internal void LeaveScene(User user)
        {
            EntityInfo info = user.Info;

            RemoveCareList(info);
            m_StorySystem.SendMessage("user_leave_scene", info.GetId(), info.GetUnitId(), info.GetCampId(), info.GetMovementStateInfo().PositionX, info.GetMovementStateInfo().PositionZ);
            user.SetHpArmor(info.Hp, info.Energy);
            user.HaveEnterPosition = false;
            user.IsEntered         = false;
            info.NeedDelete        = true;
            user.Info = null;
        }
        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);
                }
            }
        }
Exemplo n.º 12
0
        public EntityInfo GetEntityInfoByUnitId(int id)
        {
            EntityInfo entity = null;

            for (LinkedListNode <EntityInfo> linkNode = m_Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (info.GetUnitId() == id)
                {
                    entity = info;
                    break;
                }
            }
            return(entity);
        }
Exemplo n.º 13
0
        internal int GetNpcCount(int startUnitId, int endUnitId)
        {
            int ct = 0;

            for (LinkedListNode <EntityInfo> linkNode = m_EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (null != info && !info.IsDead())
                {
                    int unitId = info.GetUnitId();
                    if (unitId >= startUnitId && unitId <= endUnitId)
                    {
                        ++ct;
                    }
                }
            }
            return(ct);
        }
Exemplo n.º 14
0
        public void EnterScene(User newUser)
        {
            Msg_LR_RoomUserInfo lobbyUserData = newUser.LobbyUserData;

            if (null == lobbyUserData)
            {
                return;
            }
            TableConfig.Actor cfg  = TableConfig.ActorProvider.Instance.GetActor(lobbyUserData.Hero);
            EntityInfo        info = m_EntityMgr.AddEntity(0, lobbyUserData.Camp, cfg, string.Empty);

            info.SetUnitId(EntityInfo.c_StartUserUnitId + info.GetId());
            info.GetMovementStateInfo().FormationIndex = 0;
            if (null != m_SceneConfig)
            {
                info.GetMovementStateInfo().SetPosition2D(m_SceneConfig.EnterX + (Helper.Random.NextFloat() - 0.5f) * m_SceneConfig.EnterRadius, m_SceneConfig.EnterY + (Helper.Random.NextFloat() - 0.5f) * m_SceneConfig.EnterRadius);
            }
            newUser.Info = info;

            AttrCalculator.Calc(info);
            if (newUser.HaveHpArmor)
            {
                info.Hp     = newUser.Hp;
                info.Energy = newUser.Energy;
            }
            else
            {
                info.Hp     = newUser.Info.HpMax;
                info.Energy = newUser.Info.EnergyMax;
            }

            info.SceneContext = m_SceneContext;
            AddCareList(info);
            if (newUser.IsEntered)
            {
                var args = m_StorySystem.NewBoxedValueList();
                args.Add(info.GetId());
                args.Add(info.GetUnitId());
                args.Add(info.GetCampId());
                args.Add(info.GetMovementStateInfo().PositionX);
                args.Add(info.GetMovementStateInfo().PositionZ);
                m_StorySystem.SendMessage("user_enter_scene", args);
            }
        }
        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);
            }
        }
 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 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);
            }
        }
Exemplo n.º 18
0
        public void LeaveScene(User user)
        {
            user.HaveEnterPosition = false;
            user.IsEntered         = false;
            EntityInfo info = user.Info;

            if (null != info)
            {
                RemoveCareList(info);
                var args = m_StorySystem.NewBoxedValueList();
                args.Add(info.GetId());
                args.Add(info.GetUnitId());
                args.Add(info.GetCampId());
                args.Add(info.GetMovementStateInfo().PositionX);
                args.Add(info.GetMovementStateInfo().PositionZ);
                m_StorySystem.SendMessage("user_leave_scene", args);
                user.SetHpArmor(info.Hp, info.Energy);
                info.NeedDelete = true;
                user.Info       = null;
            }
        }
        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)
            {
                if (!string.IsNullOrEmpty(data.Event))
                {
                    GfxStorySystem.Instance.SendMessage(data.Event, npc.GetId(), npc.GetUnitId());
                }
                AiStopPursue(npc);
                npc.GetAiStateInfo().ChangeToState((int)PredefinedAiStateId.Idle);
            }
        }
Exemplo n.º 20
0
        internal void EnterScene(User newUser)
        {
            Msg_LR_RoomUserInfo lobbyUserData = newUser.LobbyUserData;

            if (null == lobbyUserData)
            {
                return;
            }
            TableConfig.Actor cfg  = TableConfig.ActorProvider.Instance.GetActor(lobbyUserData.Hero);
            EntityInfo        info = m_EntityMgr.AddEntity(0, lobbyUserData.Camp, cfg, (int)AiStateLogicId.Entity_Leader);

            info.SetUnitId(EntityInfo.c_StartUserUnitId + info.GetId());
            info.GetMovementStateInfo().FormationIndex = 0;
            if (null != m_SceneConfig)
            {
                info.GetMovementStateInfo().SetPosition2D(m_SceneConfig.EnterX + (Helper.Random.NextFloat() - 0.5f) * m_SceneConfig.EnterRadius, m_SceneConfig.EnterY + (Helper.Random.NextFloat() - 0.5f) * m_SceneConfig.EnterRadius);
            }
            newUser.Info = info;

            AttrCalculator.Calc(info);
            if (newUser.HaveHpArmor)
            {
                info.SetHp(Operate_Type.OT_Absolute, newUser.Hp);
                info.SetEnergy(Operate_Type.OT_Absolute, newUser.Energy);
            }
            else
            {
                info.SetHp(Operate_Type.OT_Absolute, newUser.Info.GetActualProperty().HpMax);
                info.SetEnergy(Operate_Type.OT_Absolute, newUser.Info.GetActualProperty().EnergyMax);
            }

            info.SceneContext = m_SceneContext;
            AddCareList(info);
            if (newUser.IsEntered)
            {
                m_StorySystem.SendMessage("user_enter_scene", info.GetId(), info.GetUnitId(), info.GetCampId(), info.GetMovementStateInfo().PositionX, info.GetMovementStateInfo().PositionZ);
            }
        }
Exemplo n.º 21
0
        public static void Execute(object msg, User user)
        {
            Msg_CR_Enter enter_msg = msg as Msg_CR_Enter;

            if (enter_msg == null)
            {
                return;
            }
            LogSys.Log(LOG_TYPE.DEBUG, "user {0}({1},{2},{3}) enter.", user.RoleId, user.GetKey(), user.Guid, user.Name);
            user.UserControlState = (int)UserControlState.User;
            user.IsEntered        = true;

            RoomUserManager roomUserMgr = user.OwnRoomUserManager;

            if (null != roomUserMgr)
            {
                Scene scene = roomUserMgr.ActiveScene;
                if (null != scene)
                {
                    EntityInfo userInfo = user.Info;
                    if (null != userInfo)
                    {
                        if (scene.SceneState == SceneState.Running)
                        {
                            scene.SyncForNewUser(user);
                            var args = scene.StorySystem.NewBoxedValueList();
                            args.Add(userInfo.GetId());
                            args.Add(userInfo.GetUnitId());
                            args.Add(userInfo.GetCampId());
                            args.Add(userInfo.GetMovementStateInfo().PositionX);
                            args.Add(userInfo.GetMovementStateInfo().PositionZ);
                            scene.StorySystem.SendMessage("user_enter_scene", args);
                        }
                    }
                }
            }
        }
 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);
     }
 }
Exemplo n.º 23
0
        private void OnEntityKilled(EntityInfo ni)
        {
            int leftEnemyCt = GetBattleNpcCount((int)CampIdEnum.Blue, CharacterRelation.RELATION_ENEMY);
            int leftFriendCt = GetBattleNpcCount((int)CampIdEnum.Blue);

            m_StorySystem.SendMessage("obj_killed", ni.GetId(), leftEnemyCt, leftFriendCt);
            m_StorySystem.SendMessage("npc_killed:" + ni.GetUnitId(), ni.GetId(), leftEnemyCt, leftFriendCt);
        }
 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);
         }
     }
 }
 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);
            }
        }
        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);
                    }
                }
            }
        }
Exemplo n.º 28
0
 public void NotifyAiMeetEnemy(EntityInfo entity)
 {
     if (null != OnAiMeetEnemy) {
         OnAiMeetEnemy(entity);
     }
     AiSendStoryMessage(entity, "obj_meet_enemy", entity.GetId());
     AiSendStoryMessage(entity, "npc_meet_enemy:" + entity.GetUnitId(), entity.GetId());
 }