From 0b9ac4cbf79d563bd0037f5e338d42e39976a558 Mon Sep 17 00:00:00 2001 From: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Date: Sat, 21 Dec 2024 05:51:52 -0800 Subject: [PATCH] Add kill fellow traitor objective (#2488) * add feature * opps * fixes * increase weight to 0.2 Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com> --------- Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> --- .../Components/PickRandomTraitorComponent.cs | 9 +++ .../KillFellowTraitorObjectiveSystem.cs | 73 +++++++++++++++++++ .../conditions/kill-fellow-traitor.ftl | 1 + .../Prototypes/DeltaV/Objectives/traitor.yml | 14 ++++ .../Prototypes/Objectives/objectiveGroups.yml | 1 + 5 files changed, 98 insertions(+) create mode 100644 Content.Server/DeltaV/Objectives/Components/PickRandomTraitorComponent.cs create mode 100644 Content.Server/DeltaV/Objectives/Systems/KillFellowTraitorObjectiveSystem.cs create mode 100644 Resources/Locale/en-US/deltav/objectives/conditions/kill-fellow-traitor.ftl diff --git a/Content.Server/DeltaV/Objectives/Components/PickRandomTraitorComponent.cs b/Content.Server/DeltaV/Objectives/Components/PickRandomTraitorComponent.cs new file mode 100644 index 00000000000..8f870ed7738 --- /dev/null +++ b/Content.Server/DeltaV/Objectives/Components/PickRandomTraitorComponent.cs @@ -0,0 +1,9 @@ +using Content.Server.Objectives.Systems; + +namespace Content.Server.DeltaV.Objectives.Components; + +/// +/// Sets the target for to a random traitor. +/// +[RegisterComponent] +public sealed partial class PickRandomTraitorComponent : Component; diff --git a/Content.Server/DeltaV/Objectives/Systems/KillFellowTraitorObjectiveSystem.cs b/Content.Server/DeltaV/Objectives/Systems/KillFellowTraitorObjectiveSystem.cs new file mode 100644 index 00000000000..781040ddc0a --- /dev/null +++ b/Content.Server/DeltaV/Objectives/Systems/KillFellowTraitorObjectiveSystem.cs @@ -0,0 +1,73 @@ +using Content.Server.DeltaV.Objectives.Components; +using Content.Server.Objectives.Components; +using Content.Server.GameTicking.Rules; +using Content.Server.Objectives.Systems; +using Content.Shared.Objectives.Components; +using Robust.Shared.Random; + +namespace Content.Server.DeltaV.Objectives.Systems; + +/// +/// Handles the kill fellow traitor objective. +/// +public sealed class KillFellowTraitorObjectiveSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly TargetObjectiveSystem _target = default!; + [Dependency] private readonly TraitorRuleSystem _traitorRule = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnTraitorKillAssigned); + } + + private void OnTraitorKillAssigned(EntityUid uid, PickRandomTraitorComponent comp, ref ObjectiveAssignedEvent args) + { + if (!TryComp(uid, out var target)) + { + Log.Error($"Missing components for {uid}."); + args.Cancelled = true; + return; + } + + // Target already assigned + if (target.Target != null) + { + Log.Error($"Target already assigned for {uid}."); + args.Cancelled = true; + return; + } + + var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind); + + List validTraitorMinds = []; + + // Going through each OTHER traitor + foreach (var traitor in traitors) + { + var valid = true; + // Going through each of OUR objectives. + foreach (var objective in args.Mind.Objectives) + { + // If one of OUR objectives already targets a traitor, don't add it to the list. + if (TryComp(objective, out var targetComp) && targetComp.Target == traitor.Id) + { + valid = false; + break; + } + } + if (valid) + validTraitorMinds.Add(traitor.Id); + } + + // No other traitors + if (validTraitorMinds.Count == 0) + { + args.Cancelled = true; + return; + } + + _target.SetTarget(uid, _random.Pick(validTraitorMinds), target); + } +} diff --git a/Resources/Locale/en-US/deltav/objectives/conditions/kill-fellow-traitor.ftl b/Resources/Locale/en-US/deltav/objectives/conditions/kill-fellow-traitor.ftl new file mode 100644 index 00000000000..1d043930db6 --- /dev/null +++ b/Resources/Locale/en-US/deltav/objectives/conditions/kill-fellow-traitor.ftl @@ -0,0 +1 @@ +objective-condition-traitor-kill-title = Kill fellow traitor {$targetName}, {CAPITALIZE($job)} diff --git a/Resources/Prototypes/DeltaV/Objectives/traitor.yml b/Resources/Prototypes/DeltaV/Objectives/traitor.yml index 371dbba0a71..1a45300a8f7 100644 --- a/Resources/Prototypes/DeltaV/Objectives/traitor.yml +++ b/Resources/Prototypes/DeltaV/Objectives/traitor.yml @@ -80,3 +80,17 @@ - type: TargetObjective title: objective-condition-teach-person-title - type: PickRandomPerson + +# Kill fellow traitor objective +- type: entity + parent: [BaseTraitorObjective, BaseKillObjective] + id: KillRandomTraitorObjective + description: We have reason to believe that they have begun to question the syndicate and need to be eliminated. + components: + - type: Objective + difficulty: 2 # They can easily buy weapons to defend themselves if they think something is up. + - type: TargetObjective + title: objective-condition-traitor-kill-title + - type: PickRandomTraitor + - type: KillPersonCondition + requireDead: true # Being able to leave them on the shuttle doesn't make sense when killing another traitor. diff --git a/Resources/Prototypes/Objectives/objectiveGroups.yml b/Resources/Prototypes/Objectives/objectiveGroups.yml index 19e8b908762..5d7a0947c54 100644 --- a/Resources/Prototypes/Objectives/objectiveGroups.yml +++ b/Resources/Prototypes/Objectives/objectiveGroups.yml @@ -35,6 +35,7 @@ # KillRandomPersonObjective: 1 # DeltaV Replaced for Teach Lesson TeachLessonRandomPersonObjective: 1 KillRandomHeadObjective: 0.25 + KillRandomTraitorObjective: 0.2 # DeltaV - type: weightedRandom id: TraitorObjectiveGroupState