コード例 #1
0
        public void MovePlayer(MotionCommand command, bool start, float speed, bool mouse, bool newHoldRun)
        {
            if (Player == null || Player.InqInterpretedMotionState() == null)
            {
                return;
            }

            // if vfptr[10] - PlayerIsDead
            if (PlayerIsDead())
            {
                // vfptr[9].OnAction - LoseKeyboardFocus
                LoseKeyboardFocus();
                // vfptr[17](0, 0) - SetAutoRun
                SetAutoRun(false, false);
                return;
            }

            // if !ICIDM::s_cidm->m_UseMouseTurning
            // - goto LABEL_55

            var mvp = new MovementParameters();

            if (mouse)
            {
                // someFlags &= 0xFFFFF7FF;
                // unset bit 11
                mvp.SetHoldKey = false;
                var holdRun = Convert.ToInt32(newHoldRun) + 1;
            }

            var turn     = (MotionCommand)MotionStance.Invalid;
            var sidestep = (MotionCommand)MotionStance.Invalid;

            if (TurnList.Count != 0)
            {
                turn = TurnList.FirstOrDefault().Command;
            }

            if (SidestepList.Count != 0)
            {
                sidestep = SidestepList.FirstOrDefault().Command;
            }

            // vfptr[17].OnLoseFocus - GetMouseLookActive
            var mouselook = GetMouseLookActive();

            bool start_turn_left      = false;
            bool start_turn_right     = false;
            bool start_sidestep_left  = false;
            bool start_sidestep_right = false;

            bool cancel_turn_left      = false;
            bool cancel_turn_right     = false;
            bool cancel_sidestep_left  = false;
            bool cancel_sidestep_right = false;

            MotionCommand cmd1;

            if (!mouse)
            {
                if (!mouselook)
                {
                    cmd1 = command;
                    // goto LABEL_59
                }
                if (command != MotionCommand.TurnRight)
                {
                    if (command != MotionCommand.TurnLeft)
                    {
                        if (start)
                        {
                            cancel_turn_left    = true;
                            start_sidestep_left = true;
                        }
                        else
                        {
                            cancel_sidestep_left = true;
                        }
                    }
                    else
                    {
                        cancel_turn_right = true;
                        cancel_turn_left  = true;
                    }
                    // goto LABEL_38
                }
                if (!start)
                {
                    cancel_sidestep_right = true;
                    // goto LABEL_38
                }
                // LABEL_31:
                cancel_turn_right    = true;
                start_sidestep_right = true;
                // goto LABEL_38
            }

            if (!mouselook)
            {
                if (turn == MotionCommand.TurnRight)
                {
                    cancel_sidestep_right = true;
                    start_turn_right      = true;
                }
                else if (turn == MotionCommand.TurnLeft)
                {
                    cancel_sidestep_left = true;
                    start_turn_left      = true;
                }
                // goto LABEL_38
            }

            if (command != MotionCommand.MouseLook)
            {
                // goto LABEL_38
            }

            if (turn == MotionCommand.TurnRight)
            {
                cancel_turn_right = true;

                if (sidestep == MotionCommand.SideStepLeft)
                {
                    start_sidestep_left = true;
                }
                else
                {
                    start_sidestep_right = true;
                }

                // goto LABEL_38
            }

            if (turn == MotionCommand.TurnLeft)
            {
                if (sidestep != MotionCommand.SideStepRight)
                {
                    cancel_turn_left    = true;
                    start_sidestep_left = true;

                    // goto LABEL_38
                }
                // goto LABEL_31
            }

            if (MouseLeftDown)
            {
                start   = true;
                command = MotionCommand.WalkForward;
            }

            // ============
            // LABEL 38:

            // vfptr[8].OnLoseFocus - TakeControlFromServer
            TakeControlFromServer();

            if (cancel_sidestep_right)
            {
                Player.StopMotion((uint)MotionCommand.SideStepRight, mvp, true);
            }

            if (cancel_sidestep_left)
            {
                Player.StopMotion((uint)MotionCommand.SideStepLeft, mvp, true);
            }

            if (cancel_turn_right)
            {
                Player.StopMotion((uint)MotionCommand.TurnRight, mvp, true);
            }

            if (cancel_turn_left)
            {
                Player.StopMotion((uint)MotionCommand.TurnLeft, mvp, true);
            }

            if (start_turn_right)
            {
                start = true;
                cmd1  = MotionCommand.TurnRight;
            }
            else
            {
                cmd1 = command;
            }

            if (start_turn_left)
            {
                start = true;
                cmd1  = MotionCommand.TurnLeft;
            }

            if (start_sidestep_right)
            {
                start = true;
                cmd1  = MotionCommand.SideStepRight;
                speed = 1.0f;
            }

            if (start_sidestep_left)
            {
                start   = true;
                command = MotionCommand.SideStepLeft;
                speed   = 1.0f;

                // LABEL_55:
                cmd1 = command;
            }

            var holdRunRel1 = 0;

            if (mouse)
            {
                holdRunRel1 = Convert.ToInt32(newHoldRun) + 1;
                // goto LABEL_60
            }

            // LABEL_59:
            holdRunRel1 = 0;

            // LABEL_60:
            if (AutonomyLevel != 0)
            {
                if (start)
                {
                    if (cmd1 != MotionCommand.Jump)
                    {
                        mvp = new MovementParameters();
                        // set 12th flag
                        mvp.Autonomous = true;
                        if (mouse)
                        {
                            mvp.SetHoldKey = false;     // unset 11th flag
                        }
                        if (((uint)cmd1 & (uint)CommandMask.Action) != 0)
                        {
                            // vfptr[15].OnLoseFocus(this)
                        }
                        var werror = Player.DoMotion((uint)cmd1, mvp);
                        switch (werror)
                        {
                        case WeenieError.None:
                            if (((uint)cmd1 & (uint)CommandMask.Action) != 0)
                            {
                                ActionStamp++;
                            }
                            return;

                        case WeenieError.CantCrouchInCombat:
                            break;      // 72

                        case WeenieError.CantSitInCombat:
                            break;      // 73

                        case WeenieError.CantLieDownInCombat:
                            break;      // 73

                        case WeenieError.YouAreTooTiredToDoThat:
                            break;      // 73

                        case WeenieError.CantChatEmoteInCombat:
                            break;      // 73

                        case WeenieError.CantChatEmoteNotStanding:
                            break;

                        default:
                            return;
                        }
                    }
                }
                else if (cmd1 != MotionCommand.Jump)
                {
                    mvp = new MovementParameters();
                    var holdRunRel = 0;
                    if (mouse)
                    {
                        mvp.SetHoldKey = false;
                        holdRunRel     = Convert.ToInt32(newHoldRun) + 1;
                    }
                    Player.StopMotion((uint)cmd1, mvp, true);
                }
            }
            else
            {
                // vfptr[4].OnLoseFocus - NonAutonomous?
                MovePlayer_NonAutonomous(cmd1, start, speed, (HoldKey)holdRunRel1);
            }
        }
コード例 #2
0
        public void OnMoveToState_ClientMethod(MoveToState moveToState)
        {
            var rawState  = moveToState.RawMotionState;
            var prevState = LastMoveToState?.RawMotionState ?? RawMotionState.None;

            var mvp = new Physics.Animation.MovementParameters();

            mvp.HoldKeyToApply = rawState.CurrentHoldKey;

            if (!PhysicsObj.IsMovingOrAnimating)
            {
                PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime;
            }

            // ForwardCommand
            if (rawState.ForwardCommand != MotionCommand.Invalid)
            {
                // press new key
                if (prevState.ForwardCommand == MotionCommand.Invalid)
                {
                    PhysicsObj.DoMotion((uint)MotionCommand.Ready, mvp);
                    PhysicsObj.DoMotion((uint)rawState.ForwardCommand, mvp);
                }
                // press alternate key
                else if (prevState.ForwardCommand != rawState.ForwardCommand)
                {
                    PhysicsObj.DoMotion((uint)rawState.ForwardCommand, mvp);
                }
            }
            else if (prevState.ForwardCommand != MotionCommand.Invalid)
            {
                // release key
                PhysicsObj.StopMotion((uint)prevState.ForwardCommand, mvp, true);
            }

            // StrafeCommand
            if (rawState.SidestepCommand != MotionCommand.Invalid)
            {
                // press new key
                if (prevState.SidestepCommand == MotionCommand.Invalid)
                {
                    PhysicsObj.DoMotion((uint)rawState.SidestepCommand, mvp);
                }
                // press alternate key
                else if (prevState.SidestepCommand != rawState.SidestepCommand)
                {
                    PhysicsObj.DoMotion((uint)rawState.SidestepCommand, mvp);
                }
            }
            else if (prevState.SidestepCommand != MotionCommand.Invalid)
            {
                // release key
                PhysicsObj.StopMotion((uint)prevState.SidestepCommand, mvp, true);
            }

            // TurnCommand
            if (rawState.TurnCommand != MotionCommand.Invalid)
            {
                // press new key
                if (prevState.TurnCommand == MotionCommand.Invalid)
                {
                    PhysicsObj.DoMotion((uint)rawState.TurnCommand, mvp);
                }
                // press alternate key
                else if (prevState.TurnCommand != rawState.TurnCommand)
                {
                    PhysicsObj.DoMotion((uint)rawState.TurnCommand, mvp);
                }
            }
            else if (prevState.TurnCommand != MotionCommand.Invalid)
            {
                // release key
                PhysicsObj.StopMotion((uint)prevState.TurnCommand, mvp, true);
            }
        }
コード例 #3
0
        public void DoMotion(MotionCommand motionCommand, float speed = 1.0f, bool start = true)
        {
            var keyboardState = Keyboard.GetState();

            var holdKey = keyboardState.IsKeyDown(Keys.LeftShift) ? HoldKey.None : HoldKey.Run;

            var mvp = new MovementParameters();

            mvp.HoldKeyToApply = holdKey;

            SetHoldKey(holdKey);

            if (!PhysicsObj.TransientState.HasFlag(TransientStateFlags.OnWalkable))
            {
                BuildRawState();
            }

            // handle ForwardCommand (forward / backward)
            if (motionCommand == MotionCommand.WalkForward)
            {
                if (start)
                {
                    PhysicsObj.DoMotion((uint)MotionCommand.Ready, mvp);

                    PhysicsObj.DoMotion((uint)motionCommand, mvp);

                    SetForwardCommand(motionCommand);

                    //Console.WriteLine($"RawState.ForwardCommand: {(MotionCommand)PhysicsObj.MovementManager.MotionInterpreter.RawState.ForwardCommand}");
                    //Console.WriteLine($"InterpretedState.ForwardCommand: {(MotionCommand)PhysicsObj.MovementManager.MotionInterpreter.InterpretedState.ForwardCommand}");
                }
                else
                {
                    if (GetKeyState(keyboardState, BackwardKeys))
                    {
                        PhysicsObj.DoMotion((uint)MotionCommand.WalkBackwards, mvp);

                        SetForwardCommand(MotionCommand.WalkBackwards);
                    }
                    else
                    {
                        PhysicsObj.StopMotion((uint)motionCommand, mvp, true);

                        RemoveForwardCommand();
                    }
                }
            }

            else if (motionCommand == MotionCommand.WalkBackwards)
            {
                if (start)
                {
                    /*PhysicsObj.StopMotion((uint)MotionCommand.SideStepRight, mvp, true);
                     * PhysicsObj.StopMotion((uint)MotionCommand.TurnRight, mvp, true);
                     * PhysicsObj.StopMotion((uint)MotionCommand.SideStepLeft, mvp, true);*/
                    PhysicsObj.DoMotion((uint)MotionCommand.Ready, mvp);

                    PhysicsObj.DoMotion((uint)motionCommand, mvp);

                    SetForwardCommand(motionCommand);
                }
                else
                {
                    if (GetKeyState(keyboardState, ForwardKeys))
                    {
                        PhysicsObj.DoMotion((uint)MotionCommand.WalkForward, mvp);

                        SetForwardCommand(MotionCommand.WalkForward);
                    }
                    else
                    {
                        PhysicsObj.StopMotion((uint)motionCommand, mvp, true);

                        RemoveForwardCommand();
                    }
                }
            }

            // handle strafe
            else if (motionCommand == MotionCommand.SideStepLeft)
            {
                if (start)
                {
                    PhysicsObj.DoMotion((uint)motionCommand, mvp);

                    SetSideStepCommand(motionCommand);
                }
                else
                {
                    if (GetKeyState(keyboardState, StrafeRightKeys))
                    {
                        PhysicsObj.DoMotion((uint)MotionCommand.SideStepRight, mvp);

                        SetSideStepCommand(MotionCommand.SideStepRight);
                    }
                    else
                    {
                        PhysicsObj.StopMotion((uint)motionCommand, mvp, true);

                        RemoveSideStepCommand();
                    }
                }
            }

            else if (motionCommand == MotionCommand.SideStepRight)
            {
                if (start)
                {
                    PhysicsObj.DoMotion((uint)motionCommand, mvp);

                    SetSideStepCommand(motionCommand);
                }
                else
                {
                    if (GetKeyState(keyboardState, StrafeLeftKeys))
                    {
                        PhysicsObj.DoMotion((uint)MotionCommand.SideStepLeft, mvp);

                        SetSideStepCommand(MotionCommand.SideStepLeft);
                    }
                    else
                    {
                        PhysicsObj.StopMotion((uint)motionCommand, mvp, true);

                        RemoveSideStepCommand();
                    }
                }
            }

            // handle turning
            else if (motionCommand == MotionCommand.TurnLeft)
            {
                if (start)
                {
                    PhysicsObj.DoMotion((uint)motionCommand, mvp);

                    SetTurnCommand(motionCommand);
                }
                else
                {
                    if (GetKeyState(keyboardState, TurnRightKeys))
                    {
                        PhysicsObj.DoMotion((uint)MotionCommand.TurnRight, mvp);

                        SetTurnCommand(MotionCommand.TurnRight);
                    }
                    else
                    {
                        PhysicsObj.StopMotion((uint)motionCommand, mvp, true);

                        RemoveTurnCommand();
                    }
                }
            }

            else if (motionCommand == MotionCommand.TurnRight)
            {
                if (start)
                {
                    PhysicsObj.DoMotion((uint)motionCommand, mvp);

                    SetTurnCommand(motionCommand);
                }
                else
                {
                    if (GetKeyState(keyboardState, TurnLeftKeys))
                    {
                        PhysicsObj.DoMotion((uint)MotionCommand.TurnLeft, mvp);

                        SetTurnCommand(MotionCommand.TurnLeft);
                    }
                    else
                    {
                        PhysicsObj.StopMotion((uint)motionCommand, mvp, true);

                        RemoveTurnCommand();
                    }
                }
            }

            else
            {
                PhysicsObj.DoMotion((uint)motionCommand, mvp);
            }
        }