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:
@@ -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<Mind.Mind>();
|
||||
var query = EntityManager.EntityQuery<MindContainerComponent, HumanoidAppearanceComponent>(true);
|
||||
foreach (var (mc, _) in query)
|
||||
{
|
||||
var allHumans = EntityManager.EntityQuery<MindContainerComponent>(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<IRobustRandom>().Pick(allHumans)};
|
||||
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)};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user