diff --git a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs index 3132eefd68..98ce5e0e13 100644 --- a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs @@ -29,8 +29,9 @@ namespace Content.Server.Atmos.EntitySystems if (airtight.FixAirBlockedDirectionInitialize) { - var moveEvent = new MoveEvent(airtight.Owner, default, default, Angle.Zero, xform.LocalRotation, xform, false); - OnAirtightRotated(uid, airtight, ref moveEvent); + var moveEvent = new MoveEvent(uid, default, default, Angle.Zero, xform.LocalRotation, xform, false); + if (AirtightRotate(uid, airtight, ref moveEvent)) + return; } UpdatePosition(airtight); @@ -46,7 +47,7 @@ namespace Content.Server.Atmos.EntitySystems if (MetaData(grid.Owner).EntityLifeStage > EntityLifeStage.MapInitialized) return; } - SetAirblocked(airtight, false, xform); + SetAirblocked(uid, airtight, false, xform); } private void OnAirtightPositionChanged(EntityUid uid, AirtightComponent airtight, ref AnchorStateChangedEvent args) @@ -77,16 +78,23 @@ namespace Content.Server.Atmos.EntitySystems } private void OnAirtightRotated(EntityUid uid, AirtightComponent airtight, ref MoveEvent ev) + { + AirtightRotate(uid, airtight, ref ev); + } + + private bool AirtightRotate(EntityUid uid, AirtightComponent airtight, ref MoveEvent ev) { if (!airtight.RotateAirBlocked || airtight.InitialAirBlockedDirection == (int)AtmosDirection.Invalid) - return; + return false; airtight.CurrentAirBlockedDirection = (int) Rotate((AtmosDirection)airtight.InitialAirBlockedDirection, ev.NewRotation); UpdatePosition(airtight, ev.Component); - RaiseLocalEvent(uid, new AirtightChanged(airtight), true); + var airtightEv = new AirtightChanged(uid, airtight); + RaiseLocalEvent(uid, ref airtightEv); + return true; } - public void SetAirblocked(AirtightComponent airtight, bool airblocked, TransformComponent? xform = null) + public void SetAirblocked(EntityUid uid, AirtightComponent airtight, bool airblocked, TransformComponent? xform = null) { if (airtight.AirBlocked == airblocked) return; @@ -95,7 +103,8 @@ namespace Content.Server.Atmos.EntitySystems airtight.AirBlocked = airblocked; UpdatePosition(airtight, xform); - RaiseLocalEvent(airtight.Owner, new AirtightChanged(airtight), true); + var airtightEv = new AirtightChanged(uid, airtight); + RaiseLocalEvent(uid, ref airtightEv); } public void UpdatePosition(AirtightComponent airtight, TransformComponent? xform = null) @@ -143,13 +152,6 @@ namespace Content.Server.Atmos.EntitySystems } } - public sealed class AirtightChanged : EntityEventArgs - { - public AirtightComponent Airtight; - - public AirtightChanged(AirtightComponent airtight) - { - Airtight = airtight; - } - } + [ByRefEvent] + public readonly record struct AirtightChanged(EntityUid Entity, AirtightComponent Airtight); } diff --git a/Content.Server/Doors/Systems/DoorSystem.cs b/Content.Server/Doors/Systems/DoorSystem.cs index d9c6c25886..b47e06f6a1 100644 --- a/Content.Server/Doors/Systems/DoorSystem.cs +++ b/Content.Server/Doors/Systems/DoorSystem.cs @@ -67,7 +67,7 @@ public sealed class DoorSystem : SharedDoorSystem return; if (door.ChangeAirtight && TryComp(uid, out AirtightComponent? airtight)) - _airtightSystem.SetAirblocked(airtight, collidable); + _airtightSystem.SetAirblocked(uid, airtight, collidable); // Pathfinding / AI stuff. RaiseLocalEvent(new AccessReaderChangeEvent(uid, collidable)); diff --git a/Content.Server/Kudzu/SpreaderSystem.cs b/Content.Server/Kudzu/SpreaderSystem.cs index 38faff41c7..d75c8ad024 100644 --- a/Content.Server/Kudzu/SpreaderSystem.cs +++ b/Content.Server/Kudzu/SpreaderSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Shared.Atmos; using Robust.Shared.Map; +using Robust.Shared.Map.Components; using Robust.Shared.Random; namespace Content.Server.Kudzu; @@ -28,9 +29,9 @@ public sealed class SpreaderSystem : EntitySystem SubscribeLocalEvent(OnAirtightChanged); } - private void OnAirtightChanged(AirtightChanged e) + private void OnAirtightChanged(ref AirtightChanged ev) { - UpdateNearbySpreaders((e.Airtight).Owner, e.Airtight); + UpdateNearbySpreaders(ev.Entity, ev.Airtight); } private void SpreaderAddHandler(EntityUid uid, SpreaderComponent component, ComponentAdd args) @@ -46,15 +47,21 @@ public sealed class SpreaderSystem : EntitySystem if (!_mapManager.TryGetGrid(transform.GridUid, out var grid)) return; + var spreaderQuery = GetEntityQuery(); + var tile = grid.TileIndicesFor(transform.Coordinates); + for (var i = 0; i < Atmospherics.Directions; i++) { var direction = (AtmosDirection) (1 << i); if (!comp.AirBlockedDirection.IsFlagSet(direction)) continue; - foreach (var ent in grid.GetInDir(transform.Coordinates, direction.ToDirection())) + var directionEnumerator = + grid.GetAnchoredEntitiesEnumerator(SharedMapSystem.GetDirection(tile, direction.ToDirection())); + + while (directionEnumerator.MoveNext(out var ent)) { - if (EntityManager.TryGetComponent(ent, out var s) && s.Enabled) - _edgeGrowths.Add(ent); + if (spreaderQuery.TryGetComponent(ent, out var s) && s.Enabled) + _edgeGrowths.Add(ent.Value); } } }