Files
crystall-punk-14/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs

36 lines
1.2 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
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 partial 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;
2021-12-03 15:32:05 +01:00
if (EntityManager.TryGetComponent(entity, out MobStateComponent? mobState) &&
MobStateSystem.IsAlive(entity.Value, mobState) &&
mc.Mind != mind && mc.Mind != null)
{
allHumans.Add(mc.Mind);
}
}
2021-12-21 21:23:29 +01:00
if (allHumans.Count == 0)
return new DieCondition(); // I guess I'll die
2021-12-21 21:23:29 +01:00
return new KillRandomPersonCondition {Target = IoCManager.Resolve<IRobustRandom>().Pick(allHumans)};
}
}