Files
tbd-station-14/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs
deltanedas a4cbe81be5 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>
2023-08-12 21:01:20 -04:00

36 lines
1.2 KiB
C#

using Content.Server.Mind.Components;
using Content.Server.Objectives.Interfaces;
using Content.Shared.Humanoid;
using Content.Shared.Mobs.Components;
using Robust.Shared.Random;
namespace Content.Server.Objectives.Conditions;
[DataDefinition]
public sealed class KillRandomPersonCondition : KillPersonCondition
{
public override IObjectiveCondition GetAssigned(Mind.Mind mind)
{
var allHumans = new List<Mind.Mind>();
var query = EntityManager.EntityQuery<MindContainerComponent, HumanoidAppearanceComponent>(true);
foreach (var (mc, _) in query)
{
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)
{
allHumans.Add(mc.Mind);
}
}
if (allHumans.Count == 0)
return new DieCondition(); // I guess I'll die
return new KillRandomPersonCondition {Target = IoCManager.Resolve<IRobustRandom>().Pick(allHumans)};
}
}