Allow advertisement timers to prewarm (#26900)
Allow advertisement timers to prewarm. (cherry picked from commit 264bf7199d805bd07dbdccc4345c672b19df9333)
This commit is contained in:
parent
a8e64a0467
commit
2307d18579
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue