Predict gas valves (#33836)
* Predict gas valves * wawawewa * Fix imports before I get yelled at * soff
This commit is contained in:
@@ -1,93 +1,34 @@
|
||||
using Content.Server.Atmos.Piping.Binary.Components;
|
||||
using Content.Server.NodeContainer;
|
||||
using Content.Server.NodeContainer.EntitySystems;
|
||||
using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Shared.Atmos.Piping;
|
||||
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||
using Content.Shared.Atmos.Piping.Binary.Systems;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|
||||
namespace Content.Server.Atmos.Piping.Binary.EntitySystems;
|
||||
|
||||
public sealed class GasValveSystem : SharedGasValveSystem
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class GasValveSystem : EntitySystem
|
||||
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
||||
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
||||
|
||||
public override void Set(EntityUid uid, GasValveComponent component, bool value)
|
||||
{
|
||||
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
||||
base.Set(uid, component, value);
|
||||
|
||||
public override void Initialize()
|
||||
if (_nodeContainer.TryGetNodes(uid, component.InletName, component.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GasValveComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<GasValveComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<GasValveComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
private void OnExamined(Entity<GasValveComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
var valve = ent.Comp;
|
||||
if (!Comp<TransformComponent>(ent).Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status.
|
||||
return;
|
||||
|
||||
if (Loc.TryGetString("gas-valve-system-examined", out var str,
|
||||
("statusColor", valve.Open ? "green" : "orange"),
|
||||
("open", valve.Open)))
|
||||
if (component.Open)
|
||||
{
|
||||
args.PushMarkup(str);
|
||||
inlet.AddAlwaysReachable(outlet);
|
||||
outlet.AddAlwaysReachable(inlet);
|
||||
_ambientSoundSystem.SetAmbience(uid, true);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (args.Handled || !args.Complex)
|
||||
return;
|
||||
|
||||
Toggle(uid, component);
|
||||
_audio.PlayPvs(component.ValveSound, uid, AudioParams.Default.WithVariation(0.25f));
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public void Set(EntityUid uid, GasValveComponent component, bool value)
|
||||
{
|
||||
component.Open = value;
|
||||
|
||||
if (_nodeContainer.TryGetNodes(uid, component.InletName, component.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|
||||
else
|
||||
{
|
||||
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
{
|
||||
_appearance.SetData(uid, FilterVisuals.Enabled, component.Open, appearance);
|
||||
}
|
||||
if (component.Open)
|
||||
{
|
||||
inlet.AddAlwaysReachable(outlet);
|
||||
outlet.AddAlwaysReachable(inlet);
|
||||
_ambientSoundSystem.SetAmbience(uid, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
inlet.RemoveAlwaysReachable(outlet);
|
||||
outlet.RemoveAlwaysReachable(inlet);
|
||||
_ambientSoundSystem.SetAmbience(uid, false);
|
||||
}
|
||||
inlet.RemoveAlwaysReachable(outlet);
|
||||
outlet.RemoveAlwaysReachable(inlet);
|
||||
_ambientSoundSystem.SetAmbience(uid, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Toggle(EntityUid uid, GasValveComponent component)
|
||||
{
|
||||
Set(uid, component, !component.Open);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user