2021-06-23 12:02:28 +02:00
|
|
|
using Content.Server.Atmos.Components;
|
2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Actions;
|
|
|
|
|
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-02-10 15:30:59 +13:00
|
|
|
SubscribeLocalEvent<GasTankComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUIVerb);
|
2022-02-26 18:24:08 +13:00
|
|
|
SubscribeLocalEvent<GasTankComponent, GetActionsEvent>(OnGetActions);
|
|
|
|
|
SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
private void AddOpenUIVerb(EntityUid uid, GasTankComponent component, GetVerbsEvent<ActivationVerb> args)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
if (!args.CanAccess || !EntityManager.TryGetComponent<ActorComponent?>(args.User, out var actor))
|
2021-10-05 14:29:03 +11:00
|
|
|
return;
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
ActivationVerb verb = new();
|
2021-10-05 14:29:03 +11:00
|
|
|
verb.Act = () => component.OpenInterface(actor.PlayerSession);
|
|
|
|
|
verb.Text = Loc.GetString("control-verb-open-control-panel-text");
|
|
|
|
|
// TODO VERBS add "open UI" icon?
|
|
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|