Skip to content

Commit 48a4aa3

Browse files
Cleanup Objective files, add PickSpecificPersonComponent (space-wizards#35802)
* cleanup objectives * remove unrelated access restriction * review
1 parent 3f8be60 commit 48a4aa3

10 files changed

+246
-200
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using Content.Server.Objectives.Systems;
2-
31
namespace Content.Server.Objectives.Components;
42

53
/// <summary>
64
/// Sets the target for <see cref="TargetObjectiveComponent"/> to a random head.
75
/// If there are no heads it will fallback to any person.
86
/// </summary>
9-
[RegisterComponent, Access(typeof(KillPersonConditionSystem))]
10-
public sealed partial class PickRandomHeadComponent : Component
11-
{
12-
}
7+
[RegisterComponent]
8+
public sealed partial class PickRandomHeadComponent : Component;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using Content.Server.Objectives.Systems;
2-
31
namespace Content.Server.Objectives.Components;
42

53
/// <summary>
64
/// Sets the target for <see cref="TargetObjectiveComponent"/> to a random person.
75
/// </summary>
8-
[RegisterComponent, Access(typeof(KillPersonConditionSystem))]
9-
public sealed partial class PickRandomPersonComponent : Component
10-
{
11-
}
6+
[RegisterComponent]
7+
public sealed partial class PickRandomPersonComponent : Component;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Content.Server.Objectives.Components;
2+
3+
/// <summary>
4+
/// Sets this objective's target to the one given in <see cref="TargetOverrideComponent"/>, if the entity has it.
5+
/// This component needs to be added to objective entity itself.
6+
/// </summary>
7+
[RegisterComponent]
8+
public sealed partial class PickSpecificPersonComponent : Component;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using Content.Server.Objectives.Systems;
2-
31
namespace Content.Server.Objectives.Components;
42

53
/// <summary>
64
/// Sets the target for <see cref="KeepAliveConditionComponent"/> to a random traitor.
75
/// </summary>
8-
[RegisterComponent, Access(typeof(KeepAliveConditionSystem))]
9-
public sealed partial class RandomTraitorAliveComponent : Component
10-
{
11-
}
6+
[RegisterComponent]
7+
public sealed partial class RandomTraitorAliveComponent : Component;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using Content.Server.Objectives.Systems;
2-
31
namespace Content.Server.Objectives.Components;
42

53
/// <summary>
64
/// Sets the target for <see cref="HelpProgressConditionComponent"/> to a random traitor.
75
/// </summary>
8-
[RegisterComponent, Access(typeof(HelpProgressConditionSystem))]
9-
public sealed partial class RandomTraitorProgressComponent : Component
10-
{
11-
}
6+
[RegisterComponent]
7+
public sealed partial class RandomTraitorProgressComponent : Component;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Content.Server.Objectives.Components;
2+
3+
/// <summary>
4+
/// Sets a target objective to a specific target when receiving it.
5+
/// The objective entity needs to have <see cref="PickSpecificPersonComponent"/>.
6+
/// This component needs to be added to entity receiving the objective.
7+
/// </summary>
8+
[RegisterComponent]
9+
public sealed partial class TargetOverrideComponent : Component
10+
{
11+
/// <summary>
12+
/// The entity that should be targeted.
13+
/// </summary>
14+
[DataField]
15+
public EntityUid? Target;
16+
}

Content.Server/Objectives/Systems/HelpProgressConditionSystem.cs

+1-58
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
using Content.Server.GameTicking.Rules;
21
using Content.Server.Objectives.Components;
32
using Content.Shared.Mind;
43
using Content.Shared.Objectives.Components;
54
using Content.Shared.Objectives.Systems;
6-
using Content.Shared.Roles.Jobs;
7-
using Robust.Shared.Random;
8-
using System.Linq;
95

106
namespace Content.Server.Objectives.Systems;
117

128
/// <summary>
13-
/// Handles help progress condition logic and picking random help targets.
9+
/// Handles help progress condition logic.
1410
/// </summary>
1511
public sealed class HelpProgressConditionSystem : EntitySystem
1612
{
17-
[Dependency] private readonly IRobustRandom _random = default!;
1813
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
1914
[Dependency] private readonly TargetObjectiveSystem _target = default!;
20-
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
2115

2216
public override void Initialize()
2317
{
2418
base.Initialize();
2519

2620
SubscribeLocalEvent<HelpProgressConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
27-
28-
SubscribeLocalEvent<RandomTraitorProgressComponent, ObjectiveAssignedEvent>(OnTraitorAssigned);
2921
}
3022

3123
private void OnGetProgress(EntityUid uid, HelpProgressConditionComponent comp, ref ObjectiveGetProgressEvent args)
@@ -36,55 +28,6 @@ private void OnGetProgress(EntityUid uid, HelpProgressConditionComponent comp, r
3628
args.Progress = GetProgress(target.Value);
3729
}
3830

39-
private void OnTraitorAssigned(EntityUid uid, RandomTraitorProgressComponent comp, ref ObjectiveAssignedEvent args)
40-
{
41-
// invalid prototype
42-
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
43-
{
44-
args.Cancelled = true;
45-
return;
46-
}
47-
48-
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
49-
50-
// cant help anyone who is tasked with helping:
51-
// 1. thats boring
52-
// 2. no cyclic progress dependencies!!!
53-
foreach (var traitor in traitors)
54-
{
55-
// TODO: replace this with TryComp<ObjectivesComponent>(traitor) or something when objectives are moved out of mind
56-
if (!TryComp<MindComponent>(traitor.Id, out var mind))
57-
continue;
58-
59-
foreach (var objective in mind.Objectives)
60-
{
61-
if (HasComp<HelpProgressConditionComponent>(objective))
62-
traitors.RemoveWhere(x => x.Mind == mind);
63-
}
64-
}
65-
66-
// Can't have multiple objectives to help/save the same person
67-
foreach (var objective in args.Mind.Objectives)
68-
{
69-
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
70-
{
71-
if (TryComp<TargetObjectiveComponent>(objective, out var help))
72-
{
73-
traitors.RemoveWhere(x => x.Id == help.Target);
74-
}
75-
}
76-
}
77-
78-
// no more helpable traitors
79-
if (traitors.Count == 0)
80-
{
81-
args.Cancelled = true;
82-
return;
83-
}
84-
85-
_target.SetTarget(uid, _random.Pick(traitors).Id, target);
86-
}
87-
8831
private float GetProgress(EntityUid target)
8932
{
9033
var total = 0f; // how much progress they have

Content.Server/Objectives/Systems/KeepAliveCondition.cs

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
using Content.Server.Objectives.Components;
2-
using Content.Server.GameTicking.Rules;
32
using Content.Shared.Mind;
43
using Content.Shared.Objectives.Components;
5-
using Content.Shared.Roles.Jobs;
6-
using Robust.Shared.Random;
7-
using System.Linq;
84

95
namespace Content.Server.Objectives.Systems;
106

117
/// <summary>
12-
/// Handles keep alive condition logic and picking random traitors to keep alive.
8+
/// Handles keep alive condition logic.
139
/// </summary>
1410
public sealed class KeepAliveConditionSystem : EntitySystem
1511
{
16-
[Dependency] private readonly IRobustRandom _random = default!;
1712
[Dependency] private readonly SharedMindSystem _mind = default!;
1813
[Dependency] private readonly TargetObjectiveSystem _target = default!;
19-
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
2014

2115
public override void Initialize()
2216
{
2317
base.Initialize();
2418

2519
SubscribeLocalEvent<KeepAliveConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
26-
27-
SubscribeLocalEvent<RandomTraitorAliveComponent, ObjectiveAssignedEvent>(OnAssigned);
2820
}
2921

3022
private void OnGetProgress(EntityUid uid, KeepAliveConditionComponent comp, ref ObjectiveGetProgressEvent args)
@@ -35,39 +27,6 @@ private void OnGetProgress(EntityUid uid, KeepAliveConditionComponent comp, ref
3527
args.Progress = GetProgress(target.Value);
3628
}
3729

38-
private void OnAssigned(EntityUid uid, RandomTraitorAliveComponent comp, ref ObjectiveAssignedEvent args)
39-
{
40-
// invalid prototype
41-
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
42-
{
43-
args.Cancelled = true;
44-
return;
45-
}
46-
47-
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
48-
49-
// Can't have multiple objectives to help/save the same person
50-
foreach (var objective in args.Mind.Objectives)
51-
{
52-
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
53-
{
54-
if (TryComp<TargetObjectiveComponent>(objective, out var help))
55-
{
56-
traitors.RemoveWhere(x => x.Id == help.Target);
57-
}
58-
}
59-
}
60-
61-
// You are the first/only traitor.
62-
if (traitors.Count == 0)
63-
{
64-
args.Cancelled = true;
65-
return;
66-
}
67-
68-
_target.SetTarget(uid, _random.Pick(traitors).Id, target);
69-
}
70-
7130
private float GetProgress(EntityUid target)
7231
{
7332
if (!TryComp<MindComponent>(target, out var mind))

Content.Server/Objectives/Systems/KillPersonConditionSystem.cs

-76
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using Content.Server.Objectives.Components;
2-
using Content.Server.Revolutionary.Components;
32
using Content.Server.Shuttles.Systems;
43
using Content.Shared.CCVar;
54
using Content.Shared.Mind;
65
using Content.Shared.Objectives.Components;
76
using Robust.Shared.Configuration;
8-
using Robust.Shared.Random;
9-
using System.Linq;
107

118
namespace Content.Server.Objectives.Systems;
129

@@ -17,7 +14,6 @@ public sealed class KillPersonConditionSystem : EntitySystem
1714
{
1815
[Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
1916
[Dependency] private readonly IConfigurationManager _config = default!;
20-
[Dependency] private readonly IRobustRandom _random = default!;
2117
[Dependency] private readonly SharedMindSystem _mind = default!;
2218
[Dependency] private readonly TargetObjectiveSystem _target = default!;
2319

@@ -26,10 +22,6 @@ public override void Initialize()
2622
base.Initialize();
2723

2824
SubscribeLocalEvent<KillPersonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
29-
30-
SubscribeLocalEvent<PickRandomPersonComponent, ObjectiveAssignedEvent>(OnPersonAssigned);
31-
32-
SubscribeLocalEvent<PickRandomHeadComponent, ObjectiveAssignedEvent>(OnHeadAssigned);
3325
}
3426

3527
private void OnGetProgress(EntityUid uid, KillPersonConditionComponent comp, ref ObjectiveGetProgressEvent args)
@@ -40,74 +32,6 @@ private void OnGetProgress(EntityUid uid, KillPersonConditionComponent comp, ref
4032
args.Progress = GetProgress(target.Value, comp.RequireDead);
4133
}
4234

43-
private void OnPersonAssigned(EntityUid uid, PickRandomPersonComponent comp, ref ObjectiveAssignedEvent args)
44-
{
45-
// invalid objective prototype
46-
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
47-
{
48-
args.Cancelled = true;
49-
return;
50-
}
51-
52-
// target already assigned
53-
if (target.Target != null)
54-
return;
55-
56-
var allHumans = _mind.GetAliveHumans(args.MindId);
57-
58-
// Can't have multiple objectives to kill the same person
59-
foreach (var objective in args.Mind.Objectives)
60-
{
61-
if (HasComp<KillPersonConditionComponent>(objective) && TryComp<TargetObjectiveComponent>(objective, out var kill))
62-
{
63-
allHumans.RemoveWhere(x => x.Owner == kill.Target);
64-
}
65-
}
66-
67-
// no other humans to kill
68-
if (allHumans.Count == 0)
69-
{
70-
args.Cancelled = true;
71-
return;
72-
}
73-
74-
_target.SetTarget(uid, _random.Pick(allHumans), target);
75-
}
76-
77-
private void OnHeadAssigned(EntityUid uid, PickRandomHeadComponent comp, ref ObjectiveAssignedEvent args)
78-
{
79-
// invalid prototype
80-
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
81-
{
82-
args.Cancelled = true;
83-
return;
84-
}
85-
86-
// target already assigned
87-
if (target.Target != null)
88-
return;
89-
90-
// no other humans to kill
91-
var allHumans = _mind.GetAliveHumans(args.MindId);
92-
if (allHumans.Count == 0)
93-
{
94-
args.Cancelled = true;
95-
return;
96-
}
97-
98-
var allHeads = new HashSet<Entity<MindComponent>>();
99-
foreach (var person in allHumans)
100-
{
101-
if (TryComp<MindComponent>(person, out var mind) && mind.OwnedEntity is { } ent && HasComp<CommandStaffComponent>(ent))
102-
allHeads.Add(person);
103-
}
104-
105-
if (allHeads.Count == 0)
106-
allHeads = allHumans; // fallback to non-head target
107-
108-
_target.SetTarget(uid, _random.Pick(allHeads), target);
109-
}
110-
11135
private float GetProgress(EntityUid target, bool requireDead)
11236
{
11337
// deleted or gibbed or something, counts as dead

0 commit comments

Comments
 (0)