From cb8f1459759396552b1421aaf28c77fc8ac95003 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:31:26 +1300 Subject: [PATCH] Fix GhostRoleComponent performing randomization on ComponentInit (#26466) * Fix ghostrole ComponentInit * A * a --- .../Roles/Components/GhostRoleComponent.cs | 2 +- Content.Server/Ghost/Roles/GhostRoleSystem.cs | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs b/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs index 93e7e9efaa..abb26a8c8b 100644 --- a/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs +++ b/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs @@ -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? Requirements; diff --git a/Content.Server/Ghost/Roles/GhostRoleSystem.cs b/Content.Server/Ghost/Roles/GhostRoleSystem.cs index cd04e3fb37..0649e68a31 100644 --- a/Content.Server/Ghost/Roles/GhostRoleSystem.cs +++ b/Content.Server/Ghost/Roles/GhostRoleSystem.cs @@ -56,7 +56,8 @@ namespace Content.Server.Ghost.Roles SubscribeLocalEvent(OnMindAdded); SubscribeLocalEvent(OnMindRemoved); SubscribeLocalEvent(OnMobStateChanged); - SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnShutdown); SubscribeLocalEvent(OnPaused); SubscribeLocalEvent(OnUnpaused); @@ -317,17 +318,14 @@ namespace Content.Server.Ghost.Roles UpdateAllEui(); } - private void OnInit(Entity ent, ref ComponentInit args) + private void OnMapInit(Entity ent, ref MapInitEvent args) { - var role = ent.Comp; - if (role.Probability < 1f && !_random.Prob(role.Probability)) - { - RemComp(ent); - return; - } + if (ent.Comp.Probability < 1f && !_random.Prob(ent.Comp.Probability)) + RemCompDeferred(ent); + } - if (role.RoleRules == "") - role.RoleRules = Loc.GetString("ghost-role-component-default-rules"); + private void OnStartup(Entity ent, ref ComponentStartup args) + { RegisterGhostRole(ent); } -- 2.51.2