2020-12-01 17:05:19 +01:00
|
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Server.Mind.Components;
|
2020-12-01 17:05:19 +01:00
|
|
|
|
using Content.Server.Objectives.Interfaces;
|
2021-11-08 15:11:58 +01:00
|
|
|
|
using Content.Shared.MobState.Components;
|
2020-12-01 17:05:19 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-01 17:05:19 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Random;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-12-01 17:05:19 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Objectives.Conditions
|
|
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataDefinition]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class KillRandomPersonCondition : KillPersonCondition
|
2020-12-01 17:05:19 +01:00
|
|
|
|
{
|
2021-06-09 22:19:39 +02:00
|
|
|
|
public override IObjectiveCondition GetAssigned(Mind.Mind mind)
|
2020-12-01 17:05:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
var entityMgr = IoCManager.Resolve<IEntityManager>();
|
2021-09-28 13:35:29 +02:00
|
|
|
|
var allHumans = entityMgr.EntityQuery<MindComponent>(true).Where(mc =>
|
2020-12-01 17:05:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
var entity = mc.Mind?.OwnedEntity;
|
2021-12-03 15:32:05 +01:00
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (entity == default)
|
2021-12-03 15:32:05 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2021-12-06 14:00:39 +01:00
|
|
|
|
return entityMgr.TryGetComponent(entity, out MobStateComponent mobState) &&
|
|
|
|
|
|
mobState.IsAlive() &&
|
|
|
|
|
|
mc.Mind != mind;
|
2020-12-01 17:05:19 +01:00
|
|
|
|
}).Select(mc => mc.Mind).ToList();
|
2021-12-21 21:23:29 +01:00
|
|
|
|
|
|
|
|
|
|
if (allHumans.Count == 0)
|
|
|
|
|
|
return new DieCondition(); // I guess I'll die
|
|
|
|
|
|
|
2020-12-01 17:05:19 +01:00
|
|
|
|
return new KillRandomPersonCondition {Target = IoCManager.Resolve<IRobustRandom>().Pick(allHumans)};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|