using Content.Server.Atmos.Components;
using Content.Shared.Atmos.Components;
using Content.Shared.Atmos.EntitySystems;
namespace Content.Server.Atmos.EntitySystems;
///
/// System that handles .
///
/// Entities with a will take damage per atmostick
/// depending on the pressure they experience.
///
/// DeltaPressure logic is mostly handled in a partial class in Atmospherics.
/// This system handles the adding and removing of entities to a processing list,
/// as well as any field changes via the API.
///
public sealed partial class DeltaPressureSystem : SharedDeltaPressureSystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnComponentInit);
SubscribeLocalEvent(OnComponentShutdown);
SubscribeLocalEvent(OnGridChanged);
}
private void OnComponentInit(Entity ent, ref ComponentInit args)
{
var xform = Transform(ent);
if (xform.GridUid == null)
return;
EnsureComp(ent);
_atmosphereSystem.TryAddDeltaPressureEntity(xform.GridUid.Value, ent);
}
private void OnComponentShutdown(Entity ent, ref ComponentShutdown args)
{
// Wasn't part of a list, so nothing to clean up.
if (ent.Comp.GridUid == null)
return;
_atmosphereSystem.TryRemoveDeltaPressureEntity(ent.Comp.GridUid.Value, ent);
}
private void OnGridChanged(Entity ent, ref GridUidChangedEvent args)
{
if (args.OldGrid != null)
{
_atmosphereSystem.TryRemoveDeltaPressureEntity(args.OldGrid.Value, ent);
}
if (args.NewGrid != null)
{
_atmosphereSystem.TryAddDeltaPressureEntity(args.NewGrid.Value, ent);
}
}
}