Skip to content

Commit

Permalink
add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
beck-thompson committed Dec 20, 2024
1 parent cf61fb7 commit 6712cf8
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
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
{
}
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);
}
}
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: 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.
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

0 comments on commit 6712cf8

Please sign in to comment.