Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FireNameFN committed Dec 3, 2024
1 parent 22fc39c commit da63e5e
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions Content.Server/_CorvaxNext/Storage/AnchorableStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,33 +33,29 @@ private void OnAnchorStateChanged(Entity<AnchorableStorageComponent> 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<StorageComponent>(ent.Owner, out var storage))
return;

var entsToRemove = storage.StoredItems.Keys.Where(storedItem =>
HasComp<MindContainerComponent>(storedItem)
).ToList();

foreach (var removeUid in entsToRemove)
_container.RemoveEntity(ent.Owner, removeUid);
foreach (var item in storage.StoredItems.Keys.ToArray())
if (HasComp<MindContainerComponent>(item))
_container.RemoveEntity(ent, item);
}

private void OnAnchorAttempt(Entity<AnchorableStorageComponent> ent, ref AnchorAttemptEvent args)
{
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);
Expand All @@ -72,38 +67,29 @@ private void OnInsertAttempt(Entity<AnchorableStorageComponent> ent, ref Contain
if (args.Cancelled)
return;

// Check for living things, they should not insert when anchored.
if (!HasComp<MindContainerComponent>(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<AnchorableStorageComponent, TransformComponent> ent)
{
if (ent.Comp2.GridUid is not { } grid || !TryComp<MapGridComponent>(grid, out var gridComp))
if (transform.GridUid is not { } grid || !TryComp<MapGridComponent>(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<AnchorableStorageComponent>(otherEnt))
return true;
}
Expand Down

0 comments on commit da63e5e

Please sign in to comment.