]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
basic station event commands (#20371)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 24 Sep 2023 17:46:35 +0000 (13:46 -0400)
committerGitHub <noreply@github.com>
Sun, 24 Sep 2023 17:46:35 +0000 (12:46 -0500)
* basic station event commands

* ouagh

Content.Server/StationEvents/BasicStationEventSchedulerSystem.cs
Resources/Locale/en-US/commands/toolshed-commands.ftl

index bc77a9ce47129106d73cabe4f8f138529b4192d4..36d30f50eee6cd86a6db30eb1268bd8eb352292e 100644 (file)
@@ -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<EventManagerSystem>();
+            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<EventManagerSystem>();
+            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<EventManagerSystem>();
+            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;
+        }
+    }
 }
index 9320dac917dca3ac7b5dac23675f8ae580977a04..29c8190d6e258cbca65a98ebcb3f6ab701c837a5 100644 (file)
@@ -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 =