Allow fire extinguishers and sprays to push grids you are standing on (#31754)

* allow fire extinguishers and sprays to push grids

* add cvar and reduce pushback

* EmoGarbage Review - Resolve Conflicts

* Ensure grid parenting

---------

Co-authored-by: EmoGarbage404 <retron404@gmail.com>
This commit is contained in:
slarticodefast
2025-04-18 05:41:27 +02:00
committed by GitHub
parent 638187c253
commit e1a1150257
3 changed files with 42 additions and 5 deletions

View File

@@ -3,14 +3,16 @@ using Content.Server.Chemistry.EntitySystems;
using Content.Server.Fluids.Components;
using Content.Server.Gravity;
using Content.Server.Popups;
using Content.Shared.CCVar;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids;
using Content.Shared.Interaction;
using Content.Shared.Timing;
using Content.Shared.Vapor;
using Content.Shared.Chemistry.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
using System.Numerics;
@@ -30,6 +32,9 @@ public sealed class SpraySystem : EntitySystem
[Dependency] private readonly VaporSystem _vapor = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
private float _gridImpulseMultiplier;
public override void Initialize()
{
@@ -37,6 +42,7 @@ public sealed class SpraySystem : EntitySystem
SubscribeLocalEvent<SprayComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<SprayComponent, UserActivateInWorldEvent>(OnActivateInWorld);
Subs.CVar(_cfg, CCVars.GridImpulseMultiplier, UpdateGridMassMultiplier, true);
}
private void OnActivateInWorld(Entity<SprayComponent> entity, ref UserActivateInWorldEvent args)
@@ -51,6 +57,11 @@ public sealed class SpraySystem : EntitySystem
Spray(entity, args.User, targetMapPos);
}
private void UpdateGridMassMultiplier(float value)
{
_gridImpulseMultiplier = value;
}
private void OnAfterInteract(Entity<SprayComponent> entity, ref AfterInteractEvent args)
{
if (args.Handled)
@@ -156,7 +167,21 @@ public sealed class SpraySystem : EntitySystem
if (TryComp<PhysicsComponent>(user, out var body))
{
if (_gravity.IsWeightless(user, body))
_physics.ApplyLinearImpulse(user, -impulseDirection.Normalized() * entity.Comp.PushbackAmount, body: body);
{
// push back the player
_physics.ApplyLinearImpulse(user, -impulseDirection * entity.Comp.PushbackAmount, body: body);
}
else
{
// push back the grid the player is standing on
var userTransform = Transform(user);
if (userTransform.GridUid == userTransform.ParentUid)
{
// apply both linear and angular momentum depending on the player position
// multiply by a cvar because grid mass is currently extremely small compared to all other masses
_physics.ApplyLinearImpulse(userTransform.GridUid.Value, -impulseDirection * _gridImpulseMultiplier * entity.Comp.PushbackAmount, userTransform.LocalPosition);
}
}
}
}