CatStation/Content.Server/Body/Systems/InternalsSystem.cs
Eveloop 22a547c7c8
Use dependency injection for EntityQuery<T>s in Content.Server (#43566)
* Replace usages of EntityQuery with dependency injected ones in Content.Server

* Remove unused EntityQuery dependencies

* Restore CheckPressureAndFire override method

* Revert EntityQuery refactor changes to DisposalTubeSystem.cs & DisposableSystem.cs

* Infer Transform/Metadata directly instead of passing (#43479)

* Resolve RA0049, RA0051 errors (#43479)

* Resolve RA0049, RA0051 errors (#43479)

* Apply suggestions from code review

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2026-05-17 15:59:37 +00:00

58 lines
2.2 KiB
C#

using Content.Server.Atmos.EntitySystems;
using Content.Shared.Alert;
using Content.Shared.Atmos.Components;
using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Content.Shared.Internals;
using Content.Shared.Roles;
namespace Content.Server.Body.Systems;
public sealed partial class InternalsSystem : SharedInternalsSystem
{
[Dependency] private AlertsSystem _alerts = default!;
[Dependency] private GasTankSystem _gasTank = default!;
[Dependency] private RespiratorSystem _respirator = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InternalsComponent, InhaleLocationEvent>(OnInhaleLocation);
SubscribeLocalEvent<InternalsComponent, StartingGearEquippedEvent>(OnStartingGear);
}
private void OnStartingGear(EntityUid uid, InternalsComponent component, ref StartingGearEquippedEvent args)
{
if (component.BreathTools.Count == 0)
return;
if (component.GasTankEntity != null)
return; // already connected
// Can the entity breathe the air it is currently exposed to?
if (_respirator.CanMetabolizeInhaledAir(uid))
return;
var tank = FindBestGasTank(uid);
if (tank == null)
return;
// Could the entity metabolise the air in the linked gas tank?
if (!_respirator.CanMetabolizeInhaledAir(uid, tank.Value.Comp.Air))
return;
ToggleInternals(uid, uid, force: false, component, ToggleMode.On);
}
private void OnInhaleLocation(Entity<InternalsComponent> ent, ref InhaleLocationEvent args)
{
if (AreInternalsWorking(ent))
{
var gasTank = Comp<GasTankComponent>(ent.Comp.GasTankEntity!.Value);
// TODO ATMOS: TODO BODY: This is an incredibly stupid workaround to stop Urist McHands from horfing all 5 litres of the gas tank in 10 seconds.
args.Gas = _gasTank.RemoveAirOutput((ent.Comp.GasTankEntity.Value, gasTank), args.Respirator.BreathVolume);
// TODO ATMOS: Should listen to gas tank updates instead I guess?
_alerts.ShowAlert(ent.Owner, ent.Comp.InternalsAlert, GetSeverity(ent));
}
}
}