CatStation/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs
TemporalOroboros 84b2f07157
The IMapManager is dead (#44002)
* Axes the easy IMapManager references

* Axes the references to unported (obsolete) IMapManager methods

* Converts salvageruler command to a LocalizedEntityCommand so it can use SharedMapSystem

* Removes IMapManager from GameTicker
This required axing the map nuke during restart, but that should be fine?
Maps are entities so EntityManager.FlushEntities should delete them all and that's the preceding line

* submodule update(?)

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
2026-07-01 20:44:54 -07:00

122 lines
4.1 KiB
C#

using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Systems;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Shared.Atmos;
using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
namespace Content.Server.Storage.EntitySystems;
public sealed partial class EntityStorageSystem : SharedEntityStorageSystem
{
[Dependency] private ConstructionSystem _construction = default!;
[Dependency] private AtmosphereSystem _atmos = default!;
[Dependency] private MapSystem _mapSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EntityStorageComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<InsideEntityStorageComponent, InhaleLocationEvent>(OnInsideInhale);
SubscribeLocalEvent<InsideEntityStorageComponent, ExhaleLocationEvent>(OnInsideExhale);
SubscribeLocalEvent<InsideEntityStorageComponent, AtmosExposedGetAirEvent>(OnInsideExposed);
}
private void OnMapInit(EntityUid uid, EntityStorageComponent component, MapInitEvent args)
{
if (!component.Open && component.Air.TotalMoles == 0)
{
// If we're closed on spawn and have no air already saved, we need to pull some air into our environment from where we spawned,
// so that we have -something-. For example, if you bought an animal crate or something.
TakeGas(uid, component);
}
}
protected override void OnComponentInit(EntityUid uid, EntityStorageComponent component, ComponentInit args)
{
base.OnComponentInit(uid, component, args);
if (TryComp<ConstructionComponent>(uid, out var construction))
_construction.AddContainer(uid, ContainerName, construction);
}
protected override void TakeGas(EntityUid uid, EntityStorageComponent component)
{
if (!component.Airtight)
return;
var tile = GetOffsetTileRef(uid, component);
if (tile != null && _atmos.GetTileMixture(tile.Value.GridUid, null, tile.Value.GridIndices, true) is { } environment)
{
_atmos.Merge(component.Air, environment.RemoveVolume(component.Air.Volume));
}
}
public override void ReleaseGas(EntityUid uid, EntityStorageComponent component)
{
if (!component.Airtight)
return;
var tile = GetOffsetTileRef(uid, component);
if (tile != null && _atmos.GetTileMixture(tile.Value.GridUid, null, tile.Value.GridIndices, true) is { } environment)
{
_atmos.Merge(environment, component.Air);
component.Air.Clear();
}
}
private TileRef? GetOffsetTileRef(EntityUid uid, EntityStorageComponent component)
{
var targetCoordinates = TransformSystem.ToMapCoordinates(new EntityCoordinates(uid, component.EnteringOffset));
if (_mapSystem.TryFindGridAt(targetCoordinates, out var gridId, out var grid))
{
return _mapSystem.GetTileRef(gridId, grid, targetCoordinates);
}
return null;
}
#region Gas mix event handlers
private void OnInsideInhale(EntityUid uid, InsideEntityStorageComponent component, InhaleLocationEvent args)
{
if (TryComp<EntityStorageComponent>(component.Storage, out var storage) && storage.Airtight)
{
args.Gas = storage.Air;
}
}
private void OnInsideExhale(EntityUid uid, InsideEntityStorageComponent component, ExhaleLocationEvent args)
{
if (TryComp<EntityStorageComponent>(component.Storage, out var storage) && storage.Airtight)
{
args.Gas = storage.Air;
}
}
private void OnInsideExposed(EntityUid uid, InsideEntityStorageComponent component, ref AtmosExposedGetAirEvent args)
{
if (args.Handled)
return;
if (TryComp<EntityStorageComponent>(component.Storage, out var storage))
{
if (!storage.Airtight)
return;
args.Gas = storage.Air;
}
args.Handled = true;
}
#endregion
}