2021-07-12 09:47:59 +02:00
|
|
|
using Content.Server.Atmos.Piping.Binary.Components;
|
|
|
|
|
using Content.Server.NodeContainer;
|
2023-06-28 14:28:38 +03:00
|
|
|
using Content.Server.NodeContainer.EntitySystems;
|
2021-07-12 09:47:59 +02:00
|
|
|
using Content.Server.NodeContainer.Nodes;
|
|
|
|
|
using Content.Shared.Atmos.Piping;
|
2021-11-06 17:32:33 -07:00
|
|
|
using Content.Shared.Audio;
|
2021-10-19 21:46:31 +00:00
|
|
|
using Content.Shared.Examine;
|
2021-07-12 09:47:59 +02:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using JetBrains.Annotations;
|
2021-11-06 17:32:33 -07:00
|
|
|
using Robust.Shared.Audio;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2021-11-06 17:32:33 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-07-12 09:47:59 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-15 17:06:52 +13:00
|
|
|
public sealed class GasValveSystem : EntitySystem
|
2021-07-12 09:47:59 +02:00
|
|
|
{
|
2022-03-12 16:20:31 -06:00
|
|
|
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-11-27 22:12:34 +11:00
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
2023-06-28 14:28:38 +03:00
|
|
|
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
2022-03-12 16:20:31 -06:00
|
|
|
|
2021-07-12 09:47:59 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GasValveComponent, ComponentStartup>(OnStartup);
|
|
|
|
|
SubscribeLocalEvent<GasValveComponent, ActivateInWorldEvent>(OnActivate);
|
2021-10-19 21:46:31 +00:00
|
|
|
SubscribeLocalEvent<GasValveComponent, ExaminedEvent>(OnExamined);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
private void OnExamined(Entity<GasValveComponent> ent, ref ExaminedEvent args)
|
2021-10-19 21:46:31 +00:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
var valve = ent.Comp;
|
|
|
|
|
if (!Comp<TransformComponent>(ent).Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status.
|
2021-10-19 21:46:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (Loc.TryGetString("gas-valve-system-examined", out var str,
|
2023-11-27 22:12:34 +11:00
|
|
|
("statusColor", valve.Open ? "green" : "orange"),
|
|
|
|
|
("open", valve.Open)))
|
|
|
|
|
{
|
2021-10-19 21:46:31 +00:00
|
|
|
args.PushMarkup(str);
|
2023-11-27 22:12:34 +11:00
|
|
|
}
|
2021-07-12 09:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnStartup(EntityUid uid, GasValveComponent component, ComponentStartup args)
|
|
|
|
|
{
|
|
|
|
|
// We call set in startup so it sets the appearance, node state, etc.
|
|
|
|
|
Set(uid, component, component.Open);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivate(EntityUid uid, GasValveComponent component, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2024-05-31 16:26:19 -04:00
|
|
|
if (args.Handled || !args.Complex)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-02-15 17:06:52 +13:00
|
|
|
Toggle(uid, component);
|
2023-11-27 22:12:34 +11:00
|
|
|
_audio.PlayPvs(component.ValveSound, uid, AudioParams.Default.WithVariation(0.25f));
|
2024-05-31 16:26:19 -04:00
|
|
|
args.Handled = true;
|
2021-07-12 09:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Set(EntityUid uid, GasValveComponent component, bool value)
|
|
|
|
|
{
|
|
|
|
|
component.Open = value;
|
2024-03-30 17:17:53 +13:00
|
|
|
|
|
|
|
|
if (_nodeContainer.TryGetNodes(uid, component.InletName, component.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|
2021-07-12 09:47:59 +02:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
2022-01-15 05:18:45 -08:00
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, FilterVisuals.Enabled, component.Open, appearance);
|
2022-01-15 05:18:45 -08:00
|
|
|
}
|
|
|
|
|
if (component.Open)
|
|
|
|
|
{
|
|
|
|
|
inlet.AddAlwaysReachable(outlet);
|
|
|
|
|
outlet.AddAlwaysReachable(inlet);
|
2023-10-19 12:34:31 -07:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, true);
|
2022-01-15 05:18:45 -08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inlet.RemoveAlwaysReachable(outlet);
|
|
|
|
|
outlet.RemoveAlwaysReachable(inlet);
|
2023-10-19 12:34:31 -07:00
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
2022-01-15 05:18:45 -08:00
|
|
|
}
|
2021-07-12 09:47:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Toggle(EntityUid uid, GasValveComponent component)
|
|
|
|
|
{
|
|
|
|
|
Set(uid, component, !component.Open);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|