Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GhostRoleComponent performing randomization on ComponentInit #26466

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed partial class GhostRoleComponent : Component

[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;
Expand Down
18 changes: 8 additions & 10 deletions Content.Server/Ghost/Roles/GhostRoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public override void Initialize()
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);
Expand Down Expand Up @@ -317,17 +318,14 @@ private void OnUnpaused(EntityUid uid, GhostRoleComponent component, ref EntityU
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);
}

Expand Down
Loading