Exemple #1
0
        public void ExecuteUserCmd(IPlayerUserCmdGetter getter, IUserCmd cmd)
        {
            if (cmd.PredicatedOnce)
            {
                return;
            }

            PlayerEntity player = (PlayerEntity)getter.OwnerEntity;

            //服务器通过tcp指令修改客户端位置
            CorrectPositionByServer(cmd, player);

            CheckPlayerLifeState(player);

            var updateComponent = player.moveUpdate;

            updateComponent.LastPosition = player.position.Value.ShiftedToFixedVector3();

            updateComponent.Reset();

            if (!CanPlayerMove(player))
            {
                return;
            }

            player.playerMove.ClearState();

            // swimhandler和divehandler未解耦,handler内部函数声明为static,解耦后可以不使用switch
            MoveType moveType = GetPlayerMoveType(player);

            switch (moveType)
            {
            case MoveType.Land:
                LandHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f);
                break;

            case MoveType.Swim:
                SwimHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f);
                break;

            case MoveType.Dive:
                DiveHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f);
                break;

            case MoveType.Fly:
                FlyHandler.Move(player, cmd, cmd.FrameInterval * 0.001f);
                break;

            default:
                break;
            }

            SyncPlayerMove(player, moveType);
        }
Exemple #2
0
        public void ExecuteUserCmd(IUserCmdOwner owner, IUserCmd cmd)
        {
            PlayerEntity player = (PlayerEntity)owner.OwnerEntity;

            CorrectPositionByServer(cmd, player);

            CheckPlayerLifeState(player);

            var updateComponent = player.moveUpdate;

            updateComponent.LastPosition = player.position.Value;

            updateComponent.Reset();

            if (!CanPlayerMove(player))
            {
                return;
            }

            player.playerMove.ClearState();

            MoveType moveType = GetPlayerMoveType(player);

            switch (moveType)
            {
            case MoveType.Land:
                LandHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f);
                break;

            case MoveType.Swim:
                SwimHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f);
                break;

            case MoveType.Dive:
                DiveHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f);
                break;

            case MoveType.Fly:
                FlyHandler.Move(player, cmd, cmd.FrameInterval * 0.001f);
                break;

            default:
                break;
            }

            SyncPlayerMove(player, moveType);
        }
Exemple #3
0
        public static void Move(Contexts contexts, PlayerEntity player, float deltaTime)
        {
            var state = player.stateInterface.State;

            var postureInConfig = state.GetNextPostureState();

            var controller = player.characterContoller.Value;

            controller.SetCurrentControllerType(postureInConfig);

            controller.SetCharacterPosition(player.position.Value);

            var diveXAngle = CalcSwimXAngle(state.VerticalValue, state.HorizontalValue, state.UpDownValue);

            controller.SetCharacterRotation(new Vector3(diveXAngle, YawPitchUtility.Normalize(player.orientation.Yaw + player.orientation.PunchYaw), 0));

            var lastVel = Quaternion.Inverse(player.orientation.RotationYaw) * player.playerMove.Velocity.ToVector4();

            var velocity = player.stateInterface.State.GetSpeed(lastVel, deltaTime);

            velocity = player.orientation.RotationYaw * velocity.ToVector4();

            var velocityOffset = player.stateInterface.State.GetSpeedOffset();

            var dist = (velocity + velocityOffset) * deltaTime;

            if (DiveTest(player, velocityOffset, dist))
            {
                player.stateInterface.State.Dive();
                DiveHandler.Move(contexts, player, deltaTime);
                player.moveUpdate.BeginDive = true;
            }

            else
            {
                PlayerMoveUtility.Move(contexts, player, player.characterContoller.Value, dist, deltaTime);
                player.playerMove.Velocity = velocity;
                player.position.Value      = controller.transform.position;
            }
        }