2022-07-25 14:42:25 +10:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2025-06-26 19:33:43 -07:00
|
|
|
using Content.Server.Body.Components;
|
2023-08-14 17:25:58 -07:00
|
|
|
using Content.Server.Popups;
|
2022-07-25 14:42:25 +10:00
|
|
|
using Content.Shared.Alert;
|
2022-02-10 17:53:10 +13:00
|
|
|
using Content.Shared.Atmos;
|
2025-05-02 18:22:29 +10:00
|
|
|
using Content.Shared.Atmos.Components;
|
|
|
|
|
using Content.Shared.Body.Components;
|
|
|
|
|
using Content.Shared.Body.Systems;
|
2023-08-14 17:25:58 -07:00
|
|
|
using Content.Shared.DoAfter;
|
|
|
|
|
using Content.Shared.Internals;
|
2022-07-25 14:42:25 +10:00
|
|
|
using Content.Shared.Inventory;
|
2024-05-03 03:24:21 +02:00
|
|
|
using Content.Shared.Roles;
|
2022-02-10 17:53:10 +13:00
|
|
|
|
|
|
|
|
namespace Content.Server.Body.Systems;
|
|
|
|
|
|
2025-05-02 18:22:29 +10:00
|
|
|
public sealed class InternalsSystem : SharedInternalsSystem
|
2022-02-10 17:53:10 +13:00
|
|
|
{
|
2022-07-25 14:42:25 +10:00
|
|
|
[Dependency] private readonly AlertsSystem _alerts = default!;
|
|
|
|
|
[Dependency] private readonly GasTankSystem _gasTank = default!;
|
2024-05-31 14:28:11 +12:00
|
|
|
[Dependency] private readonly RespiratorSystem _respirator = default!;
|
2022-07-25 14:42:25 +10:00
|
|
|
|
2024-05-03 03:24:21 +02:00
|
|
|
private EntityQuery<InternalsComponent> _internalsQuery;
|
2023-12-07 16:20:51 -05:00
|
|
|
|
2022-02-10 17:53:10 +13:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2024-05-03 03:24:21 +02:00
|
|
|
_internalsQuery = GetEntityQuery<InternalsComponent>();
|
|
|
|
|
|
2022-02-10 17:53:10 +13:00
|
|
|
SubscribeLocalEvent<InternalsComponent, InhaleLocationEvent>(OnInhaleLocation);
|
2024-05-31 14:28:11 +12:00
|
|
|
SubscribeLocalEvent<InternalsComponent, StartingGearEquippedEvent>(OnStartingGear);
|
2024-05-03 03:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-31 14:28:11 +12:00
|
|
|
private void OnStartingGear(EntityUid uid, InternalsComponent component, ref StartingGearEquippedEvent args)
|
2024-05-03 03:24:21 +02:00
|
|
|
{
|
2024-06-06 00:01:45 -07:00
|
|
|
if (component.BreathTools.Count == 0)
|
2024-05-03 03:24:21 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-05-31 14:28:11 +12:00
|
|
|
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?
|
2025-07-17 09:46:38 -07:00
|
|
|
if (!_respirator.CanMetabolizeInhaledAir(uid, tank.Value.Comp.Air))
|
2024-05-31 14:28:11 +12:00
|
|
|
return;
|
|
|
|
|
|
2025-06-02 12:09:45 +01:00
|
|
|
ToggleInternals(uid, uid, force: false, component, ToggleMode.On);
|
2022-11-08 13:04:06 -08:00
|
|
|
}
|
|
|
|
|
|
2024-03-28 01:48:37 +01:00
|
|
|
private void OnInhaleLocation(Entity<InternalsComponent> ent, ref InhaleLocationEvent args)
|
2022-02-10 17:53:10 +13:00
|
|
|
{
|
2024-03-28 01:48:37 +01:00
|
|
|
if (AreInternalsWorking(ent))
|
2022-02-10 17:53:10 +13:00
|
|
|
{
|
2024-03-28 01:48:37 +01:00
|
|
|
var gasTank = Comp<GasTankComponent>(ent.Comp.GasTankEntity!.Value);
|
2025-06-26 19:33:43 -07:00
|
|
|
args.Gas = _gasTank.RemoveAirVolume((ent.Comp.GasTankEntity.Value, gasTank), args.Respirator.BreathVolume);
|
2022-07-25 14:42:25 +10:00
|
|
|
// TODO: Should listen to gas tank updates instead I guess?
|
2025-09-05 02:45:48 -07:00
|
|
|
_alerts.ShowAlert(ent.Owner, ent.Comp.InternalsAlert, GetSeverity(ent));
|
2022-07-25 14:42:25 +10:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-10 17:53:10 +13:00
|
|
|
}
|