Files
tbd-station-14/Content.Server/Objectives/Conditions/KillRandomHeadCondition.cs
deltanedas 3432a28271 add kill head objective (#17891)
Co-authored-by: deltanedas <@deltanedas:kde.org>
2023-07-09 20:26:17 -06:00

48 lines
1.6 KiB
C#

using Content.Server.Mind.Components;
using Content.Server.Objectives.Interfaces;
using Content.Server.Roles;
using Content.Shared.Mobs.Components;
using Robust.Shared.Random;
using System.Linq;
namespace Content.Server.Objectives.Conditions;
[DataDefinition]
public sealed class KillRandomHeadCondition : KillPersonCondition
{
public override IObjectiveCondition GetAssigned(Mind.Mind mind)
{
RequireDead = true;
var allHumans = EntityManager.EntityQuery<MindContainerComponent>(true).Where(mc =>
{
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
var allHeads = allHumans.Where(mind => mind?.AllRoles.Any(role => {
if (role is not Job job)
return false;
// basically a command department check, pretty sussy but whatever
return job.Prototype.RequireAdminNotify;
}) ?? false).ToList();
if (allHeads.Count == 0)
allHeads = allHumans; // fallback to non-head target
return new KillRandomHeadCondition {Target = IoCManager.Resolve<IRobustRandom>().Pick(allHeads)};
}
public string Description => Loc.GetString("objective-condition-kill-head-description");
}