Fixed various issues with kill objectives (#2723)

The fix is in doc!
This commit is contained in:
beck-thompson 2025-01-14 06:14:01 -08:00 committed by GitHub
parent 88d43a428a
commit 45ea7451ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 3 deletions

View File

@ -41,18 +41,18 @@ public sealed class KillPersonConditionSystem : EntitySystem
private void OnPersonAssigned(Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args)
{
AssignRandomTarget(ent, args, _ => true);
AssignRandomTarget(ent, ref args, _ => true);
}
private void OnHeadAssigned(Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args)
{
AssignRandomTarget(ent, args, mindId =>
AssignRandomTarget(ent, ref args, mindId =>
TryComp<MindComponent>(mindId, out var mind) &&
mind.OwnedEntity is { } ownedEnt &&
HasComp<CommandStaffComponent>(ownedEnt));
}
private void AssignRandomTarget(EntityUid uid, ObjectiveAssignedEvent args, Predicate<EntityUid> filter, bool fallbackToAny = true)
private void AssignRandomTarget(EntityUid uid, ref ObjectiveAssignedEvent args, Predicate<EntityUid> filter, bool fallbackToAny = true)
{
// invalid prototype
if (!TryComp<TargetObjectiveComponent>(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);
}