diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index 0a69fdc71c7..4eda3dd8501 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -351,7 +351,8 @@ public async Task AllComponentsOneToOneDeleteTest() "DebrisFeaturePlacerController", // Above. "LoadedChunk", // Worldgen chunk loading malding. "BiomeSelection", // Whaddya know, requires config. - "ActivatableUI", // Requires enum key + "ActivatableUI", // Frontier: Requires enum key + "AlertLevel", // Frontier: requires alert set }; // TODO TESTS diff --git a/Content.Server/AlertLevel/AlertLevelDisplaySystem.cs b/Content.Server/AlertLevel/AlertLevelDisplaySystem.cs index 3dd216c5dce..f604d810ffa 100644 --- a/Content.Server/AlertLevel/AlertLevelDisplaySystem.cs +++ b/Content.Server/AlertLevel/AlertLevelDisplaySystem.cs @@ -2,6 +2,7 @@ using Content.Server.Station.Systems; using Content.Shared.AlertLevel; using Content.Shared.Power; +using Content.Server._NF.SectorServices; // Frontier namespace Content.Server.AlertLevel; @@ -9,6 +10,7 @@ public sealed class AlertLevelDisplaySystem : EntitySystem { [Dependency] private readonly StationSystem _stationSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; + [Dependency] private readonly SectorServiceSystem _sectorService = default!; // Frontier public override void Initialize() { @@ -30,8 +32,9 @@ private void OnDisplayInit(EntityUid uid, AlertLevelDisplayComponent alertLevelD { if (TryComp(uid, out AppearanceComponent? appearance)) { - var stationUid = _stationSystem.GetOwningStation(uid); - if (stationUid != null && TryComp(stationUid, out AlertLevelComponent? alert)) + //var stationUid = _stationSystem.GetOwningStation(uid); // Frontier: sector-wide alerts + var stationUid = _sectorService.GetServiceEntity(); // Frontier: sector-wide alerts + if (stationUid.Valid && TryComp(stationUid, out AlertLevelComponent? alert)) // Frontier: uid != null < uid.Valid { _appearance.SetData(uid, AlertLevelDisplay.CurrentLevel, alert.CurrentLevel, appearance); } diff --git a/Content.Server/AlertLevel/AlertLevelSystem.cs b/Content.Server/AlertLevel/AlertLevelSystem.cs index 0b49d7e4bfa..8e43bf6a715 100644 --- a/Content.Server/AlertLevel/AlertLevelSystem.cs +++ b/Content.Server/AlertLevel/AlertLevelSystem.cs @@ -6,6 +6,9 @@ using Robust.Shared.Audio.Systems; using Robust.Shared.Configuration; using Robust.Shared.Prototypes; +using Content.Server.GameTicking; // Frontier +using Robust.Shared.Player; // Frontier +using Content.Server._NF.SectorServices; // Frontier namespace Content.Server.AlertLevel; @@ -16,13 +19,16 @@ public sealed class AlertLevelSystem : EntitySystem [Dependency] private readonly ChatSystem _chatSystem = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly StationSystem _stationSystem = default!; + [Dependency] private readonly GameTicker _ticker = default!; // Frontier + [Dependency] private readonly SectorServiceSystem _sectorService = default!; // Until stations are a prototype, this is how it's going to have to be. public const string DefaultAlertLevelSet = "stationAlerts"; public override void Initialize() { - SubscribeLocalEvent(OnStationInitialize); + //SubscribeLocalEvent(OnStationInitialize); // Frontier: sector-wide services + SubscribeLocalEvent(OnInit); // Frontier: sector-wide services SubscribeLocalEvent(OnPrototypeReload); } @@ -46,6 +52,8 @@ public override void Update(float time) } } + // Frontier: sector-wide services + /* private void OnStationInitialize(StationInitializedEvent args) { if (!TryComp(args.Station, out var alertLevelComponent)) @@ -66,6 +74,26 @@ private void OnStationInitialize(StationInitializedEvent args) SetLevel(args.Station, defaultLevel, false, false, true); } + */ + + private void OnInit(EntityUid uid, AlertLevelComponent comp, ComponentInit args) + { + if (!_prototypeManager.TryIndex(comp.AlertLevelPrototype, out AlertLevelPrototype? alerts)) + { + return; + } + + comp.AlertLevels = alerts; + + var defaultLevel = comp.AlertLevels.DefaultLevel; + if (string.IsNullOrEmpty(defaultLevel)) + { + defaultLevel = comp.AlertLevels.Levels.Keys.First(); + } + + SetLevel(uid, defaultLevel, false, false, true); + } + // End Frontier private void OnPrototypeReload(PrototypesReloadedEventArgs args) { @@ -98,20 +126,30 @@ private void OnPrototypeReload(PrototypesReloadedEventArgs args) public string GetLevel(EntityUid station, AlertLevelComponent? alert = null) { - if (!Resolve(station, ref alert)) - { + // Frontier: sector-wide alarms + if (!TryComp(_sectorService.GetServiceEntity(), out alert)) return string.Empty; - } + + // if (!Resolve(station, ref alert)) + // { + // return string.Empty; + // } + // End Frontier return alert.CurrentLevel; } public float GetAlertLevelDelay(EntityUid station, AlertLevelComponent? alert = null) { - if (!Resolve(station, ref alert)) - { + // Frontier: sector-wide alarms + if (!TryComp(_sectorService.GetServiceEntity(), out alert)) return float.NaN; - } + + // if (!Resolve(station, ref alert)) + // { + // return float.NaN; + // } + // End Frontier return alert.CurrentDelay; } @@ -128,7 +166,13 @@ public float GetAlertLevelDelay(EntityUid station, AlertLevelComponent? alert = public void SetLevel(EntityUid station, string level, bool playSound, bool announce, bool force = false, bool locked = false, MetaDataComponent? dataComponent = null, AlertLevelComponent? component = null) { - if (!Resolve(station, ref component, ref dataComponent) + // Frontier: sector-wide alerts + EntityUid sectorEnt = _sectorService.GetServiceEntity(); + if (!TryComp(sectorEnt, out component)) + return; + // End Frontier + + if (!Resolve(station, ref dataComponent) // Frontier: remove component || component.AlertLevels == null || !component.AlertLevels.Levels.TryGetValue(level, out var detail) || component.CurrentLevel == level) @@ -177,7 +221,9 @@ public void SetLevel(EntityUid station, string level, bool playSound, bool annou { if (detail.Sound != null) { - var filter = _stationSystem.GetInOwningStation(station); + //var filter = _stationSystem.GetInOwningStation(station); // Frontier: global alerts + var filter = Filter.Empty(); // Frontier + filter.AddInMap(_ticker.DefaultMap, EntityManager); // Frontier _audio.PlayGlobal(detail.Sound, filter, true, detail.Sound.Params); } else @@ -192,7 +238,7 @@ public void SetLevel(EntityUid station, string level, bool playSound, bool annou colorOverride: detail.Color, sender: stationName); } - RaiseLocalEvent(new AlertLevelChangedEvent(station, level)); + RaiseLocalEvent(new AlertLevelChangedEvent(EntityUid.Invalid, level)); // Frontier: pass invalid, we have no station } } diff --git a/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs b/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs index 405500442f7..e8648b12152 100644 --- a/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs +++ b/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs @@ -1,4 +1,5 @@ using System.Linq; +using Content.Server._NF.SectorServices; using Content.Server.Administration; using Content.Server.Station.Systems; using Content.Shared.Administration; @@ -21,11 +22,14 @@ public override CompletionResult GetCompletion(IConsoleShell shell, string[] arg var player = shell.Player; if (player?.AttachedEntity != null) { - var stationUid = _entitySystems.GetEntitySystem().GetOwningStation(player.AttachedEntity.Value); - if (stationUid != null) - { - levelNames = GetStationLevelNames(stationUid.Value); - } + // Frontier: sector-wide alerts + levelNames = GetSectorLevelNames(); + // var stationUid = _entitySystems.GetEntitySystem().GetOwningStation(player.AttachedEntity.Value); + // if (stationUid != null) + // { + // levelNames = GetStationLevelNames(stationUid.Value); + // } + // End Frontier } return args.Length switch @@ -68,7 +72,7 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) } var level = args[0]; - var levelNames = GetStationLevelNames(stationUid.Value); + var levelNames = GetSectorLevelNames(); if (!levelNames.Contains(level)) { shell.WriteLine(LocalizationManager.GetString("cmd-setalertlevel-invalid-level")); @@ -78,10 +82,12 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args) _entitySystems.GetEntitySystem().SetLevel(stationUid.Value, level, true, true, true, locked); } - private string[] GetStationLevelNames(EntityUid station) + // Frontier: sector-wide alert level names + private string[] GetSectorLevelNames() { + var sectorServiceUid = _entitySystems.GetEntitySystem().GetServiceEntity(); var entityManager = IoCManager.Resolve(); - if (!entityManager.TryGetComponent(station, out var alertLevelComp)) + if (!entityManager.TryGetComponent(sectorServiceUid, out var alertLevelComp)) return new string[]{}; if (alertLevelComp.AlertLevels == null) @@ -89,5 +95,6 @@ private string[] GetStationLevelNames(EntityUid station) return alertLevelComp.AlertLevels.Levels.Keys.ToArray(); } + // End Frontier } } diff --git a/Content.Server/Communications/CommunicationsConsoleSystem.cs b/Content.Server/Communications/CommunicationsConsoleSystem.cs index 6c320edb23c..09c12e58703 100644 --- a/Content.Server/Communications/CommunicationsConsoleSystem.cs +++ b/Content.Server/Communications/CommunicationsConsoleSystem.cs @@ -21,6 +21,7 @@ using Content.Shared.Popups; using Robust.Server.GameObjects; using Robust.Shared.Configuration; +using Content.Server._NF.SectorServices; // Frontier namespace Content.Server.Communications { @@ -37,6 +38,7 @@ public sealed class CommunicationsConsoleSystem : EntitySystem [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly SectorServiceSystem _sectorService = default!; // Frontier: sector-wide alerts private const float UIUpdateInterval = 5.0f; @@ -110,9 +112,9 @@ private void OnAlertLevelChanged(AlertLevelChangedEvent args) var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var comp)) { - var entStation = _stationSystem.GetOwningStation(uid); - if (args.Station == entStation) - UpdateCommsConsoleInterface(uid, comp); + // var entStation = _stationSystem.GetOwningStation(uid); // Frontier: sector-wide alerts + // if (args.Station == entStation) // Frontier: sector-wide alerts + UpdateCommsConsoleInterface(uid, comp); } } @@ -133,14 +135,15 @@ public void UpdateCommsConsoleInterface() /// public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComponent comp) { - var stationUid = _stationSystem.GetOwningStation(uid); + //var stationUid = _stationSystem.GetOwningStation(uid); // Frontier: sector-wide alerts + var stationUid = _sectorService.GetServiceEntity(); // Frontier: sector-wide alerts List? levels = null; string currentLevel = default!; float currentDelay = 0; - if (stationUid != null) + if (stationUid.Valid) // Frontier: != null < .Valid { - if (TryComp(stationUid.Value, out AlertLevelComponent? alertComp) && + if (TryComp(stationUid, out AlertLevelComponent? alertComp) && // Frontier: stationUid.Value(_station.GetOwningStation(uid), out var alerts)) + // Frontier: sector-wide alerts + if (!TryComp(_sectorService.GetServiceEntity(), out var alerts)) return; + // End Frontier: sector-wide alerts if (alerts.AlertLevels == null) return; @@ -94,8 +98,12 @@ private void OnEmergencyLightEvent(EntityUid uid, EmergencyLightComponent compon private void OnAlertLevelChanged(AlertLevelChangedEvent ev) { - if (!TryComp(ev.Station, out var alert)) + // Frontier: sector-wide alerts + // if (!TryComp(ev.Station, out var alert)) + // return; + if (!TryComp(_sectorService.GetServiceEntity(), out var alert)) return; + // End Frontier if (alert.AlertLevels == null || !alert.AlertLevels.Levels.TryGetValue(ev.AlertLevel, out var details)) return; @@ -103,8 +111,8 @@ private void OnAlertLevelChanged(AlertLevelChangedEvent ev) var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var light, out var pointLight, out var appearance, out var xform)) { - if (CompOrNull(xform.GridUid)?.Station != ev.Station) - continue; + // if (CompOrNull(xform.GridUid)?.Station != ev.Station) // Frontier: sector-wide alerts + // continue; // Frontier: sector-wide alerts _pointLight.SetColor(uid, details.EmergencyLightColor, pointLight); _appearance.SetData(uid, EmergencyLightVisuals.Color, details.EmergencyLightColor, appearance); diff --git a/Content.Server/PDA/PdaSystem.cs b/Content.Server/PDA/PdaSystem.cs index 09e0fb0c073..4e77fccef94 100644 --- a/Content.Server/PDA/PdaSystem.cs +++ b/Content.Server/PDA/PdaSystem.cs @@ -25,6 +25,7 @@ using Content.Shared.Bank.Components; // Frontier using Content.Shared.Shipyard.Components; // Frontier using Content.Server.Shipyard.Systems; // Frontier +using Content.Server._NF.SectorServices; // Frontier namespace Content.Server.PDA { @@ -39,6 +40,7 @@ public sealed class PdaSystem : SharedPdaSystem [Dependency] private readonly UserInterfaceSystem _ui = default!; [Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!; [Dependency] private readonly ContainerSystem _containerSystem = default!; + [Dependency] private readonly SectorServiceSystem _sectorService = default!; public override void Initialize() { @@ -295,7 +297,8 @@ private void UpdateStationName(EntityUid uid, PdaComponent pda) private void UpdateAlertLevel(EntityUid uid, PdaComponent pda) { - var station = _station.GetOwningStation(uid); + //var station = _station.GetOwningStation(uid); // Frontier + var station = _sectorService.GetServiceEntity(); // Frontier if (!TryComp(station, out AlertLevelComponent? alertComp) || alertComp.AlertLevels == null) return; diff --git a/Content.Server/RoundEnd/RoundEndSystem.cs b/Content.Server/RoundEnd/RoundEndSystem.cs index bb5934f3f08..53433f523db 100644 --- a/Content.Server/RoundEnd/RoundEndSystem.cs +++ b/Content.Server/RoundEnd/RoundEndSystem.cs @@ -22,6 +22,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Timing; using Timer = Robust.Shared.Timing.Timer; +using Content.Server._NF.SectorServices; // Frontier namespace Content.Server.RoundEnd { @@ -42,6 +43,7 @@ public sealed class RoundEndSystem : EntitySystem [Dependency] private readonly EmergencyShuttleSystem _shuttle = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly StationSystem _stationSystem = default!; + [Dependency] private readonly SectorServiceSystem _sectorService = default!; // Frontier: sector-wide alerts public TimeSpan DefaultCooldownDuration { get; set; } = TimeSpan.FromSeconds(30); @@ -131,7 +133,8 @@ public void RequestRoundEnd(EntityUid? requester = null, bool checkCooldown = tr if (requester != null) { - var stationUid = _stationSystem.GetOwningStation(requester.Value); + var stationUid = _sectorService.GetServiceEntity(); // Frontier: sector-wide alerts + // var stationUid = _stationSystem.GetOwningStation(requester.Value); // Frontier: sector-wide alerts if (TryComp(stationUid, out var alertLevel)) { duration = _protoManager diff --git a/Content.Server/StationEvents/Events/AlertLevelInterceptionRule.cs b/Content.Server/StationEvents/Events/AlertLevelInterceptionRule.cs index 916d7d16883..150517374a2 100644 --- a/Content.Server/StationEvents/Events/AlertLevelInterceptionRule.cs +++ b/Content.Server/StationEvents/Events/AlertLevelInterceptionRule.cs @@ -15,6 +15,7 @@ protected override void Started(EntityUid uid, AlertLevelInterceptionRuleCompone if (!TryGetRandomStation(out var chosenStation)) return; + // Frontier - note: levels are globally set/gotten, regardless of arg if (_alertLevelSystem.GetLevel(chosenStation.Value) != "green") return; diff --git a/Resources/Locale/en-US/alert-levels/alert-level-command.ftl b/Resources/Locale/en-US/alert-levels/alert-level-command.ftl index dda4c0cbc64..c0d9c463935 100644 --- a/Resources/Locale/en-US/alert-levels/alert-level-command.ftl +++ b/Resources/Locale/en-US/alert-levels/alert-level-command.ftl @@ -1,4 +1,5 @@ -cmd-setalertlevel-desc = Set current station alert level for grid on which the player is standing. +# Frontier: station [locked] cmd-setalertlevel-invalid-grid = You must be on grid of station code that you are going to change. cmd-setalertlevel-invalid-level = Specified alert level does not exist on that grid. diff --git a/Resources/Locale/en-US/alert-levels/alert-levels.ftl b/Resources/Locale/en-US/alert-levels/alert-levels.ftl index 9476a95a209..a290b59194a 100644 --- a/Resources/Locale/en-US/alert-levels/alert-levels.ftl +++ b/Resources/Locale/en-US/alert-levels/alert-levels.ftl @@ -1,36 +1,57 @@ -alert-level-announcement = Attention! Station alert level is now {$name}! {$announcement} +# Frontier: Station