示例#1
0
 public EntityFrame(NetEntity ent)
 {
     CurTime       = 0;
     UserCmdFields = new UserCmd.CmdFields();
     Position      = ent.Origin;
     Angles        = ent.Angles;
 }
示例#2
0
        public override void ExecuteMovement(UserCmd.CmdFields cmd)
        {
            var moving = false;
            var curPos = GetPointOnMesh(Human.Origin);

            if (cmd.Buttons.HasFlag(Movement.InputActions.HandAction))
            {
                _currentWaypoint = 1;
                NavMesh.CalculatePath(curPos, cmd.MousePosition, 1 << 0, _path);
            }

            if (_path.status != NavMeshPathStatus.PathInvalid &&
                _currentWaypoint < _path.corners.Length)
            {
                var dir        = (_path.corners[_currentWaypoint] - curPos).normalized;
                var moveVector = dir * 5.5f * Time.fixedDeltaTime;
                moving  = true;
                curPos += moveVector;

                Human.Origin = curPos;
                Human.Angles = Quaternion.LookRotation(dir).eulerAngles;

                var dist = Vector3.Distance(curPos, _path.corners[_currentWaypoint]);
                if (dist <= .1f)
                {
                    _currentWaypoint++;
                }
            }

            Human.Velocity = moving
                ? Human.HumanGameObject.ViewBody.transform.forward * 10
                : Vector3.zero;
        }
示例#3
0
        public void RunCommand(UserCmd.CmdFields userCmd)
        {
            if (userCmd.Buttons.HasFlag(InputActions.Drop) &&
                Equipped != null)
            {
                Equipped.Drop();
                return;
            }

            if (userCmd.Buttons.HasFlag(InputActions.NextItem))
            {
                EquipItem(GetNextItem());
                return;
            }

            if (userCmd.Buttons.HasFlag(InputActions.PrevItem))
            {
                EquipItem(_lastEquipped ?? GetNextItem());
                return;
            }

            foreach (var kvp in _buttonToSlot)
            {
                if (userCmd.Buttons.HasFlag(kvp.Key))
                {
                    EquipItem(GetNextItem(kvp.Value));
                    return;
                }
            }

            if (Equipped != null)
            {
                Equipped.RunCommand(userCmd);
            }
        }
示例#4
0
        public override void ProcessRunCommand(UserCmd.CmdFields userCmd)
        {
            base.ProcessRunCommand(userCmd);

            if (userCmd.Buttons.HasFlag(InputActions.Reload))
            {
                TryReload();
            }
        }
        public override void ExecuteMovement(UserCmd.CmdFields cmd)
        {
            var oldBtns = MoveData.Buttons;

            Right   = Quaternion.Euler(cmd.Angles) * Vector3.right;
            Forward = Quaternion.Euler(new Vector3(0, cmd.Angles.y, 0)) * Vector3.forward;
            Up      = Quaternion.Euler(cmd.Angles) * Vector3.up;

            MoveData.Buttons      = cmd.Buttons;
            MoveData.ViewAngles   = cmd.Angles;
            MoveData.Origin       = Human.Origin;
            MoveData.Velocity     = Human.Velocity;
            MoveData.BaseVelocity = Human.BaseVelocity;
            MoveData.ForwardMove  = 0;
            MoveData.SideMove     = 0;
            MoveData.UpMove       = 0;

            if (cmd.Buttons.HasFlag(InputActions.MoveBack))
            {
                MoveData.ForwardMove = -Human.Game.GameMovement.Config.ForwardSpeed;
            }

            if (cmd.Buttons.HasFlag(InputActions.MoveForward))
            {
                MoveData.ForwardMove = Human.Game.GameMovement.Config.ForwardSpeed;
            }

            if (cmd.Buttons.HasFlag(InputActions.MoveRight))
            {
                MoveData.SideMove = Human.Game.GameMovement.Config.SideSpeed;
            }

            if (cmd.Buttons.HasFlag(InputActions.MoveLeft))
            {
                MoveData.SideMove = -Human.Game.GameMovement.Config.SideSpeed;
            }

            _surfController.CalculateMovement(this, Human.Game.GameMovement.Config, Time.fixedDeltaTime);

            MoveData.OldButtons = MoveData.Buttons;

            if (Human.Game.IsHost || Human.Local == Human)
            {
                DetectTouchingTriggers();
                TouchTriggers();

                Human.Velocity     = MoveData.Velocity;
                Human.BaseVelocity = MoveData.BaseVelocity;
                Human.Origin       = MoveData.Origin;
                Human.Angles       = MoveData.ViewAngles;
                Human.Ducked       = MoveData.Ducked;
            }
        }
示例#6
0
        public void RunCommand(UserCmd.CmdFields userCmd)
        {
            if (!EquippableGameObject)
            {
                return;
            }

            if (_equipped)
            {
                EquippableGameObject.ProcessRunCommand(userCmd);
            }
        }
示例#7
0
        public void StashLocalCmd(UserCmd.CmdFields cmd)
        {
            _localHistory.Add(cmd);

            if (_localHistory.Count > 512)
            {
#if UNITY_EDITOR
                Debug.LogError("It can't be so!");
#endif
                _localHistory.Clear();
            }
        }
示例#8
0
        public void StashServerCmd(UserCmd.CmdFields hostFrame)
        {
            var clientFrameIndex = GetClientFrameIndex(hostFrame.PacketId);

            if (clientFrameIndex == -1)
            {
                return;
            }

            var clientFrame = _localHistory[clientFrameIndex];

            var errorPos = Vector3.Distance(hostFrame.Origin, clientFrame.Origin);
            var errorVel = Vector3.Distance(hostFrame.Velocity, clientFrame.Velocity);
            var errorAng = Vector3.Distance(hostFrame.Angles, clientFrame.Angles);

            if (errorAng > 0.001f)
            {
                _player.Angles = hostFrame.Angles;
            }

            var error = errorPos > 0.001f ||
                        errorVel > 0.001f;

            if (error)
            {
#if UNITY_EDITOR && FALSE
                Debug.LogFormat("Prediction error: pos-{0}, vel-{1}, ang-{2}", errorPos, errorVel, errorAng);
                //Debug.Log($"{Time.frameCount} - BTN - {hostFrame.Buttons}:{clientFrame.Buttons} ID - {hostFrame.PacketId}:{clientFrame.PacketId} POS - {hostFrame.Origin}:{clientFrame.Origin}");
#endif
                var prevAngles = _player.Angles;
                _player.Origin       = hostFrame.Origin;
                _player.Angles       = hostFrame.Angles;
                _player.Velocity     = hostFrame.Velocity;
                _player.BaseVelocity = hostFrame.BaseVelocity;
                for (int i = _localHistory.Count - 1; i >= 0; i--)
                {
                    if (_localHistory[i].PacketId <= hostFrame.PacketId)
                    {
                        _localHistory.RemoveAt(i);
                    }
                }
                foreach (var u in _localHistory)
                {
                    _player.MovementController?.ExecuteMovement(u);
                }
                _player.Angles = prevAngles;
            }
            else
            {
                _localHistory.RemoveRange(0, clientFrameIndex);
            }
        }
示例#9
0
        public void RunCommand(UserCmd.CmdFields userCmd, bool prediction)
        {
            if (Human == Human.Local && !prediction)
            {
                _reconciliator.StashServerCmd(userCmd);
                return;
            }

            if (Human.Game.IsHost && MouseControlsRotation)
            {
                Human.Angles = userCmd.Angles;
            }

            ExecuteMovement(userCmd);

            if (Human == Human.Local && prediction)
            {
                userCmd.Origin       = Human.Origin;
                userCmd.Velocity     = Human.Velocity;
                userCmd.BaseVelocity = Human.BaseVelocity;
                _reconciliator.StashLocalCmd(userCmd);
            }
        }
示例#10
0
 public abstract void ExecuteMovement(UserCmd.CmdFields cmd);