2024-06-14 23:38:43 -04:00
|
|
|
using Content.Server.GameTicking.Rules;
|
|
|
|
|
using Content.Server.StationEvents.Components;
|
2024-06-15 16:03:20 +02:00
|
|
|
using Content.Shared.CCVar;
|
2024-06-14 23:38:43 -04:00
|
|
|
using Content.Shared.GameTicking.Components;
|
|
|
|
|
using Content.Shared.Random.Helpers;
|
2024-06-15 16:03:20 +02:00
|
|
|
using Robust.Shared.Configuration;
|
2024-06-14 23:38:43 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.StationEvents;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This handles scheduling and launching meteors at a station at regular intervals.
|
|
|
|
|
/// TODO: there is 100% a world in which this is genericized and can be used for lots of basic event scheduling
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class MeteorSchedulerSystem : GameRuleSystem<MeteorSchedulerComponent>
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2024-06-15 16:03:20 +02:00
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
|
|
|
|
|
|
private TimeSpan _meteorMinDelay;
|
|
|
|
|
private TimeSpan _meteorMaxDelay;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
_cfg.OnValueChanged(CCVars.MeteorSwarmMinTime, f => { _meteorMinDelay = TimeSpan.FromMinutes(f); }, true);
|
|
|
|
|
_cfg.OnValueChanged(CCVars.MeteorSwarmMaxTime, f => { _meteorMaxDelay = TimeSpan.FromMinutes(f); }, true);
|
|
|
|
|
}
|
2024-06-14 23:38:43 -04:00
|
|
|
|
|
|
|
|
protected override void Started(EntityUid uid, MeteorSchedulerComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
|
|
|
{
|
|
|
|
|
base.Started(uid, component, gameRule, args);
|
|
|
|
|
|
2024-06-15 16:03:20 +02:00
|
|
|
component.NextSwarmTime = Timing.CurTime + RobustRandom.Next(_meteorMinDelay, _meteorMaxDelay);
|
2024-06-14 23:38:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ActiveTick(EntityUid uid, MeteorSchedulerComponent component, GameRuleComponent gameRule, float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.ActiveTick(uid, component, gameRule, frameTime);
|
|
|
|
|
|
|
|
|
|
if (Timing.CurTime < component.NextSwarmTime)
|
|
|
|
|
return;
|
|
|
|
|
RunSwarm((uid, component));
|
2024-06-15 16:03:20 +02:00
|
|
|
|
|
|
|
|
component.NextSwarmTime += RobustRandom.Next(_meteorMinDelay, _meteorMaxDelay);
|
2024-06-14 23:38:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RunSwarm(Entity<MeteorSchedulerComponent> ent)
|
|
|
|
|
{
|
|
|
|
|
var swarmWeights = _prototypeManager.Index(ent.Comp.Config);
|
|
|
|
|
GameTicker.StartGameRule(swarmWeights.Pick(RobustRandom));
|
|
|
|
|
}
|
|
|
|
|
}
|