private void MoveHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                return;
            }
            UserAiStateInfo         info = user.GetAiStateInfo();
            AiData_UserSelf_General data = GetAiData(user);
            Vector3 targetPos            = info.TargetPos;

            ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D();

            if (null != data && !IsReached(srcPos, targetPos))
            {
                if (info.IsTargetPosChanged)
                {
                    info.IsTargetPosChanged = false;
                    data.FoundPath.Clear();
                }
                PathToTarget(user, data.FoundPath, targetPos, deltaTime);
            }
            else
            {
                user.GetMovementStateInfo().StopMove();
                NotifyUserMove(user);
                info.Time = 0;
                data.Time = 0;
                data.FoundPath.Clear();
                ChangeToState(user, (int)AiStateId.Idle);
            }
        }
Beispiel #2
0
        internal static void Execute(object msg, User user)
        {
            Msg_CRC_MoveMeetObstacle obstacle_msg = msg as Msg_CRC_MoveMeetObstacle;

            if (null == obstacle_msg)
            {
                return;
            }
            UserInfo userInfo = user.Info;

            if (userInfo != null)
            {
                MovementStateInfo msi = userInfo.GetMovementStateInfo();
                userInfo.GetMovementStateInfo().IsMoveMeetObstacle = true;

                if (!msi.IsSkillMoving)
                {
                    float x        = obstacle_msg.cur_pos_x;
                    float z        = obstacle_msg.cur_pos_z;
                    float velocity = (float)user.Info.GetActualProperty().MoveSpeed;
                    if (!user.VerifyPosition(x, z, velocity, obstacle_msg.send_time, 4.0f))
                    {
                        //todo:记录违规次数
                    }
                    msi.SetPosition2D(x, z);

                    user.SampleMoveData(obstacle_msg.cur_pos_x, obstacle_msg.cur_pos_z, velocity, msi.MoveDirCosAngle, msi.MoveDirSinAngle, obstacle_msg.send_time);
                }

                //LogSys.Log(LOG_TYPE.DEBUG, "MoveMeetObstacleHandler User:{0} isskillmoving:{1} ismovemeetobstacle:{2} time:{3} client time:{4}", user.RoleId, msi.IsSkillMoving, msi.IsMoveMeetObstacle, TimeUtility.GetServerMilliseconds(), obstacle_msg.send_time);
            }
        }
        private void OnUserSkill(UserInfo user, int skillId)
        {
            Scene scene = user.SceneContext.CustomData as Scene;

            if (null != scene)
            {
                SkillInfo skillInfo = user.GetSkillStateInfo().GetCurSkillInfo();
                if (null == skillInfo || !skillInfo.IsSkillActivated)
                {
                    scene.SkillSystem.StartSkill(user.GetId(), skillId);

                    Msg_CRC_Skill skillBuilder = new Msg_CRC_Skill();
                    skillBuilder.role_id  = user.GetId();
                    skillBuilder.skill_id = skillId;
                    ArkCrossEngineMessage.Position posBuilder1 = new ArkCrossEngineMessage.Position();
                    posBuilder1.x               = user.GetMovementStateInfo().GetPosition3D().X;
                    posBuilder1.z               = user.GetMovementStateInfo().GetPosition3D().Z;
                    skillBuilder.stand_pos      = posBuilder1;
                    skillBuilder.face_direction = (float)user.GetMovementStateInfo().GetFaceDir();
                    skillBuilder.want_face_dir  = (float)user.GetMovementStateInfo().GetFaceDir();

                    LogSystem.Debug("Send Msg_CRC_Skill, EntityId={0}, SkillId={1}",
                                    user.GetId(), skillId);
                    scene.NotifyAreaUser(user, skillBuilder, false);
                }
            }
        }
Beispiel #4
0
 private void UpdateTowards(UserInfo playerself, float towards)
 {
     if (null != playerself && float.NegativeInfinity != towards)
     {
         playerself.GetMovementStateInfo().SetFaceDir(towards);
         playerself.GetMovementStateInfo().SetMoveDir(towards);
     }
 }
        protected override void OnStateLogicInit(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            UserAiStateInfo info = user.GetAiStateInfo();

            info.HomePos = user.GetMovementStateInfo().GetPosition3D();
            info.Time    = 0;
            user.GetMovementStateInfo().IsMoving = false;
        }
Beispiel #6
0
        private void LoadObjects()
        {
            m_SceneState = SceneState.Running;
            LogSys.Log(LOG_TYPE.DEBUG, "Scene {0} start Running.", m_SceneResId);
            // TODO: m_GameStartTime should be set when game of this scene
            // is really started
            m_GameTime.Start();
            m_SceneContext.StartTime = m_GameTime.StartTime;
            Room room = GetRoom();

            if (null != room && null != m_MapData)
            {
                MyDictionary <int, object> units = m_MapData.m_UnitMgr.GetData();
                foreach (Data_Unit unit in units.Values)
                {
                    if (null != unit && unit.m_IsEnable)
                    {
                        NpcInfo npc = m_NpcMgr.AddNpc(unit);
                        if (null != npc)
                        {
                            if (room.RoomUsers.Count() > 0)
                            {
                                npc.OwnerId = room.RoomUsers[0].RoleId;
                                LogSystem.Debug("User {0} is responsible for npc {1}", npc.OwnerId, npc.GetId());
                            }
                            else
                            {
                                LogSystem.Warn("No User is responsible for npc");
                            }
                        }
                    }
                }

                MyDictionary <int, object> slogics = m_MapData.m_SceneLogicMgr.GetData();
                foreach (SceneLogicConfig sc in slogics.Values)
                {
                    if (null != sc && sc.m_IsServer)
                    {
                        m_SceneLogicInfoMgr.AddSceneLogicInfo(sc.GetId(), sc);
                    }
                }

                foreach (User us in room.RoomUsers)
                {
                    UserInfo  info = us.Info;
                    Data_Unit unit = m_MapData.ExtractData(DataMap_Type.DT_Unit, info.GetUnitId()) as Data_Unit;
                    if (null != unit)
                    {
                        info.GetMovementStateInfo().SetPosition(unit.m_Pos);
                        info.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                        info.RevivePoint = unit.m_Pos;
                    }
                }
            }
        }
Beispiel #7
0
        internal static Msg_RC_UserMove BuildUserMoveMessage(UserInfo user)
        {
            Msg_RC_UserMove userMoveBuilder = new Msg_RC_UserMove();

            if (user.GetMovementStateInfo().IsMoving)
            {
                userMoveBuilder.role_id        = user.GetId();
                userMoveBuilder.is_moving      = true;
                userMoveBuilder.move_direction = (float)user.GetMovementStateInfo().GetMoveDir();
                userMoveBuilder.face_direction = (float)user.GetMovementStateInfo().GetFaceDir();
                userMoveBuilder.cur_pos_x      = user.GetMovementStateInfo().GetPosition3D().X;
                userMoveBuilder.cur_pos_z      = user.GetMovementStateInfo().GetPosition3D().Z;
                UserAiStateInfo data = user.GetAiStateInfo();
                userMoveBuilder.target_pos_x         = user.GetMovementStateInfo().TargetPosition.X;
                userMoveBuilder.target_pos_z         = user.GetMovementStateInfo().TargetPosition.Z;
                userMoveBuilder.velocity_coefficient = (float)user.VelocityCoefficient;
            }
            else
            {
                userMoveBuilder.role_id   = user.GetId();
                userMoveBuilder.is_moving = false;
                userMoveBuilder.cur_pos_x = user.GetMovementStateInfo().GetPosition3D().X;
                userMoveBuilder.cur_pos_z = user.GetMovementStateInfo().GetPosition3D().Z;
            }
            return(userMoveBuilder);
        }
Beispiel #8
0
        private void PrintPosition(int key_code, int what)
        {
            UserInfo myself = WorldSystem.Instance.GetPlayerSelf();

            if (null != myself)
            {
                Vector3 pos = myself.GetMovementStateInfo().GetPosition3D();
                float   dir = myself.GetMovementStateInfo().GetFaceDir();
                LogSystem.Info("PrintPosition {0:F2} {1:F2} {2:F2} {3:F2}", pos.X, pos.Y, pos.Z, dir);
            }
        }
Beispiel #9
0
        internal static void Execute(object msg, User user)
        {
            Msg_CRC_Create enter_msg = msg as Msg_CRC_Create;

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

            Room room = user.OwnRoom;

            if (null != room)
            {
                Scene scene = room.GetActiveScene();
                if (null != scene)
                {
                    UserInfo userInfo = user.Info;
                    if (null != userInfo)
                    {
                        userInfo.GetXSoulInfo().GetAllXSoulPartData().Clear();
                        foreach (var pair in user.XSouls.GetAllXSoulPartData())
                        {
                            userInfo.GetXSoulInfo().SetXSoulPartData(pair.Key, pair.Value);
                        }
                        foreach (var pair in userInfo.GetXSoulInfo().GetAllXSoulPartData())
                        {
                            XSoulPartInfo part_info = pair.Value;
                            foreach (int impactid in part_info.GetActiveImpacts())
                            {
                                //LogSys.Log(LOG_TYPE.DEBUG, "---add xsoul impact to self: " + impactid);
                                ImpactSystem.Instance.SendImpactToCharacter(userInfo, impactid, userInfo.GetId(),
                                                                            -1, -1, userInfo.GetMovementStateInfo().GetPosition3D(),
                                                                            userInfo.GetMovementStateInfo().GetFaceDir());
                            }
                        }
                        if (scene.SceneState == SceneState.Running)
                        {
                            Data_Unit unit = scene.MapData.ExtractData(DataMap_Type.DT_Unit, userInfo.GetUnitId()) as Data_Unit;
                            if (null != unit)
                            {
                                userInfo.GetMovementStateInfo().SetPosition(unit.m_Pos);
                                userInfo.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                                userInfo.RevivePoint = unit.m_Pos;
                            }
                            scene.SyncForNewUser(user);
                        }
                    }
                }
            }
        }
Beispiel #10
0
        internal static Msg_RC_Revive BuildReviveMessage(UserInfo user)
        {
            Msg_RC_Revive builder = new Msg_RC_Revive();

            builder.camp_id        = user.GetCampId();
            builder.face_direction = user.GetMovementStateInfo().GetFaceDir();
            builder.hero_id        = user.GetLinkId();
            builder.is_player_self = true;
            builder.position       = new ArkCrossEngineMessage.Position();
            builder.position.x     = user.GetMovementStateInfo().GetPosition3D().X;
            builder.position.z     = user.GetMovementStateInfo().GetPosition3D().Z;
            builder.role_id        = user.GetId();
            return(builder);
        }
Beispiel #11
0
        private void DoMove()
        {
            UserInfo myself = WorldSystem.Instance.GetPlayerSelf();

            if (null != myself)
            {
                float moveDir = myself.GetMovementStateInfo().GetMoveDir();
                myself.GetMovementStateInfo().IsMoveMeetObstacle = false;
                float newDir = CalcDir(moveDir, m_DirOffset);
                myself.GetMovementStateInfo().SetMoveDir(newDir);
                NetworkSystem.Instance.SyncPlayerMoveStart((float)newDir);

                LogSystem.Debug("MoveController adjust MoveDir:{0}+{1}", moveDir, m_DirOffset);
            }
        }
Beispiel #12
0
        public override void Adjust()
        {
            long curTime = TimeUtility.GetServerMilliseconds();

            if (m_LastAdjustTime + 100 < curTime)
            {
                m_LastAdjustTime = curTime;

                UserInfo myself = WorldSystem.Instance.GetPlayerSelf();
                if (null != myself)
                {
                    float   moveDir = myself.GetMovementStateInfo().GetMoveDir();
                    Vector2 pos     = myself.GetMovementStateInfo().GetPosition2D();
                    if (!myself.GetMovementStateInfo().IsMoving)//玩家已经停止移动,控制停止
                    {
                        m_IsTerminated = true;
                        NetworkSystem.Instance.SyncPlayerMoveStop();

                        LogSystem.Debug("MoveController finish because stop move, adjust MoveDir:{0}", moveDir);
                    }
                    else if (!Geometry.IsSameDouble(WorldSystem.Instance.InputMoveDir, m_InputDir))//玩家输入的移动方向改变,控制停止
                    {
                        m_IsTerminated = true;

                        LogSystem.Debug("MoveController finish because change move dir, adjust MoveDir:{0}", moveDir);
                    }
                    else if (CanGo(myself, pos.X, pos.Y, m_InputDir, c_ForecastDistance * 3, false))//如果输入移动方向可以行走,则恢复移动方向,并停止控制
                    {
                        m_DirOffset = 0;
                        myself.GetMovementStateInfo().SetMoveDir(m_InputDir);
                        DoMove();
                        m_IsTerminated = true;

                        LogSystem.Debug("MoveController finish because restore move dir, adjust MoveDir:{0}", moveDir);
                    }
                }
                else
                {
                    m_IsTerminated = true;

                    LogSystem.Debug("MoveController finish because can't find player");
                }
                if (m_IsTerminated)
                {
                    WorldSystem.Instance.MoveDirAdjustCount = 0;
                }
            }
        }
Beispiel #13
0
 private void TickDebugSpaceInfo()
 {
     if (GlobalVariables.Instance.IsDebug)
     {
         bool needDebug = false;
         foreach (User user in m_Room.RoomUsers)
         {
             if (user.IsDebug)
             {
                 needDebug = true;
                 break;
             }
         }
         if (needDebug)
         {
             Msg_RC_DebugSpaceInfo builder = new Msg_RC_DebugSpaceInfo();
             for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
             {
                 UserInfo info = linkNode.Value;
                 Msg_RC_DebugSpaceInfo.DebugSpaceInfo infoBuilder = new Msg_RC_DebugSpaceInfo.DebugSpaceInfo();
                 infoBuilder.obj_id    = info.GetId();
                 infoBuilder.is_player = true;
                 infoBuilder.pos_x     = (float)info.GetMovementStateInfo().GetPosition3D().X;
                 infoBuilder.pos_z     = (float)info.GetMovementStateInfo().GetPosition3D().Z;
                 infoBuilder.face_dir  = (float)info.GetMovementStateInfo().GetFaceDir();
                 builder.space_infos.Add(infoBuilder);
             }
             for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
             {
                 NpcInfo info = linkNode.Value;
                 Msg_RC_DebugSpaceInfo.DebugSpaceInfo infoBuilder = new Msg_RC_DebugSpaceInfo.DebugSpaceInfo();
                 infoBuilder.obj_id    = info.GetId();
                 infoBuilder.is_player = false;
                 infoBuilder.pos_x     = (float)info.GetMovementStateInfo().GetPosition3D().X;
                 infoBuilder.pos_z     = (float)info.GetMovementStateInfo().GetPosition3D().Z;
                 infoBuilder.face_dir  = (float)info.GetMovementStateInfo().GetFaceDir();
                 builder.space_infos.Add(infoBuilder);
             }
             foreach (User user in m_Room.RoomUsers)
             {
                 if (user.IsDebug)
                 {
                     user.SendMessage(builder);
                 }
             }
         }
     }
 }
Beispiel #14
0
        private void IdleHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            UserAiStateInfo info = user.GetAiStateInfo();

            user.GetMovementStateInfo().IsMoving = false;
            ChangeToState(user, (int)AiStateId.Wait);
        }
Beispiel #15
0
        internal static void Execute(object msg, User user)
        {
            Msg_CR_UserMoveToPos move_msg = msg as Msg_CR_UserMoveToPos;

            if (move_msg == null)
            {
                return;
            }
            UserInfo charactor = user.Info;

            if (charactor == null)
            {
                LogSys.Log(LOG_TYPE.ERROR, "charactor {0} not exist", user.RoleId);
                return;
            }
            ///
            if (charactor.GetAIEnable())
            {
                MovementStateInfo msi = charactor.GetMovementStateInfo();
                msi.PositionX = move_msg.cur_pos_x;
                msi.PositionZ = move_msg.cur_pos_z;

                UserAiStateInfo asi = charactor.GetAiStateInfo();
                Vector3         pos = new Vector3(move_msg.target_pos_x, 0, move_msg.target_pos_z);
                asi.TargetPos          = pos;
                asi.IsTargetPosChanged = true;
                asi.ChangeToState((int)(AiStateId.Move));
            }
        }
Beispiel #16
0
        internal static Msg_RC_UserFace BuildUserFaceMessage(UserInfo user)
        {
            Msg_RC_UserFace builder = new Msg_RC_UserFace();

            builder.face_direction = (float)user.GetMovementStateInfo().GetFaceDir();
            builder.role_id        = user.GetId();
            return(builder);
        }
Beispiel #17
0
        public void StartGame()
        {
            UserInfo user = GetPlayerSelf();

            if (null != user)
            {
                EntityManager.Instance.DestroyUserView(user.GetId());
                DestroyCharacterById(user.GetId());
            }
            user = CreatePlayerSelf(1, NetworkSystem.Instance.HeroId);
            user.SetCampId(NetworkSystem.Instance.CampId);
            Data_Unit unit = m_CurScene.StaticData.ExtractData(DataMap_Type.DT_Unit, GlobalVariables.GetUnitIdByCampId(NetworkSystem.Instance.CampId)) as Data_Unit;

            if (null != unit)
            {
                user.GetMovementStateInfo().SetPosition(unit.m_Pos);
                user.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                user.SetHp(Operate_Type.OT_Absolute, user.GetActualProperty().HpMax);
            }
            EntityManager.Instance.CreatePlayerSelfView(1);
            UserView view = EntityManager.Instance.GetUserViewById(1);

            if (null != view)
            {
                view.Visible = true;
            }

            foreach (Data_Unit npcUnit in m_CurScene.StaticData.m_UnitMgr.GetData().Values)
            {
                if (npcUnit.m_IsEnable)
                {
                    NpcInfo npc = m_NpcMgr.GetNpcInfoByUnitId(npcUnit.GetId());
                    if (null == npc)
                    {
                        npc = m_NpcMgr.AddNpc(npcUnit);
                    }
                    if (null != npc)
                    {
                        EntityManager.Instance.CreateNpcView(npc.GetId());
                    }
                }
            }
            GfxSystem.PublishGfxEvent("ge_on_game_start", "story");
            LogSystem.Debug("start game");
        }
Beispiel #18
0
        private void SyncUserToObservers(User infoUser)
        {
            Room room = GetRoom();

            if (null != infoUser && null != room && null != room.GetActiveScene())
            {
                UserInfo userInfo = infoUser.Info;
                if (null != userInfo)
                {
                    Vector3 pos = userInfo.GetMovementStateInfo().GetPosition3D();

                    ArkCrossEngineMessage.Position pos_bd0 = new ArkCrossEngineMessage.Position();
                    pos_bd0.x = pos.X;
                    pos_bd0.z = pos.Z;
                    Msg_CRC_Create bd0 = new Msg_CRC_Create();
                    bd0.role_id        = infoUser.RoleId;
                    bd0.hero_id        = infoUser.HeroId;
                    bd0.camp_id        = infoUser.CampId;
                    bd0.role_level     = infoUser.Level;
                    bd0.is_player_self = false;
                    bd0.position       = pos_bd0;
                    bd0.face_dirction  = (float)userInfo.GetMovementStateInfo().GetFaceDir();
                    for (int index = 0; index < userInfo.GetSkillStateInfo().GetAllSkill().Count; index++)
                    {
                        bd0.skill_levels.Add(userInfo.GetSkillStateInfo().GetSkillInfoByIndex(index).SkillLevel);
                    }
                    bd0.scene_start_time = StartTime;
                    bd0.nickname         = infoUser.Name;
                    NotifyAllObserver(bd0);

                    DataSyncUtility.SyncBuffListToObservers(userInfo, this);

                    Msg_RC_SyncProperty propBuilder = DataSyncUtility.BuildSyncPropertyMessage(userInfo);
                    NotifyAllObserver(propBuilder);

                    Msg_RC_SyncCombatStatisticInfo combatBuilder = DataSyncUtility.BuildSyncCombatStatisticInfo(userInfo);
                    NotifyAllObserver(combatBuilder);

                    LogSys.Log(LOG_TYPE.DEBUG, "send user {0} msg to observers", infoUser.RoleId);
                }
            }
        }
Beispiel #19
0
        private void UserEnterCampSight(UserInfo enter_user_info, int campid)
        {
            User enter_user = enter_user_info.CustomData as User;

            if (enter_user == null)
            {
                return;
            }
            IList <UserInfo> camp_users = m_SightManager.GetCampUsers(campid);

            foreach (UserInfo user_info in camp_users)
            {
                User user = user_info.CustomData as User;
                if (user == null)
                {
                    continue;
                }
                if (enter_user_info.GetId() != user_info.GetId())
                {
                    user.AddICareUser(enter_user);
                    //send message
                    Vector3 enter_user_pos = enter_user_info.GetMovementStateInfo().GetPosition3D();
                    ArkCrossEngineMessage.Position pos_bd0 = new ArkCrossEngineMessage.Position();
                    pos_bd0.x = enter_user_pos.X;
                    pos_bd0.z = enter_user_pos.Z;
                    Msg_RC_Enter bder = new Msg_RC_Enter();
                    bder.role_id   = enter_user.RoleId;
                    bder.hero_id   = enter_user.HeroId;
                    bder.camp_id   = enter_user.CampId;
                    bder.position  = pos_bd0;
                    bder.face_dir  = (float)enter_user_info.GetMovementStateInfo().GetFaceDir();
                    bder.is_moving = enter_user_info.GetMovementStateInfo().IsMoving;
                    bder.move_dir  = (float)enter_user_info.GetMovementStateInfo().GetMoveDir();
                    user.SendMessage(bder);

                    Msg_RC_SyncProperty propBuilder = DataSyncUtility.BuildSyncPropertyMessage(enter_user_info);
                    user.SendMessage(propBuilder);
                    DataSyncUtility.SyncBuffListToUser(enter_user_info, user);
                }
            }
        }
Beispiel #20
0
        public void ChangeHero()
        {
            UserInfo user = GetPlayerSelf();

            if (null != user)
            {
                Vector3 pos  = user.GetMovementStateInfo().GetPosition3D();
                float   dir  = user.GetMovementStateInfo().GetFaceDir();
                int     hp   = user.Hp;
                int     rage = user.Rage;

                EntityManager.Instance.DestroyUserView(user.GetId());
                DestroyCharacterById(user.GetId());

                NetworkSystem.Instance.HeroId = (NetworkSystem.Instance.HeroId + 1) % 4;
                if (NetworkSystem.Instance.HeroId == 0)
                {
                    NetworkSystem.Instance.HeroId = 1;
                }

                user = CreatePlayerSelf(1, NetworkSystem.Instance.HeroId);
                user.SetCampId(NetworkSystem.Instance.CampId);

                /*Data_Unit unit = m_CurScene.StaticData.ExtractData(DataMap_Type.DT_Unit, GlobalVariables.GetUnitIdByCampId(NetworkSystem.Instance.CampId)) as Data_Unit;
                 * if (null != unit) {
                 * user.GetMovementStateInfo().SetPosition(unit.m_Pos);
                 * user.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                 * user.SetHp(Operate_Type.OT_Absolute, 1000);
                 * }*/
                user.GetMovementStateInfo().SetPosition(pos);
                user.GetMovementStateInfo().SetFaceDir(dir);
                user.SetHp(Operate_Type.OT_Absolute, hp);
                user.SetRage(Operate_Type.OT_Absolute, rage);
                EntityManager.Instance.CreatePlayerSelfView(1);
                UserView view = EntityManager.Instance.GetUserViewById(1);
                if (null != view)
                {
                    view.Visible = true;
                }
            }
        }
Beispiel #21
0
        internal static void Execute(object msg, User user)
        {
            Msg_CR_UserMoveToAttack attack_msg = msg as Msg_CR_UserMoveToAttack;

            if (attack_msg == null)
            {
                return;
            }
            UserInfo charactor = user.Info;

            if (charactor == null)
            {
                LogSys.Log(LOG_TYPE.ERROR, "charactor {0} not exist", user.RoleId);
                return;
            }
            ///
            if (charactor.GetAIEnable())
            {
                MovementStateInfo msi = charactor.GetMovementStateInfo();
                msi.PositionX = attack_msg.cur_pos_x;
                msi.PositionZ = attack_msg.cur_pos_z;

                UserAiStateInfo aiInfo = charactor.GetAiStateInfo();

                AiData_UserSelf_General data = charactor.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>();
                if (null == data)
                {
                    data = new AiData_UserSelf_General();
                    charactor.GetAiStateInfo().AiDatas.AddData(data);
                }
                charactor.GetMovementStateInfo().IsMoving = false;
                data.FoundPath.Clear();
                aiInfo.Time        = 0;
                aiInfo.Target      = attack_msg.target_id;
                aiInfo.IsAttacked  = false;
                aiInfo.AttackRange = attack_msg.attack_range;

                aiInfo.ChangeToState((int)AiStateId.Combat);
            }
        }
Beispiel #22
0
 void UserManager_OnDamage(int receiver, int caster, bool /*isShootDamage*/ isOrdinaryDamage, bool isCritical, int hpDamage, int npDamage)
 {
     if (receiver == PlayerSelfId)
     {
         UserInfo charObj = GetPlayerSelf();
         if (null != charObj)
         {
             Vector3 pos = charObj.GetMovementStateInfo().GetPosition3D();
             if (hpDamage != 0)
             {
                 GfxSystem.PublishGfxEvent("ge_hero_blood", "ui", pos.X, pos.Y, pos.Z, hpDamage);
             }
         }
     }
 }
Beispiel #23
0
        private void MoveHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                user.GetMovementStateInfo().IsMoving = false;
                ChangeToState(user, (int)AiStateId.Wait);
                return;
            }
            UserAiStateInfo info = user.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 10)
            {
                info.Time = 0;
                Vector3 srcPos    = user.GetMovementStateInfo().GetPosition3D();
                Vector3 targetPos = user.GetMovementStateInfo().TargetPosition;
                if (!IsReached(srcPos, targetPos))
                {
                    float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                    user.GetMovementStateInfo().SetMoveDir(angle);
                    user.GetMovementStateInfo().IsMoving = true;
                }
            }
        }
Beispiel #24
0
 public void Create(UserInfo user)
 {
     Init();
     if (null != user)
     {
         m_User = user;
         m_User.OnBeginAttack = ResetShootAnimation;
         MovementStateInfo msi = m_User.GetMovementStateInfo();
         Vector3           pos = msi.GetPosition3D();
         float             dir = msi.GetFaceDir();
         CreateActor(m_User.GetId(), m_User.GetModel(), pos, dir, m_User.Scale);
         InitAnimationSets();
         UpdateWeaponModel(m_User);
         if (user.GetId() == WorldSystem.Instance.PlayerSelfId)
         {
             GfxSystem.MarkPlayerSelf(Actor);
         }
     }
 }
Beispiel #25
0
        private void StopFindPath(UserInfo playerself, UserAiStateInfo aiInfo)
        {
            if (null == playerself || null == aiInfo)
            {
                return;
            }
            AiData_UserSelf_General data = playerself.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>();

            if (null == data)
            {
                data = new AiData_UserSelf_General();
                playerself.GetAiStateInfo().AiDatas.AddData(data);
            }
            playerself.GetMovementStateInfo().IsMoving = false;
            aiInfo.Time = 0;
            data.Time   = 0;
            data.FoundPath.Clear();
            aiInfo.ChangeToState((int)AiStateId.Idle);
        }
        private CharacterInfo GetCanAttackUserTarget(UserInfo user)
        {
            //float dist = user.GetActualProperty().AttackRange;
            float dist = 3f;
            LinkedListDictionary <int, UserInfo> list = user.SceneContext.UserManager.Users;

            for (LinkedListNode <UserInfo> node = list.FirstValue; null != node; node = node.Next)
            {
                UserInfo other = node.Value;
                if (null != other && CharacterRelation.RELATION_ENEMY == CharacterInfo.GetRelation(user, other))
                {
                    if (Geometry.DistanceSquare(user.GetMovementStateInfo().GetPosition3D(), other.GetMovementStateInfo().GetPosition3D()) <= dist * dist)
                    {
                        return(other);
                    }
                }
            }
            return(null);
        }
Beispiel #27
0
        private void FindPath(UserInfo playerself, Vector3 targetpos, float towards)
        {
            CharacterView view = EntityManager.Instance.GetUserViewById(playerself.GetId());

            if (view != null && view.ObjectInfo.IsGfxMoveControl && Vector3.Zero != targetpos)
            {
                return;
            }
            playerself.GetMovementStateInfo().SetFaceDir(towards);
            PlayerMovement.Motion m = Vector3.Zero == targetpos ? PlayerMovement.Motion.Stop : PlayerMovement.Motion.Moving;
            pm_.MotionChanged = pm_.MotionStatus != m || m_lastDir != towards;
            m_lastDir         = towards;
            pm_.MotionStatus  = m;
            pm_.MoveDir       = towards;
            if (Vector3.Zero == targetpos)
            {
                pm_.MotionStatus = PlayerMovement.Motion.Stop;
            }

            /*
             * UserAiStateInfo aiInfo = playerself.GetAiStateInfo();
             * if(null == aiInfo)
             * return;
             * if (Vector3.Zero == targetpos) {
             * StopFindPath(playerself, aiInfo);
             * return;
             * }
             * bool ret = (m_lastDir > towards) ? ((m_lastDir - towards) > Math.PI / 4.0f) : ((towards - m_lastDir) > Math.PI / 4.0f);
             * if (ret) {
             * StopFindPath(playerself, aiInfo);
             * m_lastDir = towards;
             * }
             * aiInfo.TargetPos = targetpos;
             * aiInfo.ChangeToState((int)AiStateId.Move);
             */
        }
        internal void SummonPartner(Msg_CR_SummonPartner msg)
        {
            UserInfo userInfo = UserManager.GetUserInfo(msg.obj_id);

            if (null != userInfo)
            {
                // summonpartner
                PartnerInfo partnerInfo = userInfo.GetPartnerInfo();
                if (null != partnerInfo && (TimeUtility.GetServerMilliseconds() - userInfo.LastSummonPartnerTime > partnerInfo.CoolDown || userInfo.LastSummonPartnerTime == 0))
                {
                    Data_Unit data = new Data_Unit();
                    data.m_Id         = -1;
                    data.m_LinkId     = partnerInfo.LinkId;
                    data.m_CampId     = userInfo.GetCampId();
                    data.m_Pos        = userInfo.GetMovementStateInfo().GetPosition3D();
                    data.m_RotAngle   = 0;
                    data.m_AiLogic    = partnerInfo.GetAiLogic();
                    data.m_AiParam[0] = "";
                    data.m_AiParam[1] = "";
                    data.m_AiParam[2] = partnerInfo.GetAiParam().ToString();
                    data.m_IsEnable   = true;
                    NpcInfo npc = NpcManager.AddNpc(data);
                    if (null != npc)
                    {
                        AppendAttributeConfig aac       = AppendAttributeConfigProvider.Instance.GetDataById(partnerInfo.GetAppendAttrConfigId());
                        float inheritAttackAttrPercent  = partnerInfo.GetInheritAttackAttrPercent();
                        float inheritDefenceAttrPercent = partnerInfo.GetInheritDefenceAttrPercent();
                        if (null != aac)
                        {
                            // attack
                            npc.GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().AttackBase *inheritAttackAttrPercent));
                            npc.GetBaseProperty().SetFireDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().FireDamage *inheritAttackAttrPercent);
                            npc.GetBaseProperty().SetIceDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().IceDamage *inheritAttackAttrPercent);
                            npc.GetBaseProperty().SetPoisonDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().PoisonDamage *inheritAttackAttrPercent);
                            // defence
                            npc.GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().HpMax *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().EnergyMax *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetADefenceBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().ADefenceBase *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetMDefenceBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().MDefenceBase *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetFireERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().FireERD *inheritDefenceAttrPercent);
                            npc.GetBaseProperty().SetIceERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().IceERD *inheritDefenceAttrPercent);
                            npc.GetBaseProperty().SetPoisonERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().PoisonERD *inheritDefenceAttrPercent);
                            // reset hp & energy
                            npc.SetHp(Operate_Type.OT_Absolute, npc.GetBaseProperty().HpMax);
                            npc.SetEnergy(Operate_Type.OT_Absolute, npc.GetBaseProperty().EnergyMax);
                        }
                        npc.SetAIEnable(true);
                        npc.GetSkillStateInfo().RemoveAllSkill();
                        npc.BornTime = TimeUtility.GetServerMilliseconds();
                        List <int> skillList = partnerInfo.GetSkillList();
                        if (null != skillList)
                        {
                            for (int i = 0; i < skillList.Count; ++i)
                            {
                                SkillInfo skillInfo = new SkillInfo(skillList[i]);
                                npc.GetSkillStateInfo().AddSkill(skillInfo);
                            }
                        }
                        userInfo.LastSummonPartnerTime = TimeUtility.GetServerMilliseconds();
                        npc.OwnerId        = userInfo.GetId();
                        userInfo.PartnerId = npc.GetId();
                        if (partnerInfo.BornSkill > 0)
                        {
                            SkillInfo skillInfo = new SkillInfo(partnerInfo.BornSkill);
                            npc.GetSkillStateInfo().AddSkill(skillInfo);
                        }
                        ArkCrossEngineMessage.Msg_RC_CreateNpc builder = DataSyncUtility.BuildCreateNpcMessage(npc);
                        NotifyAllUser(builder);
                    }
                }
            }
        }
Beispiel #29
0
        public void Tick()
        {
            long now = TimeUtility.GetServerMilliseconds();

            m_LastTickIntervalMs = now - m_LastTickTime;

            m_LastTickTime = now;

            if (WorldSystem.Instance.IsObserver && !WorldSystem.Instance.IsFollowObserver)
            {
                bool  keyPressed = false;
                float x = 0.5f, y = 0.5f;
                if (GfxSystem.IsKeyPressed(Keyboard.Code.A))
                {
                    x          = 0.1f;
                    keyPressed = true;
                }
                else if (GfxSystem.IsKeyPressed(Keyboard.Code.D))
                {
                    x          = 0.9f;
                    keyPressed = true;
                }
                if (GfxSystem.IsKeyPressed(Keyboard.Code.W))
                {
                    y          = 0.1f;
                    keyPressed = true;
                }
                else if (GfxSystem.IsKeyPressed(Keyboard.Code.S))
                {
                    y          = 0.9f;
                    keyPressed = true;
                }
                if (keyPressed)
                {
                    WorldSystem.Instance.UpdateObserverCamera(x, y);
                }
                return;
            }

            // if move input is disable
            // MotionStatus is MoveStop, and MotionChanged is reflect the change accordingly
            // pm_.Update(EnableMoveInput);

            UserInfo playerself = WorldSystem.Instance.GetPlayerSelf();

            if (null == playerself)
            {
                return;
            }

            Vector3 pos       = playerself.GetMovementStateInfo().GetPosition3D();
            Vector3 mouse_pos = new Vector3(GfxSystem.GetMouseX(), GfxSystem.GetMouseY(), GfxSystem.GetMouseZ());//GfxSystem.Instance.MainScene.GetMousePos(pos.Y);

            if (pm_.MotionStatus == PlayerMovement.Motion.Moving)
            {
                if (pm_.MotionChanged)
                {
                    WorldSystem.Instance.InputMoveDir = pm_.MoveDir;
                    playerself.GetMovementStateInfo().SetWantMoveDir(pm_.MoveDir);

                    if (WorldSystem.Instance.IsPveScene())
                    {
                        playerself.GetMovementStateInfo().SetMoveDir(pm_.MoveDir);
                        playerself.GetMovementStateInfo().IsMoving       = true;
                        playerself.GetMovementStateInfo().TargetPosition = Vector3.Zero;
                    }
                    else
                    {
                        NetworkSystem.Instance.SyncPlayerMoveStart((float)pm_.MoveDir);
                    }

                    if (EnableRotateInput)
                    {
                        MovementStateInfo msi = playerself.GetMovementStateInfo();
                        msi.SetFaceDir(pm_.MoveDir);
                        NetworkSystem.Instance.SyncFaceDirection((float)pm_.MoveDir);
                    }
                }
            }
            else
            {
                if (pm_.MotionChanged)
                {
                    WorldSystem.Instance.LastMoveDirAdjust = 0;

                    if (WorldSystem.Instance.IsPveScene())
                    {
                        playerself.GetMovementStateInfo().IsMoving = false;
                    }
                    else
                    {
                        NetworkSystem.Instance.SyncPlayerMoveStop();
                    }
                }
            }

            old_mouse_pos_ = mouse_pos_;
            mouse_pos_.X   = GfxSystem.GetMouseX();
            mouse_pos_.Y   = GfxSystem.GetMouseY();

            UserAiStateInfo aiInfo = playerself.GetAiStateInfo();

            if (null != aiInfo && (int)AiStateId.Idle == aiInfo.CurState)
            {
                m_lastSelectObjId = -1;
            }
        }
        private void CombatHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                return;
            }
            UserAiStateInfo info = user.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                AiData_UserSelf_General data = GetAiData(user);
                if (null != data)
                {
                    data.Time += info.Time;
                    info.Time  = 0;
                    ///
                    CharacterInfo target    = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target);
                    Vector3       targetPos = Vector3.Zero;
                    float         dist      = info.AttackRange;
                    if (null != target)
                    {
                        targetPos = target.GetMovementStateInfo().GetPosition3D();
                    }
                    else
                    {
                        targetPos = info.TargetPos;
                    }
                    Vector3 srcPos  = user.GetMovementStateInfo().GetPosition3D();
                    float   powDist = Geometry.DistanceSquare(srcPos, targetPos);
                    if (!info.IsAttacked)
                    {
                        if (powDist < dist * dist)
                        {
                            data.Time        = 0;
                            info.AttackRange = 0;
                            info.IsAttacked  = true;
                            float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            user.GetMovementStateInfo().SetFaceDir(dir);
                            user.GetMovementStateInfo().SetMoveDir(dir);
                            if (null != target)
                            {
                                if (null != OnUserStartAttack)
                                {
                                    OnUserStartAttack(user, targetPos.X, targetPos.Y, targetPos.Z);
                                }
                            }
                            else
                            {
                                if (null != OnUserSkill)
                                {
                                    OnUserSkill(user);
                                }
                            }
                            ///
                            user.GetMovementStateInfo().StopMove();
                            NotifyUserMove(user);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(user, (int)AiStateId.Idle);
                        }
                        else
                        {
                            if (null != OnSkillPursuit)
                            {
                                OnSkillPursuit(user);
                            }
                            user.GetMovementStateInfo().StopMove();
                            NotifyUserMove(user);
                            info.Time       = 0;
                            info.IsAttacked = false;
                            data.FoundPath.Clear();
                            ChangeToState(user, (int)AiStateId.Pursuit);
                        }
                    }
                }
                else
                {
                    info.Time = 0;
                }
            }
        }