basic station event commands (#20371)
* basic station event commands * ouagh
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user