]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix RotateWhilePulling not working (#29032)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sun, 16 Jun 2024 11:30:35 +0000 (23:30 +1200)
committerGitHub <noreply@github.com>
Sun, 16 Jun 2024 11:30:35 +0000 (21:30 +1000)
Content.Server/Movement/Components/PullMoverComponent.cs [deleted file]
Content.Server/Movement/Systems/PullController.cs
Content.Shared/Movement/Pulling/Components/ActivePullerComponent.cs [new file with mode: 0644]
Content.Shared/Movement/Pulling/Components/PullerComponent.cs
Content.Shared/Movement/Pulling/Systems/PullingSystem.cs

diff --git a/Content.Server/Movement/Components/PullMoverComponent.cs b/Content.Server/Movement/Components/PullMoverComponent.cs
deleted file mode 100644 (file)
index 19a01c6..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace Content.Server.Movement.Components;
-
-/// <summary>
-/// Added to an entity that is ctrl-click moving their pulled object.
-/// </summary>
-/// <remarks>
-/// This just exists so we don't have MoveEvent subs going off for every single mob constantly.
-/// </remarks>
-[RegisterComponent]
-public sealed partial class PullMoverComponent : Component
-{
-
-}
index 72110ff67d244c3ec3dfc1c444dca7cb6801ee10..f227d9c55cdaeb743092a3a7cf3ffe007cdfa013 100644 (file)
@@ -18,6 +18,7 @@ using Robust.Shared.Physics.Controllers;
 using Robust.Shared.Physics.Dynamics.Joints;
 using Robust.Shared.Player;
 using Robust.Shared.Timing;
+using Robust.Shared.Utility;
 
 namespace Content.Server.Movement.Systems;
 
@@ -91,7 +92,7 @@ public sealed class PullController : VirtualController
 
         UpdatesAfter.Add(typeof(MoverController));
         SubscribeLocalEvent<PullMovingComponent, PullStoppedMessage>(OnPullStop);
-        SubscribeLocalEvent<PullMoverComponent, MoveEvent>(OnPullerMove);
+        SubscribeLocalEvent<ActivePullerComponent, MoveEvent>(OnPullerMove);
 
         base.Initialize();
     }
@@ -155,19 +156,22 @@ public sealed class PullController : VirtualController
             coords = fromUserCoords.WithEntityId(coords.EntityId);
         }
 
-        EnsureComp<PullMoverComponent>(player);
         var moving = EnsureComp<PullMovingComponent>(pulled!.Value);
         moving.MovingTo = coords;
         return false;
     }
 
-    private void OnPullerMove(EntityUid uid, PullMoverComponent component, ref MoveEvent args)
+    private void OnPullerMove(EntityUid uid, ActivePullerComponent component, ref MoveEvent args)
     {
         if (!_pullerQuery.TryComp(uid, out var puller))
             return;
 
         if (puller.Pulling is not { } pullable)
+        {
+            DebugTools.Assert($"Failed to clean up puller: {ToPrettyString(uid)}");
+            RemCompDeferred(uid, component);
             return;
+        }
 
         UpdatePulledRotation(uid, pullable);
 
@@ -182,13 +186,7 @@ public sealed class PullController : VirtualController
         if (_physicsQuery.TryComp(uid, out var physics))
             PhysicsSystem.WakeBody(uid, body: physics);
 
-        StopMove(uid, pullable);
-    }
-
-    private void StopMove(Entity<PullMoverComponent?> mover, Entity<PullMovingComponent?> moving)
-    {
-        RemCompDeferred<PullMoverComponent>(mover.Owner);
-        RemCompDeferred<PullMovingComponent>(moving.Owner);
+        RemCompDeferred<PullMovingComponent>(pullable);
     }
 
     private void UpdatePulledRotation(EntityUid puller, EntityUid pulled)
@@ -302,17 +300,5 @@ public sealed class PullController : VirtualController
                 PhysicsSystem.ApplyLinearImpulse(puller, -impulse);
             }
         }
-
-        // Cleanup PullMover
-        var moverQuery = EntityQueryEnumerator<PullMoverComponent, PullerComponent>();
-
-        while (moverQuery.MoveNext(out var uid, out _, out var puller))
-        {
-            if (!HasComp<PullMovingComponent>(puller.Pulling))
-            {
-                RemCompDeferred<PullMoverComponent>(uid);
-                continue;
-            }
-        }
     }
 }
diff --git a/Content.Shared/Movement/Pulling/Components/ActivePullerComponent.cs b/Content.Shared/Movement/Pulling/Components/ActivePullerComponent.cs
new file mode 100644 (file)
index 0000000..83bfd9f
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Content.Shared.Movement.Pulling.Components;
+
+/// <summary>
+/// Component that indicates that an entity is currently pulling some other entity.
+/// </summary>
+[RegisterComponent]
+public sealed partial class ActivePullerComponent : Component;
index f47ae32f90bf5df4d4f0fb68c627f5561e14b800..32e4d9b1f31677abb54c0bbea872096f38d0a5b4 100644 (file)
@@ -9,7 +9,7 @@ namespace Content.Shared.Movement.Pulling.Components;
 /// <summary>
 /// Specifies an entity as being able to pull another entity with <see cref="PullableComponent"/>
 /// </summary>
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
 [Access(typeof(PullingSystem))]
 public sealed partial class PullerComponent : Component
 {
index 161868370eaddca85b8c285794fc3da14a668dc3..72b87476bb0a1d61d7456eda1037689abe6b4a80 100644 (file)
@@ -61,6 +61,7 @@ public sealed class PullingSystem : EntitySystem
         SubscribeLocalEvent<PullableComponent, EntGotInsertedIntoContainerMessage>(OnPullableContainerInsert);
         SubscribeLocalEvent<PullableComponent, ModifyUncuffDurationEvent>(OnModifyUncuffDuration);
 
+        SubscribeLocalEvent<PullerComponent, AfterAutoHandleStateEvent>(OnAfterState);
         SubscribeLocalEvent<PullerComponent, EntGotInsertedIntoContainerMessage>(OnPullerContainerInsert);
         SubscribeLocalEvent<PullerComponent, EntityUnpausedEvent>(OnPullerUnpaused);
         SubscribeLocalEvent<PullerComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
@@ -72,6 +73,14 @@ public sealed class PullingSystem : EntitySystem
             .Register<PullingSystem>();
     }
 
+    private void OnAfterState(Entity<PullerComponent> ent, ref AfterAutoHandleStateEvent args)
+    {
+        if (ent.Comp.Pulling == null)
+            RemComp<ActivePullerComponent>(ent.Owner);
+        else
+            EnsureComp<ActivePullerComponent>(ent.Owner);
+    }
+
     private void OnDropHandItems(EntityUid uid, PullerComponent pullerComp, DropHandItemsEvent args)
     {
         if (pullerComp.Pulling == null || pullerComp.NeedsHands)
@@ -228,6 +237,9 @@ public sealed class PullingSystem : EntitySystem
         }
 
         var oldPuller = pullableComp.Puller;
+        if (oldPuller != null)
+            RemComp<ActivePullerComponent>(oldPuller.Value);
+
         pullableComp.PullJointId = null;
         pullableComp.Puller = null;
         Dirty(pullableUid, pullableComp);
@@ -410,6 +422,7 @@ public sealed class PullingSystem : EntitySystem
         // Use net entity so it's consistent across client and server.
         pullableComp.PullJointId = $"pull-joint-{GetNetEntity(pullableUid)}";
 
+        EnsureComp<ActivePullerComponent>(pullerUid);
         pullerComp.Pulling = pullableUid;
         pullableComp.Puller = pullerUid;