Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kill fellow traitor objective #2488

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1 # DeltaV

- type: weightedRandom
id: TraitorObjectiveGroupState
Expand Down
Loading