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:
@@ -19,12 +19,14 @@ public sealed partial class SalvageSystem
|
|||||||
private const string MagnetChannel = "Supply";
|
private const string MagnetChannel = "Supply";
|
||||||
|
|
||||||
private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
|
private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
|
||||||
|
private EntityQuery<MobStateComponent> _mobStateQuery;
|
||||||
|
|
||||||
private List<(Entity<TransformComponent> Entity, EntityUid MapUid, Vector2 LocalPosition)> _detachEnts = new();
|
private List<(Entity<TransformComponent> Entity, EntityUid MapUid, Vector2 LocalPosition)> _detachEnts = new();
|
||||||
|
|
||||||
private void InitializeMagnet()
|
private void InitializeMagnet()
|
||||||
{
|
{
|
||||||
_salvMobQuery = GetEntityQuery<SalvageMobRestrictionsComponent>();
|
_salvMobQuery = GetEntityQuery<SalvageMobRestrictionsComponent>();
|
||||||
|
_mobStateQuery = GetEntityQuery<MobStateComponent>();
|
||||||
|
|
||||||
SubscribeLocalEvent<SalvageMagnetDataComponent, MapInitEvent>(OnMagnetDataMapInit);
|
SubscribeLocalEvent<SalvageMagnetDataComponent, MapInitEvent>(OnMagnetDataMapInit);
|
||||||
|
|
||||||
@@ -155,6 +157,21 @@ public sealed partial class SalvageSystem
|
|||||||
if (_salvMobQuery.HasComp(mobUid))
|
if (_salvMobQuery.HasComp(mobUid))
|
||||||
continue;
|
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.
|
// Can't parent directly to map as it runs grid traversal.
|
||||||
_detachEnts.Add(((mobUid, xform), xform.MapUid.Value, _transform.GetWorldPosition(xform)));
|
_detachEnts.Add(((mobUid, xform), xform.MapUid.Value, _transform.GetWorldPosition(xform)));
|
||||||
_transform.DetachEntity(mobUid, xform);
|
_transform.DetachEntity(mobUid, xform);
|
||||||
|
|||||||
Reference in New Issue
Block a user