From 45ea7451ca383ac5b6adfedf00ad4024fc29e610 Mon Sep 17 00:00:00 2001 From: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Date: Tue, 14 Jan 2025 06:14:01 -0800 Subject: [PATCH] Fixed various issues with kill objectives (#2723) The fix is in doc! --- .../Objectives/Systems/KillPersonConditionSystem.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Content.Server/Objectives/Systems/KillPersonConditionSystem.cs b/Content.Server/Objectives/Systems/KillPersonConditionSystem.cs index bd062e7456..9d9c6aa7f3 100644 --- a/Content.Server/Objectives/Systems/KillPersonConditionSystem.cs +++ b/Content.Server/Objectives/Systems/KillPersonConditionSystem.cs @@ -41,18 +41,18 @@ public sealed class KillPersonConditionSystem : EntitySystem private void OnPersonAssigned(Entity ent, ref ObjectiveAssignedEvent args) { - AssignRandomTarget(ent, args, _ => true); + AssignRandomTarget(ent, ref args, _ => true); } private void OnHeadAssigned(Entity ent, ref ObjectiveAssignedEvent args) { - AssignRandomTarget(ent, args, mindId => + AssignRandomTarget(ent, ref args, mindId => TryComp(mindId, out var mind) && mind.OwnedEntity is { } ownedEnt && HasComp(ownedEnt)); } - private void AssignRandomTarget(EntityUid uid, ObjectiveAssignedEvent args, Predicate filter, bool fallbackToAny = true) + private void AssignRandomTarget(EntityUid uid, ref ObjectiveAssignedEvent args, Predicate filter, bool fallbackToAny = true) { // invalid prototype if (!TryComp(uid, out var target)) @@ -97,6 +97,13 @@ public sealed class KillPersonConditionSystem : EntitySystem // Pick between humans matching our filter or fall back to all humans alive var selectedHumans = filteredHumans.Count > 0 ? filteredHumans : allHumans; + // Still no valid targets even after the fallback + if (selectedHumans.Count == 0) + { + args.Cancelled = true; + return; + } + _target.SetTarget(uid, _random.Pick(selectedHumans), target); }