2024-04-19 17:26:21 +12:00
|
|
|
using Content.Client.Administration.Managers;
|
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;
|
2024-06-06 02:19:24 +12:00
|
|
|
using Content.Shared.Roles;
|
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;
|
2024-04-26 05:39:56 -07:00
|
|
|
using Robust.Client.UserInterface;
|
2024-06-06 02:19:24 +12:00
|
|
|
using Robust.Shared.Prototypes;
|
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!;
|
2024-04-19 17:26:21 +12:00
|
|
|
[Dependency] private readonly IClientAdminManager _admin = default!;
|
|
|
|
|
[Dependency] private readonly IClyde _clyde = default!;
|
2024-04-26 05:39:56 -07:00
|
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
2022-06-23 16:32:06 +07:00
|
|
|
|
2024-06-06 02:19:24 +12:00
|
|
|
private Dictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> _jobsAvailable = new();
|
2023-09-11 09:42:41 +10:00
|
|
|
private Dictionary<NetEntity, string> _stationNames = new();
|
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
|
|
|
|
2024-06-06 02:19:24 +12:00
|
|
|
[ViewVariables] public IReadOnlyDictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> JobsAvailable => _jobsAvailable;
|
2023-09-11 09:42:41 +10:00
|
|
|
[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;
|
2024-06-06 02:19:24 +12:00
|
|
|
public event Action<IReadOnlyDictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>>>? 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
|
|
|
{
|
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);
|
2024-04-19 17:26:21 +12:00
|
|
|
SubscribeNetworkEvent<RequestWindowAttentionEvent>(OnAttentionRequest);
|
2021-06-20 10:09:24 +02:00
|
|
|
SubscribeNetworkEvent<TickerLateJoinStatusEvent>(LateJoinStatus);
|
|
|
|
|
SubscribeNetworkEvent<TickerJobsAvailableEvent>(UpdateJobsAvailable);
|
2018-11-25 19:04:49 +01:00
|
|
|
|
2024-04-19 17:26:21 +12:00
|
|
|
_admin.AdminStatusUpdated += OnAdminUpdated;
|
|
|
|
|
OnAdminUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
_admin.AdminStatusUpdated -= OnAdminUpdated;
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAdminUpdated()
|
|
|
|
|
{
|
|
|
|
|
// Hide some map/grid related logs from clients. This is to try prevent some easy metagaming by just
|
|
|
|
|
// reading the console. E.g., logs like this one could leak the nuke station/grid:
|
|
|
|
|
// > Grid NT-Arrivals 1101 (122/n25896) changed parent. Old parent: map 10 (121/n25895). New parent: FTL (123/n26470)
|
|
|
|
|
#if !DEBUG
|
2024-06-06 02:19:24 +12:00
|
|
|
EntityManager.System<SharedMapSystem>().Log.Level = _admin.IsAdmin() ? LogLevel.Info : LogLevel.Warning;
|
2024-04-19 17:26:21 +12:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAttentionRequest(RequestWindowAttentionEvent ev)
|
|
|
|
|
{
|
|
|
|
|
_clyde.RequestWindowAttention();
|
2018-11-25 19:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2024-04-26 05:39:56 -07:00
|
|
|
_userInterfaceManager.GetUIController<RoundEndSummaryUIController>().OpenRoundEndSummaryWindow(message);
|
2020-04-08 06:07:54 -05:00
|
|
|
}
|
2018-11-25 19:04:49 +01:00
|
|
|
}
|
|
|
|
|
}
|