Remove PilotComponent when someone stop piloting (#4922)
This commit is contained in:
@@ -8,6 +8,7 @@ using Content.Shared.Popups;
|
|||||||
using Content.Shared.Shuttles;
|
using Content.Shared.Shuttles;
|
||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ namespace Content.Server.Shuttles
|
|||||||
{
|
{
|
||||||
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -28,16 +31,24 @@ namespace Content.Server.Shuttles
|
|||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
foreach (var comp in EntityManager.EntityQuery<PilotComponent>().ToArray())
|
|
||||||
|
var toRemove = new RemQueue<PilotComponent>();
|
||||||
|
|
||||||
|
foreach (var comp in EntityManager.EntityQuery<PilotComponent>())
|
||||||
{
|
{
|
||||||
if (comp.Console == null) continue;
|
if (comp.Console == null) continue;
|
||||||
|
|
||||||
if (!Get<ActionBlockerSystem>().CanInteract(comp.Owner))
|
if (!_blocker.CanInteract(comp.Owner))
|
||||||
|
{
|
||||||
|
toRemove.Add(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var comp in toRemove)
|
||||||
{
|
{
|
||||||
RemovePilot(comp);
|
RemovePilot(comp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Console requires power to operate.
|
/// Console requires power to operate.
|
||||||
@@ -75,7 +86,7 @@ namespace Content.Server.Shuttles
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pilotComponent = args.User.EnsureComponent<PilotComponent>();
|
var pilotComponent = EntityManager.EnsureComponent<PilotComponent>(args.User.Uid);
|
||||||
|
|
||||||
if (!component.Enabled)
|
if (!component.Enabled)
|
||||||
{
|
{
|
||||||
@@ -111,7 +122,7 @@ namespace Content.Server.Shuttles
|
|||||||
|
|
||||||
public void AddPilot(IEntity entity, ShuttleConsoleComponent component)
|
public void AddPilot(IEntity entity, ShuttleConsoleComponent component)
|
||||||
{
|
{
|
||||||
if (!Get<ActionBlockerSystem>().CanInteract(entity) ||
|
if (!_blocker.CanInteract(entity) ||
|
||||||
!entity.TryGetComponent(out PilotComponent? pilotComponent) ||
|
!entity.TryGetComponent(out PilotComponent? pilotComponent) ||
|
||||||
component.SubscribedPilots.Contains(pilotComponent))
|
component.SubscribedPilots.Contains(pilotComponent))
|
||||||
{
|
{
|
||||||
@@ -146,10 +157,7 @@ namespace Content.Server.Shuttles
|
|||||||
}
|
}
|
||||||
|
|
||||||
pilotComponent.Owner.PopupMessage(Loc.GetString("shuttle-pilot-end"));
|
pilotComponent.Owner.PopupMessage(Loc.GetString("shuttle-pilot-end"));
|
||||||
// TODO: RemoveComponent<T> is cooked and doesn't sync to client so this fucks up movement prediction.
|
EntityManager.RemoveComponent<PilotComponent>(pilotComponent.Owner.Uid);
|
||||||
// EntityManager.RemoveComponent<PilotComponent>(pilotComponent.Owner.Uid);
|
|
||||||
pilotComponent.Console = null;
|
|
||||||
pilotComponent.Dirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemovePilot(IEntity entity)
|
public void RemovePilot(IEntity entity)
|
||||||
|
|||||||
Reference in New Issue
Block a user