Add cooldown to shuttle calling (#3225)
This commit is contained in:
@@ -21,10 +21,15 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
public const float RestartRoundTime = 20f;
|
||||
|
||||
private CancellationTokenSource _roundEndCancellationTokenSource = new();
|
||||
private CancellationTokenSource _callCooldownEndedTokenSource = new();
|
||||
public bool IsRoundEndCountdownStarted { get; private set; }
|
||||
public TimeSpan RoundEndCountdownTime { get; set; } = TimeSpan.FromMinutes(4);
|
||||
public TimeSpan? ExpectedCountdownEnd = null;
|
||||
|
||||
public TimeSpan LastCallTime { get; private set; }
|
||||
|
||||
public TimeSpan CallCooldown { get; } = TimeSpan.FromSeconds(30);
|
||||
|
||||
public delegate void RoundEndCountdownStarted();
|
||||
public event RoundEndCountdownStarted OnRoundEndCountdownStarted;
|
||||
|
||||
@@ -34,12 +39,31 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
public delegate void RoundEndCountdownFinished();
|
||||
public event RoundEndCountdownFinished OnRoundEndCountdownFinished;
|
||||
|
||||
public delegate void CallCooldownEnded();
|
||||
public event CallCooldownEnded OnCallCooldownEnded;
|
||||
|
||||
void IResettingEntitySystem.Reset()
|
||||
{
|
||||
IsRoundEndCountdownStarted = false;
|
||||
_roundEndCancellationTokenSource.Cancel();
|
||||
_roundEndCancellationTokenSource = new CancellationTokenSource();
|
||||
_callCooldownEndedTokenSource.Cancel();
|
||||
_callCooldownEndedTokenSource = new CancellationTokenSource();
|
||||
ExpectedCountdownEnd = null;
|
||||
LastCallTime = default;
|
||||
}
|
||||
|
||||
public bool CanCall()
|
||||
{
|
||||
return _gameTiming.CurTime >= LastCallTime + CallCooldown;
|
||||
}
|
||||
|
||||
private void ActivateCooldown()
|
||||
{
|
||||
_callCooldownEndedTokenSource.Cancel();
|
||||
_callCooldownEndedTokenSource = new CancellationTokenSource();
|
||||
LastCallTime = _gameTiming.CurTime;
|
||||
Timer.Spawn(CallCooldown, () => OnCallCooldownEnded?.Invoke(), _callCooldownEndedTokenSource.Token);
|
||||
}
|
||||
|
||||
public void RequestRoundEnd()
|
||||
@@ -47,6 +71,11 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if (IsRoundEndCountdownStarted)
|
||||
return;
|
||||
|
||||
if (!CanCall())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsRoundEndCountdownStarted = true;
|
||||
|
||||
_chatManager.DispatchStationAnnouncement(Loc.GetString("An emergency shuttle has been sent. ETA: {0} minutes.", RoundEndCountdownTime.Minutes), Loc.GetString("Station"));
|
||||
@@ -55,6 +84,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
ExpectedCountdownEnd = _gameTiming.CurTime + RoundEndCountdownTime;
|
||||
Timer.Spawn(RoundEndCountdownTime, EndRound, _roundEndCancellationTokenSource.Token);
|
||||
|
||||
ActivateCooldown();
|
||||
|
||||
OnRoundEndCountdownStarted?.Invoke();
|
||||
}
|
||||
|
||||
@@ -63,6 +95,11 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if (!IsRoundEndCountdownStarted)
|
||||
return;
|
||||
|
||||
if (!CanCall())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsRoundEndCountdownStarted = false;
|
||||
|
||||
_chatManager.DispatchStationAnnouncement(Loc.GetString("The emergency shuttle has been recalled."), Loc.GetString("Station"));
|
||||
@@ -74,6 +111,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
ExpectedCountdownEnd = null;
|
||||
|
||||
ActivateCooldown();
|
||||
|
||||
OnRoundEndCountdownCancelled?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user