Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traitor can no longer get multiple objectives to save/help/kill the same person #33704

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Content.Server/Objectives/Systems/HelpProgressConditionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,34 @@ private void OnTraitorAssigned(EntityUid uid, RandomTraitorProgressComponent com
return;
}

var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind)
.Select(pair => pair.Item1)
.ToHashSet();
var removeList = new List<EntityUid>();
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();

// cant help anyone who is tasked with helping:
// 1. thats boring
// 2. no cyclic progress dependencies!!!
foreach (var traitor in traitors)
{
// TODO: replace this with TryComp<ObjectivesComponent>(traitor) or something when objectives are moved out of mind
if (!TryComp<MindComponent>(traitor, out var mind))
if (!TryComp<MindComponent>(traitor.Id, out var mind))
continue;

foreach (var objective in mind.Objectives)
{
if (HasComp<HelpProgressConditionComponent>(objective))
removeList.Add(traitor);
traitors.RemoveWhere(x => x.Mind == mind);
}
}

foreach (var tot in removeList)
// Can't have multiple objectives to help/save the same person
foreach (var objective in args.Mind.Objectives)
{
traitors.Remove(tot);
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
{
if (TryComp<TargetObjectiveComponent>(objective, out var help))
{
traitors.RemoveWhere(x => x.Id == help.Target);
}
}
}

// no more helpable traitors
Expand All @@ -78,7 +82,7 @@ private void OnTraitorAssigned(EntityUid uid, RandomTraitorProgressComponent com
return;
}

_target.SetTarget(uid, _random.Pick(traitors), target);
_target.SetTarget(uid, _random.Pick(traitors).Id, target);
}

private float GetProgress(EntityUid target)
Expand Down
14 changes: 13 additions & 1 deletion Content.Server/Objectives/Systems/KeepAliveCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ private void OnAssigned(EntityUid uid, RandomTraitorAliveComponent comp, ref Obj
return;
}

var traitors = Enumerable.ToList<(EntityUid Id, MindComponent Mind)>(_traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind));
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();

// Can't have multiple objectives to help/save the same person
foreach (var objective in args.Mind.Objectives)
{
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
{
if (TryComp<TargetObjectiveComponent>(objective, out var help))
{
traitors.RemoveWhere(x => x.Id == help.Target);
}
}
}

// You are the first/only traitor.
if (traitors.Count == 0)
Expand Down
13 changes: 12 additions & 1 deletion Content.Server/Objectives/Systems/KillPersonConditionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Objectives.Components;
using Robust.Shared.Configuration;
using Robust.Shared.Random;
using System.Linq;

namespace Content.Server.Objectives.Systems;

Expand Down Expand Up @@ -52,8 +53,18 @@ private void OnPersonAssigned(EntityUid uid, PickRandomPersonComponent comp, ref
if (target.Target != null)
return;

// no other humans to kill
var allHumans = _mind.GetAliveHumans(args.MindId);

// Can't have multiple objectives to kill the same person
foreach (var objective in args.Mind.Objectives)
{
if (HasComp<KillPersonConditionComponent>(objective) && TryComp<TargetObjectiveComponent>(objective, out var kill))
{
allHumans.RemoveWhere(x => x.Owner == kill.Target);
}
}

// no other humans to kill
if (allHumans.Count == 0)
{
args.Cancelled = true;
Expand Down
Loading