diff --git a/Content.Server/StationEvents/BasicStationEventSchedulerSystem.cs b/Content.Server/StationEvents/BasicStationEventSchedulerSystem.cs index bc77a9ce47..36d30f50ee 100644 --- a/Content.Server/StationEvents/BasicStationEventSchedulerSystem.cs +++ b/Content.Server/StationEvents/BasicStationEventSchedulerSystem.cs @@ -1,8 +1,13 @@ +using System.Linq; +using Content.Server.Administration; using Content.Server.GameTicking.Rules; using Content.Server.GameTicking.Rules.Components; using Content.Server.StationEvents.Components; +using Content.Shared.Administration; using JetBrains.Annotations; using Robust.Shared.Random; +using Robust.Shared.Toolshed; +using Robust.Shared.Utility; namespace Content.Server.StationEvents { @@ -56,4 +61,54 @@ namespace Content.Server.StationEvents component.TimeUntilNextEvent = _random.Next(300, 1500); } } + + [ToolshedCommand, AdminCommand(AdminFlags.Debug)] + public sealed class StationEventCommand : ToolshedCommand + { + private EventManagerSystem? _stationEvent; + + [CommandImplementation("lsprob")] + public IEnumerable<(string, float)> LsProb() + { + _stationEvent ??= GetSys(); + var events = _stationEvent.AllEvents(); + + var totalWeight = events.Sum(x => x.Value.Weight); + + foreach (var (proto, comp) in events) + { + yield return (proto.ID, comp.Weight / totalWeight); + } + } + + [CommandImplementation("lsprobtime")] + public IEnumerable<(string, float)> LsProbTime([CommandArgument] float time) + { + _stationEvent ??= GetSys(); + var events = _stationEvent.AllEvents().Where(pair => pair.Value.EarliestStart <= time).ToList(); + + var totalWeight = events.Sum(x => x.Value.Weight); + + foreach (var (proto, comp) in events) + { + yield return (proto.ID, comp.Weight / totalWeight); + } + } + + [CommandImplementation("prob")] + public float Prob([CommandArgument] string eventId) + { + _stationEvent ??= GetSys(); + var events = _stationEvent.AllEvents(); + + var totalWeight = events.Sum(x => x.Value.Weight); + var weight = 0f; + if (events.TryFirstOrNull(p => p.Key.ID == eventId, out var pair)) + { + weight = pair.Value.Value.Weight; + } + + return weight / totalWeight; + } + } } diff --git a/Resources/Locale/en-US/commands/toolshed-commands.ftl b/Resources/Locale/en-US/commands/toolshed-commands.ftl index 9320dac917..29c8190d6e 100644 --- a/Resources/Locale/en-US/commands/toolshed-commands.ftl +++ b/Resources/Locale/en-US/commands/toolshed-commands.ftl @@ -40,6 +40,12 @@ command-description-stations-rename = Renames the given station. command-description-stations-largestgrid = Returns the largest grid the given station has, if any. +command-description-stationevent-lsprob = + Lists the probability of different station events occuring out of the entire pool. +command-description-stationevent-lsprobtime = + Lists the probability of different station events occuring based on the specified length of a round. +command-description-stationevent-prob = + Returns the probability of a single station event occuring out of the entire pool. command-description-admins-active = Returns a list of active admins. command-description-admins-all =