-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf61fb7
commit 6712cf8
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
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, Access(typeof(KillPersonConditionSystem))] | ||
public sealed partial class PickRandomTraitorComponent : Component | ||
{ | ||
} |
70 changes: 70 additions & 0 deletions
70
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,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; | ||
|
||
/// <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) | ||
{ | ||
// 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<TargetObjectiveComponent>(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); | ||
} | ||
} |
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