This reverts commit 03c56bf23e.
This commit is contained in:
@@ -17,12 +17,11 @@ using Timer = Robust.Shared.Timing.Timer;
|
|||||||
namespace Content.Server.Communications
|
namespace Content.Server.Communications
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class CommunicationsConsoleComponent : SharedCommunicationsConsoleComponent, IEntityEventSubscriber
|
public class CommunicationsConsoleComponent : SharedCommunicationsConsoleComponent
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
[Dependency] private readonly IEntityManager _entities = default!;
|
[Dependency] private readonly IEntityManager _entities = default!;
|
||||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
||||||
|
|
||||||
private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||||
|
|
||||||
@@ -43,7 +42,10 @@ namespace Content.Server.Communications
|
|||||||
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
_entityManager.EventBus.SubscribeEvent<RoundEndSystemChangedEvent>(EventSource.Local, this, (s) => UpdateBoundInterface());
|
RoundEndSystem.OnRoundEndCountdownStarted += UpdateBoundInterface;
|
||||||
|
RoundEndSystem.OnRoundEndCountdownCancelled += UpdateBoundInterface;
|
||||||
|
RoundEndSystem.OnRoundEndCountdownFinished += UpdateBoundInterface;
|
||||||
|
RoundEndSystem.OnCallCooldownEnded += UpdateBoundInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Startup()
|
protected override void Startup()
|
||||||
@@ -74,7 +76,9 @@ namespace Content.Server.Communications
|
|||||||
|
|
||||||
protected override void OnRemove()
|
protected override void OnRemove()
|
||||||
{
|
{
|
||||||
_entityManager.EventBus.UnsubscribeEvent<RoundEndSystemChangedEvent>(EventSource.Local, this);
|
RoundEndSystem.OnRoundEndCountdownStarted -= UpdateBoundInterface;
|
||||||
|
RoundEndSystem.OnRoundEndCountdownCancelled -= UpdateBoundInterface;
|
||||||
|
RoundEndSystem.OnRoundEndCountdownFinished -= UpdateBoundInterface;
|
||||||
base.OnRemove();
|
base.OnRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Server.Administration;
|
using Content.Server.Administration;
|
||||||
using Content.Server.RoundEnd;
|
using Content.Server.RoundEnd;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
namespace Content.Server.GameTicking.Commands
|
namespace Content.Server.GameTicking.Commands
|
||||||
{
|
{
|
||||||
@@ -12,7 +13,7 @@ namespace Content.Server.GameTicking.Commands
|
|||||||
{
|
{
|
||||||
public string Command => "restartround";
|
public string Command => "restartround";
|
||||||
public string Description => "Ends the current round and starts the countdown for the next lobby.";
|
public string Description => "Ends the current round and starts the countdown for the next lobby.";
|
||||||
public string Help => string.Empty;
|
public string Help => String.Empty;
|
||||||
|
|
||||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,60 +19,79 @@ namespace Content.Server.RoundEnd
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
[Dependency] private readonly GameTicker _gameTicker = default!;
|
|
||||||
|
|
||||||
[Dependency] private readonly AdminLogSystem _adminLog = default!;
|
[Dependency] private readonly AdminLogSystem _adminLog = default!;
|
||||||
|
|
||||||
|
public const float RestartRoundTime = 20f;
|
||||||
|
|
||||||
private readonly TimeSpan _cooldownDuration = TimeSpan.FromSeconds(30);
|
private CancellationTokenSource _roundEndCancellationTokenSource = new();
|
||||||
private readonly TimeSpan _countdownDuration = TimeSpan.FromMinutes(4);
|
private CancellationTokenSource _callCooldownEndedTokenSource = new();
|
||||||
private readonly TimeSpan _restartRoundDuration = TimeSpan.FromSeconds(20);
|
public bool IsRoundEndCountdownStarted { get; private set; }
|
||||||
|
public TimeSpan RoundEndCountdownTime { get; set; } = TimeSpan.FromMinutes(4);
|
||||||
|
public TimeSpan? ExpectedCountdownEnd = null;
|
||||||
|
|
||||||
private CancellationTokenSource? _countdownTokenSource = null;
|
public TimeSpan LastCallTime { get; private set; }
|
||||||
private CancellationTokenSource? _cooldownTokenSource = null;
|
|
||||||
public TimeSpan? ExpectedCountdownEnd { get; set; } = null;
|
public TimeSpan CallCooldown { get; } = TimeSpan.FromSeconds(30);
|
||||||
|
|
||||||
|
// TODO: Make these regular eventbus events...
|
||||||
|
public delegate void RoundEndCountdownStarted();
|
||||||
|
public event RoundEndCountdownStarted? OnRoundEndCountdownStarted;
|
||||||
|
|
||||||
|
public delegate void RoundEndCountdownCancelled();
|
||||||
|
public event RoundEndCountdownCancelled? OnRoundEndCountdownCancelled;
|
||||||
|
|
||||||
|
public delegate void RoundEndCountdownFinished();
|
||||||
|
public event RoundEndCountdownFinished? OnRoundEndCountdownFinished;
|
||||||
|
|
||||||
|
public delegate void CallCooldownEnded();
|
||||||
|
public event CallCooldownEnded? OnCallCooldownEnded;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Reset(RoundRestartCleanupEvent ev)
|
void Reset(RoundRestartCleanupEvent ev)
|
||||||
{
|
{
|
||||||
if (_countdownTokenSource != null)
|
IsRoundEndCountdownStarted = false;
|
||||||
{
|
_roundEndCancellationTokenSource.Cancel();
|
||||||
_countdownTokenSource.Cancel();
|
_roundEndCancellationTokenSource = new CancellationTokenSource();
|
||||||
_countdownTokenSource = null;
|
_callCooldownEndedTokenSource.Cancel();
|
||||||
}
|
_callCooldownEndedTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
if (_cooldownTokenSource != null)
|
|
||||||
{
|
|
||||||
_cooldownTokenSource.Cancel();
|
|
||||||
_cooldownTokenSource = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExpectedCountdownEnd = null;
|
ExpectedCountdownEnd = null;
|
||||||
|
LastCallTime = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanCall()
|
public bool CanCall()
|
||||||
{
|
{
|
||||||
return _cooldownTokenSource == null;
|
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(EntityUid? requester = null, bool checkCooldown = true)
|
public void RequestRoundEnd(EntityUid? requester = null, bool checkCooldown = true)
|
||||||
{
|
{
|
||||||
RequestRoundEnd(_countdownDuration, requester, checkCooldown);
|
RequestRoundEnd(RoundEndCountdownTime, requester, checkCooldown);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestRoundEnd(TimeSpan countdownTime, EntityUid? requester = null, bool checkCooldown = true)
|
public void RequestRoundEnd(TimeSpan countdownTime, EntityUid? requester = null, bool checkCooldown = true)
|
||||||
{
|
{
|
||||||
if (_gameTicker.RunLevel != GameRunLevel.InRound) return;
|
if (IsRoundEndCountdownStarted)
|
||||||
|
return;
|
||||||
|
|
||||||
if (checkCooldown && _cooldownTokenSource != null) return;
|
if (checkCooldown && !CanCall())
|
||||||
|
{
|
||||||
if (_countdownTokenSource != null) return;
|
return;
|
||||||
_countdownTokenSource = new();
|
}
|
||||||
|
|
||||||
if (requester != null)
|
if (requester != null)
|
||||||
{
|
{
|
||||||
@@ -83,25 +102,29 @@ namespace Content.Server.RoundEnd
|
|||||||
_adminLog.Add(LogType.ShuttleCalled, LogImpact.High, $"Shuttle called");
|
_adminLog.Add(LogType.ShuttleCalled, LogImpact.High, $"Shuttle called");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsRoundEndCountdownStarted = true;
|
||||||
|
|
||||||
_chatManager.DispatchStationAnnouncement(Loc.GetString("round-end-system-shuttle-called-announcement",("minutes", countdownTime.Minutes)), Loc.GetString("Station"), false);
|
_chatManager.DispatchStationAnnouncement(Loc.GetString("round-end-system-shuttle-called-announcement",("minutes", countdownTime.Minutes)), Loc.GetString("Station"), false);
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlecalled.ogg");
|
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlecalled.ogg");
|
||||||
|
|
||||||
ExpectedCountdownEnd = _gameTiming.CurTime + countdownTime;
|
ExpectedCountdownEnd = _gameTiming.CurTime + countdownTime;
|
||||||
Timer.Spawn(countdownTime, EndRound, _countdownTokenSource.Token);
|
Timer.Spawn(countdownTime, EndRound, _roundEndCancellationTokenSource.Token);
|
||||||
|
|
||||||
ActivateCooldown();
|
ActivateCooldown();
|
||||||
RaiseLocalEvent(RoundEndSystemChangedEvent.Default);
|
|
||||||
|
OnRoundEndCountdownStarted?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CancelRoundEndCountdown(EntityUid? requester = null, bool checkCooldown = true)
|
public void CancelRoundEndCountdown(EntityUid? requester = null, bool checkCooldown = true)
|
||||||
{
|
{
|
||||||
if (_gameTicker.RunLevel != GameRunLevel.InRound) return;
|
if (!IsRoundEndCountdownStarted)
|
||||||
if (checkCooldown && _cooldownTokenSource != null) return;
|
return;
|
||||||
|
|
||||||
if (_countdownTokenSource == null) return;
|
if (checkCooldown && !CanCall())
|
||||||
_countdownTokenSource.Cancel();
|
{
|
||||||
_countdownTokenSource = null;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (requester != null)
|
if (requester != null)
|
||||||
{
|
{
|
||||||
@@ -112,47 +135,31 @@ namespace Content.Server.RoundEnd
|
|||||||
_adminLog.Add(LogType.ShuttleRecalled, LogImpact.High, $"Shuttle recalled");
|
_adminLog.Add(LogType.ShuttleRecalled, LogImpact.High, $"Shuttle recalled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsRoundEndCountdownStarted = false;
|
||||||
|
|
||||||
_chatManager.DispatchStationAnnouncement(Loc.GetString("round-end-system-shuttle-recalled-announcement"), Loc.GetString("Station"), false);
|
_chatManager.DispatchStationAnnouncement(Loc.GetString("round-end-system-shuttle-recalled-announcement"), Loc.GetString("Station"), false);
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlerecalled.ogg");
|
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlerecalled.ogg");
|
||||||
|
|
||||||
|
_roundEndCancellationTokenSource.Cancel();
|
||||||
|
_roundEndCancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
ExpectedCountdownEnd = null;
|
ExpectedCountdownEnd = null;
|
||||||
|
|
||||||
ActivateCooldown();
|
ActivateCooldown();
|
||||||
RaiseLocalEvent(RoundEndSystemChangedEvent.Default);
|
|
||||||
|
OnRoundEndCountdownCancelled?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EndRound()
|
public void EndRound()
|
||||||
{
|
{
|
||||||
if (_gameTicker.RunLevel != GameRunLevel.InRound) return;
|
OnRoundEndCountdownFinished?.Invoke();
|
||||||
RaiseLocalEvent(RoundEndSystemChangedEvent.Default);
|
var gameTicker = Get<GameTicker>();
|
||||||
_gameTicker.EndRound();
|
gameTicker.EndRound();
|
||||||
_countdownTokenSource?.Cancel();
|
|
||||||
_countdownTokenSource = new();
|
|
||||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("round-end-system-round-restart-eta-announcement", ("seconds", _restartRoundDuration.Seconds)));
|
|
||||||
Timer.Spawn(_restartRoundDuration, AfterEndRoundRestart, _countdownTokenSource.Token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AfterEndRoundRestart()
|
_chatManager.DispatchServerAnnouncement(Loc.GetString("round-end-system-round-restart-eta-announcement", ("seconds", RestartRoundTime)));
|
||||||
{
|
|
||||||
if (_gameTicker.RunLevel != GameRunLevel.InRound) return;
|
|
||||||
_gameTicker.RestartRound();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ActivateCooldown()
|
Timer.Spawn(TimeSpan.FromSeconds(RestartRoundTime), () => gameTicker.RestartRound(), CancellationToken.None);
|
||||||
{
|
|
||||||
_cooldownTokenSource?.Cancel();
|
|
||||||
_cooldownTokenSource = new();
|
|
||||||
Timer.Spawn(_cooldownDuration, () =>
|
|
||||||
{
|
|
||||||
_cooldownTokenSource.Cancel();
|
|
||||||
_cooldownTokenSource = null;
|
|
||||||
RaiseLocalEvent(RoundEndSystemChangedEvent.Default);
|
|
||||||
}, _cooldownTokenSource.Token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RoundEndSystemChangedEvent : EntityEventArgs
|
|
||||||
{
|
|
||||||
public static RoundEndSystemChangedEvent Default { get; } = new();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user