The real movement refactor (#9645)
* The real movement refactor * ref events * Jetpack cleanup * a * Vehicles partially working * Balance tweaks * Restore some shitcode * AAAAAAAA * Even more prediction * ECS compstate trying to fix this * yml * vehicles kill me * Don't lock keys * a * Fix problem * Fix sounds * shuttle inputs * Shuttle controls * space brakes * Keybinds * Fix merge * Handle shutdown * Fix keys * Bump friction * fix buckle offset * Fix relay and friction * Fix jetpack turning * contexts amirite
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
public interface IMobMoverComponent : IComponent
|
||||
{
|
||||
const float GrabRangeDefault = 0.6f;
|
||||
const float PushStrengthDefault = 600.0f;
|
||||
const float WeightlessStrengthDefault = 0.4f;
|
||||
|
||||
EntityCoordinates LastPosition { get; set; }
|
||||
|
||||
public float StepSoundDistance { get; set; }
|
||||
|
||||
float GrabRange { get; set; }
|
||||
|
||||
float PushStrength { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
// Does nothing except ensure uniqueness between mover components.
|
||||
// There can only be one.
|
||||
public interface IMoverComponent : IComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the entity Sprinting (running)?
|
||||
/// </summary>
|
||||
bool Sprinting { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Can the entity currently move. Avoids having to raise move-attempt events every time a player moves.
|
||||
/// Note that this value will be overridden by the action blocker system, and shouldn't just be set directly.
|
||||
/// </summary>
|
||||
bool CanMove { get; set; }
|
||||
|
||||
Angle LastGridAngle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculated linear velocity direction of the entity.
|
||||
/// </summary>
|
||||
(Vector2 walking, Vector2 sprinting) VelocityDir { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Toggles one of the four cardinal directions. Each of the four directions are
|
||||
/// composed into a single direction vector, <see cref="SharedPlayerInputMoverComponent.VelocityDir"/>. Enabling
|
||||
/// opposite directions will cancel each other out, resulting in no direction.
|
||||
/// </summary>
|
||||
/// <param name="direction">Direction to toggle.</param>
|
||||
/// <param name="subTick"></param>
|
||||
/// <param name="enabled">If the direction is active.</param>
|
||||
void SetVelocityDirection(Direction direction, ushort subTick, bool enabled);
|
||||
|
||||
void SetSprinting(ushort subTick, bool walking);
|
||||
}
|
||||
}
|
||||
51
Content.Shared/Movement/Components/InputMoverComponent.cs
Normal file
51
Content.Shared/Movement/Components/InputMoverComponent.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
public sealed class InputMoverComponent : Component
|
||||
{
|
||||
// This class has to be able to handle server TPS being lower than client FPS.
|
||||
// While still having perfectly responsive movement client side.
|
||||
// We do this by keeping track of the exact sub-tick values that inputs are pressed on the client,
|
||||
// and then building a total movement vector based on those sub-tick steps.
|
||||
//
|
||||
// We keep track of the last sub-tick a movement input came in,
|
||||
// Then when a new input comes in, we calculate the fraction of the tick the LAST input was active for
|
||||
// (new sub-tick - last sub-tick)
|
||||
// and then add to the total-this-tick movement vector
|
||||
// by multiplying that fraction by the movement direction for the last input.
|
||||
// This allows us to incrementally build the movement vector for the current tick,
|
||||
// without having to keep track of some kind of list of inputs and calculating it later.
|
||||
//
|
||||
// We have to keep track of a separate movement vector for walking and sprinting,
|
||||
// since we don't actually know our current movement speed while processing inputs.
|
||||
// We change which vector we write into based on whether we were sprinting after the previous input.
|
||||
// (well maybe we do but the code is designed such that MoverSystem applies movement speed)
|
||||
// (and I'm not changing that)
|
||||
|
||||
/// <summary>
|
||||
/// Should our velocity be applied to our parent?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("toParent")]
|
||||
public bool ToParent = false;
|
||||
|
||||
public GameTick LastInputTick;
|
||||
public ushort LastInputSubTick;
|
||||
|
||||
public Vector2 CurTickWalkMovement;
|
||||
public Vector2 CurTickSprintMovement;
|
||||
|
||||
public MoveButtons HeldMoveButtons = MoveButtons.None;
|
||||
|
||||
[ViewVariables]
|
||||
public Angle LastGridAngle { get; set; } = new(0);
|
||||
|
||||
public bool Sprinting => (HeldMoveButtons & MoveButtons.Walk) == 0x0;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanMove { get; set; } = true;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,5 @@ namespace Content.Shared.Movement.Components;
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class JetpackUserComponent : Component
|
||||
{
|
||||
public float Acceleration = 1f;
|
||||
public float Friction = 0.3f;
|
||||
public float WeightlessModifier = 1.2f;
|
||||
public EntityUid Jetpack;
|
||||
}
|
||||
|
||||
59
Content.Shared/Movement/Components/MobMoverComponent.cs
Normal file
59
Content.Shared/Movement/Components/MobMoverComponent.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Has additional movement data such as footsteps and weightless grab range for an entity.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent()]
|
||||
public sealed class MobMoverComponent : Component
|
||||
{
|
||||
private float _stepSoundDistance;
|
||||
[DataField("grabRange")] public float GrabRange = 1.0f;
|
||||
|
||||
[DataField("pushStrength")] public float PushStrength = 600f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public EntityCoordinates LastPosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to keep track of how far we have moved before playing a step sound
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float StepSoundDistance
|
||||
{
|
||||
get => _stepSoundDistance;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(_stepSoundDistance, value)) return;
|
||||
_stepSoundDistance = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float GrabRangeVV
|
||||
{
|
||||
get => GrabRange;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(GrabRange, value)) return;
|
||||
GrabRange = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float PushStrengthVV
|
||||
{
|
||||
get => PushStrength;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(PushStrength, value)) return;
|
||||
PushStrength = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,27 @@ using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies basic movement speed and movement modifiers for an entity.
|
||||
/// If this is not present on the entity then they will use defaults for movement.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent, Access(typeof(MovementSpeedModifierSystem))]
|
||||
public sealed class MovementSpeedModifierComponent : Component
|
||||
{
|
||||
public const float DefaultBaseWalkSpeed = 3.0f;
|
||||
public const float DefaultBaseSprintSpeed = 5.0f;
|
||||
// Weightless
|
||||
public const float DefaultMinimumFrictionSpeed = 0.005f;
|
||||
public const float DefaultWeightlessFriction = 1f;
|
||||
public const float DefaultWeightlessFrictionNoInput = 0.2f;
|
||||
public const float DefaultWeightlessModifier = 0.7f;
|
||||
public const float DefaultWeightlessAcceleration = 1f;
|
||||
|
||||
public const float DefaultAcceleration = 20f;
|
||||
public const float DefaultFriction = 20f;
|
||||
public const float DefaultFrictionNoInput = 20f;
|
||||
|
||||
public const float DefaultBaseWalkSpeed = 2.5f;
|
||||
public const float DefaultBaseSprintSpeed = 4.5f;
|
||||
|
||||
[ViewVariables]
|
||||
public float WalkSpeedModifier = 1.0f;
|
||||
@@ -38,6 +53,54 @@ namespace Content.Shared.Movement.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Minimum speed a mob has to be moving before applying movement friction.
|
||||
/// </summary>
|
||||
[DataField("minimumFrictionSpeed")]
|
||||
public float MinimumFrictionSpeed = DefaultMinimumFrictionSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction when weightless and providing inputs.
|
||||
/// </summary>
|
||||
[DataField("weightlessFriction")]
|
||||
public float WeightlessFriction = DefaultWeightlessFriction;
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction when weightless and not providing inputs.
|
||||
/// This is essentially how much their speed decreases per second.
|
||||
/// </summary>
|
||||
[DataField("weightlessFrictionNoInput")]
|
||||
public float WeightlessFrictionNoInput = DefaultWeightlessFrictionNoInput;
|
||||
|
||||
/// <summary>
|
||||
/// The movement speed modifier applied to a mob's total input velocity when weightless.
|
||||
/// </summary>
|
||||
[DataField("weightlessModifier")]
|
||||
public float WeightlessModifier = DefaultWeightlessModifier;
|
||||
|
||||
/// <summary>
|
||||
/// The acceleration applied to mobs when moving and weightless.
|
||||
/// </summary>
|
||||
[DataField("weightlessAcceleration")]
|
||||
public float WeightlessAcceleration = DefaultWeightlessAcceleration;
|
||||
|
||||
/// <summary>
|
||||
/// The acceleration applied to mobs when moving.
|
||||
/// </summary>
|
||||
[DataField("acceleration")]
|
||||
public float Acceleration = DefaultAcceleration;
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction.
|
||||
/// </summary>
|
||||
[DataField("friction")]
|
||||
public float Friction = DefaultFriction;
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction.
|
||||
/// </summary>
|
||||
[DataField("frictionNoInput")] public float? FrictionNoInput = null;
|
||||
|
||||
[DataField("baseWalkSpeed")]
|
||||
public float BaseWalkSpeed { get; set; } = DefaultBaseWalkSpeed;
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the engine movement inputs for a particular entity onto the designated entity
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class RelayInputMoverComponent : Component
|
||||
{
|
||||
[ViewVariables]
|
||||
public EntityUid? RelayEntity;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IMoverComponent))]
|
||||
public sealed class SharedDummyInputMoverComponent : Component, IMoverComponent
|
||||
{
|
||||
public bool IgnorePaused => false;
|
||||
|
||||
public bool CanMove { get; set; } = true;
|
||||
|
||||
public Angle LastGridAngle { get => Angle.Zero; set {} }
|
||||
|
||||
public bool Sprinting => false;
|
||||
public (Vector2 walking, Vector2 sprinting) VelocityDir => (Vector2.Zero, Vector2.Zero);
|
||||
|
||||
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetSprinting(ushort subTick, bool walking)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IMoverComponent))]
|
||||
[NetworkedComponent()]
|
||||
public sealed class SharedPlayerInputMoverComponent : Component, IMoverComponent
|
||||
{
|
||||
// This class has to be able to handle server TPS being lower than client FPS.
|
||||
// While still having perfectly responsive movement client side.
|
||||
// We do this by keeping track of the exact sub-tick values that inputs are pressed on the client,
|
||||
// and then building a total movement vector based on those sub-tick steps.
|
||||
//
|
||||
// We keep track of the last sub-tick a movement input came in,
|
||||
// Then when a new input comes in, we calculate the fraction of the tick the LAST input was active for
|
||||
// (new sub-tick - last sub-tick)
|
||||
// and then add to the total-this-tick movement vector
|
||||
// by multiplying that fraction by the movement direction for the last input.
|
||||
// This allows us to incrementally build the movement vector for the current tick,
|
||||
// without having to keep track of some kind of list of inputs and calculating it later.
|
||||
//
|
||||
// We have to keep track of a separate movement vector for walking and sprinting,
|
||||
// since we don't actually know our current movement speed while processing inputs.
|
||||
// We change which vector we write into based on whether we were sprinting after the previous input.
|
||||
// (well maybe we do but the code is designed such that MoverSystem applies movement speed)
|
||||
// (and I'm not changing that)
|
||||
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
public GameTick _lastInputTick;
|
||||
public ushort _lastInputSubTick;
|
||||
public Vector2 CurTickWalkMovement;
|
||||
public Vector2 CurTickSprintMovement;
|
||||
|
||||
private MoveButtons _heldMoveButtons = MoveButtons.None;
|
||||
|
||||
[ViewVariables]
|
||||
public Angle LastGridAngle { get; set; } = new(0);
|
||||
|
||||
public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanMove { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated linear velocity direction of the entity.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public (Vector2 walking, Vector2 sprinting) VelocityDir
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_gameTiming.InSimulation)
|
||||
{
|
||||
// Outside of simulation we'll be running client predicted movement per-frame.
|
||||
// So return a full-length vector as if it's a full tick.
|
||||
// Physics system will have the correct time step anyways.
|
||||
var immediateDir = DirVecForButtons(_heldMoveButtons);
|
||||
return Sprinting ? (Vector2.Zero, immediateDir) : (immediateDir, Vector2.Zero);
|
||||
}
|
||||
|
||||
Vector2 walk;
|
||||
Vector2 sprint;
|
||||
float remainingFraction;
|
||||
|
||||
if (_gameTiming.CurTick > _lastInputTick)
|
||||
{
|
||||
walk = Vector2.Zero;
|
||||
sprint = Vector2.Zero;
|
||||
remainingFraction = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
walk = CurTickWalkMovement;
|
||||
sprint = CurTickSprintMovement;
|
||||
remainingFraction = (ushort.MaxValue - _lastInputSubTick) / (float) ushort.MaxValue;
|
||||
}
|
||||
|
||||
var curDir = DirVecForButtons(_heldMoveButtons) * remainingFraction;
|
||||
|
||||
if (Sprinting)
|
||||
{
|
||||
sprint += curDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
walk += curDir;
|
||||
}
|
||||
|
||||
// Logger.Info($"{curDir}{walk}{sprint}");
|
||||
return (walk, sprint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the player can move diagonally.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool DiagonalMovementEnabled => _configurationManager.GetCVar<bool>(CCVars.GameDiagonalMovement);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
LastGridAngle = _entityManager.GetComponent<TransformComponent>(Owner).Parent?.WorldRotation ?? new Angle(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles one of the four cardinal directions. Each of the four directions are
|
||||
/// composed into a single direction vector, <see cref="VelocityDir"/>. Enabling
|
||||
/// opposite directions will cancel each other out, resulting in no direction.
|
||||
/// </summary>
|
||||
/// <param name="direction">Direction to toggle.</param>
|
||||
/// <param name="subTick"></param>
|
||||
/// <param name="enabled">If the direction is active.</param>
|
||||
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
|
||||
{
|
||||
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] {direction}: {enabled}");
|
||||
|
||||
var bit = direction switch
|
||||
{
|
||||
Direction.East => MoveButtons.Right,
|
||||
Direction.North => MoveButtons.Up,
|
||||
Direction.West => MoveButtons.Left,
|
||||
Direction.South => MoveButtons.Down,
|
||||
_ => throw new ArgumentException(nameof(direction))
|
||||
};
|
||||
|
||||
SetMoveInput(subTick, enabled, bit);
|
||||
}
|
||||
|
||||
private void SetMoveInput(ushort subTick, bool enabled, MoveButtons bit)
|
||||
{
|
||||
// Modifies held state of a movement button at a certain sub tick and updates current tick movement vectors.
|
||||
|
||||
if (_gameTiming.CurTick > _lastInputTick)
|
||||
{
|
||||
CurTickWalkMovement = Vector2.Zero;
|
||||
CurTickSprintMovement = Vector2.Zero;
|
||||
_lastInputTick = _gameTiming.CurTick;
|
||||
_lastInputSubTick = 0;
|
||||
}
|
||||
|
||||
if (subTick >= _lastInputSubTick)
|
||||
{
|
||||
var fraction = (subTick - _lastInputSubTick) / (float) ushort.MaxValue;
|
||||
|
||||
ref var lastMoveAmount = ref Sprinting ? ref CurTickSprintMovement : ref CurTickWalkMovement;
|
||||
|
||||
lastMoveAmount += DirVecForButtons(_heldMoveButtons) * fraction;
|
||||
|
||||
_lastInputSubTick = subTick;
|
||||
}
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
_heldMoveButtons |= bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
_heldMoveButtons &= ~bit;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void SetSprinting(ushort subTick, bool walking)
|
||||
{
|
||||
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] Sprint: {enabled}");
|
||||
|
||||
SetMoveInput(subTick, walking, MoveButtons.Walk);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is MoverComponentState state)
|
||||
{
|
||||
_heldMoveButtons = state.Buttons;
|
||||
_lastInputTick = GameTick.Zero;
|
||||
_lastInputSubTick = 0;
|
||||
CanMove = state.CanMove;
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new MoverComponentState(_heldMoveButtons, CanMove);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the normalized direction vector for a specified combination of movement keys.
|
||||
/// </summary>
|
||||
private Vector2 DirVecForButtons(MoveButtons buttons)
|
||||
{
|
||||
// key directions are in screen coordinates
|
||||
// _moveDir is in world coordinates
|
||||
// if the camera is moved, this needs to be changed
|
||||
|
||||
var x = 0;
|
||||
x -= HasFlag(buttons, MoveButtons.Left) ? 1 : 0;
|
||||
x += HasFlag(buttons, MoveButtons.Right) ? 1 : 0;
|
||||
|
||||
var y = 0;
|
||||
if (DiagonalMovementEnabled || x == 0)
|
||||
{
|
||||
y -= HasFlag(buttons, MoveButtons.Down) ? 1 : 0;
|
||||
y += HasFlag(buttons, MoveButtons.Up) ? 1 : 0;
|
||||
}
|
||||
|
||||
var vec = new Vector2(x, y);
|
||||
|
||||
// can't normalize zero length vector
|
||||
if (vec.LengthSquared > 1.0e-6)
|
||||
{
|
||||
// Normalize so that diagonals aren't faster or something.
|
||||
vec = vec.Normalized;
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class MoverComponentState : ComponentState
|
||||
{
|
||||
public MoveButtons Buttons { get; }
|
||||
public readonly bool CanMove;
|
||||
|
||||
public MoverComponentState(MoveButtons buttons, bool canMove)
|
||||
{
|
||||
Buttons = buttons;
|
||||
CanMove = canMove;
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
private enum MoveButtons : byte
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
Walk = 16,
|
||||
}
|
||||
|
||||
private static bool HasFlag(MoveButtons buttons, MoveButtons flag)
|
||||
{
|
||||
return (buttons & flag) == flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// The basic player mover with footsteps and grabbing
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IMobMoverComponent))]
|
||||
[NetworkedComponent()]
|
||||
public sealed class SharedPlayerMobMoverComponent : Component, IMobMoverComponent
|
||||
{
|
||||
private float _stepSoundDistance;
|
||||
[DataField("grabRange")]
|
||||
private float _grabRange = IMobMoverComponent.GrabRangeDefault;
|
||||
[DataField("pushStrength")]
|
||||
private float _pushStrength = IMobMoverComponent.PushStrengthDefault;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public EntityCoordinates LastPosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to keep track of how far we have moved before playing a step sound
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float StepSoundDistance
|
||||
{
|
||||
get => _stepSoundDistance;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(_stepSoundDistance, value)) return;
|
||||
_stepSoundDistance = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float GrabRange
|
||||
{
|
||||
get => _grabRange;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(_grabRange, value)) return;
|
||||
_grabRange = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float PushStrength
|
||||
{
|
||||
get => _pushStrength;
|
||||
set
|
||||
{
|
||||
if (MathHelper.CloseToPercent(_pushStrength, value)) return;
|
||||
_pushStrength = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new PlayerMobMoverComponentState(_grabRange, _pushStrength);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
if (curState is not PlayerMobMoverComponentState playerMoverState) return;
|
||||
GrabRange = playerMoverState.GrabRange;
|
||||
PushStrength = playerMoverState.PushStrength;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class PlayerMobMoverComponentState : ComponentState
|
||||
{
|
||||
public float GrabRange;
|
||||
public float PushStrength;
|
||||
|
||||
public PlayerMobMoverComponentState(float grabRange, float pushStrength)
|
||||
{
|
||||
GrabRange = grabRange;
|
||||
PushStrength = pushStrength;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Content.Shared.Movement.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised on an entity's parent when it has movement inputs while in a container.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly struct ContainerRelayMovementEntityEvent
|
||||
{
|
||||
public readonly EntityUid Entity;
|
||||
|
||||
public ContainerRelayMovementEntityEvent(EntityUid entity)
|
||||
{
|
||||
Entity = entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Content.Shared/Movement/Events/MoveInputEvent.cs
Normal file
17
Content.Shared/Movement/Events/MoveInputEvent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Shared.Movement.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity whenever it has a movement input.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly struct MoveInputEvent
|
||||
{
|
||||
public readonly EntityUid Entity;
|
||||
|
||||
public MoveInputEvent(EntityUid entity)
|
||||
{
|
||||
Entity = entity;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Shared.Movement.Events;
|
||||
|
||||
public sealed class RelayMoveInputEvent : EntityEventArgs
|
||||
{
|
||||
public ICommonSession Session { get; }
|
||||
|
||||
public RelayMoveInputEvent(ICommonSession session)
|
||||
{
|
||||
Session = session;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Content.Shared.Movement.Events
|
||||
{
|
||||
public sealed class RelayMovementEntityEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Entity { get; }
|
||||
|
||||
public RelayMovementEntityEvent(EntityUid entity)
|
||||
{
|
||||
Entity = entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
namespace Content.Shared.Movement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains all of the relevant data for mob movement.
|
||||
/// Raised on a mob if something wants to overwrite its movement characteristics.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public struct MobMovementProfileEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Should we use this profile instead of the entity's default?
|
||||
/// </summary>
|
||||
public bool Override = false;
|
||||
|
||||
public readonly bool Touching;
|
||||
public readonly bool Weightless;
|
||||
|
||||
public float Friction;
|
||||
public float WeightlessModifier;
|
||||
public float Acceleration;
|
||||
|
||||
public MobMovementProfileEvent(
|
||||
bool touching,
|
||||
bool weightless,
|
||||
float friction,
|
||||
float weightlessModifier,
|
||||
float acceleration)
|
||||
{
|
||||
Touching = touching;
|
||||
Weightless = weightless;
|
||||
Friction = friction;
|
||||
WeightlessModifier = weightlessModifier;
|
||||
Acceleration = acceleration;
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,9 @@ public abstract class SharedJetpackSystem : EntitySystem
|
||||
SubscribeLocalEvent<JetpackComponent, GetItemActionsEvent>(OnJetpackGetAction);
|
||||
SubscribeLocalEvent<JetpackComponent, DroppedEvent>(OnJetpackDropped);
|
||||
SubscribeLocalEvent<JetpackComponent, ToggleJetpackEvent>(OnJetpackToggle);
|
||||
SubscribeLocalEvent<JetpackComponent, CanWeightlessMoveEvent>(OnJetpackCanWeightlessMove);
|
||||
|
||||
SubscribeLocalEvent<JetpackUserComponent, CanWeightlessMoveEvent>(OnJetpackUserCanWeightless);
|
||||
SubscribeLocalEvent<JetpackUserComponent, MobMovementProfileEvent>(OnJetpackUserMovement);
|
||||
SubscribeLocalEvent<JetpackUserComponent, EntParentChangedMessage>(OnJetpackUserEntParentChanged);
|
||||
SubscribeLocalEvent<JetpackUserComponent, ComponentGetState>(OnJetpackUserGetState);
|
||||
SubscribeLocalEvent<JetpackUserComponent, ComponentHandleState>(OnJetpackUserHandleState);
|
||||
@@ -38,6 +39,11 @@ public abstract class SharedJetpackSystem : EntitySystem
|
||||
SubscribeLocalEvent<GravityChangedMessage>(OnJetpackUserGravityChanged);
|
||||
}
|
||||
|
||||
private void OnJetpackCanWeightlessMove(EntityUid uid, JetpackComponent component, ref CanWeightlessMoveEvent args)
|
||||
{
|
||||
args.CanMove = true;
|
||||
}
|
||||
|
||||
private void OnJetpackUserGravityChanged(GravityChangedMessage ev)
|
||||
{
|
||||
var gridUid = ev.ChangedGridIndex;
|
||||
@@ -75,17 +81,6 @@ public abstract class SharedJetpackSystem : EntitySystem
|
||||
SetEnabled(component, false, args.User);
|
||||
}
|
||||
|
||||
private void OnJetpackUserMovement(EntityUid uid, JetpackUserComponent component, ref MobMovementProfileEvent args)
|
||||
{
|
||||
// Only overwrite jetpack movement if they're offgrid.
|
||||
if (args.Override || !args.Weightless) return;
|
||||
|
||||
args.Override = true;
|
||||
args.Acceleration = component.Acceleration;
|
||||
args.WeightlessModifier = component.WeightlessModifier;
|
||||
args.Friction = component.Friction;
|
||||
}
|
||||
|
||||
private void OnJetpackUserCanWeightless(EntityUid uid, JetpackUserComponent component, ref CanWeightlessMoveEvent args)
|
||||
{
|
||||
args.CanMove = true;
|
||||
@@ -106,12 +101,17 @@ public abstract class SharedJetpackSystem : EntitySystem
|
||||
private void SetupUser(EntityUid uid, JetpackComponent component)
|
||||
{
|
||||
var user = EnsureComp<JetpackUserComponent>(uid);
|
||||
user.Acceleration = component.Acceleration;
|
||||
user.Friction = component.Friction;
|
||||
user.WeightlessModifier = component.WeightlessModifier;
|
||||
var relay = EnsureComp<RelayInputMoverComponent>(uid);
|
||||
relay.RelayEntity = component.Owner;
|
||||
user.Jetpack = component.Owner;
|
||||
}
|
||||
|
||||
private void RemoveUser(EntityUid uid)
|
||||
{
|
||||
if (!RemComp<JetpackUserComponent>(uid)) return;
|
||||
RemComp<RelayInputMoverComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnJetpackToggle(EntityUid uid, JetpackComponent component, ToggleJetpackEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
@@ -175,7 +175,7 @@ public abstract class SharedJetpackSystem : EntitySystem
|
||||
}
|
||||
else
|
||||
{
|
||||
RemComp<JetpackUserComponent>(user.Value);
|
||||
RemoveUser(user.Value);
|
||||
}
|
||||
|
||||
_movementSpeedModifier.RefreshMovementSpeedModifiers(user.Value);
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
@@ -27,7 +30,41 @@ namespace Content.Shared.Movement.Systems
|
||||
.Bind(EngineKeyFunctions.MoveRight, moveRightCmdHandler)
|
||||
.Bind(EngineKeyFunctions.MoveDown, moveDownCmdHandler)
|
||||
.Bind(EngineKeyFunctions.Walk, new WalkInputCmdHandler(this))
|
||||
// TODO: Relay
|
||||
// Shuttle
|
||||
.Bind(ContentKeyFunctions.ShuttleStrafeUp, new ShuttleInputCmdHandler(this, ShuttleButtons.StrafeUp))
|
||||
.Bind(ContentKeyFunctions.ShuttleStrafeLeft, new ShuttleInputCmdHandler(this, ShuttleButtons.StrafeLeft))
|
||||
.Bind(ContentKeyFunctions.ShuttleStrafeRight, new ShuttleInputCmdHandler(this, ShuttleButtons.StrafeRight))
|
||||
.Bind(ContentKeyFunctions.ShuttleStrafeDown, new ShuttleInputCmdHandler(this, ShuttleButtons.StrafeDown))
|
||||
.Bind(ContentKeyFunctions.ShuttleRotateLeft, new ShuttleInputCmdHandler(this, ShuttleButtons.RotateLeft))
|
||||
.Bind(ContentKeyFunctions.ShuttleRotateRight, new ShuttleInputCmdHandler(this, ShuttleButtons.RotateRight))
|
||||
.Bind(ContentKeyFunctions.ShuttleBrake, new ShuttleInputCmdHandler(this, ShuttleButtons.Brake))
|
||||
.Register<SharedMoverController>();
|
||||
|
||||
SubscribeLocalEvent<InputMoverComponent, ComponentInit>(OnInputInit);
|
||||
SubscribeLocalEvent<InputMoverComponent, ComponentGetState>(OnInputGetState);
|
||||
SubscribeLocalEvent<InputMoverComponent, ComponentHandleState>(OnInputHandleState);
|
||||
}
|
||||
|
||||
private void SetMoveInput(InputMoverComponent component, MoveButtons buttons)
|
||||
{
|
||||
if (component.HeldMoveButtons == buttons) return;
|
||||
component.HeldMoveButtons = buttons;
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
private void OnInputHandleState(EntityUid uid, InputMoverComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not InputMoverComponentState state) return;
|
||||
component.HeldMoveButtons = state.Buttons;
|
||||
component.LastInputTick = GameTick.Zero;
|
||||
component.LastInputSubTick = 0;
|
||||
component.CanMove = state.CanMove;
|
||||
}
|
||||
|
||||
private void OnInputGetState(EntityUid uid, InputMoverComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new InputMoverComponentState(component.HeldMoveButtons, component.CanMove);
|
||||
}
|
||||
|
||||
private void ShutdownInput()
|
||||
@@ -35,46 +72,229 @@ namespace Content.Shared.Movement.Systems
|
||||
CommandBinds.Unregister<SharedMoverController>();
|
||||
}
|
||||
|
||||
private void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
||||
public bool DiagonalMovementEnabled => _configManager.GetCVar(CCVars.GameDiagonalMovement);
|
||||
|
||||
protected virtual void HandleShuttleInput(EntityUid uid, ShuttleButtons button, ushort subTick, bool state) {}
|
||||
|
||||
private void HandleDirChange(EntityUid entity, Direction dir, ushort subTick, bool state)
|
||||
{
|
||||
if (!TryComp<IMoverComponent>(session?.AttachedEntity, out var moverComp))
|
||||
return;
|
||||
TryComp<InputMoverComponent>(entity, out var moverComp);
|
||||
|
||||
var owner = session?.AttachedEntity;
|
||||
|
||||
if (owner != null && session != null)
|
||||
if (TryComp<RelayInputMoverComponent>(entity, out var relayMover))
|
||||
{
|
||||
EntityManager.EventBus.RaiseLocalEvent(owner.Value, new RelayMoveInputEvent(session), true);
|
||||
// if we swap to relay then stop our existing input if we ever change back.
|
||||
if (moverComp != null)
|
||||
{
|
||||
SetMoveInput(moverComp, MoveButtons.None);
|
||||
}
|
||||
|
||||
// For stuff like "Moving out of locker" or the likes
|
||||
if (owner.Value.IsInContainer() &&
|
||||
(!EntityManager.TryGetComponent(owner.Value, out MobStateComponent? mobState) ||
|
||||
mobState.IsAlive()))
|
||||
{
|
||||
var relayMoveEvent = new RelayMovementEntityEvent(owner.Value);
|
||||
EntityManager.EventBus.RaiseLocalEvent(EntityManager.GetComponent<TransformComponent>(owner.Value).ParentUid, relayMoveEvent, true);
|
||||
}
|
||||
// Pass the rider's inputs to the vehicle (the rider itself is on the ignored list in C.S/MoverController.cs)
|
||||
if (TryComp<RiderComponent>(owner.Value, out var rider) && rider.Vehicle != null && rider.Vehicle.HasKey)
|
||||
{
|
||||
if (TryComp<IMoverComponent>(rider.Vehicle.Owner, out var vehicleMover))
|
||||
{
|
||||
vehicleMover.SetVelocityDirection(dir, subTick, state);
|
||||
}
|
||||
}
|
||||
if (relayMover.RelayEntity == null) return;
|
||||
|
||||
HandleDirChange(relayMover.RelayEntity.Value, dir, subTick, state);
|
||||
return;
|
||||
}
|
||||
|
||||
moverComp.SetVelocityDirection(dir, subTick, state);
|
||||
if (moverComp == null)
|
||||
return;
|
||||
|
||||
// Relay the fact we had any movement event.
|
||||
// TODO: Ideally we'd do these in a tick instead of out of sim.
|
||||
var owner = moverComp.Owner;
|
||||
var moveEvent = new MoveInputEvent(entity);
|
||||
RaiseLocalEvent(owner, ref moveEvent);
|
||||
|
||||
// For stuff like "Moving out of locker" or the likes
|
||||
// We'll relay a movement input to the parent.
|
||||
if (_container.IsEntityInContainer(owner) &&
|
||||
TryComp<TransformComponent>(owner, out var xform) &&
|
||||
xform.ParentUid.IsValid() &&
|
||||
_mobState.IsAlive(owner))
|
||||
{
|
||||
var relayMoveEvent = new ContainerRelayMovementEntityEvent(owner);
|
||||
RaiseLocalEvent(xform.ParentUid, ref relayMoveEvent);
|
||||
}
|
||||
|
||||
SetVelocityDirection(moverComp, dir, subTick, state);
|
||||
}
|
||||
|
||||
private void HandleRunChange(ICommonSession? session, ushort subTick, bool walking)
|
||||
private void OnInputInit(EntityUid uid, InputMoverComponent component, ComponentInit args)
|
||||
{
|
||||
if (!TryComp<IMoverComponent>(session?.AttachedEntity, out var moverComp))
|
||||
var xform = Transform(uid);
|
||||
|
||||
if (!xform.ParentUid.IsValid()) return;
|
||||
|
||||
component.LastGridAngle = Transform(xform.ParentUid).WorldRotation;
|
||||
}
|
||||
|
||||
private void HandleRunChange(EntityUid uid, ushort subTick, bool walking)
|
||||
{
|
||||
TryComp<InputMoverComponent>(uid, out var moverComp);
|
||||
|
||||
if (TryComp<RelayInputMoverComponent>(uid, out var relayMover))
|
||||
{
|
||||
// if we swap to relay then stop our existing input if we ever change back.
|
||||
if (moverComp != null)
|
||||
{
|
||||
SetMoveInput(moverComp, MoveButtons.None);
|
||||
}
|
||||
|
||||
if (relayMover.RelayEntity == null) return;
|
||||
|
||||
HandleRunChange(relayMover.RelayEntity.Value, subTick, walking);
|
||||
return;
|
||||
}
|
||||
|
||||
moverComp.SetSprinting(subTick, walking);
|
||||
if (moverComp == null) return;
|
||||
|
||||
SetSprinting(moverComp, subTick, walking);
|
||||
}
|
||||
|
||||
public (Vector2 Walking, Vector2 Sprinting) GetVelocityInput(InputMoverComponent mover)
|
||||
{
|
||||
if (!Timing.InSimulation)
|
||||
{
|
||||
// Outside of simulation we'll be running client predicted movement per-frame.
|
||||
// So return a full-length vector as if it's a full tick.
|
||||
// Physics system will have the correct time step anyways.
|
||||
var immediateDir = DirVecForButtons(mover.HeldMoveButtons);
|
||||
return mover.Sprinting ? (Vector2.Zero, immediateDir) : (immediateDir, Vector2.Zero);
|
||||
}
|
||||
|
||||
Vector2 walk;
|
||||
Vector2 sprint;
|
||||
float remainingFraction;
|
||||
|
||||
if (Timing.CurTick > mover.LastInputTick)
|
||||
{
|
||||
walk = Vector2.Zero;
|
||||
sprint = Vector2.Zero;
|
||||
remainingFraction = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
walk = mover.CurTickWalkMovement;
|
||||
sprint = mover.CurTickSprintMovement;
|
||||
remainingFraction = (ushort.MaxValue - mover.LastInputSubTick) / (float) ushort.MaxValue;
|
||||
}
|
||||
|
||||
var curDir = DirVecForButtons(mover.HeldMoveButtons) * remainingFraction;
|
||||
|
||||
if (mover.Sprinting)
|
||||
{
|
||||
sprint += curDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
walk += curDir;
|
||||
}
|
||||
|
||||
// Logger.Info($"{curDir}{walk}{sprint}");
|
||||
return (walk, sprint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles one of the four cardinal directions. Each of the four directions are
|
||||
/// composed into a single direction vector, <see cref="VelocityDir"/>. Enabling
|
||||
/// opposite directions will cancel each other out, resulting in no direction.
|
||||
/// </summary>
|
||||
public void SetVelocityDirection(InputMoverComponent component, Direction direction, ushort subTick, bool enabled)
|
||||
{
|
||||
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] {direction}: {enabled}");
|
||||
|
||||
var bit = direction switch
|
||||
{
|
||||
Direction.East => MoveButtons.Right,
|
||||
Direction.North => MoveButtons.Up,
|
||||
Direction.West => MoveButtons.Left,
|
||||
Direction.South => MoveButtons.Down,
|
||||
_ => throw new ArgumentException(nameof(direction))
|
||||
};
|
||||
|
||||
SetMoveInput(component, subTick, enabled, bit);
|
||||
}
|
||||
|
||||
private void SetMoveInput(InputMoverComponent component, ushort subTick, bool enabled, MoveButtons bit)
|
||||
{
|
||||
// Modifies held state of a movement button at a certain sub tick and updates current tick movement vectors.
|
||||
ResetSubtick(component);
|
||||
|
||||
if (subTick >= component.LastInputSubTick)
|
||||
{
|
||||
var fraction = (subTick - component.LastInputSubTick) / (float) ushort.MaxValue;
|
||||
|
||||
ref var lastMoveAmount = ref component.Sprinting ? ref component.CurTickSprintMovement : ref component.CurTickWalkMovement;
|
||||
|
||||
lastMoveAmount += DirVecForButtons(component.HeldMoveButtons) * fraction;
|
||||
|
||||
component.LastInputSubTick = subTick;
|
||||
}
|
||||
|
||||
var buttons = component.HeldMoveButtons;
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
buttons |= bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
buttons &= ~bit;
|
||||
}
|
||||
|
||||
SetMoveInput(component, buttons);
|
||||
}
|
||||
|
||||
private void ResetSubtick(InputMoverComponent component)
|
||||
{
|
||||
if (Timing.CurTick <= component.LastInputTick) return;
|
||||
|
||||
component.CurTickWalkMovement = Vector2.Zero;
|
||||
component.CurTickSprintMovement = Vector2.Zero;
|
||||
component.LastInputTick = Timing.CurTick;
|
||||
component.LastInputSubTick = 0;
|
||||
}
|
||||
|
||||
public void SetSprinting(InputMoverComponent component, ushort subTick, bool walking)
|
||||
{
|
||||
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] Sprint: {enabled}");
|
||||
|
||||
SetMoveInput(component, subTick, walking, MoveButtons.Walk);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the normalized direction vector for a specified combination of movement keys.
|
||||
/// </summary>
|
||||
private Vector2 DirVecForButtons(MoveButtons buttons)
|
||||
{
|
||||
// key directions are in screen coordinates
|
||||
// _moveDir is in world coordinates
|
||||
// if the camera is moved, this needs to be changed
|
||||
|
||||
var x = 0;
|
||||
x -= HasFlag(buttons, MoveButtons.Left) ? 1 : 0;
|
||||
x += HasFlag(buttons, MoveButtons.Right) ? 1 : 0;
|
||||
|
||||
var y = 0;
|
||||
if (DiagonalMovementEnabled || x == 0)
|
||||
{
|
||||
y -= HasFlag(buttons, MoveButtons.Down) ? 1 : 0;
|
||||
y += HasFlag(buttons, MoveButtons.Up) ? 1 : 0;
|
||||
}
|
||||
|
||||
var vec = new Vector2(x, y);
|
||||
|
||||
// can't normalize zero length vector
|
||||
if (vec.LengthSquared > 1.0e-6)
|
||||
{
|
||||
// Normalize so that diagonals aren't faster or something.
|
||||
vec = vec.Normalized;
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
private static bool HasFlag(MoveButtons buttons, MoveButtons flag)
|
||||
{
|
||||
return (buttons & flag) == flag;
|
||||
}
|
||||
|
||||
private sealed class MoverDirInputCmdHandler : InputCmdHandler
|
||||
@@ -90,9 +310,9 @@ namespace Content.Shared.Movement.Systems
|
||||
|
||||
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||
{
|
||||
if (message is not FullInputCmdMessage full) return false;
|
||||
if (message is not FullInputCmdMessage full || session?.AttachedEntity == null) return false;
|
||||
|
||||
_controller.HandleDirChange(session, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
||||
_controller.HandleDirChange(session.AttachedEntity.Value, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -108,11 +328,68 @@ namespace Content.Shared.Movement.Systems
|
||||
|
||||
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||
{
|
||||
if (message is not FullInputCmdMessage full) return false;
|
||||
if (message is not FullInputCmdMessage full || session?.AttachedEntity == null) return false;
|
||||
|
||||
_controller.HandleRunChange(session, full.SubTick, full.State == BoundKeyState.Down);
|
||||
_controller.HandleRunChange(session.AttachedEntity.Value, full.SubTick, full.State == BoundKeyState.Down);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class InputMoverComponentState : ComponentState
|
||||
{
|
||||
public MoveButtons Buttons { get; }
|
||||
public readonly bool CanMove;
|
||||
|
||||
public InputMoverComponentState(MoveButtons buttons, bool canMove)
|
||||
{
|
||||
Buttons = buttons;
|
||||
CanMove = canMove;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ShuttleInputCmdHandler : InputCmdHandler
|
||||
{
|
||||
private SharedMoverController _controller;
|
||||
private ShuttleButtons _button;
|
||||
|
||||
public ShuttleInputCmdHandler(SharedMoverController controller, ShuttleButtons button)
|
||||
{
|
||||
_controller = controller;
|
||||
_button = button;
|
||||
}
|
||||
|
||||
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||
{
|
||||
if (message is not FullInputCmdMessage full || session?.AttachedEntity == null) return false;
|
||||
|
||||
_controller.HandleShuttleInput(session.AttachedEntity.Value, _button, full.SubTick, full.State == BoundKeyState.Down);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum MoveButtons : byte
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
Walk = 16,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ShuttleButtons : byte
|
||||
{
|
||||
None = 0,
|
||||
StrafeUp = 1 << 0,
|
||||
StrafeDown = 1 << 1,
|
||||
StrafeLeft = 1 << 2,
|
||||
StrafeRight = 1 << 3,
|
||||
RotateLeft = 1 << 4,
|
||||
RotateRight = 1 << 5,
|
||||
Brake = 1 << 6,
|
||||
}
|
||||
|
||||
39
Content.Shared/Movement/Systems/SharedMoverController.Mob.cs
Normal file
39
Content.Shared/Movement/Systems/SharedMoverController.Mob.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public abstract partial class SharedMoverController
|
||||
{
|
||||
private void InitializeMob()
|
||||
{
|
||||
SubscribeLocalEvent<MobMoverComponent, ComponentGetState>(OnMobGetState);
|
||||
SubscribeLocalEvent<MobMoverComponent, ComponentHandleState>(OnMobHandleState);
|
||||
}
|
||||
|
||||
private void OnMobHandleState(EntityUid uid, MobMoverComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not MobMoverComponentState state) return;
|
||||
component.GrabRangeVV = state.GrabRange;
|
||||
component.PushStrengthVV = state.PushStrength;
|
||||
}
|
||||
|
||||
private void OnMobGetState(EntityUid uid, MobMoverComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new MobMoverComponentState(component.GrabRange, component.PushStrength);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class MobMoverComponentState : ComponentState
|
||||
{
|
||||
public float GrabRange;
|
||||
public float PushStrength;
|
||||
|
||||
public MobMoverComponentState(float grabRange, float pushStrength)
|
||||
{
|
||||
GrabRange = grabRange;
|
||||
PushStrength = pushStrength;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,8 @@ public abstract partial class SharedMoverController
|
||||
|
||||
if (otherBody.BodyType != BodyType.Dynamic || !otherFixture.Hard) return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(ourFixture.Body.Owner, out IMobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
if (!EntityManager.TryGetComponent(ourFixture.Body.Owner, out MobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
|
||||
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrength * frameTime);
|
||||
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrengthVV * frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public abstract partial class SharedMoverController
|
||||
{
|
||||
private void InitializeRelay()
|
||||
{
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, ComponentGetState>(OnRelayGetState);
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, ComponentHandleState>(OnRelayHandleState);
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, ComponentShutdown>(OnRelayShutdown);
|
||||
}
|
||||
|
||||
private void OnRelayShutdown(EntityUid uid, RelayInputMoverComponent component, ComponentShutdown args)
|
||||
{
|
||||
// If relay is removed then cancel all inputs.
|
||||
if (!TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover)) return;
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnRelayHandleState(EntityUid uid, RelayInputMoverComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not RelayInputMoverComponentState state) return;
|
||||
|
||||
component.RelayEntity = state.Entity;
|
||||
}
|
||||
|
||||
private void OnRelayGetState(EntityUid uid, RelayInputMoverComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new RelayInputMoverComponentState()
|
||||
{
|
||||
Entity = component.RelayEntity,
|
||||
};
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class RelayInputMoverComponentState : ComponentState
|
||||
{
|
||||
public EntityUid? Entity;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,19 @@ using Content.Shared.Friction;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.MobState.EntitySystems;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Movement.Systems
|
||||
@@ -26,9 +29,12 @@ namespace Content.Shared.Movement.Systems
|
||||
public abstract partial class SharedMoverController : VirtualController
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly TagSystem _tags = default!;
|
||||
|
||||
@@ -39,46 +45,11 @@ namespace Content.Shared.Movement.Systems
|
||||
private const float FootstepVolume = 3f;
|
||||
private const float FootstepWalkingAddedVolumeMultiplier = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MinimumFrictionSpeed"/>
|
||||
/// </summary>
|
||||
private float _minimumFrictionSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.StopSpeed"/>
|
||||
/// </summary>
|
||||
private float _stopSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MobAcceleration"/>
|
||||
/// </summary>
|
||||
private float _mobAcceleration;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MobFriction"/>
|
||||
/// </summary>
|
||||
private float _frictionVelocity;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MobWeightlessAcceleration"/>
|
||||
/// </summary>
|
||||
private float _mobWeightlessAcceleration;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MobWeightlessFriction"/>
|
||||
/// </summary>
|
||||
private float _weightlessFrictionVelocity;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MobWeightlessFrictionNoInput"/>
|
||||
/// </summary>
|
||||
private float _weightlessFrictionVelocityNoInput;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CCVars.MobWeightlessModifier"/>
|
||||
/// </summary>
|
||||
private float _mobWeightlessModifier;
|
||||
|
||||
private bool _relativeMovement;
|
||||
|
||||
/// <summary>
|
||||
@@ -90,29 +61,16 @@ namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
base.Initialize();
|
||||
InitializeInput();
|
||||
InitializeMob();
|
||||
InitializePushing();
|
||||
// Hello
|
||||
InitializeRelay();
|
||||
_configManager.OnValueChanged(CCVars.RelativeMovement, SetRelativeMovement, true);
|
||||
_configManager.OnValueChanged(CCVars.MinimumFrictionSpeed, SetMinimumFrictionSpeed, true);
|
||||
_configManager.OnValueChanged(CCVars.MobFriction, SetFrictionVelocity, true);
|
||||
_configManager.OnValueChanged(CCVars.MobWeightlessFriction, SetWeightlessFrictionVelocity, true);
|
||||
_configManager.OnValueChanged(CCVars.StopSpeed, SetStopSpeed, true);
|
||||
_configManager.OnValueChanged(CCVars.MobAcceleration, SetMobAcceleration, true);
|
||||
_configManager.OnValueChanged(CCVars.MobWeightlessAcceleration, SetMobWeightlessAcceleration, true);
|
||||
_configManager.OnValueChanged(CCVars.MobWeightlessFrictionNoInput, SetWeightlessFrictionNoInput, true);
|
||||
_configManager.OnValueChanged(CCVars.MobWeightlessModifier, SetMobWeightlessModifier, true);
|
||||
UpdatesBefore.Add(typeof(SharedTileFrictionController));
|
||||
}
|
||||
|
||||
private void SetRelativeMovement(bool value) => _relativeMovement = value;
|
||||
private void SetMinimumFrictionSpeed(float value) => _minimumFrictionSpeed = value;
|
||||
private void SetStopSpeed(float value) => _stopSpeed = value;
|
||||
private void SetFrictionVelocity(float value) => _frictionVelocity = value;
|
||||
private void SetWeightlessFrictionVelocity(float value) => _weightlessFrictionVelocity = value;
|
||||
private void SetMobAcceleration(float value) => _mobAcceleration = value;
|
||||
private void SetMobWeightlessAcceleration(float value) => _mobWeightlessAcceleration = value;
|
||||
private void SetWeightlessFrictionNoInput(float value) => _weightlessFrictionVelocityNoInput = value;
|
||||
private void SetMobWeightlessModifier(float value) => _mobWeightlessModifier = value;
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
@@ -120,14 +78,7 @@ namespace Content.Shared.Movement.Systems
|
||||
ShutdownInput();
|
||||
ShutdownPushing();
|
||||
_configManager.UnsubValueChanged(CCVars.RelativeMovement, SetRelativeMovement);
|
||||
_configManager.UnsubValueChanged(CCVars.MinimumFrictionSpeed, SetMinimumFrictionSpeed);
|
||||
_configManager.UnsubValueChanged(CCVars.StopSpeed, SetStopSpeed);
|
||||
_configManager.UnsubValueChanged(CCVars.MobFriction, SetFrictionVelocity);
|
||||
_configManager.UnsubValueChanged(CCVars.MobWeightlessFriction, SetWeightlessFrictionVelocity);
|
||||
_configManager.UnsubValueChanged(CCVars.MobAcceleration, SetMobAcceleration);
|
||||
_configManager.UnsubValueChanged(CCVars.MobWeightlessAcceleration, SetMobWeightlessAcceleration);
|
||||
_configManager.UnsubValueChanged(CCVars.MobWeightlessFrictionNoInput, SetWeightlessFrictionNoInput);
|
||||
_configManager.UnsubValueChanged(CCVars.MobWeightlessModifier, SetMobWeightlessModifier);
|
||||
}
|
||||
|
||||
public override void UpdateAfterSolve(bool prediction, float frameTime)
|
||||
@@ -136,7 +87,7 @@ namespace Content.Shared.Movement.Systems
|
||||
UsedMobMovement.Clear();
|
||||
}
|
||||
|
||||
protected Angle GetParentGridAngle(TransformComponent xform, IMoverComponent mover)
|
||||
protected Angle GetParentGridAngle(TransformComponent xform, InputMoverComponent mover)
|
||||
{
|
||||
if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||
return mover.LastGridAngle;
|
||||
@@ -144,43 +95,12 @@ namespace Content.Shared.Movement.Systems
|
||||
return grid.WorldRotation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A generic kinematic mover for entities.
|
||||
/// </summary>
|
||||
protected void HandleKinematicMovement(IMoverComponent mover, PhysicsComponent physicsComponent)
|
||||
{
|
||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||
|
||||
var transform = EntityManager.GetComponent<TransformComponent>(mover.Owner);
|
||||
var parentRotation = GetParentGridAngle(transform, mover);
|
||||
|
||||
// Regular movement.
|
||||
// Target velocity.
|
||||
var moveSpeedComponent = CompOrNull<MovementSpeedModifierComponent>(mover.Owner);
|
||||
var walkSpeed = moveSpeedComponent?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
||||
var sprintSpeed = moveSpeedComponent?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
||||
var total = walkDir * walkSpeed + sprintDir * sprintSpeed;
|
||||
|
||||
var worldTotal = _relativeMovement ? parentRotation.RotateVec(total) : total;
|
||||
|
||||
if (transform.GridUid != null)
|
||||
mover.LastGridAngle = parentRotation;
|
||||
|
||||
if (worldTotal != Vector2.Zero)
|
||||
transform.LocalRotation = transform.GridUid != null
|
||||
? total.ToWorldAngle()
|
||||
: worldTotal.ToWorldAngle();
|
||||
|
||||
_physics.SetLinearVelocity(physicsComponent, worldTotal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Movement while considering actionblockers, weightlessness, etc.
|
||||
/// </summary>
|
||||
protected void HandleMobMovement(
|
||||
IMoverComponent mover,
|
||||
InputMoverComponent mover,
|
||||
PhysicsComponent physicsComponent,
|
||||
IMobMoverComponent mobMover,
|
||||
TransformComponent xform,
|
||||
float frameTime)
|
||||
{
|
||||
@@ -194,7 +114,7 @@ namespace Content.Shared.Movement.Systems
|
||||
|
||||
UsedMobMovement[mover.Owner] = true;
|
||||
var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager, entityManager: EntityManager);
|
||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||
var (walkDir, sprintDir) = GetVelocityInput(mover);
|
||||
var touching = false;
|
||||
|
||||
// Handle wall-pushes.
|
||||
@@ -208,7 +128,10 @@ namespace Content.Shared.Movement.Systems
|
||||
var ev = new CanWeightlessMoveEvent();
|
||||
RaiseLocalEvent(xform.Owner, ref ev);
|
||||
// No gravity: is our entity touching anything?
|
||||
touching = ev.CanMove || IsAroundCollider(_physics, xform, mobMover, physicsComponent);
|
||||
touching = ev.CanMove;
|
||||
|
||||
if (!touching && TryComp<MobMoverComponent>(xform.Owner, out var mobMover))
|
||||
touching |= IsAroundCollider(_physics, xform, mobMover, physicsComponent);
|
||||
}
|
||||
|
||||
if (!touching)
|
||||
@@ -222,8 +145,10 @@ namespace Content.Shared.Movement.Systems
|
||||
// Target velocity.
|
||||
// This is relative to the map / grid we're on.
|
||||
var moveSpeedComponent = CompOrNull<MovementSpeedModifierComponent>(mover.Owner);
|
||||
|
||||
var walkSpeed = moveSpeedComponent?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
||||
var sprintSpeed = moveSpeedComponent?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
||||
|
||||
var total = walkDir * walkSpeed + sprintDir * sprintSpeed;
|
||||
|
||||
var parentRotation = GetParentGridAngle(xform, mover);
|
||||
@@ -239,37 +164,30 @@ namespace Content.Shared.Movement.Systems
|
||||
if (weightless)
|
||||
{
|
||||
if (worldTotal != Vector2.Zero && touching)
|
||||
friction = _weightlessFrictionVelocity;
|
||||
friction = moveSpeedComponent?.WeightlessFriction ?? MovementSpeedModifierComponent.DefaultWeightlessFriction;
|
||||
else
|
||||
friction = _weightlessFrictionVelocityNoInput;
|
||||
friction = moveSpeedComponent?.WeightlessFrictionNoInput ?? MovementSpeedModifierComponent.DefaultWeightlessFrictionNoInput;
|
||||
|
||||
weightlessModifier = _mobWeightlessModifier;
|
||||
accel = _mobWeightlessAcceleration;
|
||||
weightlessModifier = moveSpeedComponent?.WeightlessModifier ?? MovementSpeedModifierComponent.DefaultWeightlessModifier;
|
||||
accel = moveSpeedComponent?.WeightlessAcceleration ?? MovementSpeedModifierComponent.DefaultWeightlessAcceleration;
|
||||
}
|
||||
else
|
||||
{
|
||||
friction = _frictionVelocity;
|
||||
if (worldTotal != Vector2.Zero || moveSpeedComponent?.FrictionNoInput == null)
|
||||
{
|
||||
friction = moveSpeedComponent?.Friction ?? MovementSpeedModifierComponent.DefaultFriction;
|
||||
}
|
||||
else
|
||||
{
|
||||
friction = moveSpeedComponent.FrictionNoInput ?? MovementSpeedModifierComponent.DefaultFrictionNoInput;
|
||||
}
|
||||
|
||||
weightlessModifier = 1f;
|
||||
accel = _mobAcceleration;
|
||||
accel = moveSpeedComponent?.Acceleration ?? MovementSpeedModifierComponent.DefaultAcceleration;
|
||||
}
|
||||
|
||||
var profile = new MobMovementProfileEvent(
|
||||
touching,
|
||||
weightless,
|
||||
friction,
|
||||
weightlessModifier,
|
||||
accel);
|
||||
|
||||
RaiseLocalEvent(xform.Owner, ref profile);
|
||||
|
||||
if (profile.Override)
|
||||
{
|
||||
friction = profile.Friction;
|
||||
weightlessModifier = profile.WeightlessModifier;
|
||||
accel = profile.Acceleration;
|
||||
}
|
||||
|
||||
Friction(frameTime, friction, ref velocity);
|
||||
var minimumFrictionSpeed = moveSpeedComponent?.MinimumFrictionSpeed ?? MovementSpeedModifierComponent.DefaultMinimumFrictionSpeed;
|
||||
Friction(minimumFrictionSpeed, frameTime, friction, ref velocity);
|
||||
|
||||
if (xform.GridUid != EntityUid.Invalid)
|
||||
mover.LastGridAngle = parentRotation;
|
||||
@@ -278,12 +196,24 @@ namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
// This should have its event run during island solver soooo
|
||||
xform.DeferUpdates = true;
|
||||
xform.LocalRotation = xform.GridUid != null
|
||||
TransformComponent rotateXform;
|
||||
|
||||
// If we're in a container then relay rotation to the parent instead
|
||||
if (_container.TryGetContainingContainer(xform.Owner, out var container))
|
||||
{
|
||||
rotateXform = Transform(container.Owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
rotateXform = xform;
|
||||
}
|
||||
|
||||
rotateXform.LocalRotation = xform.GridUid != null
|
||||
? total.ToWorldAngle()
|
||||
: worldTotal.ToWorldAngle();
|
||||
xform.DeferUpdates = false;
|
||||
rotateXform.DeferUpdates = false;
|
||||
|
||||
if (!weightless && TryGetSound(mover, mobMover, xform, out var variation, out var sound))
|
||||
if (!weightless && TryComp<MobMoverComponent>(mover.Owner, out var mobMover) && TryGetSound(mover, mobMover, xform, out var variation, out var sound))
|
||||
{
|
||||
var soundModifier = mover.Sprinting ? 1.0f : FootstepWalkingAddedVolumeMultiplier;
|
||||
SoundSystem.Play(sound,
|
||||
@@ -300,11 +230,11 @@ namespace Content.Shared.Movement.Systems
|
||||
_physics.SetLinearVelocity(physicsComponent, velocity);
|
||||
}
|
||||
|
||||
private void Friction(float frameTime, float friction, ref Vector2 velocity)
|
||||
private void Friction(float minimumFrictionSpeed, float frameTime, float friction, ref Vector2 velocity)
|
||||
{
|
||||
var speed = velocity.Length;
|
||||
|
||||
if (speed < _minimumFrictionSpeed) return;
|
||||
if (speed < minimumFrictionSpeed) return;
|
||||
|
||||
var drop = 0f;
|
||||
|
||||
@@ -340,11 +270,11 @@ namespace Content.Shared.Movement.Systems
|
||||
return UsedMobMovement.TryGetValue(uid, out var used) && used;
|
||||
}
|
||||
|
||||
protected bool UseMobMovement(IMoverComponent mover, PhysicsComponent body)
|
||||
protected bool UseMobMovement(InputMoverComponent mover, PhysicsComponent body)
|
||||
{
|
||||
return mover.CanMove &&
|
||||
body.BodyStatus == BodyStatus.OnGround &&
|
||||
HasComp<MobStateComponent>(body.Owner) &&
|
||||
HasComp<InputMoverComponent>(body.Owner) &&
|
||||
// If we're being pulled then don't mess with our velocity.
|
||||
(!TryComp(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled);
|
||||
}
|
||||
@@ -352,9 +282,9 @@ namespace Content.Shared.Movement.Systems
|
||||
/// <summary>
|
||||
/// Used for weightlessness to determine if we are near a wall.
|
||||
/// </summary>
|
||||
private bool IsAroundCollider(SharedPhysicsSystem broadPhaseSystem, TransformComponent transform, IMobMoverComponent mover, IPhysBody collider)
|
||||
private bool IsAroundCollider(SharedPhysicsSystem broadPhaseSystem, TransformComponent transform, MobMoverComponent mover, IPhysBody collider)
|
||||
{
|
||||
var enlargedAABB = collider.GetWorldAABB().Enlarged(mover.GrabRange);
|
||||
var enlargedAABB = collider.GetWorldAABB().Enlarged(mover.GrabRangeVV);
|
||||
|
||||
foreach (var otherCollider in broadPhaseSystem.GetCollidingEntities(transform.MapID, enlargedAABB))
|
||||
{
|
||||
@@ -381,7 +311,7 @@ namespace Content.Shared.Movement.Systems
|
||||
|
||||
protected abstract bool CanSound();
|
||||
|
||||
private bool TryGetSound(IMoverComponent mover, IMobMoverComponent mobMover, TransformComponent xform, out float variation, [NotNullWhen(true)] out string? sound)
|
||||
private bool TryGetSound(InputMoverComponent mover, MobMoverComponent mobMover, TransformComponent xform, out float variation, [NotNullWhen(true)] out string? sound)
|
||||
{
|
||||
sound = null;
|
||||
variation = 0f;
|
||||
|
||||
Reference in New Issue
Block a user