Fix station announcements (#9380)

* Fix station announcements

Doesn't just get what's on the grid. Also made it generic so other systems can use a station filter.

* bumped

* a
This commit is contained in:
metalgearsloth
2022-07-04 16:00:51 +10:00
committed by GitHub
parent ad56f5b8c9
commit 20f4c9988b
10 changed files with 72 additions and 24 deletions

View File

@@ -51,7 +51,7 @@ namespace Content.Server.Administration.UI
break; break;
// TODO: Per-station announcement support // TODO: Per-station announcement support
case AdminAnnounceType.Station: case AdminAnnounceType.Station:
_chatSystem.DispatchGlobalStationAnnouncement(doAnnounce.Announcement, doAnnounce.Announcer, colorOverride: Color.Gold); _chatSystem.DispatchGlobalAnnouncement(doAnnounce.Announcement, doAnnounce.Announcer, colorOverride: Color.Gold);
break; break;
} }

View File

@@ -24,12 +24,12 @@ namespace Content.Server.Announcements
if (args.Length == 1) if (args.Length == 1)
{ {
chat.DispatchGlobalStationAnnouncement(args[0], colorOverride: Color.Gold); chat.DispatchGlobalAnnouncement(args[0], colorOverride: Color.Gold);
} }
else else
{ {
var message = string.Join(' ', new ArraySegment<string>(args, 1, args.Length-1)); var message = string.Join(' ', new ArraySegment<string>(args, 1, args.Length-1));
chat.DispatchGlobalStationAnnouncement(message, args[0], colorOverride: Color.Gold); chat.DispatchGlobalAnnouncement(message, args[0], colorOverride: Color.Gold);
} }
shell.WriteLine("Sent!"); shell.WriteLine("Sent!");
} }

View File

@@ -165,13 +165,13 @@ public sealed partial class ChatSystem : SharedChatSystem
#region Announcements #region Announcements
/// <summary> /// <summary>
/// Dispatches an announcement to all stations /// Dispatches an announcement to all.
/// </summary> /// </summary>
/// <param name="message">The contents of the message</param> /// <param name="message">The contents of the message</param>
/// <param name="sender">The sender (Communications Console in Communications Console Announcement)</param> /// <param name="sender">The sender (Communications Console in Communications Console Announcement)</param>
/// <param name="playDefaultSound">Play the announcement sound</param> /// <param name="playDefaultSound">Play the announcement sound</param>
/// <param name="colorOverride">Optional color for the announcement message</param> /// <param name="colorOverride">Optional color for the announcement message</param>
public void DispatchGlobalStationAnnouncement(string message, string sender = "Central Command", public void DispatchGlobalAnnouncement(string message, string sender = "Central Command",
bool playDefaultSound = true, Color? colorOverride = null) bool playDefaultSound = true, Color? colorOverride = null)
{ {
var messageWrap = Loc.GetString("chat-manager-sender-announcement-wrap-message", ("sender", sender)); var messageWrap = Loc.GetString("chat-manager-sender-announcement-wrap-message", ("sender", sender));
@@ -195,7 +195,6 @@ public sealed partial class ChatSystem : SharedChatSystem
{ {
var messageWrap = Loc.GetString("chat-manager-sender-announcement-wrap-message", ("sender", sender)); var messageWrap = Loc.GetString("chat-manager-sender-announcement-wrap-message", ("sender", sender));
var station = _stationSystem.GetOwningStation(source); var station = _stationSystem.GetOwningStation(source);
var filter = Filter.Empty();
if (station == null) if (station == null)
{ {
@@ -205,10 +204,7 @@ public sealed partial class ChatSystem : SharedChatSystem
if (!EntityManager.TryGetComponent<StationDataComponent>(station, out var stationDataComp)) return; if (!EntityManager.TryGetComponent<StationDataComponent>(station, out var stationDataComp)) return;
foreach (var gridEnt in stationDataComp.Grids) var filter = _stationSystem.GetInStation(stationDataComp);
{
filter.AddInGrid(gridEnt);
}
_chatManager.ChatMessageToManyFiltered(filter, ChatChannel.Radio, message, messageWrap, source, false, colorOverride); _chatManager.ChatMessageToManyFiltered(filter, ChatChannel.Radio, message, messageWrap, source, false, colorOverride);
@@ -422,7 +418,7 @@ public sealed partial class ChatSystem : SharedChatSystem
private IEnumerable<INetChannel> GetDeadChatClients() private IEnumerable<INetChannel> GetDeadChatClients()
{ {
return Filter.Empty() return Filter.Empty()
.AddWhereAttachedEntity(uid => HasComp<GhostComponent>(uid)) .AddWhereAttachedEntity(HasComp<GhostComponent>)
.Recipients .Recipients
.Union(_adminManager.ActiveAdmins) .Union(_adminManager.ActiveAdmins)
.Select(p => p.ConnectedClient); .Select(p => p.ConnectedClient);

View File

@@ -249,7 +249,7 @@ namespace Content.Server.Communications
msg += "\n" + Loc.GetString("comms-console-announcement-sent-by") + " " + author; msg += "\n" + Loc.GetString("comms-console-announcement-sent-by") + " " + author;
if (comp.AnnounceGlobal) if (comp.AnnounceGlobal)
{ {
_chatSystem.DispatchGlobalStationAnnouncement(msg, title, colorOverride: comp.AnnouncementColor); _chatSystem.DispatchGlobalAnnouncement(msg, title, colorOverride: comp.AnnouncementColor);
return; return;
} }
_chatSystem.DispatchStationAnnouncement(uid, msg, title, colorOverride: comp.AnnouncementColor); _chatSystem.DispatchStationAnnouncement(uid, msg, title, colorOverride: comp.AnnouncementColor);

View File

@@ -483,7 +483,7 @@ namespace Content.Server.GameTicking
if (!proto.GamePresets.Contains(Preset.ID)) continue; if (!proto.GamePresets.Contains(Preset.ID)) continue;
if (proto.Message != null) if (proto.Message != null)
_chatSystem.DispatchGlobalStationAnnouncement(Loc.GetString(proto.Message), playDefaultSound: true); _chatSystem.DispatchGlobalAnnouncement(Loc.GetString(proto.Message), playDefaultSound: true);
if (proto.Sound != null) if (proto.Sound != null)
SoundSystem.Play(proto.Sound.GetSound(), Filter.Broadcast()); SoundSystem.Play(proto.Sound.GetSound(), Filter.Broadcast());

View File

@@ -80,7 +80,7 @@ namespace Content.Server.Nuke
if (wasSent) if (wasSent)
{ {
var msg = Loc.GetString("nuke-component-announcement-send-codes"); var msg = Loc.GetString("nuke-component-announcement-send-codes");
_chatSystem.DispatchGlobalStationAnnouncement(msg, colorOverride: Color.Red); _chatSystem.DispatchGlobalAnnouncement(msg, colorOverride: Color.Red);
} }
return wasSent; return wasSent;

View File

@@ -128,7 +128,7 @@ namespace Content.Server.RoundEnd
units = "eta-units-minutes"; units = "eta-units-minutes";
} }
_chatSystem.DispatchGlobalStationAnnouncement(Loc.GetString("round-end-system-shuttle-called-announcement", _chatSystem.DispatchGlobalAnnouncement(Loc.GetString("round-end-system-shuttle-called-announcement",
("time", time), ("time", time),
("units", Loc.GetString(units))), ("units", Loc.GetString(units))),
Loc.GetString("Station"), Loc.GetString("Station"),
@@ -163,7 +163,7 @@ namespace Content.Server.RoundEnd
_adminLogger.Add(LogType.ShuttleRecalled, LogImpact.High, $"Shuttle recalled"); _adminLogger.Add(LogType.ShuttleRecalled, LogImpact.High, $"Shuttle recalled");
} }
_chatSystem.DispatchGlobalStationAnnouncement(Loc.GetString("round-end-system-shuttle-recalled-announcement"), _chatSystem.DispatchGlobalAnnouncement(Loc.GetString("round-end-system-shuttle-recalled-announcement"),
Loc.GetString("Station"), false, colorOverride: Color.Gold); Loc.GetString("Station"), false, colorOverride: Color.Gold);
SoundSystem.Play("/Audio/Announcements/shuttlerecalled.ogg", Filter.Broadcast()); SoundSystem.Play("/Audio/Announcements/shuttlerecalled.ogg", Filter.Broadcast());

View File

@@ -133,7 +133,7 @@ public sealed partial class ShuttleSystem
if (_consoleAccumulator <= 0f) if (_consoleAccumulator <= 0f)
{ {
_launchedShuttles = true; _launchedShuttles = true;
_chatSystem.DispatchGlobalStationAnnouncement(Loc.GetString("emergency-shuttle-left", ("transitTime", $"{_transitTime:0}"))); _chatSystem.DispatchGlobalAnnouncement(Loc.GetString("emergency-shuttle-left", ("transitTime", $"{_transitTime:0}")));
_roundEndCancelToken = new CancellationTokenSource(); _roundEndCancelToken = new CancellationTokenSource();
Timer.Spawn((int) (_transitTime * 1000) + _bufferTime.Milliseconds, () => _roundEnd.EndRound(), _roundEndCancelToken.Token); Timer.Spawn((int) (_transitTime * 1000) + _bufferTime.Milliseconds, () => _roundEnd.EndRound(), _roundEndCancelToken.Token);
@@ -174,7 +174,7 @@ public sealed partial class ShuttleSystem
_logger.Add(LogType.EmergencyShuttle, LogImpact.High, $"Emergency shuttle early launch REPEAL by {args.Session:user}"); _logger.Add(LogType.EmergencyShuttle, LogImpact.High, $"Emergency shuttle early launch REPEAL by {args.Session:user}");
var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count; var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count;
_chatSystem.DispatchGlobalStationAnnouncement(Loc.GetString("emergency-shuttle-console-auth-revoked", ("remaining", remaining))); _chatSystem.DispatchGlobalAnnouncement(Loc.GetString("emergency-shuttle-console-auth-revoked", ("remaining", remaining)));
CheckForLaunch(component); CheckForLaunch(component);
UpdateAllEmergencyConsoles(); UpdateAllEmergencyConsoles();
} }
@@ -197,7 +197,7 @@ public sealed partial class ShuttleSystem
var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count; var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count;
if (remaining > 0) if (remaining > 0)
_chatSystem.DispatchGlobalStationAnnouncement( _chatSystem.DispatchGlobalAnnouncement(
Loc.GetString("emergency-shuttle-console-auth-left", ("remaining", remaining)), Loc.GetString("emergency-shuttle-console-auth-left", ("remaining", remaining)),
playDefaultSound: false, colorOverride: DangerColor); playDefaultSound: false, colorOverride: DangerColor);
@@ -261,7 +261,7 @@ public sealed partial class ShuttleSystem
_consoleAccumulator = MathF.Max(1f, MathF.Min(_consoleAccumulator, _authorizeTime)); _consoleAccumulator = MathF.Max(1f, MathF.Min(_consoleAccumulator, _authorizeTime));
EarlyLaunchAuthorized = true; EarlyLaunchAuthorized = true;
RaiseLocalEvent(new EmergencyShuttleAuthorizedEvent()); RaiseLocalEvent(new EmergencyShuttleAuthorizedEvent());
_chatSystem.DispatchGlobalStationAnnouncement( _chatSystem.DispatchGlobalAnnouncement(
Loc.GetString("emergency-shuttle-launch-time", ("consoleAccumulator", $"{_consoleAccumulator:0}")), Loc.GetString("emergency-shuttle-launch-time", ("consoleAccumulator", $"{_consoleAccumulator:0}")),
playDefaultSound: false, playDefaultSound: false,
colorOverride: DangerColor); colorOverride: DangerColor);

View File

@@ -6,8 +6,11 @@ using Content.Server.GameTicking;
using Content.Server.Station.Components; using Content.Server.Station.Components;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Player;
using Robust.Shared.Collections;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
namespace Content.Server.Station.Systems; namespace Content.Server.Station.Systems;
@@ -24,9 +27,11 @@ public sealed class StationSystem : EntitySystem
[Dependency] private readonly IConfigurationManager _configurationManager = default!; [Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!; [Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly GameTicker _gameTicker = default!; [Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
private ISawmill _sawmill = default!; private ISawmill _sawmill = default!;
@@ -153,12 +158,59 @@ public sealed class StationSystem : EntitySystem
#endregion Event handlers #endregion Event handlers
/// <summary>
/// Retrieves a filter for everything in a particular station or near its member grids.
/// </summary>
public Filter GetInStation(StationDataComponent dataComponent, float range = 32f)
{
// Could also use circles if you wanted.
var bounds = new ValueList<Box2>(dataComponent.Grids.Count);
var filter = Filter.Empty();
var mapIds = new ValueList<MapId>();
var xformQuery = GetEntityQuery<TransformComponent>();
foreach (var gridUid in dataComponent.Grids)
{
if (!_mapManager.TryGetGrid(gridUid, out var grid) ||
!xformQuery.TryGetComponent(gridUid, out var xform)) continue;
var mapId = xform.MapID;
var position = _transform.GetWorldPosition(xform, xformQuery);
var bound = grid.LocalAABB.Enlarged(range).Translated(position);
bounds.Add(bound);
if (!mapIds.Contains(mapId))
{
mapIds.Add(grid.ParentMapId);
}
}
foreach (var session in Filter.GetAllPlayers(_player))
{
var entity = session.AttachedEntity;
if (entity == null || !xformQuery.TryGetComponent(entity, out var xform)) continue;
var mapId = xform.MapID;
if (!mapIds.Contains(mapId)) continue;
var position = _transform.GetWorldPosition(xform, xformQuery);
foreach (var bound in bounds)
{
if (!bound.Contains(position)) continue;
filter.AddPlayer(session);
break;
}
}
return filter;
}
/// <summary> /// <summary>
/// Generates a station name from the given config. /// Generates a station name from the given config.
/// </summary> /// </summary>
/// <param name="config"></param>
/// <returns></returns>
public static string GenerateStationName(StationConfig config) public static string GenerateStationName(StationConfig config)
{ {
return config.NameGenerator is not null return config.NameGenerator is not null

View File

@@ -148,7 +148,7 @@ namespace Content.Server.StationEvents.Events
if (AnnounceEvent && StartAnnouncement != null) if (AnnounceEvent && StartAnnouncement != null)
{ {
var chatSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>(); var chatSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
chatSystem.DispatchGlobalStationAnnouncement(StartAnnouncement, playDefaultSound: false, colorOverride: Color.Gold); chatSystem.DispatchGlobalAnnouncement(StartAnnouncement, playDefaultSound: false, colorOverride: Color.Gold);
} }
if (AnnounceEvent && StartAudio != null) if (AnnounceEvent && StartAudio != null)
@@ -171,7 +171,7 @@ namespace Content.Server.StationEvents.Events
if (AnnounceEvent && EndAnnouncement != null) if (AnnounceEvent && EndAnnouncement != null)
{ {
var chatSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>(); var chatSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
chatSystem.DispatchGlobalStationAnnouncement(EndAnnouncement, playDefaultSound: false, colorOverride: Color.Gold); chatSystem.DispatchGlobalAnnouncement(EndAnnouncement, playDefaultSound: false, colorOverride: Color.Gold);
} }
if (AnnounceEvent && EndAudio != null) if (AnnounceEvent && EndAudio != null)