diff --git a/Content.Server/Ghost/Roles/GhostRoleSystem.cs b/Content.Server/Ghost/Roles/GhostRoleSystem.cs index 6cbb51b009..bdb0d97186 100644 --- a/Content.Server/Ghost/Roles/GhostRoleSystem.cs +++ b/Content.Server/Ghost/Roles/GhostRoleSystem.cs @@ -54,6 +54,8 @@ namespace Content.Server.Ghost.Roles SubscribeLocalEvent(OnMobStateChanged); SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnPaused); + SubscribeLocalEvent(OnUnpaused); SubscribeLocalEvent(OnSpawnerTakeRole); SubscribeLocalEvent(OnTakeoverTakeRole); _playerManager.PlayerStatusChanged += PlayerStatusChanged; @@ -153,7 +155,7 @@ namespace Content.Server.Ghost.Roles if (_needsUpdateGhostRoleCount) { _needsUpdateGhostRoleCount = false; - var response = new GhostUpdateGhostRoleCountEvent(_ghostRoles.Count); + var response = new GhostUpdateGhostRoleCountEvent(GetGhostRolesInfo().Length); foreach (var player in _playerManager.Sessions) { RaiseNetworkEvent(response, player.ConnectedClient); @@ -228,17 +230,20 @@ namespace Content.Server.Ghost.Roles public GhostRoleInfo[] GetGhostRolesInfo() { - var roles = new GhostRoleInfo[_ghostRoles.Count]; - - var i = 0; + var roles = new List(); + var metaQuery = GetEntityQuery(); foreach (var (id, role) in _ghostRoles) { - roles[i] = new GhostRoleInfo(){Identifier = id, Name = role.RoleName, Description = role.RoleDescription, Rules = role.RoleRules}; - i++; + var uid = role.Owner; + + if (metaQuery.GetComponent(uid).EntityPaused) + continue; + + roles.Add(new GhostRoleInfo {Identifier = id, Name = role.RoleName, Description = role.RoleDescription, Rules = role.RoleRules}); } - return roles; + return roles.ToArray(); } private void OnPlayerAttached(PlayerAttachedEvent message) @@ -283,6 +288,22 @@ namespace Content.Server.Ghost.Roles _nextRoleIdentifier = 0; } + private void OnPaused(EntityUid uid, GhostRoleComponent component, ref EntityPausedEvent args) + { + if (HasComp(uid)) + return; + + UpdateAllEui(); + } + + private void OnUnpaused(EntityUid uid, GhostRoleComponent component, ref EntityUnpausedEvent args) + { + if (HasComp(uid)) + return; + + UpdateAllEui(); + } + private void OnInit(EntityUid uid, GhostRoleComponent role, ComponentInit args) { if (role.Probability < 1f && !_random.Prob(role.Probability)) @@ -304,7 +325,7 @@ namespace Content.Server.Ghost.Roles private void OnSpawnerTakeRole(EntityUid uid, GhostRoleMobSpawnerComponent component, ref TakeGhostRoleEvent args) { if (!TryComp(uid, out GhostRoleComponent? ghostRole) || - ghostRole.Taken) + !CanTakeGhost(uid, ghostRole)) { args.TookRole = false; return; @@ -340,10 +361,17 @@ namespace Content.Server.Ghost.Roles args.TookRole = true; } + private bool CanTakeGhost(EntityUid uid, GhostRoleComponent? component = null) + { + return Resolve(uid, ref component, false) && + !component.Taken && + !MetaData(uid).EntityPaused; + } + private void OnTakeoverTakeRole(EntityUid uid, GhostTakeoverAvailableComponent component, ref TakeGhostRoleEvent args) { if (!TryComp(uid, out GhostRoleComponent? ghostRole) || - ghostRole.Taken) + !CanTakeGhost(uid, ghostRole)) { args.TookRole = false; return;