diff --git a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs index d84b75fff3..94b8794749 100644 --- a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs +++ b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs @@ -1,34 +1,35 @@ -using System.Linq; using Content.Server.Mind.Components; using Content.Server.Objectives.Interfaces; +using Content.Shared.Humanoid; using Content.Shared.Mobs.Components; -using JetBrains.Annotations; using Robust.Shared.Random; -namespace Content.Server.Objectives.Conditions +namespace Content.Server.Objectives.Conditions; + +[DataDefinition] +public sealed class KillRandomPersonCondition : KillPersonCondition { - [UsedImplicitly] - [DataDefinition] - public sealed class KillRandomPersonCondition : KillPersonCondition + public override IObjectiveCondition GetAssigned(Mind.Mind mind) { - public override IObjectiveCondition GetAssigned(Mind.Mind mind) + var allHumans = new List(); + var query = EntityManager.EntityQuery(true); + foreach (var (mc, _) in query) { - var allHumans = EntityManager.EntityQuery(true).Where(mc => + var entity = mc.Mind?.OwnedEntity; + if (entity == default) + continue; + + if (EntityManager.TryGetComponent(entity, out MobStateComponent? mobState) && + MobStateSystem.IsAlive(entity.Value, mobState) && + mc.Mind != mind && mc.Mind != null) { - var entity = mc.Mind?.OwnedEntity; - - if (entity == default) - return false; - - return EntityManager.TryGetComponent(entity, out MobStateComponent? mobState) && - MobStateSystem.IsAlive(entity.Value, mobState) && - mc.Mind != mind; - }).Select(mc => mc.Mind).ToList(); - - if (allHumans.Count == 0) - return new DieCondition(); // I guess I'll die - - return new KillRandomPersonCondition {Target = IoCManager.Resolve().Pick(allHumans)}; + allHumans.Add(mc.Mind); + } } + + if (allHumans.Count == 0) + return new DieCondition(); // I guess I'll die + + return new KillRandomPersonCondition {Target = IoCManager.Resolve().Pick(allHumans)}; } }