Make the round end summary use recursive PVS overrides (#19083)

This commit is contained in:
Leon Friedrich
2023-08-22 16:55:52 +12:00
committed by GitHub
parent 6be5ec4f3f
commit 89b0dba68e
2 changed files with 6 additions and 62 deletions

View File

@@ -7,7 +7,6 @@ using Content.Shared.GameTicking;
using Content.Shared.Preferences;
using JetBrains.Annotations;
using Prometheus;
using Robust.Server.GameStates;
using Robust.Server.Maps;
using Robust.Server.Player;
using Robust.Shared.Audio;
@@ -46,22 +45,6 @@ namespace Content.Server.GameTicking
[ViewVariables]
private bool _startingRound;
/// <summary>
/// This is a list of players that are going to appear in the round-end
/// crew manifest so their children entities can be collected each update
/// and sent to far-away players.
/// </summary>
[ViewVariables]
private HashSet<EntityUid> _expandPvsPlayers = new();
/// <summary>
/// This is the list of the children entities that should be sent to
/// all players at the end of the round, to keep distant characters from
/// looking naked in the crew manifest.
/// </summary>
[ViewVariables]
private HashSet<EntityUid> _expandPvsEntities = new();
[ViewVariables]
private GameRunLevel _runLevel;
@@ -81,16 +64,6 @@ namespace Content.Server.GameTicking
}
}
private void InitializeRoundFlow()
{
SubscribeLocalEvent<ExpandPvsEvent>(OnExpandPvs);
}
private void OnEntityDeleted(EntityUid uid)
{
_expandPvsEntities.Remove(uid);
}
/// <summary>
/// Returns true if the round's map is eligible to be updated.
/// </summary>
@@ -332,14 +305,6 @@ namespace Content.Server.GameTicking
ShowRoundEndScoreboard(text);
}
private void OnExpandPvs(ref ExpandPvsEvent args)
{
if (RunLevel != GameRunLevel.PostRound)
return;
args.Entities.AddRange(_expandPvsEntities);
}
public void ShowRoundEndScoreboard(string text = "")
{
// Log end of round
@@ -357,11 +322,6 @@ namespace Content.Server.GameTicking
//Get the timespan of the round.
var roundDuration = RoundDuration();
// Should already be empty, but just in case.
_expandPvsEntities.Clear();
_expandPvsPlayers.Clear();
EntityManager.EntityDeleted += OnEntityDeleted;
//Generate a list of basic player info to display in the end round summary.
var listOfPlayerInfo = new List<RoundEndMessageEvent.RoundEndPlayerInfo>();
// Grab the great big book of all the Minds, we'll need them for this.
@@ -395,8 +355,9 @@ namespace Content.Server.GameTicking
else if (mind.CurrentEntity != null && TryName(mind.CurrentEntity.Value, out var icName))
playerIcName = icName;
if (Exists(mind.OriginalOwnedEntity))
_expandPvsPlayers.Add(mind.OriginalOwnedEntity.Value);
var entity = mind.OriginalOwnedEntity;
if (Exists(entity))
_pvsOverride.AddGlobalOverride(entity.Value, recursive: true);
var playerEndRoundInfo = new RoundEndMessageEvent.RoundEndPlayerInfo()
{
@@ -405,7 +366,7 @@ namespace Content.Server.GameTicking
PlayerOOCName = contentPlayerData?.Name ?? "(IMPOSSIBLE: REGISTERED MIND WITH NO OWNER)",
// Character name takes precedence over current entity name
PlayerICName = playerIcName,
PlayerEntityUid = mind.OriginalOwnedEntity,
PlayerEntityUid = entity,
Role = antag
? mind.AllRoles.First(role => role.Antagonist).Name
: mind.AllRoles.FirstOrDefault()?.Name ?? Loc.GetString("game-ticker-unknown-role"),
@@ -416,20 +377,6 @@ namespace Content.Server.GameTicking
listOfPlayerInfo.Add(playerEndRoundInfo);
}
// Recursively collect entities for the crew manifest.
void RecursePvsEntities(IEnumerable<EntityUid> entities)
{
_expandPvsEntities.UnionWith(entities);
foreach (var entity in entities)
{
if (TryComp<TransformComponent>(entity, out var xform))
RecursePvsEntities(xform.ChildEntities);
}
}
RecursePvsEntities(_expandPvsPlayers);
// This ordering mechanism isn't great (no ordering of minds) but functions
var listOfPlayerInfoFinal = listOfPlayerInfo.OrderBy(pi => pi.PlayerOOCName).ToArray();
@@ -527,10 +474,6 @@ namespace Content.Server.GameTicking
_allPreviousGameRules.Clear();
EntityManager.EntityDeleted -= OnEntityDeleted;
_expandPvsPlayers.Clear();
_expandPvsEntities.Clear();
// Round restart cleanup event, so entity systems can reset.
var ev = new RoundRestartCleanupEvent();
RaiseLocalEvent(ev);