]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix GhostRoleComponent performing randomization on ComponentInit (#26466)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 27 Mar 2024 04:31:26 +0000 (17:31 +1300)
committerGitHub <noreply@github.com>
Wed, 27 Mar 2024 04:31:26 +0000 (00:31 -0400)
* Fix ghostrole ComponentInit

* A

* a

Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs
Content.Server/Ghost/Roles/GhostRoleSystem.cs

index 93e7e9efaa650e413ee622df53287007b87937e9..abb26a8c8bc1586dc87c89c0e639940f16d4e1b7 100644 (file)
@@ -11,7 +11,7 @@ namespace Content.Server.Ghost.Roles.Components
 
         [DataField("description")] private string _roleDescription = "Unknown";
 
-        [DataField("rules")] private string _roleRules = "";
+        [DataField("rules")] private string _roleRules = "ghost-role-component-default-rules";
 
         [DataField("requirements")]
         public HashSet<JobRequirement>? Requirements;
index cd04e3fb3734f48e1b3df8b3d7d56115a1bdb7e8..0649e68a317c22cdbb1dfdf022868cbd4f696eaa 100644 (file)
@@ -56,7 +56,8 @@ namespace Content.Server.Ghost.Roles
             SubscribeLocalEvent<GhostTakeoverAvailableComponent, MindAddedMessage>(OnMindAdded);
             SubscribeLocalEvent<GhostTakeoverAvailableComponent, MindRemovedMessage>(OnMindRemoved);
             SubscribeLocalEvent<GhostTakeoverAvailableComponent, MobStateChangedEvent>(OnMobStateChanged);
-            SubscribeLocalEvent<GhostRoleComponent, ComponentInit>(OnInit);
+            SubscribeLocalEvent<GhostRoleComponent, MapInitEvent>(OnMapInit);
+            SubscribeLocalEvent<GhostRoleComponent, ComponentStartup>(OnStartup);
             SubscribeLocalEvent<GhostRoleComponent, ComponentShutdown>(OnShutdown);
             SubscribeLocalEvent<GhostRoleComponent, EntityPausedEvent>(OnPaused);
             SubscribeLocalEvent<GhostRoleComponent, EntityUnpausedEvent>(OnUnpaused);
@@ -317,17 +318,14 @@ namespace Content.Server.Ghost.Roles
             UpdateAllEui();
         }
 
-        private void OnInit(Entity<GhostRoleComponent> ent, ref ComponentInit args)
+        private void OnMapInit(Entity<GhostRoleComponent> ent, ref MapInitEvent args)
         {
-            var role = ent.Comp;
-            if (role.Probability < 1f && !_random.Prob(role.Probability))
-            {
-                RemComp<GhostRoleComponent>(ent);
-                return;
-            }
+            if (ent.Comp.Probability < 1f && !_random.Prob(ent.Comp.Probability))
+                RemCompDeferred<GhostRoleComponent>(ent);
+        }
 
-            if (role.RoleRules == "")
-                role.RoleRules = Loc.GetString("ghost-role-component-default-rules");
+        private void OnStartup(Entity<GhostRoleComponent> ent, ref ComponentStartup args)
+        {
             RegisterGhostRole(ent);
         }