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:
@@ -22,20 +22,20 @@ namespace Content.Shared.ActionBlocker
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<IMoverComponent, ComponentStartup>(OnMoverStartup);
|
||||
SubscribeLocalEvent<InputMoverComponent, ComponentStartup>(OnMoverStartup);
|
||||
}
|
||||
|
||||
private void OnMoverStartup(EntityUid uid, IMoverComponent component, ComponentStartup args)
|
||||
private void OnMoverStartup(EntityUid uid, InputMoverComponent component, ComponentStartup args)
|
||||
{
|
||||
UpdateCanMove(uid, component);
|
||||
}
|
||||
|
||||
public bool CanMove(EntityUid uid, IMoverComponent? component = null)
|
||||
public bool CanMove(EntityUid uid, InputMoverComponent? component = null)
|
||||
{
|
||||
return Resolve(uid, ref component, false) && component.CanMove;
|
||||
}
|
||||
|
||||
public bool UpdateCanMove(EntityUid uid, IMoverComponent? component = null)
|
||||
public bool UpdateCanMove(EntityUid uid, InputMoverComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -8,6 +9,8 @@ namespace Content.Shared.Buckle.Components
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedBuckleComponent : Component, IDraggable
|
||||
{
|
||||
[Dependency] protected readonly IEntityManager EntMan = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The range from which this entity can buckle to a <see cref="SharedStrapComponent"/>.
|
||||
/// </summary>
|
||||
@@ -35,6 +38,33 @@ namespace Content.Shared.Buckle.Components
|
||||
{
|
||||
return TryBuckle(args.User, args.Target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reattaches this entity to the strap, modifying its position and rotation.
|
||||
/// </summary>
|
||||
/// <param name="strap">The strap to reattach to.</param>
|
||||
public void ReAttach(SharedStrapComponent strap)
|
||||
{
|
||||
var ownTransform = EntMan.GetComponent<TransformComponent>(Owner);
|
||||
var strapTransform = EntMan.GetComponent<TransformComponent>(strap.Owner);
|
||||
|
||||
ownTransform.AttachParent(strapTransform);
|
||||
ownTransform.LocalRotation = Angle.Zero;
|
||||
|
||||
switch (strap.Position)
|
||||
{
|
||||
case StrapPosition.None:
|
||||
break;
|
||||
case StrapPosition.Stand:
|
||||
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
|
||||
break;
|
||||
case StrapPosition.Down:
|
||||
EntitySystem.Get<StandingStateSystem>().Down(Owner, false, false);
|
||||
break;
|
||||
}
|
||||
|
||||
ownTransform.LocalPosition = strap.BuckleOffset;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -26,6 +26,40 @@ namespace Content.Shared.Buckle.Components
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedStrapComponent : Component, IDragDropOn
|
||||
{
|
||||
/// <summary>
|
||||
/// The change in position to the strapped mob
|
||||
/// </summary>
|
||||
[DataField("position")]
|
||||
public StrapPosition Position { get; set; } = StrapPosition.None;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is currently buckled here, synced from <see cref="BuckleComponent.BuckledTo"/>
|
||||
/// </summary>
|
||||
public readonly HashSet<EntityUid> BuckledEntities = new();
|
||||
|
||||
/// <summary>
|
||||
/// The distance above which a buckled entity will be automatically unbuckled.
|
||||
/// Don't change it unless you really have to
|
||||
/// </summary>
|
||||
[DataField("maxBuckleDistance", required: false)]
|
||||
public float MaxBuckleDistance = 0.1f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets and clamps the buckle offset to MaxBuckleDistance
|
||||
/// </summary>
|
||||
public Vector2 BuckleOffset => Vector2.Clamp(
|
||||
BuckleOffsetUnclamped,
|
||||
Vector2.One * -MaxBuckleDistance,
|
||||
Vector2.One * MaxBuckleDistance);
|
||||
|
||||
/// <summary>
|
||||
/// The buckled entity will be offset by this amount from the center of the strap object.
|
||||
/// If this offset it too big, it will be clamped to <see cref="MaxBuckleDistance"/>
|
||||
/// </summary>
|
||||
[DataField("buckleOffset", required: false)]
|
||||
public Vector2 BuckleOffsetUnclamped = Vector2.Zero;
|
||||
|
||||
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Dragged, out SharedBuckleComponent? buckleComponent)) return false;
|
||||
@@ -40,15 +74,22 @@ namespace Content.Shared.Buckle.Components
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StrapComponentState : ComponentState
|
||||
{
|
||||
public StrapComponentState(StrapPosition position)
|
||||
{
|
||||
Position = position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The change in position that this strap makes to the strapped mob
|
||||
/// </summary>
|
||||
public StrapPosition Position { get; }
|
||||
public StrapPosition Position;
|
||||
|
||||
public float MaxBuckleDistance;
|
||||
public Vector2 BuckleOffsetClamped;
|
||||
public HashSet<EntityUid> BuckledEntities;
|
||||
|
||||
public StrapComponentState(StrapPosition position, Vector2 offset, HashSet<EntityUid> buckled, float maxBuckleDistance)
|
||||
{
|
||||
Position = position;
|
||||
BuckleOffsetClamped = offset;
|
||||
BuckledEntities = buckled;
|
||||
MaxBuckleDistance = maxBuckleDistance;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Content.Shared.Buckle
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SharedStrapComponent, RotateEvent>(OnStrapRotate);
|
||||
|
||||
SubscribeLocalEvent<SharedBuckleComponent, PreventCollideEvent>(PreventCollision);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, DownAttemptEvent>(HandleDown);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, StandAttemptEvent>(HandleStand);
|
||||
@@ -21,6 +23,23 @@ namespace Content.Shared.Buckle
|
||||
SubscribeLocalEvent<SharedBuckleComponent, ChangeDirectionAttemptEvent>(OnBuckleChangeDirectionAttempt);
|
||||
}
|
||||
|
||||
private void OnStrapRotate(EntityUid uid, SharedStrapComponent component, ref RotateEvent args)
|
||||
{
|
||||
// TODO: This looks dirty af.
|
||||
// On rotation of a strap, reattach all buckled entities.
|
||||
// This fixes buckle offsets and draw depths.
|
||||
foreach (var buckledEntity in component.BuckledEntities)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(buckledEntity, out SharedBuckleComponent? buckled))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
buckled.ReAttach(component);
|
||||
Dirty(buckled);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBuckleChangeDirectionAttempt(EntityUid uid, SharedBuckleComponent component, ChangeDirectionAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
|
||||
@@ -406,54 +406,6 @@ namespace Content.Shared.CCVar
|
||||
* Physics
|
||||
*/
|
||||
|
||||
/*
|
||||
* WARNING: These are liable to get changed to datafields whenever movement refactor occurs and may no longer be valid.
|
||||
* You were warned!
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Minimum speed a mob has to be moving before applying movement friction.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MinimumFrictionSpeed =
|
||||
CVarDef.Create("physics.minimum_friction_speed", 0.005f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The acceleration applied to mobs when moving.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MobAcceleration =
|
||||
CVarDef.Create("physics.mob_acceleration", 14f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MobFriction =
|
||||
CVarDef.Create("physics.mob_friction", 14f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The acceleration applied to mobs when moving and weightless.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MobWeightlessAcceleration =
|
||||
CVarDef.Create("physics.mob_weightless_acceleration", 1f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction when weightless and providing inputs.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MobWeightlessFriction =
|
||||
CVarDef.Create("physics.mob_weightless_friction", 1f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The negative velocity applied for friction when weightless and not providing inputs.
|
||||
/// This is essentially how much their speed decreases per second.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MobWeightlessFrictionNoInput =
|
||||
CVarDef.Create("physics.mob_weightless_friction_no_input", 0.2f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The movement speed modifier applied to a mob's total input velocity when weightless.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> MobWeightlessModifier =
|
||||
CVarDef.Create("physics.mob_weightless_modifier", 0.7f, CVar.ARCHIVE | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// When a mob is walking should its X / Y movement be relative to its parent (true) or the map (false).
|
||||
/// </summary>
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
{
|
||||
if (sound == null || !_gameTiming.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
|
||||
var filter = Filter.Pvs(uid, entityManager: EntityManager);
|
||||
|
||||
if (excluded != null && _netMan.IsServer)
|
||||
|
||||
@@ -14,7 +14,7 @@ public sealed class FollowerSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GetVerbsEvent<AlternativeVerb>>(OnGetAlternativeVerbs);
|
||||
SubscribeLocalEvent<FollowerComponent, RelayMoveInputEvent>(OnFollowerMove);
|
||||
SubscribeLocalEvent<FollowerComponent, MoveInputEvent>(OnFollowerMove);
|
||||
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public sealed class FollowerSystem : EntitySystem
|
||||
ev.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void OnFollowerMove(EntityUid uid, FollowerComponent component, RelayMoveInputEvent args)
|
||||
private void OnFollowerMove(EntityUid uid, FollowerComponent component, ref MoveInputEvent args)
|
||||
{
|
||||
StopFollowingEntity(uid, component.Following);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,13 @@ namespace Content.Shared.Input
|
||||
public static readonly BoundKeyFunction Arcade2 = "Arcade2";
|
||||
public static readonly BoundKeyFunction Arcade3 = "Arcade3";
|
||||
public static readonly BoundKeyFunction OpenActionsMenu = "OpenAbilitiesMenu";
|
||||
public static readonly BoundKeyFunction ShuttleStrafeLeft = "ShuttleStrafeLeft";
|
||||
public static readonly BoundKeyFunction ShuttleStrafeUp = "ShuttleStrafeUp";
|
||||
public static readonly BoundKeyFunction ShuttleStrafeRight = "ShuttleStrafeRight";
|
||||
public static readonly BoundKeyFunction ShuttleStrafeDown = "ShuttleStrafeDown";
|
||||
public static readonly BoundKeyFunction ShuttleRotateLeft = "ShuttleRotateLeft";
|
||||
public static readonly BoundKeyFunction ShuttleRotateRight = "ShuttleRotateRight";
|
||||
public static readonly BoundKeyFunction ShuttleBrake = "ShuttleBrake";
|
||||
public static readonly BoundKeyFunction Hotbar0 = "Hotbar0";
|
||||
public static readonly BoundKeyFunction Hotbar1 = "Hotbar1";
|
||||
public static readonly BoundKeyFunction Hotbar2 = "Hotbar2";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.MobState.EntitySystems;
|
||||
using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Shared.Pulling.Systems
|
||||
@@ -8,19 +8,20 @@ namespace Content.Shared.Pulling.Systems
|
||||
public sealed class SharedPullableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedPullingSystem _pullSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SharedPullableComponent, RelayMoveInputEvent>(OnRelayMoveInput);
|
||||
SubscribeLocalEvent<SharedPullableComponent, MoveInputEvent>(OnRelayMoveInput);
|
||||
}
|
||||
|
||||
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, RelayMoveInputEvent args)
|
||||
private void OnRelayMoveInput(EntityUid uid, SharedPullableComponent component, ref MoveInputEvent args)
|
||||
{
|
||||
var entity = args.Session.AttachedEntity;
|
||||
if (entity == null || !_blocker.CanMove(entity.Value)) return;
|
||||
if (TryComp<MobStateComponent>(component.Owner, out var mobState) && mobState.IsIncapacitated()) return;
|
||||
var entity = args.Entity;
|
||||
if (_mobState.IsIncapacitated(entity) || !_blocker.CanMove(entity)) return;
|
||||
|
||||
_pullSystem.TryStopPull(component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@ public sealed class ShuttleConsoleBoundInterfaceState : RadarConsoleBoundInterfa
|
||||
/// When the next FTL state change happens.
|
||||
/// </summary>
|
||||
public readonly TimeSpan FTLTime;
|
||||
public readonly ShuttleMode Mode;
|
||||
|
||||
public List<(EntityUid Entity, string Destination, bool Enabled)> Destinations;
|
||||
|
||||
public ShuttleConsoleBoundInterfaceState(
|
||||
FTLState ftlState,
|
||||
TimeSpan ftlTime,
|
||||
ShuttleMode mode,
|
||||
List<(EntityUid Entity, string Destination, bool Enabled)> destinations,
|
||||
float maxRange,
|
||||
EntityCoordinates? coordinates,
|
||||
@@ -33,6 +32,5 @@ public sealed class ShuttleConsoleBoundInterfaceState : RadarConsoleBoundInterfa
|
||||
FTLState = ftlState;
|
||||
FTLTime = ftlTime;
|
||||
Destinations = destinations;
|
||||
Mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Shuttles.Components
|
||||
{
|
||||
@@ -18,5 +19,15 @@ namespace Content.Shared.Shuttles.Components
|
||||
[ViewVariables] public EntityCoordinates? Position { get; set; }
|
||||
|
||||
public const float BreakDistance = 0.25f;
|
||||
|
||||
public Vector2 CurTickStrafeMovement = Vector2.Zero;
|
||||
public float CurTickRotationMovement;
|
||||
public float CurTickBraking;
|
||||
|
||||
public GameTick LastInputTick = GameTick.Zero;
|
||||
public ushort LastInputSubTick = 0;
|
||||
|
||||
[ViewVariables]
|
||||
public ShuttleButtons HeldButtons = ShuttleButtons.None;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Content.Shared.Shuttles.Components
|
||||
{
|
||||
public enum ShuttleMode : byte
|
||||
{
|
||||
Strafing,
|
||||
Cruise,
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Shuttles.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised by the client to request the server change a particular shuttle's mode.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ShuttleModeRequestMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public ShuttleMode Mode;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
Vector2 direction,
|
||||
float strength = 1.0f,
|
||||
EntityUid? user = null,
|
||||
float pushbackRatio = 10.0f,
|
||||
float pushbackRatio = 5.0f,
|
||||
PhysicsComponent? physics = null,
|
||||
TransformComponent? transform = null,
|
||||
EntityQuery<PhysicsComponent>? physicsQuery = null,
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Vehicle.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Added to objects inside a vehicle to stop people besides the rider from
|
||||
/// removing them.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class InVehicleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The vehicle this rider is currently riding.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public VehicleComponent Vehicle = default!;
|
||||
[ViewVariables] public VehicleComponent? Vehicle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Vehicle.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Added to people when they are riding in a vehicle
|
||||
/// used mostly to keep track of them for entityquery.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class RiderComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The vehicle this rider is currently riding.
|
||||
/// </summary>
|
||||
[ViewVariables] public VehicleComponent? Vehicle;
|
||||
[ViewVariables] public EntityUid? Vehicle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -17,7 +16,7 @@ namespace Content.Shared.Vehicle.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether someone is currently riding the vehicle
|
||||
/// </summary
|
||||
/// </summary>
|
||||
public bool HasRider = false;
|
||||
|
||||
/// <summary>
|
||||
@@ -27,7 +26,47 @@ namespace Content.Shared.Vehicle.Components
|
||||
public EntityUid? Rider;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the vehicle should treat north as it's unique direction in its visualizer
|
||||
/// The base offset for the vehicle (when facing east)
|
||||
/// </summary>
|
||||
public Vector2 BaseBuckleOffset = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// The sound that the horn makes
|
||||
/// </summary>
|
||||
[DataField("hornSound")] public SoundSpecifier? HornSound =
|
||||
new SoundPathSpecifier("/Audio/Effects/Vehicle/carhorn.ogg")
|
||||
{
|
||||
Params =
|
||||
{
|
||||
Volume = -3f,
|
||||
}
|
||||
};
|
||||
|
||||
public IPlayingAudioStream? HonkPlayingStream;
|
||||
|
||||
/// Use ambient sound component for the idle sound.
|
||||
|
||||
/// <summary>
|
||||
/// The action for the horn (if any)
|
||||
/// </summary>
|
||||
[DataField("hornAction")]
|
||||
public InstantAction HornAction = new()
|
||||
{
|
||||
UseDelay = TimeSpan.FromSeconds(3.4),
|
||||
Icon = new SpriteSpecifier.Texture(new ResourcePath("Objects/Fun/bikehorn.rsi/icon.png")),
|
||||
Name = "action-name-honk",
|
||||
Description = "action-desc-honk",
|
||||
Event = new HonkActionEvent(),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Whether the vehicle has a key currently inside it or not.
|
||||
/// </summary>
|
||||
public bool HasKey = false;
|
||||
|
||||
// TODO: Fix this
|
||||
/// <summary>
|
||||
/// Whether the vehicle should treat north as its unique direction in its visualizer
|
||||
/// </summary>
|
||||
[DataField("northOnly")]
|
||||
public bool NorthOnly = false;
|
||||
@@ -43,55 +82,5 @@ namespace Content.Shared.Vehicle.Components
|
||||
/// </summary>
|
||||
[DataField("southOverride")]
|
||||
public float SouthOverride = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The base offset for the vehicle (when facing east)
|
||||
/// </summary>
|
||||
public Vector2 BaseBuckleOffset = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// The sound that the horn makes
|
||||
/// </summary>
|
||||
[DataField("hornSound")]
|
||||
public SoundSpecifier? HornSound = new SoundPathSpecifier("/Audio/Effects/Vehicle/carhorn.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Whether the horn is a siren or not.
|
||||
/// </summary>
|
||||
[DataField("hornIsSiren")]
|
||||
public bool HornIsLooping = false;
|
||||
|
||||
/// <summary>
|
||||
/// If this vehicle has a siren currently playing.
|
||||
/// </summary>
|
||||
public bool LoopingHornIsPlaying = false;
|
||||
|
||||
public IPlayingAudioStream? SirenPlayingStream;
|
||||
|
||||
/// Use ambient sound component for the idle sound.
|
||||
|
||||
/// <summary>
|
||||
/// The action for the horn (if any)
|
||||
/// </summary>
|
||||
[DataField("hornAction")]
|
||||
public InstantAction HornAction = new()
|
||||
{
|
||||
UseDelay = TimeSpan.FromSeconds(3.4),
|
||||
Icon = new SpriteSpecifier.Texture(new ResourcePath("Objects/Fun/bikehorn.rsi/icon.png")),
|
||||
Name = "action-name-honk",
|
||||
Description = "action-desc-honk",
|
||||
Event = new HonkActionEvent(),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The prototype ID of the key that was inserted so it can be
|
||||
/// spawned when the key is removed.
|
||||
/// </summary>
|
||||
public ItemSlot KeySlot = new();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the vehicle has a key currently inside it or not.
|
||||
/// </summary>
|
||||
public bool HasKey = false;
|
||||
}
|
||||
}
|
||||
|
||||
20
Content.Shared/Vehicle/SharedVehicleSystem.Rider.cs
Normal file
20
Content.Shared/Vehicle/SharedVehicleSystem.Rider.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Vehicle;
|
||||
|
||||
public abstract partial class SharedVehicleSystem
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class RiderComponentState : ComponentState
|
||||
{
|
||||
public EntityUid? Entity;
|
||||
}
|
||||
|
||||
private void OnRiderPull(EntityUid uid, RiderComponent component, PullAttemptEvent args)
|
||||
{
|
||||
if (component.Vehicle != null)
|
||||
args.Cancelled = true;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,174 @@
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Vehicle;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the VehicleVisuals and shared event
|
||||
/// Nothing for a system but these need to be put somewhere in
|
||||
/// Content.Shared
|
||||
/// </summary>
|
||||
namespace Content.Shared.Vehicle
|
||||
public abstract partial class SharedVehicleSystem : EntitySystem
|
||||
{
|
||||
public sealed class SharedVehicleSystem : EntitySystem
|
||||
[Dependency] private readonly MovementSpeedModifierSystem _modifier = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<InVehicleComponent, GettingPickedUpAttemptEvent>(OnPickupAttempt);
|
||||
}
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<InVehicleComponent, GettingPickedUpAttemptEvent>(OnPickupAttempt);
|
||||
SubscribeLocalEvent<RiderComponent, PullAttemptEvent>(OnRiderPull);
|
||||
SubscribeLocalEvent<VehicleComponent, RefreshMovementSpeedModifiersEvent>(OnVehicleModifier);
|
||||
SubscribeLocalEvent<VehicleComponent, ComponentStartup>(OnVehicleStartup);
|
||||
SubscribeLocalEvent<VehicleComponent, RotateEvent>(OnVehicleRotate);
|
||||
}
|
||||
|
||||
private void OnPickupAttempt(EntityUid uid, InVehicleComponent component, GettingPickedUpAttemptEvent args)
|
||||
private void OnVehicleModifier(EntityUid uid, VehicleComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||
{
|
||||
if (!component.HasKey)
|
||||
{
|
||||
if (component.Vehicle == null || !component.Vehicle.HasRider)
|
||||
return;
|
||||
|
||||
if (component.Vehicle.Rider != args.User)
|
||||
args.Cancel();
|
||||
args.ModifySpeed(0f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stores the vehicle's draw depth mostly
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public enum VehicleVisuals : byte
|
||||
private void OnPickupAttempt(EntityUid uid, InVehicleComponent component, GettingPickedUpAttemptEvent args)
|
||||
{
|
||||
/// <summary>
|
||||
/// What layer the vehicle should draw on (assumed integer)
|
||||
/// </summary>
|
||||
DrawDepth,
|
||||
/// <summary>
|
||||
/// Whether the wheels should be turning
|
||||
/// </summary>
|
||||
AutoAnimate
|
||||
if (component.Vehicle == null || component.Vehicle.Rider != null && component.Vehicle.Rider != args.User)
|
||||
args.Cancel();
|
||||
}
|
||||
/// <summary>
|
||||
/// Raised when someone honks a vehicle horn
|
||||
/// </summary>
|
||||
public sealed class HonkActionEvent : InstantActionEvent { }
|
||||
|
||||
/// <summary>
|
||||
/// Raised on the rider when someone is buckled to a vehicle.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BuckledToVehicleEvent : EntityEventArgs
|
||||
// TODO: Shitcode, needs to use sprites instead of actual offsets.
|
||||
private void OnVehicleRotate(EntityUid uid, VehicleComponent component, ref RotateEvent args)
|
||||
{
|
||||
public EntityUid Vehicle;
|
||||
|
||||
public EntityUid Rider;
|
||||
|
||||
/// <summary>
|
||||
/// Whether they were buckled or unbuckled
|
||||
/// </summary>
|
||||
public bool Buckling;
|
||||
public BuckledToVehicleEvent(EntityUid vehicle, EntityUid rider, bool buckling)
|
||||
// This first check is just for safety
|
||||
if (!HasComp<InputMoverComponent>(uid))
|
||||
{
|
||||
Vehicle = vehicle;
|
||||
Rider = rider;
|
||||
Buckling = buckling;
|
||||
UpdateAutoAnimate(uid, false);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateBuckleOffset(args.Component, component);
|
||||
UpdateDrawDepth(uid, GetDrawDepth(args.Component, component.NorthOnly));
|
||||
}
|
||||
|
||||
private void OnVehicleStartup(EntityUid uid, VehicleComponent component, ComponentStartup args)
|
||||
{
|
||||
UpdateDrawDepth(uid, 2);
|
||||
|
||||
// This code should be purged anyway but with that being said this doesn't handle components being changed.
|
||||
if (TryComp<SharedStrapComponent>(uid, out var strap))
|
||||
{
|
||||
component.BaseBuckleOffset = strap.BuckleOffset;
|
||||
strap.BuckleOffsetUnclamped = Vector2.Zero;
|
||||
}
|
||||
|
||||
_modifier.RefreshMovementSpeedModifiers(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Depending on which direction the vehicle is facing,
|
||||
/// change its draw depth. Vehicles can choose between special drawdetph
|
||||
/// when facing north or south. East and west are easy.
|
||||
/// </summary>
|
||||
protected int GetDrawDepth(TransformComponent xform, bool northOnly)
|
||||
{
|
||||
// TODO: I can't even
|
||||
if (northOnly)
|
||||
{
|
||||
return xform.LocalRotation.Degrees switch
|
||||
{
|
||||
< 135f => (int) DrawDepth.DrawDepth.Doors,
|
||||
<= 225f => (int) DrawDepth.DrawDepth.WallMountedItems,
|
||||
_ => 5
|
||||
};
|
||||
}
|
||||
return xform.LocalRotation.Degrees switch
|
||||
{
|
||||
< 45f => (int) DrawDepth.DrawDepth.Doors,
|
||||
<= 315f => (int) DrawDepth.DrawDepth.WallMountedItems,
|
||||
_ => (int) DrawDepth.DrawDepth.Doors,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the buckle offset based on what direction the vehicle is facing and
|
||||
/// teleport any buckled entities to it. This is the most crucial part of making
|
||||
/// buckled vehicles work.
|
||||
/// </summary>
|
||||
protected void UpdateBuckleOffset(TransformComponent xform, VehicleComponent component)
|
||||
{
|
||||
if (!TryComp<SharedStrapComponent>(component.Owner, out var strap))
|
||||
return;
|
||||
|
||||
// TODO: Strap should handle this but buckle E/C moment.
|
||||
var oldOffset = strap.BuckleOffsetUnclamped;
|
||||
|
||||
strap.BuckleOffsetUnclamped = xform.LocalRotation.Degrees switch
|
||||
{
|
||||
< 45f => (0, component.SouthOverride),
|
||||
<= 135f => component.BaseBuckleOffset,
|
||||
< 225f => (0, component.NorthOverride),
|
||||
<= 315f => (component.BaseBuckleOffset.X * -1, component.BaseBuckleOffset.Y),
|
||||
_ => (0, component.SouthOverride)
|
||||
};
|
||||
|
||||
if (!oldOffset.Equals(strap.BuckleOffsetUnclamped))
|
||||
Dirty(strap);
|
||||
|
||||
foreach (var buckledEntity in strap.BuckledEntities)
|
||||
{
|
||||
var buckleXform = Transform(buckledEntity);
|
||||
_transform.SetLocalPositionNoLerp(buckleXform, strap.BuckleOffset);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the draw depth for the sprite.
|
||||
/// </summary>
|
||||
protected void UpdateDrawDepth(EntityUid uid, int drawDepth)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
return;
|
||||
|
||||
appearance.SetData(VehicleVisuals.DrawDepth, drawDepth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set whether the vehicle's base layer is animating or not.
|
||||
/// </summary>
|
||||
protected void UpdateAutoAnimate(EntityUid uid, bool autoAnimate)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
return;
|
||||
|
||||
appearance.SetData(VehicleVisuals.AutoAnimate, autoAnimate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores the vehicle's draw depth mostly
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public enum VehicleVisuals : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// What layer the vehicle should draw on (assumed integer)
|
||||
/// </summary>
|
||||
DrawDepth,
|
||||
/// <summary>
|
||||
/// Whether the wheels should be turning
|
||||
/// </summary>
|
||||
AutoAnimate
|
||||
}
|
||||
/// <summary>
|
||||
/// Raised when someone honks a vehicle horn
|
||||
/// </summary>
|
||||
public sealed class HonkActionEvent : InstantActionEvent { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user