Refactor minds to be entities with components, make roles components (#19591)

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2023-08-28 16:53:24 -07:00
committed by GitHub
parent e0ee397af7
commit 15c0211fb2
119 changed files with 1445 additions and 1289 deletions

View File

@@ -1,46 +1,43 @@
using System.Linq;
using Content.Server.Mind;
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 partial class KillRandomHeadCondition : KillPersonCondition
{
public override IObjectiveCondition GetAssigned(Mind.Mind mind)
// TODO refactor all of this to be ecs
public override IObjectiveCondition GetAssigned(EntityUid mindId, MindComponent mind)
{
RequireDead = true;
var allHumans = EntityManager.EntityQuery<MindContainerComponent>(true).Where(mc =>
{
var entity = mc.Mind?.OwnedEntity;
var entity = EntityManager.GetComponentOrNull<MindComponent>(mc.Mind)?.OwnedEntity;
if (entity == default)
return false;
return EntityManager.TryGetComponent(entity, out MobStateComponent? mobState) &&
MobStateSystem.IsAlive(entity.Value, mobState) &&
mc.Mind != mind;
MobStateSystem.IsAlive(entity.Value, mobState) &&
mc.Mind != mindId;
}).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();
var allHeads = allHumans
.Where(mind => Jobs.MindTryGetJob(mind, out _, out var prototype) && prototype.RequireAdminNotify)
.ToList();
if (allHeads.Count == 0)
allHeads = allHumans; // fallback to non-head target
return new KillRandomHeadCondition {Target = IoCManager.Resolve<IRobustRandom>().Pick(allHeads)};
return new KillRandomHeadCondition { TargetMindId = IoCManager.Resolve<IRobustRandom>().Pick(allHeads) };
}
public string Description => Loc.GetString("objective-condition-kill-head-description");