Reimplement anchor/unanchor delay (#11128)

This commit is contained in:
theashtronaut
2022-09-11 06:30:10 +00:00
committed by GitHub
parent b3c1a1aa19
commit 6f9065a1de
2 changed files with 22 additions and 17 deletions

View File

@@ -14,8 +14,8 @@ namespace Content.Server.Atmos.Piping.EntitySystems
[UsedImplicitly] [UsedImplicitly]
public sealed class AtmosUnsafeUnanchorSystem : EntitySystem public sealed class AtmosUnsafeUnanchorSystem : EntitySystem
{ {
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popup = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -28,17 +28,18 @@ namespace Content.Server.Atmos.Piping.EntitySystems
if (!component.Enabled || !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodes)) if (!component.Enabled || !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodes))
return; return;
if (_atmosphereSystem.GetContainingMixture(uid, true) is not {} environment) if (_atmosphere.GetContainingMixture(uid, true) is not {} environment)
return; return;
foreach (var node in nodes.Nodes.Values) foreach (var node in nodes.Nodes.Values)
{ {
if (node is not PipeNode pipe) continue; if (node is not PipeNode pipe)
continue;
if ((pipe.Air.Pressure - environment.Pressure) > 2 * Atmospherics.OneAtmosphere) if (pipe.Air.Pressure - environment.Pressure > 2 * Atmospherics.OneAtmosphere)
{ {
args.Delay += 1.5f; args.Delay += 2f;
_popupSystem.PopupCursor(Loc.GetString("comp-atmos-unsafe-unanchor-warning"), _popup.PopupEntity(Loc.GetString("comp-atmos-unsafe-unanchor-warning"), pipe.Owner,
Filter.Entities(args.User), PopupType.MediumCaution); Filter.Entities(args.User), PopupType.MediumCaution);
return; // Show the warning only once. return; // Show the warning only once.
} }
@@ -50,7 +51,7 @@ namespace Content.Server.Atmos.Piping.EntitySystems
if (!component.Enabled || !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodes)) if (!component.Enabled || !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodes))
return; return;
if (_atmosphereSystem.GetContainingMixture(uid, true, true) is not {} environment) if (_atmosphere.GetContainingMixture(uid, true, true) is not {} environment)
environment = GasMixture.SpaceGas; environment = GasMixture.SpaceGas;
var lost = 0f; var lost = 0f;
@@ -58,7 +59,8 @@ namespace Content.Server.Atmos.Piping.EntitySystems
foreach (var node in nodes.Nodes.Values) foreach (var node in nodes.Nodes.Values)
{ {
if (node is not PipeNode pipe) continue; if (node is not PipeNode pipe)
continue;
var difference = pipe.Air.Pressure - environment.Pressure; var difference = pipe.Air.Pressure - environment.Pressure;
lost += difference * environment.Volume / (environment.Temperature * Atmospherics.R); lost += difference * environment.Volume / (environment.Temperature * Atmospherics.R);
@@ -70,12 +72,13 @@ namespace Content.Server.Atmos.Piping.EntitySystems
foreach (var node in nodes.Nodes.Values) foreach (var node in nodes.Nodes.Values)
{ {
if (node is not PipeNode pipe) continue; if (node is not PipeNode pipe)
continue;
_atmosphereSystem.Merge(buffer, pipe.Air.Remove(sharedLoss)); _atmosphere.Merge(buffer, pipe.Air.Remove(sharedLoss));
} }
_atmosphereSystem.Merge(environment, buffer); _atmosphere.Merge(environment, buffer);
} }
} }
} }

View File

@@ -20,8 +20,8 @@ namespace Content.Server.Construction
[Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly ToolSystem _toolSystem = default!; [Dependency] private readonly ToolSystem _tool = default!;
[Dependency] private readonly PullingSystem _pullingSystem = default!; [Dependency] private readonly PullingSystem _pulling = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -85,7 +85,7 @@ namespace Content.Server.Construction
if (TryComp<SharedPullableComponent>(uid, out var pullable) && pullable.Puller != null) if (TryComp<SharedPullableComponent>(uid, out var pullable) && pullable.Puller != null)
{ {
_pullingSystem.TryStopPull(pullable); _pulling.TryStopPull(pullable);
} }
// TODO: Anchoring snaps rn anyway! // TODO: Anchoring snaps rn anyway!
@@ -155,6 +155,8 @@ namespace Content.Server.Construction
else else
RaiseLocalEvent(uid, (UnanchorAttemptEvent) attempt, false); RaiseLocalEvent(uid, (UnanchorAttemptEvent) attempt, false);
anchorable.Delay += attempt.Delay;
if (attempt.Cancelled) if (attempt.Cancelled)
return false; return false;
@@ -192,7 +194,7 @@ namespace Content.Server.Construction
anchorable.CancelToken = new CancellationTokenSource(); anchorable.CancelToken = new CancellationTokenSource();
_toolSystem.UseTool(usingUid, userUid, uid, 0f, anchorable.Delay, usingTool.Qualities, _tool.UseTool(usingUid, userUid, uid, 0f, anchorable.Delay, usingTool.Qualities,
new TryAnchorCompletedEvent(), new TryAnchorCancelledEvent(), uid, cancelToken: anchorable.CancelToken.Token); new TryAnchorCompletedEvent(), new TryAnchorCancelledEvent(), uid, cancelToken: anchorable.CancelToken.Token);
} }
@@ -215,7 +217,7 @@ namespace Content.Server.Construction
anchorable.CancelToken = new CancellationTokenSource(); anchorable.CancelToken = new CancellationTokenSource();
_toolSystem.UseTool(usingUid, userUid, uid, 0f, anchorable.Delay, usingTool.Qualities, _tool.UseTool(usingUid, userUid, uid, 0f, anchorable.Delay, usingTool.Qualities,
new TryUnanchorCompletedEvent(), new TryUnanchorCancelledEvent(), uid, cancelToken: anchorable.CancelToken.Token); new TryUnanchorCompletedEvent(), new TryUnanchorCancelledEvent(), uid, cancelToken: anchorable.CancelToken.Token);
} }