From 614b815798bf282facd8eb3d497032ddaef71c73 Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Mon, 2 Sep 2024 15:20:26 +0200 Subject: [PATCH 1/4] allow fire extinguishers and sprays to push grids --- .../Fluids/Components/SprayComponent.cs | 12 ++++++++++-- .../Fluids/EntitySystems/SpraySystem.cs | 19 +++++++++++++++---- .../Objects/Misc/fire_extinguisher.yml | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Content.Server/Fluids/Components/SprayComponent.cs b/Content.Server/Fluids/Components/SprayComponent.cs index e5362eb4e9c680..9cba7236b9cd6e 100644 --- a/Content.Server/Fluids/Components/SprayComponent.cs +++ b/Content.Server/Fluids/Components/SprayComponent.cs @@ -32,10 +32,18 @@ public sealed partial class SprayComponent : Component /// /// How much the player is pushed back for each spray. /// - [ViewVariables(VVAccess.ReadWrite), DataField] + [DataField] public float PushbackAmount = 2f; - [ViewVariables(VVAccess.ReadWrite), DataField(required: true)] + /// + /// How much the grid the player is standing on is pushed back for each spray when gravity or magboots are on. + /// We need to make this separate because the mass of a grid is completely unrealistic at the moment. + /// The Dev map weights only 700kg for example. + /// + [DataField] + public float GridPushbackAmount = 1; + + [DataField(required: true)] [Access(typeof(SpraySystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends public SoundSpecifier SpraySound { get; private set; } = default!; } diff --git a/Content.Server/Fluids/EntitySystems/SpraySystem.cs b/Content.Server/Fluids/EntitySystems/SpraySystem.cs index 215ed7c33ff5aa..a29acd81d3416e 100644 --- a/Content.Server/Fluids/EntitySystems/SpraySystem.cs +++ b/Content.Server/Fluids/EntitySystems/SpraySystem.cs @@ -1,9 +1,9 @@ using Content.Server.Chemistry.Components; -using Content.Server.Chemistry.Containers.EntitySystems; using Content.Server.Chemistry.EntitySystems; using Content.Server.Fluids.Components; using Content.Server.Gravity; using Content.Server.Popups; +using Content.Shared.Chemistry.EntitySystems; using Content.Shared.FixedPoint; using Content.Shared.Fluids; using Content.Shared.Interaction; @@ -25,7 +25,7 @@ public sealed class SpraySystem : EntitySystem [Dependency] private readonly UseDelaySystem _useDelay = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; - [Dependency] private readonly SolutionContainerSystem _solutionContainer = default!; + [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; [Dependency] private readonly VaporSystem _vapor = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; @@ -66,7 +66,7 @@ private void OnAfterInteract(Entity entity, ref AfterInteractEve var userXform = xformQuery.GetComponent(args.User); var userMapPos = _transform.GetMapCoordinates(userXform); - var clickMapPos = args.ClickLocation.ToMap(EntityManager, _transform); + var clickMapPos = _transform.ToMapCoordinates(args.ClickLocation); var diffPos = clickMapPos.Position - userMapPos.Position; if (diffPos == Vector2.Zero || diffPos == Vector2Helpers.NaN) @@ -138,7 +138,18 @@ private void OnAfterInteract(Entity entity, ref AfterInteractEve if (TryComp(args.User, out var body)) { if (_gravity.IsWeightless(args.User, body)) - _physics.ApplyLinearImpulse(args.User, -impulseDirection.Normalized() * entity.Comp.PushbackAmount, body: body); + { + // push back the player + _physics.ApplyLinearImpulse(args.User, -impulseDirection * entity.Comp.PushbackAmount, body: body); + } + else + { + // push back the grid the player is standing on + var userTransform = Transform(args.User); + if (userTransform.GridUid != null) + // apply both linear and angular momentum depending on the player position + _physics.ApplyLinearImpulse(userTransform.GridUid.Value, -impulseDirection * entity.Comp.GridPushbackAmount, userTransform.LocalPosition); + } } } diff --git a/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml b/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml index 0389db27ea0365..9d041e03fcc366 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml @@ -30,6 +30,7 @@ - type: Spray transferAmount: 10 pushbackAmount: 60 + gridPushbackAmount: 2 spraySound: path: /Audio/Effects/extinguish.ogg sprayedPrototype: ExtinguisherSpray From 2566c95551ac2e69f053ba9e123d913f977546fe Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:10:36 +0200 Subject: [PATCH 2/4] add cvar and reduce pushback --- .../Fluids/Components/SprayComponent.cs | 10 +--------- .../Fluids/EntitySystems/SpraySystem.cs | 16 +++++++++++++++- Content.Shared/CCVar/CCVars.cs | 12 ++++++++++++ .../Entities/Objects/Misc/fire_extinguisher.yml | 1 - 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Content.Server/Fluids/Components/SprayComponent.cs b/Content.Server/Fluids/Components/SprayComponent.cs index 9cba7236b9cd6e..128fdecfa7f50d 100644 --- a/Content.Server/Fluids/Components/SprayComponent.cs +++ b/Content.Server/Fluids/Components/SprayComponent.cs @@ -33,15 +33,7 @@ public sealed partial class SprayComponent : Component /// How much the player is pushed back for each spray. /// [DataField] - public float PushbackAmount = 2f; - - /// - /// How much the grid the player is standing on is pushed back for each spray when gravity or magboots are on. - /// We need to make this separate because the mass of a grid is completely unrealistic at the moment. - /// The Dev map weights only 700kg for example. - /// - [DataField] - public float GridPushbackAmount = 1; + public float PushbackAmount = 5f; [DataField(required: true)] [Access(typeof(SpraySystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends diff --git a/Content.Server/Fluids/EntitySystems/SpraySystem.cs b/Content.Server/Fluids/EntitySystems/SpraySystem.cs index a29acd81d3416e..e3541b624127af 100644 --- a/Content.Server/Fluids/EntitySystems/SpraySystem.cs +++ b/Content.Server/Fluids/EntitySystems/SpraySystem.cs @@ -3,6 +3,7 @@ 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; @@ -11,6 +12,7 @@ using Content.Shared.Vapor; 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; @@ -29,12 +31,21 @@ 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() { base.Initialize(); SubscribeLocalEvent(OnAfterInteract); + Subs.CVar(_cfg, CCVars.GridImpulseMultiplier, UpdateGridMassMultiplier, true); + } + + private void UpdateGridMassMultiplier(float value) + { + _gridImpulseMultiplier = value; } private void OnAfterInteract(Entity entity, ref AfterInteractEvent args) @@ -147,8 +158,11 @@ private void OnAfterInteract(Entity entity, ref AfterInteractEve // push back the grid the player is standing on var userTransform = Transform(args.User); if (userTransform.GridUid != null) + { // apply both linear and angular momentum depending on the player position - _physics.ApplyLinearImpulse(userTransform.GridUid.Value, -impulseDirection * entity.Comp.GridPushbackAmount, userTransform.LocalPosition); + // 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); + } } } } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 95fb7bd692c597..1638dc848b9fdf 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1491,6 +1491,18 @@ public static readonly CVarDef public static readonly CVarDef HideSplitGridsUnder = CVarDef.Create("shuttle.hide_split_grids_under", 30, CVar.SERVERONLY); + /// + /// Impulse multiplier for player interactions that move grids (other than shuttle thrusters, gyroscopes and grid collisons). + /// At the moment this only affects the pushback in SpraySystem. + /// A higher value means grids have a lower effective mass and therefore will get pushed stronger. + /// A value of 0 will disable pushback. + /// The default has been chosen such that a one tile grid roughly equals 2/3 Urist masses. + /// TODO: Make grid mass a sane number so we can get rid of this. + /// At the moment they have a very low mass of roughly 0.48 kg per tile independent of any walls or anchored objects on them. + /// + public static readonly CVarDef GridImpulseMultiplier = + CVarDef.Create("shuttle.grid_impulse_multiplier", 0.01f, CVar.SERVERONLY); + /// /// Whether to automatically spawn escape shuttles. /// diff --git a/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml b/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml index 9d041e03fcc366..0389db27ea0365 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/fire_extinguisher.yml @@ -30,7 +30,6 @@ - type: Spray transferAmount: 10 pushbackAmount: 60 - gridPushbackAmount: 2 spraySound: path: /Audio/Effects/extinguish.ogg sprayedPrototype: ExtinguisherSpray From 8813ad355517f8c92134d63e7299c7aee219758b Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:46:01 +0200 Subject: [PATCH 3/4] gun pushback --- Content.Shared/CCVar/CCVars.cs | 2 +- .../Weapons/Ranged/Components/GunComponent.cs | 7 ++++ .../Weapons/Ranged/Systems/SharedGunSystem.cs | 34 ++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 1638dc848b9fdf..0cf7881dff0c63 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1493,7 +1493,7 @@ public static readonly CVarDef /// /// Impulse multiplier for player interactions that move grids (other than shuttle thrusters, gyroscopes and grid collisons). - /// At the moment this only affects the pushback in SpraySystem. + /// At the moment this affects the pushback in SpraySystem and from shooting guns. /// A higher value means grids have a lower effective mass and therefore will get pushed stronger. /// A value of 0 will disable pushback. /// The default has been chosen such that a one tile grid roughly equals 2/3 Urist masses. diff --git a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs index b404221abfc731..2d89f051fb6223 100644 --- a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs @@ -232,6 +232,13 @@ public sealed partial class GunComponent : Component /// [DataField] public bool ClumsyProof = false; + + /// + /// Pushback impulse applied to the gun's holder or the grid they are standing on when fired. + /// In kg*m/s + /// + [DataField] + public float ImpulseStrength = 25f; } [Flags] diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 794237b145a052..59675f9f9330ef 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -4,6 +4,7 @@ using Content.Shared.Actions; using Content.Shared.Administration.Logs; using Content.Shared.Audio; +using Content.Shared.CCVar; using Content.Shared.CombatMode; using Content.Shared.Containers.ItemSlots; using Content.Shared.Damage; @@ -24,6 +25,7 @@ using Content.Shared.Whitelist; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; +using Robust.Shared.Configuration; using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Network; @@ -65,7 +67,9 @@ public abstract partial class SharedGunSystem : EntitySystem [Dependency] protected readonly ThrowingSystem ThrowingSystem = default!; [Dependency] private readonly UseDelaySystem _useDelay = default!; [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; + private float _gridImpulseMultiplier; private const float InteractNextFire = 0.3f; private const double SafetyNextFire = 0.5; private const float EjectOffset = 0.4f; @@ -97,6 +101,12 @@ public override void Initialize() SubscribeLocalEvent(OnCycleMode); SubscribeLocalEvent(OnGunSelected); SubscribeLocalEvent(OnMapInit); + Subs.CVar(_cfg, CCVars.GridImpulseMultiplier, UpdateGridMassMultiplier, true); + } + + private void UpdateGridMassMultiplier(float value) + { + _gridImpulseMultiplier = value; } private void OnMapInit(Entity gun, ref MapInitEvent args) @@ -355,7 +365,7 @@ private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun) if (userImpulse && TryComp(user, out var userPhysics)) { if (_gravity.IsWeightless(user, userPhysics)) - CauseImpulse(fromCoordinates, toCoordinates.Value, user, userPhysics); + CauseImpulse(gun.ImpulseStrength, fromCoordinates, toCoordinates.Value, user, userPhysics); } Dirty(gunUid, gun); @@ -479,15 +489,29 @@ protected void MuzzleFlash(EntityUid gun, AmmoComponent component, Angle worldAn CreateEffect(gun, ev, gun); } - public void CauseImpulse(EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid user, PhysicsComponent userPhysics) + public void CauseImpulse(float impulseStrength, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid user, PhysicsComponent userPhysics) { var fromMap = fromCoordinates.ToMapPos(EntityManager, TransformSystem); var toMap = toCoordinates.ToMapPos(EntityManager, TransformSystem); var shotDirection = (toMap - fromMap).Normalized(); - const float impulseStrength = 25.0f; - var impulseVector = shotDirection * impulseStrength; - Physics.ApplyLinearImpulse(user, -impulseVector, body: userPhysics); + var impulseVector = shotDirection * impulseStrength; + if (_gravity.IsWeightless(user, userPhysics)) + { + // push back the player + Physics.ApplyLinearImpulse(user, -impulseVector, body: userPhysics); + } + else + { + // push back the grid the player is standing on + var userTransform = Transform(user); + if (userTransform.GridUid != null) + { + // 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, -impulseVector * _gridImpulseMultiplier, userTransform.LocalPosition); + } + } } public void RefreshModifiers(Entity gun) From 3ff41e9fe3c074d2a2a06734c91bd36458e4bffd Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:16:26 +0200 Subject: [PATCH 4/4] fix --- Content.Shared/CCVar/CCVars.cs | 2 +- Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 348deeb00bc77f..d2f5a76e7da2e0 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1514,7 +1514,7 @@ public static readonly CVarDef /// At the moment they have a very low mass of roughly 0.48 kg per tile independent of any walls or anchored objects on them. /// public static readonly CVarDef GridImpulseMultiplier = - CVarDef.Create("shuttle.grid_impulse_multiplier", 0.01f, CVar.SERVERONLY); + CVarDef.Create("shuttle.grid_impulse_multiplier", 0.01f, CVar.REPLICATED | CVar.SERVER); /// /// Whether to automatically spawn escape shuttles. diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 59675f9f9330ef..637495b6119def 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -364,8 +364,7 @@ private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun) if (userImpulse && TryComp(user, out var userPhysics)) { - if (_gravity.IsWeightless(user, userPhysics)) - CauseImpulse(gun.ImpulseStrength, fromCoordinates, toCoordinates.Value, user, userPhysics); + CauseImpulse(gun.ImpulseStrength, fromCoordinates, toCoordinates.Value, user, userPhysics); } Dirty(gunUid, gun);