2022-09-04 17:21:14 -07:00
|
|
|
using Content.Client.Gameplay;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Lobby;
|
|
|
|
|
using Content.Client.RoundEnd;
|
2020-10-14 22:45:53 +02:00
|
|
|
using Content.Shared.GameTicking;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.GameWindow;
|
2021-06-20 10:09:24 +02:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.State;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Utility;
|
2018-11-25 19:04:49 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.GameTicking.Managers
|
2018-11-25 19:04:49 +01:00
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ClientGameTicker : SharedGameTicker
|
2018-11-25 19:04:49 +01:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IStateManager _stateManager = default!;
|
2022-06-23 16:32:06 +07:00
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
|
2020-01-18 01:54:13 +01:00
|
|
|
[ViewVariables] private bool _initialized;
|
2023-09-11 09:42:41 +10:00
|
|
|
private Dictionary<NetEntity, Dictionary<string, uint?>> _jobsAvailable = new();
|
|
|
|
|
private Dictionary<NetEntity, string> _stationNames = new();
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2023-06-05 16:33:49 +12:00
|
|
|
/// <summary>
|
|
|
|
|
/// The current round-end window. Could be used to support re-opening the window after closing it.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private RoundEndSummaryWindow? _window;
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
[ViewVariables] public bool AreWeReady { get; private set; }
|
|
|
|
|
[ViewVariables] public bool IsGameStarted { get; private set; }
|
2024-01-20 03:40:00 +00:00
|
|
|
[ViewVariables] public string? RestartSound { get; private set; }
|
2022-03-13 19:33:19 -07:00
|
|
|
[ViewVariables] public string? LobbyBackground { get; private set; }
|
2020-08-20 16:20:48 +02:00
|
|
|
[ViewVariables] public bool DisallowedLateJoin { get; private set; }
|
2021-03-10 14:48:29 +01:00
|
|
|
[ViewVariables] public string? ServerInfoBlob { get; private set; }
|
2021-01-11 09:03:58 +01:00
|
|
|
[ViewVariables] public TimeSpan StartTime { get; private set; }
|
2022-01-21 01:38:35 -08:00
|
|
|
[ViewVariables] public new bool Paused { get; private set; }
|
2022-08-14 12:54:49 -07:00
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
[ViewVariables] public IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>> JobsAvailable => _jobsAvailable;
|
|
|
|
|
[ViewVariables] public IReadOnlyDictionary<NetEntity, string> StationNames => _stationNames;
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public event Action? InfoBlobUpdated;
|
|
|
|
|
public event Action? LobbyStatusUpdated;
|
|
|
|
|
public event Action? LobbyLateJoinStatusUpdated;
|
2023-09-11 09:42:41 +10:00
|
|
|
public event Action<IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>>>? LobbyJobsAvailableUpdated;
|
2018-11-25 19:04:49 +01:00
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
public override void Initialize()
|
2018-11-25 19:04:49 +01:00
|
|
|
{
|
|
|
|
|
DebugTools.Assert(!_initialized);
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
SubscribeNetworkEvent<TickerJoinLobbyEvent>(JoinLobby);
|
|
|
|
|
SubscribeNetworkEvent<TickerJoinGameEvent>(JoinGame);
|
2024-01-07 21:30:10 -03:00
|
|
|
SubscribeNetworkEvent<TickerConnectionStatusEvent>(ConnectionStatus);
|
2021-06-20 10:09:24 +02:00
|
|
|
SubscribeNetworkEvent<TickerLobbyStatusEvent>(LobbyStatus);
|
|
|
|
|
SubscribeNetworkEvent<TickerLobbyInfoEvent>(LobbyInfo);
|
|
|
|
|
SubscribeNetworkEvent<TickerLobbyCountdownEvent>(LobbyCountdown);
|
|
|
|
|
SubscribeNetworkEvent<RoundEndMessageEvent>(RoundEnd);
|
|
|
|
|
SubscribeNetworkEvent<RequestWindowAttentionEvent>(msg =>
|
2020-08-16 23:36:50 +02:00
|
|
|
{
|
|
|
|
|
IoCManager.Resolve<IClyde>().RequestWindowAttention();
|
|
|
|
|
});
|
2021-06-20 10:09:24 +02:00
|
|
|
SubscribeNetworkEvent<TickerLateJoinStatusEvent>(LateJoinStatus);
|
|
|
|
|
SubscribeNetworkEvent<TickerJobsAvailableEvent>(UpdateJobsAvailable);
|
2018-11-25 19:04:49 +01:00
|
|
|
|
|
|
|
|
_initialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void LateJoinStatus(TickerLateJoinStatusEvent message)
|
2020-08-20 16:20:48 +02:00
|
|
|
{
|
|
|
|
|
DisallowedLateJoin = message.Disallowed;
|
|
|
|
|
LobbyLateJoinStatusUpdated?.Invoke();
|
|
|
|
|
}
|
2020-04-08 06:07:54 -05:00
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void UpdateJobsAvailable(TickerJobsAvailableEvent message)
|
2020-10-16 11:22:58 +02:00
|
|
|
{
|
2023-09-15 15:59:15 +10:00
|
|
|
_jobsAvailable.Clear();
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
foreach (var (job, data) in message.JobsAvailableByStation)
|
|
|
|
|
{
|
|
|
|
|
_jobsAvailable[job] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_stationNames.Clear();
|
|
|
|
|
foreach (var weh in message.StationNames)
|
|
|
|
|
{
|
|
|
|
|
_stationNames[weh.Key] = weh.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 11:22:58 +02:00
|
|
|
LobbyJobsAvailableUpdated?.Invoke(JobsAvailable);
|
|
|
|
|
}
|
2020-04-08 06:07:54 -05:00
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void JoinLobby(TickerJoinLobbyEvent message)
|
2018-11-25 19:04:49 +01:00
|
|
|
{
|
2020-02-26 16:42:12 +01:00
|
|
|
_stateManager.RequestStateChange<LobbyState>();
|
2020-01-20 00:15:39 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-07 21:30:10 -03:00
|
|
|
private void ConnectionStatus(TickerConnectionStatusEvent message)
|
|
|
|
|
{
|
|
|
|
|
RoundStartTimeSpan = message.RoundStartTimeSpan;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void LobbyStatus(TickerLobbyStatusEvent message)
|
2018-11-25 19:04:49 +01:00
|
|
|
{
|
2020-02-26 16:42:12 +01:00
|
|
|
StartTime = message.StartTime;
|
2022-07-30 19:55:43 -07:00
|
|
|
RoundStartTimeSpan = message.RoundStartTimeSpan;
|
2020-02-26 16:42:12 +01:00
|
|
|
IsGameStarted = message.IsRoundStarted;
|
|
|
|
|
AreWeReady = message.YouAreReady;
|
2022-03-13 19:33:19 -07:00
|
|
|
LobbyBackground = message.LobbyBackground;
|
2020-06-23 21:30:37 +02:00
|
|
|
Paused = message.Paused;
|
2019-12-05 16:00:03 +01:00
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
LobbyStatusUpdated?.Invoke();
|
2019-08-05 22:59:37 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void LobbyInfo(TickerLobbyInfoEvent message)
|
2019-08-05 22:59:37 -07:00
|
|
|
{
|
2020-02-26 16:42:12 +01:00
|
|
|
ServerInfoBlob = message.TextBlob;
|
2019-12-05 16:00:03 +01:00
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
InfoBlobUpdated?.Invoke();
|
2018-11-25 19:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void JoinGame(TickerJoinGameEvent message)
|
2018-11-25 19:04:49 +01:00
|
|
|
{
|
2022-09-04 17:21:14 -07:00
|
|
|
_stateManager.RequestStateChange<GameplayState>();
|
2018-11-25 19:04:49 +01:00
|
|
|
}
|
2020-04-08 06:07:54 -05:00
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void LobbyCountdown(TickerLobbyCountdownEvent message)
|
2020-06-21 22:05:47 +02:00
|
|
|
{
|
|
|
|
|
StartTime = message.StartTime;
|
|
|
|
|
Paused = message.Paused;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void RoundEnd(RoundEndMessageEvent message)
|
2020-08-18 14:52:59 +02:00
|
|
|
{
|
2023-08-21 14:54:44 -04:00
|
|
|
// Force an update in the event of this song being the same as the last.
|
2024-01-20 03:40:00 +00:00
|
|
|
RestartSound = message.RestartSound;
|
2022-06-12 03:23:28 +02:00
|
|
|
|
2023-06-05 16:33:49 +12:00
|
|
|
// Don't open duplicate windows (mainly for replays).
|
|
|
|
|
if (_window?.RoundId == message.RoundId)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-04-08 06:07:54 -05:00
|
|
|
//This is not ideal at all, but I don't see an immediately better fit anywhere else.
|
2023-06-05 16:33:49 +12:00
|
|
|
_window = new RoundEndSummaryWindow(message.GamemodeTitle, message.RoundEndText, message.RoundDuration, message.RoundId, message.AllPlayersEndInfo, _entityManager);
|
2020-04-08 06:07:54 -05:00
|
|
|
}
|
2018-11-25 19:04:49 +01:00
|
|
|
}
|
|
|
|
|
}
|