2021-06-23 12:02:28 +02:00
|
|
|
using Content.Server.Atmos.Components;
|
2022-03-17 10:30:40 +13:00
|
|
|
using Content.Server.UserInterface;
|
2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Actions;
|
2022-03-13 21:47:28 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Toggleable;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Verbs;
|
2021-06-23 12:02:28 +02:00
|
|
|
using JetBrains.Annotations;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Robust.Server.GameObjects;
|
2021-06-23 12:02:28 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class GasTankSystem : EntitySystem
|
2021-06-23 12:02:28 +02:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
|
|
|
|
|
2021-06-23 12:02:28 +02:00
|
|
|
private const float TimerDelay = 0.5f;
|
|
|
|
|
private float _timer = 0f;
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2022-03-17 10:30:40 +13:00
|
|
|
SubscribeLocalEvent<GasTankComponent, BeforeActivatableUIOpenEvent>(BeforeUiOpen);
|
2022-02-26 18:24:08 +13:00
|
|
|
SubscribeLocalEvent<GasTankComponent, GetActionsEvent>(OnGetActions);
|
|
|
|
|
SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle);
|
2022-03-13 21:47:28 +13:00
|
|
|
SubscribeLocalEvent<GasTankComponent, DroppedEvent>(OnDropped);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 10:30:40 +13:00
|
|
|
private void BeforeUiOpen(EntityUid uid, GasTankComponent component, BeforeActivatableUIOpenEvent args)
|
|
|
|
|
{
|
|
|
|
|
// Only initial update includes output pressure information, to avoid overwriting client-input as the updates come in.
|
|
|
|
|
component.UpdateUserInterface(true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 21:47:28 +13:00
|
|
|
private void OnDropped(EntityUid uid, GasTankComponent component, DroppedEvent args)
|
|
|
|
|
{
|
|
|
|
|
component.DisconnectFromInternals(args.User);
|
2022-02-26 18:24:08 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGetActions(EntityUid uid, GasTankComponent component, GetActionsEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Actions.Add(component.ToggleAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActionToggle(EntityUid uid, GasTankComponent component, ToggleActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component.ToggleInternals();
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
|
|
|
|
|
2021-06-23 12:02:28 +02:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
|
|
|
_timer += frameTime;
|
|
|
|
|
|
|
|
|
|
if (_timer < TimerDelay) return;
|
|
|
|
|
_timer -= TimerDelay;
|
|
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
foreach (var gasTank in EntityManager.EntityQuery<GasTankComponent>())
|
2021-06-23 12:02:28 +02:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
_atmosphereSystem.React(gasTank.Air, gasTank);
|
2021-06-23 12:02:28 +02:00
|
|
|
gasTank.CheckStatus();
|
|
|
|
|
gasTank.UpdateUserInterface();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|