]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
move nukie profile loading into its own rule (#28208)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sat, 25 May 2024 20:15:56 +0000 (20:15 +0000)
committerGitHub <noreply@github.com>
Sat, 25 May 2024 20:15:56 +0000 (16:15 -0400)
* move profile loading out of nukeops rule

* make BaseNukeopsRule and use AntagLoadProfileRule

* untroll

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/GameTicking/Rules/AntagLoadProfileRuleSystem.cs [new file with mode: 0644]
Content.Server/GameTicking/Rules/Components/AntagLoadProfileRuleCOmponent.cs [new file with mode: 0644]
Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs
Resources/Prototypes/GameRules/events.yml
Resources/Prototypes/GameRules/roundstart.yml

diff --git a/Content.Server/GameTicking/Rules/AntagLoadProfileRuleSystem.cs b/Content.Server/GameTicking/Rules/AntagLoadProfileRuleSystem.cs
new file mode 100644 (file)
index 0000000..fd3fb6c
--- /dev/null
@@ -0,0 +1,39 @@
+using Content.Server.Antag;
+using Content.Server.GameTicking.Rules.Components;
+using Content.Server.Humanoid;
+using Content.Server.Preferences.Managers;
+using Content.Shared.Humanoid;
+using Content.Shared.Humanoid.Prototypes;
+using Content.Shared.Preferences;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.GameTicking.Rules;
+
+public sealed class AntagLoadProfileRuleSystem : GameRuleSystem<AntagLoadProfileRuleComponent>
+{
+    [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
+    [Dependency] private readonly IPrototypeManager _proto = default!;
+    [Dependency] private readonly IServerPreferencesManager _prefs = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<AntagLoadProfileRuleComponent, AntagSelectEntityEvent>(OnSelectEntity);
+    }
+
+    private void OnSelectEntity(Entity<AntagLoadProfileRuleComponent> ent, ref AntagSelectEntityEvent args)
+    {
+        if (args.Handled)
+            return;
+
+        var profile = args.Session != null
+            ? _prefs.GetPreferences(args.Session.UserId).SelectedCharacter as HumanoidCharacterProfile
+            : HumanoidCharacterProfile.RandomWithSpecies();
+        if (profile?.Species is not {} speciesId || !_proto.TryIndex<SpeciesPrototype>(speciesId, out var species))
+            species = _proto.Index<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies);
+
+        args.Entity = Spawn(species.Prototype);
+        _humanoid.LoadProfile(args.Entity.Value, profile);
+    }
+}
diff --git a/Content.Server/GameTicking/Rules/Components/AntagLoadProfileRuleCOmponent.cs b/Content.Server/GameTicking/Rules/Components/AntagLoadProfileRuleCOmponent.cs
new file mode 100644 (file)
index 0000000..5e58fd1
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Content.Server.GameTicking.Rules.Components;
+
+/// <summary>
+/// Makes this rules antags spawn a humanoid, either from the player's profile or a random one.
+/// </summary>
+[RegisterComponent]
+public sealed partial class AntagLoadProfileRuleComponent : Component;
index 232d24004b90bb38414953ff02f3129bb0278676..d6f1c3c619ab059c91333ad20e688a71659abf86 100644 (file)
@@ -1,11 +1,9 @@
 using Content.Server.Antag;
 using Content.Server.Communications;
 using Content.Server.GameTicking.Rules.Components;
-using Content.Server.Humanoid;
 using Content.Server.Nuke;
 using Content.Server.NukeOps;
 using Content.Server.Popups;
-using Content.Server.Preferences.Managers;
 using Content.Server.Roles;
 using Content.Server.RoundEnd;
 using Content.Server.Shuttles.Events;
@@ -13,20 +11,16 @@ using Content.Server.Shuttles.Systems;
 using Content.Server.Station.Components;
 using Content.Server.Store.Components;
 using Content.Server.Store.Systems;
-using Content.Shared.Humanoid;
-using Content.Shared.Humanoid.Prototypes;
 using Content.Shared.Mobs;
 using Content.Shared.Mobs.Components;
 using Content.Shared.NPC.Components;
 using Content.Shared.NPC.Systems;
 using Content.Shared.Nuke;
 using Content.Shared.NukeOps;
-using Content.Shared.Preferences;
 using Content.Shared.Store;
 using Content.Shared.Tag;
 using Content.Shared.Zombies;
 using Robust.Shared.Map;
-using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 using Robust.Shared.Utility;
 using System.Linq;
@@ -36,10 +30,7 @@ namespace Content.Server.GameTicking.Rules;
 
 public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
 {
-    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
-    [Dependency] private readonly IServerPreferencesManager _prefs = default!;
     [Dependency] private readonly EmergencyShuttleSystem _emergency = default!;
-    [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
     [Dependency] private readonly NpcFactionSystem _npcFaction = default!;
     [Dependency] private readonly AntagSelectionSystem _antag = default!;
     [Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -71,7 +62,6 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
         SubscribeLocalEvent<WarDeclaredEvent>(OnWarDeclared);
         SubscribeLocalEvent<CommunicationConsoleCallShuttleAttemptEvent>(OnShuttleCallAttempt);
 
-        SubscribeLocalEvent<NukeopsRuleComponent, AntagSelectEntityEvent>(OnAntagSelectEntity);
         SubscribeLocalEvent<NukeopsRuleComponent, AfterAntagEntitySelectedEvent>(OnAfterAntagEntSelected);
     }
 
@@ -471,24 +461,6 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
         nukeops.RoundEndBehavior = RoundEndBehavior.Nothing;
     }
 
-    // this should really go anywhere else but im tired.
-    private void OnAntagSelectEntity(Entity<NukeopsRuleComponent> ent, ref AntagSelectEntityEvent args)
-    {
-        if (args.Handled)
-            return;
-
-        var profile = args.Session != null
-            ? _prefs.GetPreferences(args.Session.UserId).SelectedCharacter as HumanoidCharacterProfile
-            : HumanoidCharacterProfile.RandomWithSpecies();
-        if (!_prototypeManager.TryIndex(profile?.Species ?? SharedHumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species))
-        {
-            species = _prototypeManager.Index<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies);
-        }
-
-        args.Entity = Spawn(species.Prototype);
-        _humanoid.LoadProfile(args.Entity.Value, profile);
-    }
-
     private void OnAfterAntagEntSelected(Entity<NukeopsRuleComponent> ent, ref AfterAntagEntitySelectedEvent args)
     {
         if (ent.Comp.TargetStation is not { } station)
index 593122eee55838914d7da1d2d461f341f3cbcfb1..b1b48258bade2d0bd955911367297076c3ed0f40 100644 (file)
         prototype: InitialInfected
 
 - type: entity
-  id: LoneOpsSpawn
-  parent: BaseGameRule
   noSpawn: true
+  parent: BaseNukeopsRule
+  id: LoneOpsSpawn
   components:
   - type: StationEvent
     earliestStart: 35
index be5f617c8dc8bd3ab87450c262ed74c8948825a7..57e59f10e213a8db8e1b43e3b97b81640969f1b1 100644 (file)
     roundEndDelay: 10
 
 - type: entity
-  id: Nukeops
+  abstract: true
   parent: BaseGameRule
-  noSpawn: true
+  id: BaseNukeopsRule
   components:
-  - type: GameRule
-    minPlayers: 20
   - type: RandomMetadata #this generates the random operation name cuz it's cool.
     nameSegments:
     - operationPrefix
     - operationSuffix
   - type: NukeopsRule
+  - type: AntagSelection
+  - type: AntagLoadProfileRule
+
+- type: entity
+  noSpawn: true
+  parent: BaseNukeopsRule
+  id: Nukeops
+  components:
+  - type: GameRule
+    minPlayers: 20
   - type: LoadMapRule
     gameMap: NukieOutpost
   - type: AntagSelection