Exemple #1
0
        private void MoveUser(UserInfo obj, long deltaTime)
        {
            MovementStateInfo msi = obj.GetMovementStateInfo();

            if (null != obj.ControlledObject)
            {
                MovementStateInfo ctrlMsi = obj.ControlledObject.GetMovementStateInfo();
                ctrlMsi.IsMoving = msi.IsMoving;
                ctrlMsi.SetFaceDir(msi.GetFaceDir());
                ctrlMsi.SetMoveDir(msi.GetMoveDir());
            }
            if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition))
            {
                return;
            }
            //玩家移动中忽略阻挡,由客户端与AI来规划路径。
            if (!obj.IsDead() && msi.IsMoving && !msi.IsSkillMoving && !msi.IsMoveMeetObstacle)
            {
                Vector3 pos      = msi.GetPosition3D();
                float   speed    = (float)obj.GetRealControlledObject().GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient;
                float   distance = (speed * (float)(int)deltaTime) / 1000.0f;

                //LogSystem.Debug("MovementSystem user:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float   x = 0, y = 0;
                Vector2 newPos = new Vector2();
                if (obj.GetAiStateInfo().CurState != (int)AiStateId.Invalid && msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    AdjustPosition(obj.SpatialSystem, ref x, ref y);
                    newPos = new Vector2(x, y);
                    msi.SetPosition2D(newPos);
                }
                else
                {
                    float cosV = (float)msi.MoveDirCosAngle;
                    float sinV = (float)msi.MoveDirSinAngle;
                    y = pos.Z + distance * cosV;
                    x = pos.X + distance * sinV;
                    AdjustPosition(obj.SpatialSystem, ref x, ref y);
                    newPos = new Vector2(x, y);
                    msi.SetPosition2D(newPos);
                }
                if (null != obj.ControlledObject)
                {
                    obj.ControlledObject.GetMovementStateInfo().SetPosition2D(newPos);
                }
            }
        }
Exemple #2
0
        protected void SimulateMove()
        {
            if (!m_Npc.IsSimulateMove)
            {
                return;
            }
            if (m_Npc.SummonOwnerId < 0)
            {
                return;
            }
            CharacterInfo owner = WorldSystem.Instance.GetCharacterById(m_Npc.SummonOwnerId);

            if (owner == null)
            {
                return;
            }
            CharacterView owner_view = EntityManager.Instance.GetCharacterViewById(m_Npc.SummonOwnerId);

            if (owner_view == null)
            {
                return;
            }
            MovementStateInfo msi     = m_Npc.GetMovementStateInfo();
            MovementStateInfo sim_msi = owner.GetMovementStateInfo();

            m_Npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, owner.GetActualProperty().MoveSpeed);
            m_Npc.VelocityCoefficient = owner.VelocityCoefficient;
            if (owner_view.ObjectInfo.IsGfxMoveControl)
            {
                msi.IsMoving = false;
            }
            else
            {
                msi.IsMoving = sim_msi.IsMoving;
            }
            msi.SetFaceDir(sim_msi.GetFaceDir());
            msi.SetWantFaceDir(sim_msi.GetWantFaceDir());
            msi.SetMoveDir(sim_msi.GetMoveDir());
        }
        internal 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;
            }


            UserInfo playerself = WorldSystem.Instance.GetPlayerSelf();

            if (null == playerself)
            {
                return;
            }
            // if move input is disable
            // MotionStatus is MoveStop, and MotionChanged is reflect the change accordingly

            if (EnableMoveInput)
            {
                if (!IsKeyboardControl())
                {
                    CheckJoystickControl();
                }
            }

            if (!m_IsJoystickControl)
            {
                pm_.Update(EnableMoveInput);
            }
            MovementStateInfo msi = playerself.GetMovementStateInfo();
            Vector3           pos = msi.GetPosition3D();

            //LogSystem.Debug("Pos : {0}, Dir : {1}", pos.ToString(), playerself.GetMovementStateInfo().GetFaceDir());
            bool reface = false;

            if (m_LastTickIsSkillMoving && !msi.IsSkillMoving)
            {
                reface = true;
            }

            //操作同步机制改为发给服务器同时本地就开始执行(服务器转发给其它客户端,校验失败则同时发回原客户端进行位置调整)
            Vector3 mouse_pos = new Vector3(GfxSystem.GetMouseX(), GfxSystem.GetMouseY(), GfxSystem.GetMouseZ());

            if (pm_.MotionStatus == PlayerMovement.Motion.Moving || pm_.JoyStickMotionStatus == PlayerMovement.Motion.Moving)
            {
                if (pm_.MotionChanged || pm_.JoyStickMotionChanged || !m_LastTickIsMoving)
                {
                    StopAiMove();

                    playerself.SkillController.AddBreakSkillTask();
                    float moveDir = RoundMoveDir(pm_.MoveDir);

                    //GfxSystem.GfxLog("PlayerControl.Tick MoveDir:{0} RoundMoveDir:{1}", pm_.MoveDir, moveDir);

                    if (!m_LastTickIsMoving || !Geometry.IsSameFloat(moveDir, m_lastMoveDir))
                    {
                        msi.SetMoveDir(moveDir);
                        //ControlSystemOperation.AdjustCharacterMoveDir(playerself.GetId(), moveDir);
                        msi.IsMoving       = true;
                        msi.TargetPosition = Vector3.Zero;

                        if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                        {
                            NetworkSystem.Instance.SyncPlayerMoveStart(moveDir);
                        }
                    }
                    if (EnableRotateInput)
                    {
                        if (reface || !m_LastTickIsMoving || !Geometry.IsSameFloat(pm_.MoveDir, m_lastDir))
                        {
                            msi.SetFaceDir(pm_.MoveDir);
                            //ControlSystemOperation.AdjustCharacterFaceDir(playerself.GetId(), pm_.MoveDir);
                            msi.SetWantFaceDir(pm_.MoveDir);

                            if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                            {
                                NetworkSystem.Instance.SyncFaceDirection(pm_.MoveDir);
                            }
                        }
                    }
                    m_lastDir     = pm_.MoveDir;
                    m_lastMoveDir = moveDir;
                }
                m_LastTickIsMoving = true;
            }
            else
            {
                if (m_LastTickIsMoving)
                {
                    playerself.SkillController.CancelBreakSkillTask();
                    playerself.GetMovementStateInfo().IsMoving = false;
                    if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                    {
                        NetworkSystem.Instance.SyncPlayerMoveStop();
                    }
                    if (EnableRotateInput)
                    {
                        if (reface)
                        {
                            msi.SetFaceDir(m_lastDir);
                            //ControlSystemOperation.AdjustCharacterFaceDir(playerself.GetId(), m_lastDir);
                            msi.SetWantFaceDir(m_lastDir);

                            if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                            {
                                NetworkSystem.Instance.SyncFaceDirection(m_lastDir);
                            }
                        }
                    }
                }
                m_LastTickIsMoving = false;
            }
            m_LastTickIsSkillMoving = msi.IsSkillMoving;

            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;
            }
        }