StationEvent Toolshed Command fixes. (#32200)

* toolshed makes me want to take a long walk off a short pier.

* fuck it everything is in seconds.

* catch rounding error

* reviews

* lsprobtheoretical to mins

* Git please.

* Git Please.

* GIT PLEASE.

* unchange file

* take2

* empty line?

* new new lines?

* idk 1000 commits I guess

* spacius maximus
This commit is contained in:
IProduceWidgets
2025-04-18 03:44:29 -04:00
committed by GitHub
parent 8d1cd9a3aa
commit 42cb3ccb5b
3 changed files with 41 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.TypeParsers;
using Robust.Shared.Utility;
namespace Content.Server.StationEvents
@@ -94,7 +95,7 @@ namespace Content.Server.StationEvents
/// to even exist) so I think it's fine.
/// </remarks>
[CommandImplementation("simulate")]
public IEnumerable<(string, float)> Simulate(EntityPrototype eventScheduler, int rounds, int playerCount, float roundEndMean, float roundEndStdDev)
public IEnumerable<(string, float)> Simulate([CommandArgument] Prototype<EntityPrototype> eventSchedulerProto, [CommandArgument] int rounds, [CommandArgument] int playerCount, [CommandArgument] float roundEndMean, [CommandArgument] float roundEndStdDev)
{
_stationEvent ??= GetSys<EventManagerSystem>();
_entityTable ??= GetSys<EntityTableSystem>();
@@ -108,6 +109,8 @@ namespace Content.Server.StationEvents
occurrences.Add(ev.Key.ID, 0);
}
eventSchedulerProto.Deconstruct(out EntityPrototype eventScheduler);
if (!eventScheduler.TryGetComponent<BasicStationEventSchedulerComponent>(out var basicScheduler, _compFac))
{
return occurrences.Select(p => (p.Key, (float)p.Value)).OrderByDescending(p => p.Item2);
@@ -118,7 +121,7 @@ namespace Content.Server.StationEvents
for (var i = 0; i < rounds; i++)
{
var curTime = TimeSpan.Zero;
var randomEndTime = _random.NextGaussian(roundEndMean, roundEndStdDev) * 60; // *60 = minutes to seconds
var randomEndTime = _random.NextGaussian(roundEndMean, roundEndStdDev); // Its in minutes, should probably be a better time format once we get that in toolshed like [hh:mm:ss]
if (randomEndTime <= 0)
continue;
@@ -127,14 +130,13 @@ namespace Content.Server.StationEvents
// sim an event
curTime += TimeSpan.FromSeconds(compMinMax.Next(_random));
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, out var selectedEvents))
var available = _stationEvent.AvailableEvents(false, playerCount, curTime);
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, available, out var selectedEvents))
{
continue; // doesnt break because maybe the time is preventing events being available.
}
var available = _stationEvent.AvailableEvents(false, playerCount, curTime);
var plausibleEvents = new Dictionary<EntityPrototype, StationEventComponent>(available.Intersect(selectedEvents)); // C# makes me sad
var ev = _stationEvent.FindEvent(plausibleEvents);
var ev = _stationEvent.FindEvent(selectedEvents);
if (ev == null)
continue;
@@ -146,15 +148,18 @@ namespace Content.Server.StationEvents
}
[CommandImplementation("lsprob")]
public IEnumerable<(string, float)> LsProb(EntityPrototype eventScheduler)
public IEnumerable<(string, float)> LsProb([CommandArgument] Prototype<EntityPrototype> eventSchedulerProto)
{
_compFac ??= IoCManager.Resolve<IComponentFactory>();
_stationEvent ??= GetSys<EventManagerSystem>();
eventSchedulerProto.Deconstruct(out EntityPrototype eventScheduler);
if (!eventScheduler.TryGetComponent<BasicStationEventSchedulerComponent>(out var basicScheduler, _compFac))
yield break;
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, out var events))
var available = _stationEvent.AvailableEvents();
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, available, out var events))
yield break;
var totalWeight = events.Sum(x => x.Value.Weight); // Well this shit definitely isnt correct now, and I see no way to make it correct.
@@ -165,19 +170,24 @@ namespace Content.Server.StationEvents
}
}
[CommandImplementation("lsprobtime")]
public IEnumerable<(string, float)> LsProbTime(EntityPrototype eventScheduler, float time)
[CommandImplementation("lsprobtheoretical")]
public IEnumerable<(string, float)> LsProbTime([CommandArgument] Prototype<EntityPrototype> eventSchedulerProto, [CommandArgument] int playerCount, [CommandArgument] float time)
{
_compFac ??= IoCManager.Resolve<IComponentFactory>();
_stationEvent ??= GetSys<EventManagerSystem>();
eventSchedulerProto.Deconstruct(out EntityPrototype eventScheduler);
if (!eventScheduler.TryGetComponent<BasicStationEventSchedulerComponent>(out var basicScheduler, _compFac))
yield break;
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, out var untimedEvents))
var timemins = time * 60;
var theoryTime = TimeSpan.Zero + TimeSpan.FromSeconds(timemins);
var available = _stationEvent.AvailableEvents(false, playerCount, theoryTime);
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, available, out var untimedEvents))
yield break;
var events = untimedEvents.Where(pair => pair.Value.EarliestStart <= time).ToList();
var events = untimedEvents.Where(pair => pair.Value.EarliestStart <= timemins).ToList();
var totalWeight = events.Sum(x => x.Value.Weight); // same subsetting issue as lsprob.
@@ -188,15 +198,18 @@ namespace Content.Server.StationEvents
}
[CommandImplementation("prob")]
public float Prob(EntityPrototype eventScheduler, string eventId)
public float Prob([CommandArgument] Prototype<EntityPrototype> eventSchedulerProto, [CommandArgument] string eventId)
{
_compFac ??= IoCManager.Resolve<IComponentFactory>();
_stationEvent ??= GetSys<EventManagerSystem>();
eventSchedulerProto.Deconstruct(out EntityPrototype eventScheduler);
if (!eventScheduler.TryGetComponent<BasicStationEventSchedulerComponent>(out var basicScheduler, _compFac))
return 0f;
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, out var events))
var available = _stationEvent.AvailableEvents();
if (!_stationEvent.TryBuildLimitedEvents(basicScheduler.ScheduledGameRules, available, out var events))
return 0f;
var totalWeight = events.Sum(x => x.Value.Weight); // same subsetting issue as lsprob.