From 7a3087609af5d387812b14f532e9f762d5529d93 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sun, 22 May 2022 20:01:54 -0500 Subject: [PATCH] Adds a reoccurrence delay to station events (#8359) * Adds a reoccurence delay to station events * typo * total minutes * Update Content.Server/StationEvents/Events/StationEvent.cs * Update Content.Server/StationEvents/Events/StationEvent.cs * reset Co-authored-by: ike709 --- Content.Server/StationEvents/Events/StationEvent.cs | 12 ++++++++++++ Content.Server/StationEvents/StationEventSystem.cs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/Content.Server/StationEvents/Events/StationEvent.cs b/Content.Server/StationEvents/Events/StationEvent.cs index bb93459883..e2960ccffc 100644 --- a/Content.Server/StationEvents/Events/StationEvent.cs +++ b/Content.Server/StationEvents/Events/StationEvent.cs @@ -1,6 +1,7 @@ using Content.Server.Administration.Logs; using Content.Server.Atmos.EntitySystems; using Content.Server.Chat.Managers; +using Content.Server.GameTicking; using Content.Server.Station.Components; using Content.Server.Station.Systems; using Content.Shared.Database; @@ -25,6 +26,11 @@ namespace Content.Server.StationEvents.Events /// public bool Running { get; set; } + /// + /// The time when this event last ran. + /// + public TimeSpan LastRun { get; set; } = TimeSpan.Zero; + /// /// Human-readable name for the event. /// @@ -62,6 +68,11 @@ namespace Content.Server.StationEvents.Events /// public virtual int EarliestStart { get; } = 5; + /// + /// In minutes, the amount of time before the same event can occur again + /// + public virtual int ReoccurrenceDelay { get; } = 30; + /// /// When in the lifetime to call Start(). /// @@ -112,6 +123,7 @@ namespace Content.Server.StationEvents.Events { Started = true; Occurrences += 1; + LastRun = EntitySystem.Get().RoundDuration(); EntitySystem.Get() .Add(LogType.EventStarted, LogImpact.High, $"Event startup: {Name}"); diff --git a/Content.Server/StationEvents/StationEventSystem.cs b/Content.Server/StationEvents/StationEventSystem.cs index 1e8f4f3c4d..6a230ed248 100644 --- a/Content.Server/StationEvents/StationEventSystem.cs +++ b/Content.Server/StationEvents/StationEventSystem.cs @@ -352,6 +352,12 @@ namespace Content.Server.StationEvents return false; } + if (stationEvent.LastRun != TimeSpan.Zero && currentTime.TotalMinutes < + stationEvent.ReoccurrenceDelay + stationEvent.LastRun.TotalMinutes) + { + return false; + } + return true; } @@ -372,6 +378,7 @@ namespace Content.Server.StationEvents foreach (var stationEvent in _stationEvents) { stationEvent.Occurrences = 0; + stationEvent.LastRun = TimeSpan.Zero; } _timeUntilNextEvent = MinimumTimeUntilFirstEvent;