diff --git a/Content.Server/_CorvaxNext/Storage/AnchorableStorageSystem.cs b/Content.Server/_CorvaxNext/Storage/AnchorableStorageSystem.cs index 4a60da8aa89..b655f6c6124 100644 --- a/Content.Server/_CorvaxNext/Storage/AnchorableStorageSystem.cs +++ b/Content.Server/_CorvaxNext/Storage/AnchorableStorageSystem.cs @@ -3,7 +3,6 @@ using Content.Shared.Construction.Components; using Content.Shared.Mind.Components; using Content.Shared.Storage; -using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.Map.Components; @@ -34,24 +33,21 @@ private void OnAnchorStateChanged(Entity ent, ref An if (!args.Anchored) return; - if (CheckOverlap((ent, ent.Comp, Transform(ent)))) + var transform = Transform(ent); + + if (CheckOverlap(ent, transform)) { _popup.PopupEntity(Loc.GetString("anchored-storage-already-present"), ent); - _xform.Unanchor(ent, Transform(ent)); + _xform.Unanchor(ent, transform); return; } - // Eject any sapient creatures inside the storage. - // Does not recurse down into bags in bags - player characters are the largest concern, and they'll only fit in duffelbags. - if (!TryComp(ent.Owner, out StorageComponent? storage)) + if (!TryComp(ent.Owner, out var storage)) return; - var entsToRemove = storage.StoredItems.Keys.Where(storedItem => - HasComp(storedItem) - ).ToList(); - - foreach (var removeUid in entsToRemove) - _container.RemoveEntity(ent.Owner, removeUid); + foreach (var item in storage.StoredItems.Keys.ToArray()) + if (HasComp(item)) + _container.RemoveEntity(ent, item); } private void OnAnchorAttempt(Entity ent, ref AnchorAttemptEvent args) @@ -59,8 +55,7 @@ private void OnAnchorAttempt(Entity ent, ref AnchorA if (args.Cancelled) return; - // Nothing around? We can anchor without issue. - if (!CheckOverlap((ent, ent.Comp, Transform(ent)))) + if (!CheckOverlap(ent)) return; _popup.PopupEntity(Loc.GetString("anchored-storage-already-present"), ent, args.User); @@ -72,38 +67,29 @@ private void OnInsertAttempt(Entity ent, ref Contain if (args.Cancelled) return; - // Check for living things, they should not insert when anchored. if (!HasComp(args.EntityUid)) return; - if (Transform(ent.Owner).Anchored) + if (Transform(ent).Anchored) args.Cancel(); } - [PublicAPI] - public bool CheckOverlap(EntityUid uid) + public bool CheckOverlap(EntityUid entity, TransformComponent? transform = null) { - if (!TryComp(uid, out AnchorableStorageComponent? comp)) + if (!Resolve(entity, ref transform)) return false; - return CheckOverlap((uid, comp, Transform(uid))); - } - - public bool CheckOverlap(Entity ent) - { - if (ent.Comp2.GridUid is not { } grid || !TryComp(grid, out var gridComp)) + if (transform.GridUid is not { } grid || !TryComp(grid, out var gridComp)) return false; - var indices = _map.TileIndicesFor(grid, gridComp, ent.Comp2.Coordinates); + var indices = _map.TileIndicesFor(grid, gridComp, transform.Coordinates); var enumerator = _map.GetAnchoredEntitiesEnumerator(grid, gridComp, indices); while (enumerator.MoveNext(out var otherEnt)) { - // Don't match yourself. - if (otherEnt == ent.Owner) + if (otherEnt == entity) continue; - // Is another storage entity is already anchored here? if (HasComp(otherEnt)) return true; }