using Content.Server.Atmos.Components; using Content.Shared.Examine; using Robust.Shared.Map.Components; 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 class DeltaPressureSystem : EntitySystem { [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly SharedMapSystem _map = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentShutdown); SubscribeLocalEvent(OnExamined); SubscribeLocalEvent(OnMoveEvent); SubscribeLocalEvent(OnGridChanged); } private void OnMoveEvent(Entity ent, ref MoveEvent args) { var xform = Transform(ent); // May move off-grid, so, might as well protect against that. if (!TryComp(xform.GridUid, out var mapGridComponent)) { return; } ent.Comp.CurrentPosition = _map.CoordinatesToTile(xform.GridUid.Value, mapGridComponent, args.NewPosition); } private void OnComponentInit(Entity ent, ref ComponentInit args) { var xform = Transform(ent); if (xform.GridUid == null) return; _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 OnExamined(Entity ent, ref ExaminedEvent args) { if (ent.Comp.IsTakingDamage) args.PushMarkup(Loc.GetString("window-taking-damage")); } 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); } } }