Don't show paused ghosts in window (#17188)
This commit is contained in:
@@ -54,6 +54,8 @@ namespace Content.Server.Ghost.Roles
|
|||||||
SubscribeLocalEvent<GhostTakeoverAvailableComponent, MobStateChangedEvent>(OnMobStateChanged);
|
SubscribeLocalEvent<GhostTakeoverAvailableComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||||
SubscribeLocalEvent<GhostRoleComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<GhostRoleComponent, ComponentInit>(OnInit);
|
||||||
SubscribeLocalEvent<GhostRoleComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<GhostRoleComponent, ComponentShutdown>(OnShutdown);
|
||||||
|
SubscribeLocalEvent<GhostRoleComponent, EntityPausedEvent>(OnPaused);
|
||||||
|
SubscribeLocalEvent<GhostRoleComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||||
SubscribeLocalEvent<GhostRoleMobSpawnerComponent, TakeGhostRoleEvent>(OnSpawnerTakeRole);
|
SubscribeLocalEvent<GhostRoleMobSpawnerComponent, TakeGhostRoleEvent>(OnSpawnerTakeRole);
|
||||||
SubscribeLocalEvent<GhostTakeoverAvailableComponent, TakeGhostRoleEvent>(OnTakeoverTakeRole);
|
SubscribeLocalEvent<GhostTakeoverAvailableComponent, TakeGhostRoleEvent>(OnTakeoverTakeRole);
|
||||||
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
||||||
@@ -153,7 +155,7 @@ namespace Content.Server.Ghost.Roles
|
|||||||
if (_needsUpdateGhostRoleCount)
|
if (_needsUpdateGhostRoleCount)
|
||||||
{
|
{
|
||||||
_needsUpdateGhostRoleCount = false;
|
_needsUpdateGhostRoleCount = false;
|
||||||
var response = new GhostUpdateGhostRoleCountEvent(_ghostRoles.Count);
|
var response = new GhostUpdateGhostRoleCountEvent(GetGhostRolesInfo().Length);
|
||||||
foreach (var player in _playerManager.Sessions)
|
foreach (var player in _playerManager.Sessions)
|
||||||
{
|
{
|
||||||
RaiseNetworkEvent(response, player.ConnectedClient);
|
RaiseNetworkEvent(response, player.ConnectedClient);
|
||||||
@@ -228,17 +230,20 @@ namespace Content.Server.Ghost.Roles
|
|||||||
|
|
||||||
public GhostRoleInfo[] GetGhostRolesInfo()
|
public GhostRoleInfo[] GetGhostRolesInfo()
|
||||||
{
|
{
|
||||||
var roles = new GhostRoleInfo[_ghostRoles.Count];
|
var roles = new List<GhostRoleInfo>();
|
||||||
|
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
foreach (var (id, role) in _ghostRoles)
|
foreach (var (id, role) in _ghostRoles)
|
||||||
{
|
{
|
||||||
roles[i] = new GhostRoleInfo(){Identifier = id, Name = role.RoleName, Description = role.RoleDescription, Rules = role.RoleRules};
|
var uid = role.Owner;
|
||||||
i++;
|
|
||||||
|
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)
|
private void OnPlayerAttached(PlayerAttachedEvent message)
|
||||||
@@ -283,6 +288,22 @@ namespace Content.Server.Ghost.Roles
|
|||||||
_nextRoleIdentifier = 0;
|
_nextRoleIdentifier = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPaused(EntityUid uid, GhostRoleComponent component, ref EntityPausedEvent args)
|
||||||
|
{
|
||||||
|
if (HasComp<ActorComponent>(uid))
|
||||||
|
return;
|
||||||
|
|
||||||
|
UpdateAllEui();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUnpaused(EntityUid uid, GhostRoleComponent component, ref EntityUnpausedEvent args)
|
||||||
|
{
|
||||||
|
if (HasComp<ActorComponent>(uid))
|
||||||
|
return;
|
||||||
|
|
||||||
|
UpdateAllEui();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, GhostRoleComponent role, ComponentInit args)
|
private void OnInit(EntityUid uid, GhostRoleComponent role, ComponentInit args)
|
||||||
{
|
{
|
||||||
if (role.Probability < 1f && !_random.Prob(role.Probability))
|
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)
|
private void OnSpawnerTakeRole(EntityUid uid, GhostRoleMobSpawnerComponent component, ref TakeGhostRoleEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp(uid, out GhostRoleComponent? ghostRole) ||
|
if (!TryComp(uid, out GhostRoleComponent? ghostRole) ||
|
||||||
ghostRole.Taken)
|
!CanTakeGhost(uid, ghostRole))
|
||||||
{
|
{
|
||||||
args.TookRole = false;
|
args.TookRole = false;
|
||||||
return;
|
return;
|
||||||
@@ -340,10 +361,17 @@ namespace Content.Server.Ghost.Roles
|
|||||||
args.TookRole = true;
|
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)
|
private void OnTakeoverTakeRole(EntityUid uid, GhostTakeoverAvailableComponent component, ref TakeGhostRoleEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp(uid, out GhostRoleComponent? ghostRole) ||
|
if (!TryComp(uid, out GhostRoleComponent? ghostRole) ||
|
||||||
ghostRole.Taken)
|
!CanTakeGhost(uid, ghostRole))
|
||||||
{
|
{
|
||||||
args.TookRole = false;
|
args.TookRole = false;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user