-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kill fellow traitor objective (#2488)
* add feature * opps * fixes * increase weight to 0.2 Signed-off-by: deltanedas <[email protected]> --------- Signed-off-by: deltanedas <[email protected]> Co-authored-by: deltanedas <[email protected]>
- Loading branch information
1 parent
abe9d74
commit 0b9ac4c
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
Content.Server/DeltaV/Objectives/Components/PickRandomTraitorComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Content.Server.Objectives.Systems; | ||
|
||
namespace Content.Server.DeltaV.Objectives.Components; | ||
|
||
/// <summary> | ||
/// Sets the target for <see cref="TargetObjectiveComponent"/> to a random traitor. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class PickRandomTraitorComponent : Component; |
73 changes: 73 additions & 0 deletions
73
Content.Server/DeltaV/Objectives/Systems/KillFellowTraitorObjectiveSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/// <summary> | ||
/// Handles the kill fellow traitor objective. | ||
/// </summary> | ||
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<PickRandomTraitorComponent, ObjectiveAssignedEvent>(OnTraitorKillAssigned); | ||
} | ||
|
||
private void OnTraitorKillAssigned(EntityUid uid, PickRandomTraitorComponent comp, ref ObjectiveAssignedEvent args) | ||
{ | ||
if (!TryComp<TargetObjectiveComponent>(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<EntityUid> 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<TargetObjectiveComponent>(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); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Resources/Locale/en-US/deltav/objectives/conditions/kill-fellow-traitor.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
objective-condition-traitor-kill-title = Kill fellow traitor {$targetName}, {CAPITALIZE($job)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters