]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow advertisement timers to prewarm (#26900)
authorTayrtahn <tayrtahn@gmail.com>
Fri, 12 Apr 2024 06:42:20 +0000 (02:42 -0400)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2024 06:42:20 +0000 (16:42 +1000)
Allow advertisement timers to prewarm.

Content.Server/Advertise/Components/AdvertiseComponent.cs
Content.Server/Advertise/EntitySystems/AdvertiseSystem.cs

index 531b31031d279af7a215af5030053f43bf756081..3d617e3a340e65deb9515f5a1d506b5c2d307b6e 100644 (file)
@@ -24,6 +24,14 @@ public sealed partial class AdvertiseComponent : Component
     [DataField]
     public int MaximumWait { get; private set; } = 10 * 60;
 
+    /// <summary>
+    /// If true, the delay before the first advertisement (at MapInit) will ignore <see cref="MinimumWait"/>
+    /// and instead be rolled between 0 and <see cref="MaximumWait"/>. This only applies to the initial delay;
+    /// <see cref="MinimumWait"/> will be respected after that.
+    /// </summary>
+    [DataField]
+    public bool Prewarm = true;
+
     /// <summary>
     /// The identifier for the advertisements pack prototype.
     /// </summary>
index 12eac72cfe3d2d8d9f01f30ea1a4fdf38538826a..28fa01628f43d0648dfcadb12b08261efe64904a 100644 (file)
@@ -37,13 +37,14 @@ public sealed class AdvertiseSystem : EntitySystem
 
     private void OnMapInit(EntityUid uid, AdvertiseComponent advert, MapInitEvent args)
     {
-        RandomizeNextAdvertTime(advert);
+        var prewarm = advert.Prewarm;
+        RandomizeNextAdvertTime(advert, prewarm);
         _nextCheckTime = MathHelper.Min(advert.NextAdvertisementTime, _nextCheckTime);
     }
 
-    private void RandomizeNextAdvertTime(AdvertiseComponent advert)
+    private void RandomizeNextAdvertTime(AdvertiseComponent advert, bool prewarm = false)
     {
-        var minDuration = Math.Max(1, advert.MinimumWait);
+        var minDuration = prewarm ? 0 : Math.Max(1, advert.MinimumWait);
         var maxDuration = Math.Max(minDuration, advert.MaximumWait);
         var waitDuration = TimeSpan.FromSeconds(_random.Next(minDuration, maxDuration));