CatStation/Content.Server/Construction/AnchorOnlyOnStationSystem.cs

39 lines
1.1 KiB
C#

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<GridSplitEvent>(OnGridSplit);
}
private void OnGridSplit(ref GridSplitEvent args)
{
var allGrids = args.NewGrids.ToList();
var query = AllEntityQuery<AnchorOnlyOnStationComponent, TransformComponent>();
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);
}
}
}