From 3644602fb830004428464eb35b80cc71520838d2 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sat, 15 Jun 2024 23:38:17 -0400 Subject: [PATCH] Fix magboots not needing a grid to work (#29034) * Fix magboots not needing a grid to work * ok fix it for realsies --- Content.Shared/Clothing/MagbootsComponent.cs | 6 ++++ .../Clothing/SharedMagbootsSystem.cs | 5 +++ Content.Shared/Gravity/SharedGravitySystem.cs | 32 ++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Clothing/MagbootsComponent.cs b/Content.Shared/Clothing/MagbootsComponent.cs index 0d074ff38b69a2..b3fb607a38be4c 100644 --- a/Content.Shared/Clothing/MagbootsComponent.cs +++ b/Content.Shared/Clothing/MagbootsComponent.cs @@ -20,4 +20,10 @@ public sealed partial class MagbootsComponent : Component [DataField] public ProtoId MagbootsAlert = "Magboots"; + + /// + /// If true, the user must be standing on a grid or planet map to experience the weightlessness-canceling effect + /// + [DataField] + public bool RequiresGrid = true; } diff --git a/Content.Shared/Clothing/SharedMagbootsSystem.cs b/Content.Shared/Clothing/SharedMagbootsSystem.cs index bb3b05074f2f3f..68145936152e40 100644 --- a/Content.Shared/Clothing/SharedMagbootsSystem.cs +++ b/Content.Shared/Clothing/SharedMagbootsSystem.cs @@ -17,6 +17,7 @@ public sealed class SharedMagbootsSystem : EntitySystem [Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!; [Dependency] private readonly ClothingSystem _clothing = default!; + [Dependency] private readonly SharedGravitySystem _gravity = default!; [Dependency] private readonly InventorySystem _inventory = default!; [Dependency] private readonly SharedActionsSystem _sharedActions = default!; [Dependency] private readonly SharedActionsSystem _actionContainer = default!; @@ -147,6 +148,10 @@ private void OnIsWeightless(Entity ent, ref InventoryRelayedE if (!ent.Comp.On) return; + // do not cancel weightlessness if the person is in off-grid. + if (ent.Comp.RequiresGrid && !_gravity.EntityOnGravitySupportingGridOrMap(ent.Owner)) + return; + args.Args.IsWeightless = false; args.Args.Handled = true; } diff --git a/Content.Shared/Gravity/SharedGravitySystem.cs b/Content.Shared/Gravity/SharedGravitySystem.cs index 42a6d5d1f8024e..2f532d0f1d3414 100644 --- a/Content.Shared/Gravity/SharedGravitySystem.cs +++ b/Content.Shared/Gravity/SharedGravitySystem.cs @@ -17,6 +17,8 @@ public abstract partial class SharedGravitySystem : EntitySystem [ValidatePrototypeId] public const string WeightlessAlert = "Weightless"; + private EntityQuery _gravityQuery; + public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null) { Resolve(uid, ref body, false); @@ -36,15 +38,35 @@ public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, Transform return true; // If grid / map has gravity - if (TryComp(xform.GridUid, out var gravity) && gravity.Enabled || - TryComp(xform.MapUid, out var mapGravity) && mapGravity.Enabled) - { + if (EntityGridOrMapHaveGravity((uid, xform))) return false; - } return true; } + /// + /// Checks if a given entity is currently standing on a grid or map that supports having gravity at all. + /// + public bool EntityOnGravitySupportingGridOrMap(Entity entity) + { + entity.Comp ??= Transform(entity); + + return _gravityQuery.HasComp(entity.Comp.GridUid) || + _gravityQuery.HasComp(entity.Comp.MapUid); + } + + + /// + /// Checks if a given entity is currently standing on a grid or map that has gravity of some kind. + /// + public bool EntityGridOrMapHaveGravity(Entity entity) + { + entity.Comp ??= Transform(entity); + + return _gravityQuery.TryComp(entity.Comp.GridUid, out var gravity) && gravity.Enabled || + _gravityQuery.TryComp(entity.Comp.MapUid, out var mapGravity) && mapGravity.Enabled; + } + public override void Initialize() { base.Initialize(); @@ -54,6 +76,8 @@ public override void Initialize() SubscribeLocalEvent(OnGravityChange); SubscribeLocalEvent(OnGetState); SubscribeLocalEvent(OnHandleState); + + _gravityQuery = GetEntityQuery(); } public override void Update(float frameTime)