Fix accidentally selling mobs (#15578)

This commit is contained in:
metalgearsloth
2023-04-20 22:09:48 +10:00
committed by GitHub
parent 2264c7d0e3
commit e75d9d7e33

View File

@@ -405,8 +405,8 @@ public sealed partial class CargoSystem
// - anything anchored (e.g. light fixtures) // - anything anchored (e.g. light fixtures)
// - anything blacklisted (e.g. players). // - anything blacklisted (e.g. players).
if (toSell.Contains(ent) || if (toSell.Contains(ent) ||
(xformQuery.TryGetComponent(ent, out var xform) && xform.Anchored) || xformQuery.TryGetComponent(ent, out var xform) &&
!CanSell(ent, mobStateQuery)) (xform.Anchored || !CanSell(ent, xform, mobStateQuery, xformQuery)))
{ {
continue; continue;
} }
@@ -423,7 +423,7 @@ public sealed partial class CargoSystem
} }
} }
private bool CanSell(EntityUid uid, EntityQuery<MobStateComponent> mobStateQuery) private bool CanSell(EntityUid uid, TransformComponent xform, EntityQuery<MobStateComponent> mobStateQuery, EntityQuery<TransformComponent> xformQuery)
{ {
if (mobStateQuery.TryGetComponent(uid, out var mobState) && if (mobStateQuery.TryGetComponent(uid, out var mobState) &&
mobState.CurrentState != MobState.Dead) mobState.CurrentState != MobState.Dead)
@@ -431,6 +431,14 @@ public sealed partial class CargoSystem
return false; return false;
} }
// Recursively check for mobs at any point.
var children = xform.ChildEnumerator;
while (children.MoveNext(out var child))
{
if (!CanSell(child.Value, xformQuery.GetComponent(child.Value), mobStateQuery, xformQuery))
return false;
}
return true; return true;
} }