using System.Linq; using Content.Shared.Construction.Components; using Content.Shared.Station.Systems; using Robust.Server.GameObjects; namespace Content.Server.Construction; public sealed partial class AnchorOnlyOnStationSystem : EntitySystem { [Dependency] private StationSystem _stationSystem = null!; [Dependency] private TransformSystem _transform = null!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnGridSplit); } private void OnGridSplit(ref GridSplitEvent args) { var allGrids = args.NewGrids.ToList(); var query = AllEntityQuery(); while (query.MoveNext(out var ent, out var anchorOnlyOnStationComp, out var entXform)) { if (entXform.GridUid == null) continue; if (!allGrids.Contains(entXform.GridUid.Value)) continue; if (_stationSystem.IsOnStation(ent, anchorOnlyOnStationComp.OnlyCountLargestGrid)) continue; _transform.Unanchor(ent, entXform); } } }