Files
crystall-punk-14/Content.Server/StationEvents/RampingStationEventSchedulerSystem.cs

76 lines
2.9 KiB
C#
Raw Permalink Normal View History

using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
2023-04-25 20:23:14 -04:00
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using Robust.Shared.Random;
namespace Content.Server.StationEvents;
2023-04-25 20:23:14 -04:00
public sealed class RampingStationEventSchedulerSystem : GameRuleSystem<RampingStationEventSchedulerComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EventManagerSystem _event = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
/// <summary>
/// Returns the ChaosModifier which increases as round time increases to a point.
/// </summary>
2023-04-25 20:23:14 -04:00
public float GetChaosModifier(EntityUid uid, RampingStationEventSchedulerComponent component)
{
2023-04-25 20:23:14 -04:00
var roundTime = (float) _gameTicker.RoundDuration().TotalSeconds;
if (roundTime > component.EndTime)
return component.MaxChaos;
2023-04-25 20:23:14 -04:00
return component.MaxChaos / component.EndTime * roundTime + component.StartingChaos;
}
2023-04-25 20:23:14 -04:00
protected override void Started(EntityUid uid, RampingStationEventSchedulerComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
2023-04-25 20:23:14 -04:00
base.Started(uid, component, gameRule, args);
// Worlds shittiest probability distribution
// Got a complaint? Send them to
component.MaxChaos = _random.NextFloat(component.AverageChaos - component.AverageChaos / 4, component.AverageChaos + component.AverageChaos / 4);
// This is in minutes, so *60 for seconds (for the chaos calc)
component.EndTime = _random.NextFloat(component.AverageEndTime - component.AverageEndTime / 4, component.AverageEndTime + component.AverageEndTime / 4) * 60f;
2023-04-25 20:23:14 -04:00
component.StartingChaos = component.MaxChaos / 10;
2023-04-25 20:23:14 -04:00
PickNextEventTime(uid, component);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
2023-04-25 20:23:14 -04:00
if (!_event.EventsEnabled)
return;
2023-04-25 20:23:14 -04:00
var query = EntityQueryEnumerator<RampingStationEventSchedulerComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var scheduler, out var gameRule))
{
2023-04-25 20:23:14 -04:00
if (!GameTicker.IsGameRuleActive(uid, gameRule))
continue;
2023-04-24 16:21:05 +10:00
2023-04-25 20:23:14 -04:00
if (scheduler.TimeUntilNextEvent > 0f)
{
scheduler.TimeUntilNextEvent -= frameTime;
continue;
2023-04-25 20:23:14 -04:00
}
PickNextEventTime(uid, scheduler);
_event.RunRandomEvent(scheduler.ScheduledGameRules);
2023-04-25 20:23:14 -04:00
}
}
/// <summary>
/// Sets the timing of the next event addition.
/// </summary>
2023-04-25 20:23:14 -04:00
private void PickNextEventTime(EntityUid uid, RampingStationEventSchedulerComponent component)
{
2023-04-25 20:23:14 -04:00
var mod = GetChaosModifier(uid, component);
// 4-12 minutes baseline. Will get faster over time as the chaos mod increases.
2023-04-25 20:23:14 -04:00
component.TimeUntilNextEvent = _random.NextFloat(240f / mod, 720f / mod);
}
}