]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Cleanup Objective files, add PickSpecificPersonComponent (#35802)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Thu, 13 Mar 2025 00:41:50 +0000 (01:41 +0100)
committerGitHub <noreply@github.com>
Thu, 13 Mar 2025 00:41:50 +0000 (01:41 +0100)
* cleanup objectives

* remove unrelated access restriction

* review

Content.Server/Objectives/Components/PickRandomHeadComponent.cs
Content.Server/Objectives/Components/PickRandomPersonComponent.cs
Content.Server/Objectives/Components/PickSpecificPersonComponent.cs [new file with mode: 0644]
Content.Server/Objectives/Components/RandomTraitorAliveComponent.cs
Content.Server/Objectives/Components/RandomTraitorProgressComponent.cs
Content.Server/Objectives/Components/TargetOverrideComponent.cs [new file with mode: 0644]
Content.Server/Objectives/Systems/HelpProgressConditionSystem.cs
Content.Server/Objectives/Systems/KeepAliveCondition.cs
Content.Server/Objectives/Systems/KillPersonConditionSystem.cs
Content.Server/Objectives/Systems/PickObjectiveTargetSystem.cs [new file with mode: 0644]

index c2f82fb6c5945341078f6dd390a39ca51dd1f968..38ed2522646f56aa1a9105e4c2eb0ed00af20087 100644 (file)
@@ -1,12 +1,8 @@
-using Content.Server.Objectives.Systems;
-
 namespace Content.Server.Objectives.Components;
 
 /// <summary>
 /// Sets the target for <see cref="TargetObjectiveComponent"/> to a random head.
 /// If there are no heads it will fallback to any person.
 /// </summary>
-[RegisterComponent, Access(typeof(KillPersonConditionSystem))]
-public sealed partial class PickRandomHeadComponent : Component
-{
-}
+[RegisterComponent]
+public sealed partial class PickRandomHeadComponent : Component;
index 4188b1da3d2507585612cc82fd0c3fb335a899ba..bf4135e2a9b34820ef0915502fa6f2d8e2f65e82 100644 (file)
@@ -1,11 +1,7 @@
-using Content.Server.Objectives.Systems;
-
 namespace Content.Server.Objectives.Components;
 
 /// <summary>
 /// Sets the target for <see cref="TargetObjectiveComponent"/> to a random person.
 /// </summary>
-[RegisterComponent, Access(typeof(KillPersonConditionSystem))]
-public sealed partial class PickRandomPersonComponent : Component
-{
-}
+[RegisterComponent]
+public sealed partial class PickRandomPersonComponent : Component;
diff --git a/Content.Server/Objectives/Components/PickSpecificPersonComponent.cs b/Content.Server/Objectives/Components/PickSpecificPersonComponent.cs
new file mode 100644 (file)
index 0000000..03a482f
--- /dev/null
@@ -0,0 +1,8 @@
+namespace Content.Server.Objectives.Components;
+
+/// <summary>
+/// Sets this objective's target to the one given in <see cref="TargetOverrideComponent"/>, if the entity has it.
+/// This component needs to be added to objective entity itself.
+/// </summary>
+[RegisterComponent]
+public sealed partial class PickSpecificPersonComponent : Component;
index fd37d0d2c849a3fb3cf39d22262bb357f7251182..1c45cb45d5abbb7e0ad9da6153e21ff93f551dac 100644 (file)
@@ -1,11 +1,7 @@
-using Content.Server.Objectives.Systems;
-
 namespace Content.Server.Objectives.Components;
 
 /// <summary>
 /// Sets the target for <see cref="KeepAliveConditionComponent"/> to a random traitor.
 /// </summary>
-[RegisterComponent, Access(typeof(KeepAliveConditionSystem))]
-public sealed partial class RandomTraitorAliveComponent : Component
-{
-}
+[RegisterComponent]
+public sealed partial class RandomTraitorAliveComponent : Component;
index c05ac0d3efee2bfe9ce0b1c69b2ccb6462271141..f2da9778eb74b1ae428ca4a6d109664ffa19f485 100644 (file)
@@ -1,11 +1,7 @@
-using Content.Server.Objectives.Systems;
-
 namespace Content.Server.Objectives.Components;
 
 /// <summary>
 /// Sets the target for <see cref="HelpProgressConditionComponent"/> to a random traitor.
 /// </summary>
-[RegisterComponent, Access(typeof(HelpProgressConditionSystem))]
-public sealed partial class RandomTraitorProgressComponent : Component
-{
-}
+[RegisterComponent]
+public sealed partial class RandomTraitorProgressComponent : Component;
diff --git a/Content.Server/Objectives/Components/TargetOverrideComponent.cs b/Content.Server/Objectives/Components/TargetOverrideComponent.cs
new file mode 100644 (file)
index 0000000..faa4020
--- /dev/null
@@ -0,0 +1,16 @@
+namespace Content.Server.Objectives.Components;
+
+/// <summary>
+/// Sets a target objective to a specific target when receiving it.
+/// The objective entity needs to have <see cref="PickSpecificPersonComponent"/>.
+/// This component needs to be added to entity receiving the objective.
+/// </summary>
+[RegisterComponent]
+public sealed partial class TargetOverrideComponent : Component
+{
+    /// <summary>
+    /// The entity that should be targeted.
+    /// </summary>
+    [DataField]
+    public EntityUid? Target;
+}
index 7639e69bfdaa3aa1cc42c4298b1c64a5a78fa96c..1816896ecc9b59b2905e9d6809b1e9799c71bd82 100644 (file)
@@ -1,31 +1,23 @@
-using Content.Server.GameTicking.Rules;
 using Content.Server.Objectives.Components;
 using Content.Shared.Mind;
 using Content.Shared.Objectives.Components;
 using Content.Shared.Objectives.Systems;
-using Content.Shared.Roles.Jobs;
-using Robust.Shared.Random;
-using System.Linq;
 
 namespace Content.Server.Objectives.Systems;
 
 /// <summary>
-/// Handles help progress condition logic and picking random help targets.
+/// Handles help progress condition logic.
 /// </summary>
 public sealed class HelpProgressConditionSystem : EntitySystem
 {
-    [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly SharedObjectivesSystem _objectives = default!;
     [Dependency] private readonly TargetObjectiveSystem _target = default!;
-    [Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
 
     public override void Initialize()
     {
         base.Initialize();
 
         SubscribeLocalEvent<HelpProgressConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
-
-        SubscribeLocalEvent<RandomTraitorProgressComponent, ObjectiveAssignedEvent>(OnTraitorAssigned);
     }
 
     private void OnGetProgress(EntityUid uid, HelpProgressConditionComponent comp, ref ObjectiveGetProgressEvent args)
@@ -36,55 +28,6 @@ public sealed class HelpProgressConditionSystem : EntitySystem
         args.Progress = GetProgress(target.Value);
     }
 
-    private void OnTraitorAssigned(EntityUid uid, RandomTraitorProgressComponent comp, ref ObjectiveAssignedEvent args)
-    {
-        // invalid prototype
-        if (!TryComp<TargetObjectiveComponent>(uid, out var target))
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
-
-        // cant help anyone who is tasked with helping:
-        // 1. thats boring
-        // 2. no cyclic progress dependencies!!!
-        foreach (var traitor in traitors)
-        {
-            // TODO: replace this with TryComp<ObjectivesComponent>(traitor) or something when objectives are moved out of mind
-            if (!TryComp<MindComponent>(traitor.Id, out var mind))
-                continue;
-
-            foreach (var objective in mind.Objectives)
-            {
-                if (HasComp<HelpProgressConditionComponent>(objective))
-                    traitors.RemoveWhere(x => x.Mind == mind);
-            }
-        }
-
-        // Can't have multiple objectives to help/save the same person
-        foreach (var objective in args.Mind.Objectives)
-        {
-            if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
-            {
-                if (TryComp<TargetObjectiveComponent>(objective, out var help))
-                {
-                    traitors.RemoveWhere(x => x.Id == help.Target);
-                }
-            }
-        }
-
-        // no more helpable traitors
-        if (traitors.Count == 0)
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        _target.SetTarget(uid, _random.Pick(traitors).Id, target);
-    }
-
     private float GetProgress(EntityUid target)
     {
         var total = 0f; // how much progress they have
index fad8aa6d18e150eb2b87031e7c35fa150cd1445c..f68227e861a76611ba4b440f10db3d0afba4aae0 100644 (file)
@@ -1,30 +1,22 @@
 using Content.Server.Objectives.Components;
-using Content.Server.GameTicking.Rules;
 using Content.Shared.Mind;
 using Content.Shared.Objectives.Components;
-using Content.Shared.Roles.Jobs;
-using Robust.Shared.Random;
-using System.Linq;
 
 namespace Content.Server.Objectives.Systems;
 
 /// <summary>
-/// Handles keep alive condition logic and picking random traitors to keep alive.
+/// Handles keep alive condition logic.
 /// </summary>
 public sealed class KeepAliveConditionSystem : EntitySystem
 {
-    [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly SharedMindSystem _mind = default!;
     [Dependency] private readonly TargetObjectiveSystem _target = default!;
-    [Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
 
     public override void Initialize()
     {
         base.Initialize();
 
         SubscribeLocalEvent<KeepAliveConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
-
-        SubscribeLocalEvent<RandomTraitorAliveComponent, ObjectiveAssignedEvent>(OnAssigned);
     }
 
     private void OnGetProgress(EntityUid uid, KeepAliveConditionComponent comp, ref ObjectiveGetProgressEvent args)
@@ -35,39 +27,6 @@ public sealed class KeepAliveConditionSystem : EntitySystem
         args.Progress = GetProgress(target.Value);
     }
 
-    private void OnAssigned(EntityUid uid, RandomTraitorAliveComponent comp, ref ObjectiveAssignedEvent args)
-    {
-        // invalid prototype
-        if (!TryComp<TargetObjectiveComponent>(uid, out var target))
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
-
-        // Can't have multiple objectives to help/save the same person
-        foreach (var objective in args.Mind.Objectives)
-        {
-            if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
-            {
-                if (TryComp<TargetObjectiveComponent>(objective, out var help))
-                {
-                    traitors.RemoveWhere(x => x.Id == help.Target);
-                }
-            }
-        }
-
-        // You are the first/only traitor.
-        if (traitors.Count == 0)
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        _target.SetTarget(uid, _random.Pick(traitors).Id, target);
-    }
-
     private float GetProgress(EntityUid target)
     {
         if (!TryComp<MindComponent>(target, out var mind))
index 3aa4d606fc3bd40f2e8a782682955522cc839647..45ad68e28b6c13a033a59b51a6461914d0625efa 100644 (file)
@@ -1,12 +1,9 @@
 using Content.Server.Objectives.Components;
-using Content.Server.Revolutionary.Components;
 using Content.Server.Shuttles.Systems;
 using Content.Shared.CCVar;
 using Content.Shared.Mind;
 using Content.Shared.Objectives.Components;
 using Robust.Shared.Configuration;
-using Robust.Shared.Random;
-using System.Linq;
 
 namespace Content.Server.Objectives.Systems;
 
@@ -17,7 +14,6 @@ public sealed class KillPersonConditionSystem : EntitySystem
 {
     [Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
     [Dependency] private readonly IConfigurationManager _config = default!;
-    [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly SharedMindSystem _mind = default!;
     [Dependency] private readonly TargetObjectiveSystem _target = default!;
 
@@ -26,10 +22,6 @@ public sealed class KillPersonConditionSystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<KillPersonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
-
-        SubscribeLocalEvent<PickRandomPersonComponent, ObjectiveAssignedEvent>(OnPersonAssigned);
-
-        SubscribeLocalEvent<PickRandomHeadComponent, ObjectiveAssignedEvent>(OnHeadAssigned);
     }
 
     private void OnGetProgress(EntityUid uid, KillPersonConditionComponent comp, ref ObjectiveGetProgressEvent args)
@@ -40,74 +32,6 @@ public sealed class KillPersonConditionSystem : EntitySystem
         args.Progress = GetProgress(target.Value, comp.RequireDead);
     }
 
-    private void OnPersonAssigned(EntityUid uid, PickRandomPersonComponent comp, ref ObjectiveAssignedEvent args)
-    {
-        // invalid objective prototype
-        if (!TryComp<TargetObjectiveComponent>(uid, out var target))
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        // target already assigned
-        if (target.Target != null)
-            return;
-
-        var allHumans = _mind.GetAliveHumans(args.MindId);
-
-        // Can't have multiple objectives to kill the same person
-        foreach (var objective in args.Mind.Objectives)
-        {
-            if (HasComp<KillPersonConditionComponent>(objective) && TryComp<TargetObjectiveComponent>(objective, out var kill))
-            {
-                allHumans.RemoveWhere(x => x.Owner == kill.Target);
-            }
-        }
-
-        // no other humans to kill
-        if (allHumans.Count == 0)
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        _target.SetTarget(uid, _random.Pick(allHumans), target);
-    }
-
-    private void OnHeadAssigned(EntityUid uid, PickRandomHeadComponent comp, ref ObjectiveAssignedEvent args)
-    {
-        // invalid prototype
-        if (!TryComp<TargetObjectiveComponent>(uid, out var target))
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        // target already assigned
-        if (target.Target != null)
-            return;
-
-        // no other humans to kill
-        var allHumans = _mind.GetAliveHumans(args.MindId);
-        if (allHumans.Count == 0)
-        {
-            args.Cancelled = true;
-            return;
-        }
-
-        var allHeads = new HashSet<Entity<MindComponent>>();
-        foreach (var person in allHumans)
-        {
-            if (TryComp<MindComponent>(person, out var mind) && mind.OwnedEntity is { } ent && HasComp<CommandStaffComponent>(ent))
-                allHeads.Add(person);
-        }
-
-        if (allHeads.Count == 0)
-            allHeads = allHumans; // fallback to non-head target
-
-        _target.SetTarget(uid, _random.Pick(allHeads), target);
-    }
-
     private float GetProgress(EntityUid target, bool requireDead)
     {
         // deleted or gibbed or something, counts as dead
diff --git a/Content.Server/Objectives/Systems/PickObjectiveTargetSystem.cs b/Content.Server/Objectives/Systems/PickObjectiveTargetSystem.cs
new file mode 100644 (file)
index 0000000..2977e10
--- /dev/null
@@ -0,0 +1,212 @@
+using Content.Server.Objectives.Components;
+using Content.Shared.Mind;
+using Content.Shared.Objectives.Components;
+using Content.Server.GameTicking.Rules;
+using Content.Server.Revolutionary.Components;
+using Robust.Shared.Random;
+using System.Linq;
+
+namespace Content.Server.Objectives.Systems;
+
+/// <summary>
+/// Handles assinging a target to an objective entity with <see cref="TargetObjectiveComponent"/> using different components.
+/// These can be combined with condition components for objective completions in order to create a variety of objectives.
+/// </summary>
+public sealed class PickObjectiveTargetSystem : EntitySystem
+{
+    [Dependency] private readonly TargetObjectiveSystem _target = default!;
+    [Dependency] private readonly SharedMindSystem _mind = default!;
+    [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<PickSpecificPersonComponent, ObjectiveAssignedEvent>(OnSpecificPersonAssigned);
+        SubscribeLocalEvent<PickRandomPersonComponent, ObjectiveAssignedEvent>(OnRandomPersonAssigned);
+        SubscribeLocalEvent<PickRandomHeadComponent, ObjectiveAssignedEvent>(OnRandomHeadAssigned);
+
+        SubscribeLocalEvent<RandomTraitorProgressComponent, ObjectiveAssignedEvent>(OnRandomTraitorProgressAssigned);
+        SubscribeLocalEvent<RandomTraitorAliveComponent, ObjectiveAssignedEvent>(OnRandomTraitorAliveAssigned);
+    }
+
+    private void OnSpecificPersonAssigned(Entity<PickSpecificPersonComponent> ent, ref ObjectiveAssignedEvent args)
+    {
+        // invalid objective prototype
+        if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        // target already assigned
+        if (target.Target != null)
+            return;
+
+        if (args.Mind.OwnedEntity == null)
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        var user = args.Mind.OwnedEntity.Value;
+        if (!TryComp<TargetOverrideComponent>(user, out var targetComp) || targetComp.Target == null)
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        _target.SetTarget(ent.Owner, targetComp.Target.Value);
+    }
+
+    private void OnRandomPersonAssigned(Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args)
+    {
+        // invalid objective prototype
+        if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        // target already assigned
+        if (target.Target != null)
+            return;
+
+        var allHumans = _mind.GetAliveHumans(args.MindId);
+
+        // Can't have multiple objectives to kill the same person
+        foreach (var objective in args.Mind.Objectives)
+        {
+            if (HasComp<KillPersonConditionComponent>(objective) && TryComp<TargetObjectiveComponent>(objective, out var kill))
+            {
+                allHumans.RemoveWhere(x => x.Owner == kill.Target);
+            }
+        }
+
+        // no other humans to kill
+        if (allHumans.Count == 0)
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        _target.SetTarget(ent.Owner, _random.Pick(allHumans), target);
+    }
+
+    private void OnRandomHeadAssigned(Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args)
+    {
+        // invalid prototype
+        if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        // target already assigned
+        if (target.Target != null)
+            return;
+
+        // no other humans to kill
+        var allHumans = _mind.GetAliveHumans(args.MindId);
+        if (allHumans.Count == 0)
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        var allHeads = new HashSet<Entity<MindComponent>>();
+        foreach (var person in allHumans)
+        {
+            if (TryComp<MindComponent>(person, out var mind) && mind.OwnedEntity is { } owned && HasComp<CommandStaffComponent>(owned))
+                allHeads.Add(person);
+        }
+
+        if (allHeads.Count == 0)
+            allHeads = allHumans; // fallback to non-head target
+
+        _target.SetTarget(ent.Owner, _random.Pick(allHeads), target);
+    }
+
+    private void OnRandomTraitorProgressAssigned(Entity<RandomTraitorProgressComponent> ent, ref ObjectiveAssignedEvent args)
+    {
+        // invalid prototype
+        if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
+
+        // cant help anyone who is tasked with helping:
+        // 1. thats boring
+        // 2. no cyclic progress dependencies!!!
+        foreach (var traitor in traitors)
+        {
+            // TODO: replace this with TryComp<ObjectivesComponent>(traitor) or something when objectives are moved out of mind
+            if (!TryComp<MindComponent>(traitor.Id, out var mind))
+                continue;
+
+            foreach (var objective in mind.Objectives)
+            {
+                if (HasComp<HelpProgressConditionComponent>(objective))
+                    traitors.RemoveWhere(x => x.Mind == mind);
+            }
+        }
+
+        // Can't have multiple objectives to help/save the same person
+        foreach (var objective in args.Mind.Objectives)
+        {
+            if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
+            {
+                if (TryComp<TargetObjectiveComponent>(objective, out var help))
+                {
+                    traitors.RemoveWhere(x => x.Id == help.Target);
+                }
+            }
+        }
+
+        // no more helpable traitors
+        if (traitors.Count == 0)
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        _target.SetTarget(ent.Owner, _random.Pick(traitors).Id, target);
+    }
+
+    private void OnRandomTraitorAliveAssigned(Entity<RandomTraitorAliveComponent> ent, ref ObjectiveAssignedEvent args)
+    {
+        // invalid prototype
+        if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
+
+        // Can't have multiple objectives to help/save the same person
+        foreach (var objective in args.Mind.Objectives)
+        {
+            if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
+            {
+                if (TryComp<TargetObjectiveComponent>(objective, out var help))
+                {
+                    traitors.RemoveWhere(x => x.Id == help.Target);
+                }
+            }
+        }
+
+        // You are the first/only traitor.
+        if (traitors.Count == 0)
+        {
+            args.Cancelled = true;
+            return;
+        }
+
+        _target.SetTarget(ent.Owner, _random.Pick(traitors).Id, target);
+    }
+}