Cache CanMove (#7480)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -16,6 +17,9 @@ namespace Content.Shared.Shuttles.Components
|
||||
[NetworkedComponent]
|
||||
public sealed class PilotComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
[ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -37,15 +41,14 @@ namespace Content.Shared.Shuttles.Components
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!entityManager.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent))
|
||||
if (!_entMan.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent))
|
||||
{
|
||||
Logger.Warning($"Unable to set Helmsman console to {console}");
|
||||
return;
|
||||
}
|
||||
|
||||
Console = shuttleConsoleComponent;
|
||||
_sysMan.GetEntitySystem<ActionBlockerSystem>().UpdateCanMove(Owner);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Shuttles
|
||||
{
|
||||
public abstract class SharedShuttleConsoleSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly ActionBlockerSystem ActionBlockerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PilotComponent, MovementAttemptEvent>(HandleMovementBlock);
|
||||
SubscribeLocalEvent<PilotComponent, UpdateCanMoveEvent>(HandleMovementBlock);
|
||||
SubscribeLocalEvent<PilotComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
|
||||
}
|
||||
|
||||
private void HandleMovementBlock(EntityUid uid, PilotComponent component, MovementAttemptEvent args)
|
||||
protected virtual void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
|
||||
{
|
||||
ActionBlockerSystem.UpdateCanMove(uid);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, PilotComponent component, ComponentStartup args)
|
||||
{
|
||||
ActionBlockerSystem.UpdateCanMove(uid);
|
||||
}
|
||||
|
||||
private void HandleMovementBlock(EntityUid uid, PilotComponent component, UpdateCanMoveEvent args)
|
||||
{
|
||||
if (component.LifeStage > ComponentLifeStage.Running)
|
||||
return;
|
||||
|
||||
if (component.Console == null) return;
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user