Fix salvage sites ejecting borg brains when they despawn (#35855)

* Fix salvage sites ejecting borg brains when they despawn

* Extra check in while loop

* Move mobStateQuery to InitializeMagnet
This commit is contained in:
Tayrtahn
2025-03-16 14:15:39 -04:00
committed by GitHub
parent af36b3983c
commit 6ee3ae80a5

View File

@@ -19,12 +19,14 @@ public sealed partial class SalvageSystem
private const string MagnetChannel = "Supply";
private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
private EntityQuery<MobStateComponent> _mobStateQuery;
private List<(Entity<TransformComponent> Entity, EntityUid MapUid, Vector2 LocalPosition)> _detachEnts = new();
private void InitializeMagnet()
{
_salvMobQuery = GetEntityQuery<SalvageMobRestrictionsComponent>();
_mobStateQuery = GetEntityQuery<MobStateComponent>();
SubscribeLocalEvent<SalvageMagnetDataComponent, MapInitEvent>(OnMagnetDataMapInit);
@@ -155,6 +157,21 @@ public sealed partial class SalvageSystem
if (_salvMobQuery.HasComp(mobUid))
continue;
bool CheckParents(EntityUid uid)
{
do
{
uid = _transform.GetParentUid(uid);
if (_mobStateQuery.HasComp(uid))
return true;
}
while (uid != xform.GridUid && uid != EntityUid.Invalid);
return false;
}
if (CheckParents(mobUid))
continue;
// Can't parent directly to map as it runs grid traversal.
_detachEnts.Add(((mobUid, xform), xform.MapUid.Value, _transform.GetWorldPosition(xform)));
_transform.DetachEntity(mobUid, xform);