From cfc6ed065ee09395679211ebe799850deb13447b Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 17 Oct 2021 23:33:12 +1100 Subject: [PATCH] Remove PilotComponent when someone stop piloting (#4922) --- .../Shuttles/ShuttleConsoleSystem.cs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Content.Server/Shuttles/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/ShuttleConsoleSystem.cs index 46c48f500c..63c04ac6e5 100644 --- a/Content.Server/Shuttles/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/ShuttleConsoleSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.Popups; using Content.Shared.Shuttles; using Content.Shared.Tag; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Utility; @@ -15,6 +16,8 @@ namespace Content.Server.Shuttles { internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem { + [Dependency] private readonly ActionBlockerSystem _blocker = default!; + public override void Initialize() { base.Initialize(); @@ -28,15 +31,23 @@ namespace Content.Server.Shuttles public override void Update(float frameTime) { base.Update(frameTime); - foreach (var comp in EntityManager.EntityQuery().ToArray()) + + var toRemove = new RemQueue(); + + foreach (var comp in EntityManager.EntityQuery()) { if (comp.Console == null) continue; - if (!Get().CanInteract(comp.Owner)) + if (!_blocker.CanInteract(comp.Owner)) { - RemovePilot(comp); + toRemove.Add(comp); } } + + foreach (var comp in toRemove) + { + RemovePilot(comp); + } } /// @@ -75,7 +86,7 @@ namespace Content.Server.Shuttles return; } - var pilotComponent = args.User.EnsureComponent(); + var pilotComponent = EntityManager.EnsureComponent(args.User.Uid); if (!component.Enabled) { @@ -111,7 +122,7 @@ namespace Content.Server.Shuttles public void AddPilot(IEntity entity, ShuttleConsoleComponent component) { - if (!Get().CanInteract(entity) || + if (!_blocker.CanInteract(entity) || !entity.TryGetComponent(out PilotComponent? pilotComponent) || component.SubscribedPilots.Contains(pilotComponent)) { @@ -146,10 +157,7 @@ namespace Content.Server.Shuttles } pilotComponent.Owner.PopupMessage(Loc.GetString("shuttle-pilot-end")); - // TODO: RemoveComponent is cooked and doesn't sync to client so this fucks up movement prediction. - // EntityManager.RemoveComponent(pilotComponent.Owner.Uid); - pilotComponent.Console = null; - pilotComponent.Dirty(); + EntityManager.RemoveComponent(pilotComponent.Owner.Uid); } public void RemovePilot(IEntity entity)