Files
Delta-v/Content.Server/StationEvents/RampingStationEventSchedulerSystem.cs
T
Vanessaandpre-commit-ci[bot] b2b08e698e Ramping Scheduler Fixes / Convert to Survival Fixes (#6416)
* Fixed nukie behavior check firing early

* Fixed ZombieOutbreak adding ramping schedulers

* RampingSchedulers now look at when they were added for keypoint times

* Xenoborgs no longer has a RampingScheduler roundstart.

* Added number of cuffed hands check

* Use GameRule activation time.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* silly compiler flag

* Apply suggestions from code review

Co-authored-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com>
Signed-off-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com>

* Fix other locale usages

* silly me

* PR feedback

---------

Signed-off-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-17 15:26:09 -05:00

150 lines
6.8 KiB
C#

using Content.Server.Chat.Managers; // DeltaV
using Content.Server._DV.StationEvents.NextEvent; // DeltaV
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using Robust.Shared.Random;
using Robust.Shared.Timing; // DeltaV
namespace Content.Server.StationEvents;
public sealed class RampingStationEventSchedulerSystem : GameRuleSystem<RampingStationEventSchedulerComponent>
{
[Dependency] private readonly IChatManager _chatManager = default!; // DeltaV
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EventManagerSystem _event = default!;
#if DEBUG // DeltaV - Only used if built by Debug
[Dependency] private readonly GameTicker _gameTicker = default!;
#endif
[Dependency] private readonly NextEventSystem _next = default!; // DeltaV
[Dependency] private readonly IGameTiming _timing = default!; // DeltaV
/* DeltaV
/// <summary>
/// Returns the ChaosModifier which increases as round time increases to a point.
/// </summary>
public float GetChaosModifier(EntityUid uid, RampingStationEventSchedulerComponent component)
{
var roundTime = (float) _gameTicker.RoundDuration().TotalSeconds;
if (roundTime > component.EndTime)
return component.MaxChaos;
return component.MaxChaos / component.EndTime * roundTime + component.StartingChaos;
}
*/
protected override void Started(EntityUid uid, RampingStationEventSchedulerComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
/* DeltaV
// Worlds shittiest probability distribution
// Got a complaint? Send them to
component.MaxChaos = _random.NextFloat(component.AverageChaos, component.AverageChaos + component.AverageChaos / 4); // DeltaV - Survival starts a bit faster but ends the same
// 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;
component.StartingChaos = component.MaxChaos / 10;
*/
PickNextEventTime(uid, component);
// Begin DeltaV Additions: init NextEventComp
if (TryComp<NextEventComponent>(uid, out var nextEventComponent)
&& _event.TryGenerateRandomEvent(component.ScheduledGameRules, TimeSpan.FromSeconds(component.TimeUntilNextEvent)) is {} firstEvent)
{
var nextEventTime = GameTicker.RoundDuration() + TimeSpan.FromSeconds(component.TimeUntilNextEvent);
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-run-event-delayed", ("eventName", firstEvent), ("time", nextEventTime.ToString(@"hh\:mm\:ss"))));
_next.UpdateNextEvent(nextEventComponent, firstEvent, GameTicker.RoundDuration() + TimeSpan.FromSeconds(component.TimeUntilNextEvent));
}
// End DeltaV Additions: init NextEventComp
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!_event.EventsEnabled)
return;
var query = EntityQueryEnumerator<RampingStationEventSchedulerComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var scheduler, out var gameRule))
{
if (!GameTicker.IsGameRuleActive(uid, gameRule))
continue;
if (scheduler.TimeUntilNextEvent > 0f)
{
scheduler.TimeUntilNextEvent -= frameTime;
continue;
}
// Begin DeltaV Additions: events using NextEventComponent
if (TryComp<NextEventComponent>(uid, out var nextEventComponent)) // If there is a nextEventComponent use the stashed event instead of running it directly.
{
PickNextEventTime(uid, scheduler);
var nextEventTime = GameTicker.RoundDuration() + TimeSpan.FromSeconds(scheduler.TimeUntilNextEvent);
if (_event.TryGenerateRandomEvent(scheduler.ScheduledGameRules, nextEventTime) is not {} generatedEvent)
continue;
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-run-event-delayed", ("eventName", generatedEvent), ("time", nextEventTime.ToString(@"hh\:mm\:ss"))));
// Cycle the stashed event with the new generated event and time.
string? storedEvent = _next.UpdateNextEvent(nextEventComponent, generatedEvent, nextEventTime);
if (string.IsNullOrEmpty(storedEvent)) //If there was no stored event don't try to run it.
continue;
GameTicker.AddGameRule(storedEvent);
continue;
}
// End DeltaV Additions: events using NextEventComponent
PickNextEventTime(uid, scheduler);
_event.RunRandomEvent(scheduler.ScheduledGameRules);
}
}
/// <summary>
/// Sets the timing of the next event addition.
/// </summary>
private void PickNextEventTime(EntityUid uid, RampingStationEventSchedulerComponent component)
{
/* DeltaV
var mod = GetChaosModifier(uid, component);
// 4-12 minutes baseline. Will get faster over time as the chaos mod increases.
component.TimeUntilNextEvent = _random.NextFloat(240f / mod, 720f / mod);
*/
// Begin DeltaV Additions
var averageTimeUntilNextEvent = component.TimeKeyPoints[0].Y;
var timeUntilNextEventDeviation = _random.NextFloat(-1f, 1f) * component.TimeDeviation;
var ruleActivated = TimeSpan.FromSeconds(0);
if (TryComp<GameRuleComponent>(uid, out var gameRule))
{
ruleActivated = gameRule.ActivatedAt;
}
var ruleTime = _timing.CurTime.Subtract(ruleActivated);
#if DEBUG
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-debug-round-time", ("time", _gameTicker.RoundDuration())));
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-debug-ramping-time", ("time", ruleActivated)));
// This will be what the keypoint system looks at to determine where to start ramping
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-debug-keypoint-time", ("time", ruleTime)));
_chatManager.SendAdminAlert("_______________"); // Easier to read
#endif
var absoluteTimePoint = 0f;
foreach (var point in component.TimeKeyPoints)
{
absoluteTimePoint += point.X;
if (ruleTime.TotalMinutes >= absoluteTimePoint)
averageTimeUntilNextEvent = point.Y;
}
component.TimeUntilNextEvent = (averageTimeUntilNextEvent + timeUntilNextEventDeviation) * 60;
// End DeltaV Additions
}
}