]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix magboots not needing a grid to work (#29034)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 16 Jun 2024 03:38:17 +0000 (23:38 -0400)
committerGitHub <noreply@github.com>
Sun, 16 Jun 2024 03:38:17 +0000 (13:38 +1000)
* Fix magboots not needing a grid to work

* ok fix it for realsies

Content.Shared/Clothing/MagbootsComponent.cs
Content.Shared/Clothing/SharedMagbootsSystem.cs
Content.Shared/Gravity/SharedGravitySystem.cs

index 0d074ff38b69a2a3354751cc4224fcd998efc92f..b3fb607a38be4c5ad92105d73a2aac5808db2303 100644 (file)
@@ -20,4 +20,10 @@ public sealed partial class MagbootsComponent : Component
 
     [DataField]
     public ProtoId<AlertPrototype> MagbootsAlert = "Magboots";
+
+    /// <summary>
+    /// If true, the user must be standing on a grid or planet map to experience the weightlessness-canceling effect
+    /// </summary>
+    [DataField]
+    public bool RequiresGrid = true;
 }
index bb3b05074f2f3fa3f02f85c2d5e8c2dc29676c9d..68145936152e400b590c0c688cb9deb047d004a8 100644 (file)
@@ -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 @@ public sealed class SharedMagbootsSystem : EntitySystem
         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;
     }
index 42a6d5d1f8024e72af81508b44db70bd653fb699..2f532d0f1d34140daa88e7b77bdf33add6884fb5 100644 (file)
@@ -17,6 +17,8 @@ namespace Content.Shared.Gravity
         [ValidatePrototypeId<AlertPrototype>]
         public const string WeightlessAlert = "Weightless";
 
+        private EntityQuery<GravityComponent> _gravityQuery;
+
         public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null)
         {
             Resolve(uid, ref body, false);
@@ -36,15 +38,35 @@ namespace Content.Shared.Gravity
                 return true;
 
             // If grid / map has gravity
-            if (TryComp<GravityComponent>(xform.GridUid, out var gravity) && gravity.Enabled ||
-                 TryComp<GravityComponent>(xform.MapUid, out var mapGravity) && mapGravity.Enabled)
-            {
+            if (EntityGridOrMapHaveGravity((uid, xform)))
                 return false;
-            }
 
             return true;
         }
 
+        /// <summary>
+        /// Checks if a given entity is currently standing on a grid or map that supports having gravity at all.
+        /// </summary>
+        public bool EntityOnGravitySupportingGridOrMap(Entity<TransformComponent?> entity)
+        {
+            entity.Comp ??= Transform(entity);
+
+            return _gravityQuery.HasComp(entity.Comp.GridUid) ||
+                   _gravityQuery.HasComp(entity.Comp.MapUid);
+        }
+
+
+        /// <summary>
+        /// Checks if a given entity is currently standing on a grid or map that has gravity of some kind.
+        /// </summary>
+        public bool EntityGridOrMapHaveGravity(Entity<TransformComponent?> 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 @@ namespace Content.Shared.Gravity
             SubscribeLocalEvent<GravityChangedEvent>(OnGravityChange);
             SubscribeLocalEvent<GravityComponent, ComponentGetState>(OnGetState);
             SubscribeLocalEvent<GravityComponent, ComponentHandleState>(OnHandleState);
+
+            _gravityQuery = GetEntityQuery<GravityComponent>();
         }
 
         public override void Update(float frameTime)