Files
tbd-station-14/Content.Server/StationEvents/StationEventCommand.cs
nuke b8fef91922 Random events no longer start while in lobby and round ending forces current event to end (#1782)
* Random events cannot run in lobby and round ending forces events to end.

* Thanks p4merge

* Get rid of unused

* Apply suggestions from code review

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
2020-08-19 08:54:10 +02:00

101 lines
3.6 KiB
C#

#nullable enable
using Content.Server.GameObjects.EntitySystems.StationEvents;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Localization;
namespace Content.Client.Commands
{
[UsedImplicitly]
public sealed class StationEventCommand : IClientCommand
{
public string Command => "events";
public string Description => "Provides admin control to station events";
public string Help => "events <list/pause/resume/stop/run <eventname/random>>\n" +
"list: return all event names that can be run\n " +
"pause: stop all random events from running\n" +
"resume: allow random events to run again\n" +
"run: start a particular event now; <eventname> is case-insensitive and not localized";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
if (args.Length == 0)
{
shell.SendText(player, "Need more args");
return;
}
if (args[0] == "list")
{
var resultText = "Random\n" + EntitySystem.Get<StationEventSystem>().GetEventNames();
shell.SendText(player, resultText);
return;
}
// Didn't use a "toggle" so it's explicit
if (args[0] == "pause")
{
var stationEventSystem = EntitySystem.Get<StationEventSystem>();
if (!stationEventSystem.Enabled)
{
shell.SendText(player, Loc.GetString("Station events are already paused"));
return;
}
else
{
stationEventSystem.Enabled = false;
shell.SendText(player, Loc.GetString("Station events paused"));
return;
}
}
if (args[0] == "resume")
{
var stationEventSystem = EntitySystem.Get<StationEventSystem>();
if (stationEventSystem.Enabled)
{
shell.SendText(player, Loc.GetString("Station events are already running"));
return;
}
else
{
stationEventSystem.Enabled = true;
shell.SendText(player, Loc.GetString("Station events resumed"));
return;
}
}
if (args[0] == "stop")
{
var resultText = EntitySystem.Get<StationEventSystem>().StopEvent();
shell.SendText(player, resultText);
return;
}
if (args[0] == "run" && args.Length == 2)
{
var eventName = args[1];
string resultText;
if (eventName == "random")
{
resultText = EntitySystem.Get<StationEventSystem>().RunRandomEvent();
}
else
{
resultText = EntitySystem.Get<StationEventSystem>().RunEvent(eventName);
}
shell.SendText(player, resultText);
return;
}
shell.SendText(player, Loc.GetString("Invalid events command"));
return;
}
}
}