Skip to content

Commit

Permalink
what even was this
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Nov 26, 2024
1 parent 75e5857 commit 810f724
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Content.Server/Objectives/Systems/KillPersonConditionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent((Entity<KillPersonConditionComponent> ent, ref ObjectiveGetProgressEvent args) => OnGetProgress(ent, ref args));
SubscribeLocalEvent((Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args) => OnPersonAssigned(ent, ref args));
SubscribeLocalEvent((Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args) => OnHeadAssigned(ent, ref args));
SubscribeLocalEvent<KillPersonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
SubscribeLocalEvent<PickRandomPersonComponent, ObjectiveAssignedEvent>(OnPersonAssigned);
SubscribeLocalEvent<PickRandomHeadComponent, ObjectiveAssignedEvent>(OnHeadAssigned);
}

private void OnGetProgress(Entity<KillPersonConditionComponent> ent, ref ObjectiveGetProgressEvent args)
private void OnGetProgress(EntityUid uid, KillPersonConditionComponent comp, ref ObjectiveGetProgressEvent args)
{
if (!_target.GetTarget(ent, out var target))
if (!_target.GetTarget(uid, out var target))
return;

args.Progress = GetProgress(target.Value, ent.Comp.RequireDead);
args.Progress = GetProgress(target.Value, comp.RequireDead);
}

private void OnPersonAssigned(Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args)
Expand All @@ -45,13 +45,16 @@ private void OnPersonAssigned(Entity<PickRandomPersonComponent> ent, ref Objecti

private void OnHeadAssigned(Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args)
{
AssignRandomTarget(ent, args, _ => HasComp<CommandStaffComponent>(ent));
AssignRandomTarget(ent, args, mindId =>
TryComp<MindComponent>(mindId, out var mind) &&
mind.OwnedEntity is { } ownedEnt &&
HasComp<CommandStaffComponent>(ownedEnt));
}

private void AssignRandomTarget<T>(Entity<T> ent, ObjectiveAssignedEvent args, Predicate<EntityUid> filter, bool fallbackToAny = true) where T : IComponent
private void AssignRandomTarget(EntityUid uid, ObjectiveAssignedEvent args, Predicate<EntityUid> filter, bool fallbackToAny = true)
{
// invalid prototype
if (!TryComp<TargetObjectiveComponent>(ent, out var target))
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
{
args.Cancelled = true;
return;
Expand Down Expand Up @@ -84,7 +87,7 @@ private void AssignRandomTarget<T>(Entity<T> ent, ObjectiveAssignedEvent args, P
// Pick between humans matching our filter or fall back to all humans alive
var selectedHumans = filteredHumans.Count > 0 ? filteredHumans : allHumans;

_target.SetTarget(ent, _random.Pick(selectedHumans), target);
_target.SetTarget(uid, _random.Pick(selectedHumans), target);
}

private float GetProgress(EntityUid target, bool requireDead)
Expand Down

0 comments on commit 810f724

Please sign in to comment.