Jetpacks (#9023)
* Movement acceleration * tweaks * Weightless refactor coz fuck it * CCVars * weightless movement tweaks * Some cleanup while I'm here * dorkpacks * thanks fork * fixes * zoomies * toggles * hmm * yamls * b * so true * Effects refactor * namespace * review
This commit is contained in:
@@ -6,6 +6,7 @@ using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Speech;
|
||||
using Content.Shared.Throwing;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
@@ -2,6 +2,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Pulling;
|
||||
using Content.Shared.Pulling.Components;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
@@ -2,7 +2,7 @@ using Content.Shared.Chemistry.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using static Content.Shared.Chemistry.Components.MovespeedModifierMetabolismComponent;
|
||||
|
||||
namespace Content.Shared.Chemistry
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Shared.Climbing;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Pulling.Events;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
|
||||
namespace Content.Shared.Damage
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Follower.Components;
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
namespace Content.Shared.Follower;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
@@ -8,7 +8,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Strip.Components;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Electrocution;
|
||||
using Content.Shared.Explosion;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Slippery;
|
||||
|
||||
namespace Content.Shared.Inventory;
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Shared.Item;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.MobState.State;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Pulling.Events;
|
||||
using Content.Shared.Speech;
|
||||
using Content.Shared.Standing;
|
||||
|
||||
13
Content.Shared/Movement/Components/ActiveJetpackComponent.cs
Normal file
13
Content.Shared/Movement/Components/ActiveJetpackComponent.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Added to an enabled jetpack. Tracks gas usage on server / effect spawning on client.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class ActiveJetpackComponent : Component
|
||||
{
|
||||
public float EffectCooldown = 0.3f;
|
||||
public float Accumulator = 0f;
|
||||
}
|
||||
24
Content.Shared/Movement/Components/JetpackComponent.cs
Normal file
24
Content.Shared/Movement/Components/JetpackComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class JetpackComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("volumeUsage")]
|
||||
public float VolumeUsage = Atmospherics.BreathVolume;
|
||||
|
||||
[ViewVariables, DataField("toggleAction", required: true)]
|
||||
public InstantAction ToggleAction = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("acceleration")]
|
||||
public float Acceleration = 1f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("friction")]
|
||||
public float Friction = 0.3f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("weightlessModifier")]
|
||||
public float WeightlessModifier = 1.2f;
|
||||
}
|
||||
14
Content.Shared/Movement/Components/JetpackUserComponent.cs
Normal file
14
Content.Shared/Movement/Components/JetpackUserComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Added to someone using a jetpack for movement purposes
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class JetpackUserComponent : Component
|
||||
{
|
||||
public float Acceleration = 1f;
|
||||
public float Friction = 0.3f;
|
||||
public float WeightlessModifier = 1.2f;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Shared.Movement.EntitySystems
|
||||
{
|
||||
public sealed class SharedMobMoverSystem : EntitySystem
|
||||
{
|
||||
private bool _pushingEnabled;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Get<SharedPhysicsSystem>().KinematicControllerCollision += OnMobCollision;
|
||||
IoCManager.Resolve<IConfigurationManager>().OnValueChanged(CCVars.MobPushing, SetPushing, true);
|
||||
}
|
||||
|
||||
private void SetPushing(bool value)
|
||||
{
|
||||
_pushingEnabled = value;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
IoCManager.Resolve<IConfigurationManager>().UnsubValueChanged(CCVars.MobPushing, SetPushing);
|
||||
Get<SharedPhysicsSystem>().KinematicControllerCollision -= OnMobCollision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fake pushing for player collisions.
|
||||
/// </summary>
|
||||
private void OnMobCollision(Fixture ourFixture, Fixture otherFixture, float frameTime, Vector2 worldNormal)
|
||||
{
|
||||
if (!_pushingEnabled) return;
|
||||
|
||||
var otherBody = otherFixture.Body;
|
||||
|
||||
if (otherBody.BodyType != BodyType.Dynamic || !otherFixture.Hard) return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(ourFixture.Body.Owner, out IMobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
|
||||
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrength * frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Content.Shared/Movement/Events/RelayMoveInputEvent.cs
Normal file
13
Content.Shared/Movement/Events/RelayMoveInputEvent.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
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,4 +1,4 @@
|
||||
namespace Content.Shared.Movement
|
||||
namespace Content.Shared.Movement.Events
|
||||
{
|
||||
public sealed class RelayMovementEntityEvent : EntityEventArgs
|
||||
{
|
||||
8
Content.Shared/Movement/Events/ToggleJetpackEvent.cs
Normal file
8
Content.Shared/Movement/Events/ToggleJetpackEvent.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Actions;
|
||||
|
||||
namespace Content.Shared.Movement.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a jetpack whenever it is toggled.
|
||||
/// </summary>
|
||||
public sealed class ToggleJetpackEvent : InstantActionEvent {}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
|
||||
namespace Content.Shared.Movement;
|
||||
namespace Content.Shared.Movement.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised whenever <see cref="IMoverComponent.CanMove"/> needs to be updated. Cancel this event to prevent a
|
||||
14
Content.Shared/Movement/Events/WeightlessMoveEvent.cs
Normal file
14
Content.Shared/Movement/Events/WeightlessMoveEvent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Content.Shared.Movement.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity to check if it can move while weightless.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public struct CanWeightlessMoveEvent
|
||||
{
|
||||
public bool CanMove = false;
|
||||
|
||||
public CanWeightlessMoveEvent()
|
||||
{
|
||||
}
|
||||
}
|
||||
35
Content.Shared/Movement/MobMovementProfileEvent.cs
Normal file
35
Content.Shared/Movement/MobMovementProfileEvent.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.EntitySystems;
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public sealed class MovementIgnoreGravitySystem : EntitySystem
|
||||
{
|
||||
@@ -3,26 +3,13 @@ using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Movement.EntitySystems
|
||||
namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
public sealed class MovementSpeedModifierSystem : EntitySystem
|
||||
{
|
||||
private readonly HashSet<EntityUid> _needsRefresh = new();
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var uid in _needsRefresh)
|
||||
{
|
||||
RecalculateMovementSpeedModifiers(uid);
|
||||
}
|
||||
|
||||
_needsRefresh.Clear();
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
UpdatesOutsidePrediction = true;
|
||||
SubscribeLocalEvent<MovementSpeedModifierComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<MovementSpeedModifierComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
@@ -47,23 +34,18 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
component.SprintSpeedModifier = state.SprintSpeedModifier;
|
||||
}
|
||||
|
||||
public void RefreshMovementSpeedModifiers(EntityUid uid)
|
||||
{
|
||||
_needsRefresh.Add(uid);
|
||||
}
|
||||
|
||||
private void RecalculateMovementSpeedModifiers(EntityUid uid, MovementSpeedModifierComponent? move = null)
|
||||
public void RefreshMovementSpeedModifiers(EntityUid uid, MovementSpeedModifierComponent? move = null)
|
||||
{
|
||||
if (!Resolve(uid, ref move, false))
|
||||
return;
|
||||
|
||||
var ev = new RefreshMovementSpeedModifiersEvent();
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
RaiseLocalEvent(uid, ev);
|
||||
|
||||
move.WalkSpeedModifier = ev.WalkSpeedModifier;
|
||||
move.SprintSpeedModifier = ev.SprintSpeedModifier;
|
||||
|
||||
move.Dirty();
|
||||
Dirty(move);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
124
Content.Shared/Movement/Systems/SharedJetpackSystem.cs
Normal file
124
Content.Shared/Movement/Systems/SharedJetpackSystem.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public abstract class SharedJetpackSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly SharedContainerSystem Container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<JetpackComponent, GetItemActionsEvent>(OnJetpackGetAction);
|
||||
SubscribeLocalEvent<JetpackComponent, DroppedEvent>(OnJetpackDropped);
|
||||
SubscribeLocalEvent<JetpackComponent, ToggleJetpackEvent>(OnJetpackToggle);
|
||||
SubscribeLocalEvent<JetpackUserComponent, CanWeightlessMoveEvent>(OnJetpackUserCanWeightless);
|
||||
SubscribeLocalEvent<JetpackUserComponent, MobMovementProfileEvent>(OnJetpackUserMovement);
|
||||
}
|
||||
|
||||
private void OnJetpackDropped(EntityUid uid, JetpackComponent component, DroppedEvent args)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
private void SetupUser(EntityUid uid, JetpackComponent component)
|
||||
{
|
||||
var user = EnsureComp<JetpackUserComponent>(uid);
|
||||
user.Acceleration = component.Acceleration;
|
||||
user.Friction = component.Friction;
|
||||
user.WeightlessModifier = component.WeightlessModifier;
|
||||
}
|
||||
|
||||
private void OnJetpackToggle(EntityUid uid, JetpackComponent component, ToggleJetpackEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
|
||||
SetEnabled(component, !IsEnabled(uid));
|
||||
}
|
||||
|
||||
private void OnJetpackGetAction(EntityUid uid, JetpackComponent component, GetItemActionsEvent args)
|
||||
{
|
||||
args.Actions.Add(component.ToggleAction);
|
||||
}
|
||||
|
||||
private bool IsEnabled(EntityUid uid)
|
||||
{
|
||||
return HasComp<ActiveJetpackComponent>(uid);
|
||||
}
|
||||
|
||||
public void SetEnabled(JetpackComponent component, bool enabled, EntityUid? user = null)
|
||||
{
|
||||
if (IsEnabled(component.Owner) == enabled ||
|
||||
enabled && !CanEnable(component)) return;
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
EnsureComp<ActiveJetpackComponent>(component.Owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemComp<ActiveJetpackComponent>(component.Owner);
|
||||
}
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
Container.TryGetContainingContainer(component.Owner, out var container);
|
||||
user = container?.Owner;
|
||||
}
|
||||
|
||||
// Can't activate if no one's using.
|
||||
if (user == null && enabled) return;
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
SetupUser(user.Value, component);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemComp<JetpackUserComponent>(user.Value);
|
||||
}
|
||||
}
|
||||
|
||||
TryComp<AppearanceComponent>(component.Owner, out var appearance);
|
||||
appearance?.SetData(JetpackVisuals.Enabled, enabled);
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
protected abstract bool CanEnable(JetpackComponent component);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class JetpackComponentState : ComponentState
|
||||
{
|
||||
public bool Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum JetpackVisuals : byte
|
||||
{
|
||||
Enabled,
|
||||
}
|
||||
@@ -1,47 +1,43 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Shared.Movement.EntitySystems
|
||||
namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles converting inputs into movement.
|
||||
/// </summary>
|
||||
public sealed class SharedMoverSystem : EntitySystem
|
||||
public abstract partial class SharedMoverController
|
||||
{
|
||||
public override void Initialize()
|
||||
private void InitializeInput()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
var moveUpCmdHandler = new MoverDirInputCmdHandler(Direction.North);
|
||||
var moveLeftCmdHandler = new MoverDirInputCmdHandler(Direction.West);
|
||||
var moveRightCmdHandler = new MoverDirInputCmdHandler(Direction.East);
|
||||
var moveDownCmdHandler = new MoverDirInputCmdHandler(Direction.South);
|
||||
var moveUpCmdHandler = new MoverDirInputCmdHandler(this, Direction.North);
|
||||
var moveLeftCmdHandler = new MoverDirInputCmdHandler(this, Direction.West);
|
||||
var moveRightCmdHandler = new MoverDirInputCmdHandler(this, Direction.East);
|
||||
var moveDownCmdHandler = new MoverDirInputCmdHandler(this, Direction.South);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(EngineKeyFunctions.MoveUp, moveUpCmdHandler)
|
||||
.Bind(EngineKeyFunctions.MoveLeft, moveLeftCmdHandler)
|
||||
.Bind(EngineKeyFunctions.MoveRight, moveRightCmdHandler)
|
||||
.Bind(EngineKeyFunctions.MoveDown, moveDownCmdHandler)
|
||||
.Bind(EngineKeyFunctions.Walk, new WalkInputCmdHandler())
|
||||
.Register<SharedMoverSystem>();
|
||||
.Bind(EngineKeyFunctions.Walk, new WalkInputCmdHandler(this))
|
||||
.Register<SharedMoverController>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Shutdown()
|
||||
private void ShutdownInput()
|
||||
{
|
||||
CommandBinds.Unregister<SharedMoverSystem>();
|
||||
base.Shutdown();
|
||||
CommandBinds.Unregister<SharedMoverController>();
|
||||
}
|
||||
|
||||
private void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
||||
{
|
||||
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||
if (!TryComp<IMoverComponent>(session?.AttachedEntity, out var moverComp))
|
||||
return;
|
||||
|
||||
var owner = session?.AttachedEntity;
|
||||
@@ -71,9 +67,9 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
moverComp.SetVelocityDirection(dir, subTick, state);
|
||||
}
|
||||
|
||||
private static void HandleRunChange(ICommonSession? session, ushort subTick, bool walking)
|
||||
private void HandleRunChange(ICommonSession? session, ushort subTick, bool walking)
|
||||
{
|
||||
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||
if (!TryComp<IMoverComponent>(session?.AttachedEntity, out var moverComp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -81,68 +77,42 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
moverComp.SetSprinting(subTick, walking);
|
||||
}
|
||||
|
||||
private static bool TryGetAttachedComponent<T>(ICommonSession? session, [NotNullWhen(true)] out T? component)
|
||||
where T : class, IComponent
|
||||
{
|
||||
component = default;
|
||||
|
||||
var ent = session?.AttachedEntity;
|
||||
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (ent == null || !entMan.EntityExists(ent.Value))
|
||||
return false;
|
||||
|
||||
if (!entMan.TryGetComponent(ent.Value, out T? comp))
|
||||
return false;
|
||||
|
||||
component = comp;
|
||||
return true;
|
||||
}
|
||||
|
||||
private sealed class MoverDirInputCmdHandler : InputCmdHandler
|
||||
{
|
||||
private SharedMoverController _controller;
|
||||
private readonly Direction _dir;
|
||||
|
||||
public MoverDirInputCmdHandler(Direction dir)
|
||||
public MoverDirInputCmdHandler(SharedMoverController controller, Direction dir)
|
||||
{
|
||||
_controller = controller;
|
||||
_dir = dir;
|
||||
}
|
||||
|
||||
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||
{
|
||||
if (message is not FullInputCmdMessage full)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (message is not FullInputCmdMessage full) return false;
|
||||
|
||||
Get<SharedMoverSystem>().HandleDirChange(session, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
||||
_controller.HandleDirChange(session, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class WalkInputCmdHandler : InputCmdHandler
|
||||
{
|
||||
private SharedMoverController _controller;
|
||||
|
||||
public WalkInputCmdHandler(SharedMoverController controller)
|
||||
{
|
||||
_controller = controller;
|
||||
}
|
||||
|
||||
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||
{
|
||||
if (message is not FullInputCmdMessage full)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (message is not FullInputCmdMessage full) return false;
|
||||
|
||||
HandleRunChange(session, full.SubTick, full.State == BoundKeyState.Down);
|
||||
_controller.HandleRunChange(session, full.SubTick, full.State == BoundKeyState.Down);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RelayMoveInputEvent : EntityEventArgs
|
||||
{
|
||||
public ICommonSession Session { get; }
|
||||
|
||||
public RelayMoveInputEvent(ICommonSession session)
|
||||
{
|
||||
Session = session;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public abstract partial class SharedMoverController
|
||||
{
|
||||
private bool _pushingEnabled;
|
||||
|
||||
private void InitializePushing()
|
||||
{
|
||||
_configManager.OnValueChanged(CCVars.MobPushing, SetPushing, true);
|
||||
}
|
||||
|
||||
private void SetPushing(bool value)
|
||||
{
|
||||
if (_pushingEnabled == value) return;
|
||||
|
||||
_pushingEnabled = value;
|
||||
|
||||
if (_pushingEnabled)
|
||||
{
|
||||
_physics.KinematicControllerCollision += OnMobCollision;
|
||||
}
|
||||
else
|
||||
{
|
||||
_physics.KinematicControllerCollision -= OnMobCollision;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShutdownPushing()
|
||||
{
|
||||
if (_pushingEnabled)
|
||||
_physics.KinematicControllerCollision -= OnMobCollision;
|
||||
|
||||
_configManager.UnsubValueChanged(CCVars.MobPushing, SetPushing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fake pushing for player collisions.
|
||||
/// </summary>
|
||||
private void OnMobCollision(Fixture ourFixture, Fixture otherFixture, float frameTime, Vector2 worldNormal)
|
||||
{
|
||||
if (!_pushingEnabled) return;
|
||||
|
||||
var otherBody = otherFixture.Body;
|
||||
|
||||
if (otherBody.BodyType != BodyType.Dynamic || !otherFixture.Hard) return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(ourFixture.Body.Owner, out IMobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
|
||||
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrength * frameTime);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Inventory;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -16,14 +17,15 @@ using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Movement
|
||||
namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles player and NPC mob movement.
|
||||
/// NPCs are handled server-side only.
|
||||
/// </summary>
|
||||
public abstract class SharedMoverController : VirtualController
|
||||
public abstract partial class SharedMoverController : VirtualController
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
@@ -86,17 +88,18 @@ namespace Content.Shared.Movement
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
InitializeInput();
|
||||
InitializePushing();
|
||||
// Hello
|
||||
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);
|
||||
_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));
|
||||
}
|
||||
|
||||
@@ -113,16 +116,17 @@ namespace Content.Shared.Movement
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
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);
|
||||
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)
|
||||
@@ -187,13 +191,21 @@ namespace Content.Shared.Movement
|
||||
UsedMobMovement[mover.Owner] = true;
|
||||
var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager, entityManager: EntityManager);
|
||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||
bool touching = true;
|
||||
var touching = false;
|
||||
|
||||
// Handle wall-pushes.
|
||||
if (weightless)
|
||||
{
|
||||
// No gravity: is our entity touching anything?
|
||||
touching = xform.GridUid != null || IsAroundCollider(_physics, xform, mobMover, physicsComponent);
|
||||
if (xform.GridUid != null)
|
||||
touching = true;
|
||||
|
||||
if (!touching)
|
||||
{
|
||||
var ev = new CanWeightlessMoveEvent();
|
||||
RaiseLocalEvent(xform.Owner, ref ev);
|
||||
// No gravity: is our entity touching anything?
|
||||
touching = ev.CanMove || IsAroundCollider(_physics, xform, mobMover, physicsComponent);
|
||||
}
|
||||
|
||||
if (!touching)
|
||||
{
|
||||
@@ -233,6 +245,22 @@ namespace Content.Shared.Movement
|
||||
accel = _mobAcceleration;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (xform.GridUid != EntityUid.Invalid)
|
||||
@@ -242,7 +270,7 @@ namespace Content.Shared.Movement
|
||||
{
|
||||
// This should have its event run during island solver soooo
|
||||
xform.DeferUpdates = true;
|
||||
xform.LocalRotation = xform.GridUid != EntityUid.Invalid
|
||||
xform.LocalRotation = xform.GridUid != null
|
||||
? total.ToWorldAngle()
|
||||
: worldTotal.ToWorldAngle();
|
||||
xform.DeferUpdates = false;
|
||||
@@ -257,7 +285,7 @@ namespace Content.Shared.Movement
|
||||
|
||||
worldTotal *= weightlessModifier;
|
||||
|
||||
if (touching)
|
||||
if (!weightless || touching)
|
||||
Accelerate(ref velocity, in worldTotal, accel, frameTime);
|
||||
|
||||
_physics.SetLinearVelocity(physicsComponent, velocity);
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Shared.Movement.EntitySystems;
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public sealed class SlowContactsSystem : EntitySystem
|
||||
{
|
||||
@@ -52,7 +52,7 @@ public sealed class SlowContactsSystem : EntitySystem
|
||||
Logger.ErrorS("slowscontacts", $"The entity {otherUid} left a body ({uid}) it was never in.");
|
||||
_statusCapableInContact[otherUid]--;
|
||||
if (_statusCapableInContact[otherUid] == 0)
|
||||
EntityManager.RemoveComponent<SlowsOnContactComponent>(otherUid);
|
||||
EntityManager.RemoveComponentDeferred<SlowsOnContactComponent>(otherUid);
|
||||
_speedModifierSystem.RefreshMovementSpeedModifiers(otherUid);
|
||||
|
||||
}
|
||||
@@ -65,8 +65,8 @@ public sealed class SlowContactsSystem : EntitySystem
|
||||
if (!_statusCapableInContact.ContainsKey(otherUid))
|
||||
_statusCapableInContact[otherUid] = 0;
|
||||
_statusCapableInContact[otherUid]++;
|
||||
if (!EntityManager.HasComponent<SlowsOnContactComponent>(otherUid))
|
||||
EntityManager.AddComponent<SlowsOnContactComponent>(otherUid);
|
||||
|
||||
EnsureComp<SlowsOnContactComponent>(otherUid);
|
||||
_speedModifierSystem.RefreshMovementSpeedModifiers(otherUid);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
|
||||
namespace Content.Shared.Nutrition.EntitySystems
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.PAI
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
|
||||
namespace Content.Shared.Pulling.Systems
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
|
||||
15
Content.Shared/Spawners/Components/TimedDespawnComponent.cs
Normal file
15
Content.Shared/Spawners/Components/TimedDespawnComponent.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Content.Shared.Spawners.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Put this component on something you would like to despawn after a certain amount of time
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class TimedDespawnComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// How long the entity will exist before despawning
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("lifetime")]
|
||||
public float Lifetime = 5f;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Content.Shared.Spawners.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Spawners.EntitySystems;
|
||||
|
||||
public abstract class SharedTimedDespawnSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
if (!_timing.IsFirstTimePredicted) return;
|
||||
|
||||
foreach (var comp in EntityQuery<TimedDespawnComponent>())
|
||||
{
|
||||
if (!CanDelete(comp.Owner)) continue;
|
||||
|
||||
comp.Lifetime -= frameTime;
|
||||
|
||||
if (comp.Lifetime <= 0)
|
||||
EntityManager.QueueDeleteEntity(comp.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract bool CanDelete(EntityUid uid);
|
||||
}
|
||||
@@ -6,7 +6,8 @@ using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Throwing;
|
||||
@@ -31,7 +32,7 @@ namespace Content.Shared.Stunnable
|
||||
SubscribeLocalEvent<KnockedDownComponent, ComponentRemove>(OnKnockRemove);
|
||||
|
||||
SubscribeLocalEvent<SlowedDownComponent, ComponentInit>(OnSlowInit);
|
||||
SubscribeLocalEvent<SlowedDownComponent, ComponentRemove>(OnSlowRemove);
|
||||
SubscribeLocalEvent<SlowedDownComponent, ComponentShutdown>(OnSlowRemove);
|
||||
|
||||
SubscribeLocalEvent<StunnedComponent, ComponentStartup>(UpdateCanMove);
|
||||
SubscribeLocalEvent<StunnedComponent, ComponentShutdown>(UpdateCanMove);
|
||||
@@ -105,7 +106,7 @@ namespace Content.Shared.Stunnable
|
||||
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
|
||||
}
|
||||
|
||||
private void OnSlowRemove(EntityUid uid, SlowedDownComponent component, ComponentRemove args)
|
||||
private void OnSlowRemove(EntityUid uid, SlowedDownComponent component, ComponentShutdown args)
|
||||
{
|
||||
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
|
||||
}
|
||||
|
||||
@@ -384,11 +384,11 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
{
|
||||
public List<(EntityCoordinates coordinates, Angle angle, SpriteSpecifier Sprite, float Distance)> Sprites = new();
|
||||
}
|
||||
}
|
||||
|
||||
public enum EffectLayers : byte
|
||||
{
|
||||
Unshaded,
|
||||
}
|
||||
public enum EffectLayers : byte
|
||||
{
|
||||
Unshaded,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
Reference in New Issue
Block a user