diff --git a/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announce.cs b/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announce.cs index d062895333..65361f01de 100644 --- a/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announce.cs +++ b/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announce.cs @@ -2,7 +2,6 @@ using Content.Shared.SimpleStation14.Announcements.Prototypes; using Robust.Shared.Audio; using Robust.Shared.Player; -using Robust.Shared.Utility; namespace Content.Server.SimpleStation14.Announcements.Systems; @@ -19,13 +18,9 @@ private string GetAnnouncementPath(string announcementId, string? announcerId = // Get the announcement data from the announcer // Will be the fallback if the data for the announcementId is not found - // A fallback is REQUIRED // TODO: Make a test to see if there is a fallback on every announcerPrototype var announcementType = announcer.AnnouncementPaths.FirstOrDefault(a => a.ID == announcementId) ?? announcer.AnnouncementPaths.First(a => a.ID.ToLower() == "fallback"); - // This is not possible, throw an error if this happens - DebugTools.Assert(announcementType.Path == null && announcementType.IgnoreBasePath); - // If the greedy announcementType wants to do the job of announcer, ignore the base path and just return the path if (announcementType.IgnoreBasePath) return announcementType.Path!; diff --git a/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announcer.cs b/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announcer.cs index 874da52bd6..704d7b2150 100644 --- a/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announcer.cs +++ b/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.Announcer.cs @@ -1,34 +1,53 @@ using System.Linq; +using Content.Shared.GameTicking; using Content.Shared.SimpleStation14.Announcements.Prototypes; using Content.Shared.SimpleStation14.CCVar; using Robust.Shared.Random; +using Robust.Shared.Utility; namespace Content.Server.SimpleStation14.Announcements.Systems; public sealed partial class AnnouncerSystem { + private void OnRoundRestarting(RoundRestartCleanupEvent ev) + { + var announcer = _configManager.GetCVar(SimpleStationCCVars.Announcer); + if (string.IsNullOrEmpty(announcer)) + SetAnnouncer(PickAnnouncer()); + else + SetAnnouncer(announcer); + } + + /// /// Picks a random announcer /// - public void PickAnnouncer() + public AnnouncerPrototype PickAnnouncer() { - Announcer = _random.Pick(_prototypeManager.EnumeratePrototypes() + return _random.Pick(_prototypeManager.EnumeratePrototypes() .Where(x => !_configManager.GetCVar(SimpleStationCCVars.AnnouncerBlacklist).Contains(x.ID)) .ToArray()); } + /// /// Sets the announcer /// /// ID of the announcer to choose public void SetAnnouncer(string announcerId) { - if (announcerId == "random") - { - PickAnnouncer(); - return; - } + if (!_prototypeManager.TryIndex(announcerId, out var announcer)) + DebugTools.Assert("Set announcer does not exist, attempting to use previously set one."); + else + Announcer = announcer; + } - Announcer = _prototypeManager.Index(announcerId); + /// + /// Sets the announcer + /// + /// The announcer prototype to set the current announcer to + public void SetAnnouncer(AnnouncerPrototype announcer) + { + Announcer = announcer; } } diff --git a/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.cs b/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.cs index b5cab4d1f6..a2c651cdc2 100644 --- a/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.cs +++ b/Content.Server/SimpleStation14/Announcements/Systems/AnnouncerSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Chat.Systems; using Content.Server.GameTicking.Events; +using Content.Shared.GameTicking; using Content.Shared.SimpleStation14.Announcements.Prototypes; using Content.Shared.SimpleStation14.CCVar; using Robust.Shared.Configuration; @@ -30,12 +31,6 @@ public override void Initialize() _configManager.OnValueChanged(SimpleStationCCVars.Announcer, SetAnnouncer); - SubscribeLocalEvent(OnRoundStarting); - } - - - private void OnRoundStarting(RoundStartingEvent ev) - { - SetAnnouncer(_configManager.GetCVar(SimpleStationCCVars.Announcer)); + SubscribeLocalEvent(OnRoundRestarting); } } diff --git a/Content.Shared/SimpleStation14/CCVar/SSCVars.cs b/Content.Shared/SimpleStation14/CCVar/SSCVars.cs index 41e34e61b7..ea411aaa96 100644 --- a/Content.Shared/SimpleStation14/CCVar/SSCVars.cs +++ b/Content.Shared/SimpleStation14/CCVar/SSCVars.cs @@ -9,7 +9,7 @@ public sealed class SimpleStationCCVars /// Optionally force set an announcer /// public static readonly CVarDef Announcer = - CVarDef.Create("announcer.announcer", "random", CVar.SERVERONLY); + CVarDef.Create("announcer.announcer", "", CVar.SERVERONLY); /// /// Optionally blacklist announcers