Files
Delta-v/Content.Server/StationEvents/RampingStationEventSchedulerSystem.cs
T
SolStar d5716a8d41 New psionic ablility: Precognition (#2131)
* TESTING enable events for dev enviroment

* Add NextEventComponent

* Check for schedulers NextEventComponent

* Seperate gernateing event to its own method

* Add NextEventSystem and use in BasicStationEventSchedulerSystem

* TESTING: Override time and player restrictions

* Stash events in NextEventComponent (#1)

* Add NextEventComponent

* Check for schedulers NextEventComponent

* Seperate gernateing event to its own method

* Add NextEventSystem and use in BasicStationEventSchedulerSystem

* Format code

* Add nextEvent time perdiction

* Use RunTime instead of float minutes

* Bug fixes

* Add NextEvent to Ramping and Meteors

* Fix timing on BasticStationEvents

* initialize NextEventComponent when created

* Event scheduler caching (#2)

* Check for schedulers NextEventComponent

* Seperate gernateing event to its own method

* Add NextEventSystem and use in BasicStationEventSchedulerSystem

* Format code

* Add nextEvent time perdiction

* Use RunTime instead of float minutes

* Bug fixes

* Add NextEvent to Ramping and Meteors

* Fix timing on BasticStationEvents

* initialize NextEventComponent when created

---------

Signed-off-by: SolStar <44028047+ewokswagger@users.noreply.github.com>

* Revert "Event scheduler caching (#2)"

This reverts commit bf9cd26ed4.

* Revert "Merge branch 'seer' into stash-next-event"

This reverts commit 656ca26173, reversing
changes made to 36f45be10e.

* Revert "Caching next exent"

This reverts commit 9f1bee4131, reversing
changes made to 82678d9c18.

* Reapply "Event scheduler caching (#2)"

This reverts commit 82678d9c18.

* More merge conflict nonsence

* oops

* oops 2

* Oops 3

* Precognition Psionic ability (#3)

* Precognition ability added

* Precog get next event

* Get soonest event and display

* update prototypes with precog results

* Add random

* Use Timespan for UseDelay

* Damage breaks doafter

* typo

* fix localization

* fix do after

* Add effects durring do after

* Revert "TESTING enable events for dev enviroment"

This reverts commit 03453133bd.

* Revert testing changes

* add deltav comments

* Cleaning up!

* Move NextEvent to server space

* Fix NextEventId init value

* Reverted upstream file to block scoped namespace

* Add precognitnon result messages

* reverting testing changes for real

* Add admin alert for upcoming events

* Add sound effect

* make alert more subtule

* extended max window size

* fix message mixup

* yaml fixes

* more yaml fixes

* Delta Changes

* totaly a yaml error trust

* remove unsessesary weights

---------

Signed-off-by: SolStar <44028047+ewokswagger@users.noreply.github.com>
2024-12-19 03:55:15 +00:00

109 lines
5.2 KiB
C#

using Content.Server.Chat.Managers; // DeltaV
using Content.Server.DeltaV.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 IGameTiming _timing = default!; // DeltaV
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EventManagerSystem _event = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly NextEventSystem _next = default!; // 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);
// 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;
component.StartingChaos = component.MaxChaos / 10;
PickNextEventTime(uid, component);
// DeltaV - end init NextEventComp
if (TryComp<NextEventComponent>(uid, out var nextEventComponent)
&& _event.TryGenerateRandomEvent(component.ScheduledGameRules, out string? firstEvent, TimeSpan.FromSeconds(component.TimeUntilNextEvent))
&& firstEvent != null)
{
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-run-event-delayed", ("eventName", firstEvent), ("seconds", (int)component.TimeUntilNextEvent)));
_next.UpdateNextEvent(nextEventComponent, firstEvent, TimeSpan.FromSeconds(component.TimeUntilNextEvent));
}
// DeltaV - end 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;
}
// DeltaV 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 = _timing.CurTime + TimeSpan.FromSeconds(scheduler.TimeUntilNextEvent);
if (!_event.TryGenerateRandomEvent(scheduler.ScheduledGameRules, out string? generatedEvent, nextEventTime) || generatedEvent == null)
continue;
_chatManager.SendAdminAlert(Loc.GetString("station-event-system-run-event-delayed", ("eventName", generatedEvent), ("seconds", (int)scheduler.TimeUntilNextEvent)));
// 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;
}
// DeltaV end 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)
{
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);
}
}