kill target has to be human (#18995)

* kill target has to be human

* death to linq

* file scope

* !!!

* :trollface:

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-08-13 02:01:20 +01:00
committed by GitHub
parent 4136353ece
commit a4cbe81be5

View File

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