Skip to content

Commit

Permalink
Add kill fellow traitor objective (#2488)
Browse files Browse the repository at this point in the history
* 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
beck-thompson and deltanedas authored Dec 21, 2024
1 parent abe9d74 commit 0b9ac4c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
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;
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
objective-condition-traitor-kill-title = Kill fellow traitor {$targetName}, {CAPITALIZE($job)}
14 changes: 14 additions & 0 deletions Resources/Prototypes/DeltaV/Objectives/traitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions Resources/Prototypes/Objectives/objectiveGroups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# KillRandomPersonObjective: 1 # DeltaV Replaced for Teach Lesson
TeachLessonRandomPersonObjective: 1
KillRandomHeadObjective: 0.25
KillRandomTraitorObjective: 0.2 # DeltaV

- type: weightedRandom
id: TraitorObjectiveGroupState
Expand Down

0 comments on commit 0b9ac4c

Please sign in to comment.