From 6712cf8eb65bd5c1fc41994f6101090fec093225 Mon Sep 17 00:00:00 2001 From: Beck Date: Fri, 20 Dec 2024 12:33:46 -0800 Subject: [PATCH] add feature --- .../Components/PickRandomTraitorComponent.cs | 11 +++ .../KillFellowTraitorObjectiveSystem.cs | 70 +++++++++++++++++++ .../conditions/kill-fellow-traitor.ftl | 1 + .../Prototypes/DeltaV/Objectives/traitor.yml | 14 ++++ .../Prototypes/Objectives/objectiveGroups.yml | 1 + 5 files changed, 97 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..d0cf14e51db --- /dev/null +++ b/Content.Server/DeltaV/Objectives/Components/PickRandomTraitorComponent.cs @@ -0,0 +1,11 @@ +using Content.Server.Objectives.Systems; + +namespace Content.Server.DeltaV.Objectives.Components; + +/// +/// Sets the target for to a random traitor. +/// +[RegisterComponent, Access(typeof(KillPersonConditionSystem))] +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..4eeba585ebe --- /dev/null +++ b/Content.Server/DeltaV/Objectives/Systems/KillFellowTraitorObjectiveSystem.cs @@ -0,0 +1,70 @@ +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) + { + // Assume it will be a valid traitor. + validTraitorMinds.Add(traitor.Id); + + // Going through each of OUR objectives. + foreach (var objective in args.Mind.Objectives) + { + // If one of OUR objectives already targets a traitor, remove them from the vaild list. + if (TryComp(objective, out var targetComp) && targetComp.Target == traitor.Id) + validTraitorMinds.RemoveAt(validTraitorMinds.Count - 1); + } + } + + // 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..1a6e0ca0fb8 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: 4 # 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..10266297961 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.1 # DeltaV - type: weightedRandom id: TraitorObjectiveGroupState