Skip to content

Commit

Permalink
basic station event commands (space-wizards#20371)
Browse files Browse the repository at this point in the history
* basic station event commands

* ouagh
  • Loading branch information
EmoGarbage404 authored Sep 24, 2023
1 parent 2be2890 commit d225bd3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Content.Server/StationEvents/BasicStationEventSchedulerSystem.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -56,4 +61,54 @@ private void ResetTimer(BasicStationEventSchedulerComponent component)
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;
}
}
}
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/commands/toolshed-commands.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit d225bd3

Please sign in to comment.