Пример #1
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;
            }
        }
Пример #2
0
        public void Update(bool move_enable)
        {
            UserInfo playerself = WorldSystem.Instance.GetPlayerSelf();

            if (playerself == null || playerself.IsDead())
            {
                return;
            }
            KeyHit kh = KeyHit.None;

            if (move_enable)
            {
                if (DashFireSpatial.SpatialObjType.kNPC == playerself.GetRealControlledObject().SpaceObject.GetObjType())
                {
                    NpcInfo npcInfo = playerself.GetRealControlledObject().CastNpcInfo();
                    if (null != npcInfo)
                    {
                        if (!npcInfo.CanMove)
                        {
                            return;
                        }
                    }
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.W)))
                {
                    kh |= KeyHit.Up;
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.A)))
                {
                    kh |= KeyHit.Left;
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.S)))
                {
                    kh |= KeyHit.Down;
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.D)))
                {
                    kh |= KeyHit.Right;
                }
            }

            Motion m = kh == KeyHit.None ? Motion.Stop : Motion.Moving;

            MotionChanged = MotionStatus != m || last_key_hit_ != kh;

            if (MotionChanged)
            {
                //LogSystem.Debug("MotionChanged:{0}!={1} || {2}!={3}", MotionStatus, m, last_key_hit_, kh);
            }

            last_key_hit_ = kh;
            MotionStatus  = m;
            MoveDir       = CalcMoveDir(kh);
            if (MoveDir < 0)
            {
                MotionStatus = Motion.Stop;
            }
            if (MotionChanged)
            {
                //GfxSystem.GfxLog(string.Format("InputMoveDir:{0} Pos:{1}", MoveDir, playerself.GetMovementStateInfo().GetPosition3D().ToString()));
            }
        }