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 <ike709@github.com>
This commit is contained in:
@@ -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
|
||||
/// </summary>
|
||||
public bool Running { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time when this event last ran.
|
||||
/// </summary>
|
||||
public TimeSpan LastRun { get; set; } = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable name for the event.
|
||||
/// </summary>
|
||||
@@ -62,6 +68,11 @@ namespace Content.Server.StationEvents.Events
|
||||
/// </summary>
|
||||
public virtual int EarliestStart { get; } = 5;
|
||||
|
||||
/// <summary>
|
||||
/// In minutes, the amount of time before the same event can occur again
|
||||
/// </summary>
|
||||
public virtual int ReoccurrenceDelay { get; } = 30;
|
||||
|
||||
/// <summary>
|
||||
/// When in the lifetime to call Start().
|
||||
/// </summary>
|
||||
@@ -112,6 +123,7 @@ namespace Content.Server.StationEvents.Events
|
||||
{
|
||||
Started = true;
|
||||
Occurrences += 1;
|
||||
LastRun = EntitySystem.Get<GameTicker>().RoundDuration();
|
||||
|
||||
EntitySystem.Get<AdminLogSystem>()
|
||||
.Add(LogType.EventStarted, LogImpact.High, $"Event startup: {Name}");
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user