From 1fc7c72b225d2ae469d301bd142cff30f9cf3bae Mon Sep 17 00:00:00 2001 From: Morbo <14136326+Morb0@users.noreply.github.com> Date: Sun, 29 May 2022 07:36:50 +0300 Subject: [PATCH] Set alert level command (#8507) * Add force mode for setting alert level * Add console command for changing alert level * Filename typo * Return delta disableSelection property * Make locked a component property * Not lock green level after nuke disarm --- .../AlertLevel/AlertLevelComponent.cs | 7 ++- .../AlertLevel/AlertLevelPrototype.cs | 2 +- Content.Server/AlertLevel/AlertLevelSystem.cs | 7 ++- .../Commands/SetAlertLevelCommand.cs | 60 +++++++++++++++++++ Content.Server/Nuke/NukeSystem.cs | 2 +- 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs diff --git a/Content.Server/AlertLevel/AlertLevelComponent.cs b/Content.Server/AlertLevel/AlertLevelComponent.cs index 4a9c32d4a3..6bb703e886 100644 --- a/Content.Server/AlertLevel/AlertLevelComponent.cs +++ b/Content.Server/AlertLevel/AlertLevelComponent.cs @@ -22,6 +22,11 @@ public sealed class AlertLevelComponent : Component /// [ViewVariables(VVAccess.ReadWrite)] public string CurrentLevel = string.Empty; + /// + /// Is current station level can be changed by crew. + /// + [ViewVariables(VVAccess.ReadWrite)] public bool IsLevelLocked = false; + [ViewVariables] public const float Delay = 300; [ViewVariables] public float CurrentDelay = 0; [ViewVariables] public bool ActiveDelay; @@ -40,7 +45,7 @@ public sealed class AlertLevelComponent : Component return false; } - return level.Selectable && !level.DisableSelection; + return level.Selectable && !level.DisableSelection && !IsLevelLocked; } } } diff --git a/Content.Server/AlertLevel/AlertLevelPrototype.cs b/Content.Server/AlertLevel/AlertLevelPrototype.cs index b74e64013b..bfb2b5d6bb 100644 --- a/Content.Server/AlertLevel/AlertLevelPrototype.cs +++ b/Content.Server/AlertLevel/AlertLevelPrototype.cs @@ -20,7 +20,7 @@ public sealed class AlertLevelPrototype : IPrototype /// Default level that the station is on upon initialization. /// If this isn't in the dictionary, this will default to whatever .First() gives. /// - [DataField("defaultLevel")] public string DefaultLevel { get; }= default!; + [DataField("defaultLevel")] public string DefaultLevel { get; } = default!; } /// diff --git a/Content.Server/AlertLevel/AlertLevelSystem.cs b/Content.Server/AlertLevel/AlertLevelSystem.cs index 5000f96ba3..026c5de86d 100644 --- a/Content.Server/AlertLevel/AlertLevelSystem.cs +++ b/Content.Server/AlertLevel/AlertLevelSystem.cs @@ -85,8 +85,9 @@ public sealed class AlertLevelSystem : EntitySystem /// Play the alert level's sound. /// Say the alert level's announcement. /// Force the alert change. This applies if the alert level is not selectable or not. + /// Will it be possible to change level by crew. public void SetLevel(EntityUid station, string level, bool playSound, bool announce, bool force = false, - MetaDataComponent? dataComponent = null, AlertLevelComponent? component = null) + bool locked = false, MetaDataComponent? dataComponent = null, AlertLevelComponent? component = null) { if (!Resolve(station, ref component, ref dataComponent) || component.AlertLevels == null @@ -99,7 +100,8 @@ public sealed class AlertLevelSystem : EntitySystem if (!force) { if (!detail.Selectable - || component.CurrentDelay > 0) + || component.CurrentDelay > 0 + || component.IsLevelLocked) { return; } @@ -109,6 +111,7 @@ public sealed class AlertLevelSystem : EntitySystem } component.CurrentLevel = level; + component.IsLevelLocked = locked; var stationName = dataComponent.EntityName; diff --git a/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs b/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs new file mode 100644 index 0000000000..a1594c9612 --- /dev/null +++ b/Content.Server/AlertLevel/Commands/SetAlertLevelCommand.cs @@ -0,0 +1,60 @@ +using Content.Server.Administration; +using Content.Server.AlertLevel; +using Content.Server.Players; +using Content.Server.Station.Systems; +using Content.Shared.Administration; +using JetBrains.Annotations; +using Robust.Server.Player; +using Robust.Shared.Console; + +namespace Content.Server.AlertLevel.Commands +{ + [UsedImplicitly] + [AdminCommand(AdminFlags.Fun)] + public sealed class SetAlertLevelCommand : IConsoleCommand + { + public string Command => "setalertlevel"; + public string Description => "Set current station alert level."; + public string Help => "setalertlevel [locked]"; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length < 1) + { + shell.WriteError("Incorrect number of arguments. " + Help); + return; + } + + var locked = false; + if (args.Length > 1 && !bool.TryParse(args[1], out locked)) + { + shell.WriteLine("Invalid boolean flag"); + return; + } + + var player = shell.Player as IPlayerSession; + if (player == null) + { + shell.WriteLine("You cannot run this from the server or without an attached entity."); + return; + } + + var playerEntityUid = player.AttachedEntity; + if (playerEntityUid == null) + { + shell.WriteLine("You cannot run this from the server or without an attached entity."); + return; + } + + var stationUid = EntitySystem.Get().GetOwningStation(playerEntityUid.Value); + if (stationUid == null) + { + shell.WriteLine("You must be on grid of station code that you are going to change."); + return; + } + + var level = args[0]; + EntitySystem.Get().SetLevel(stationUid.Value, level, true, true, true, locked); + } + } +} diff --git a/Content.Server/Nuke/NukeSystem.cs b/Content.Server/Nuke/NukeSystem.cs index 7e62cda098..188c4c2e59 100644 --- a/Content.Server/Nuke/NukeSystem.cs +++ b/Content.Server/Nuke/NukeSystem.cs @@ -333,7 +333,7 @@ namespace Content.Server.Nuke // Otherwise, you could set every station to whatever AlertLevelOnActivate is. if (stationUid != null) { - _alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true); + _alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true); } // warn a crew