From cf9114356ce919894457120947b639268ed8dae3 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:08:25 +0200 Subject: [PATCH] Clean up CoopGame and improve "Waiting for X..." --- Fika.Core/Coop/GameMode/CoopGame.cs | 33 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 5be94ca8..96ade4ac 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -58,7 +58,7 @@ internal sealed class CoopGame : BaseLocalGame, IBotGame, IF { public string InfiltrationPoint; public bool HasAddedFenceRep = false; - public bool forceStart = false; + //public bool forceStart = false; public ExitStatus MyExitStatus { get; set; } = ExitStatus.Survived; public string MyExitLocation { get; set; } = null; public ISpawnSystem SpawnSystem; @@ -599,7 +599,6 @@ private IEnumerator WaitForOtherPlayers() } NetDataWriter writer = new(); - forceStart = false; MatchmakerAcceptPatches.GClass3182.ChangeStatus("Waiting for other players to finish loading..."); @@ -608,10 +607,12 @@ private IEnumerator WaitForOtherPlayers() fikaStartButton.SetActive(true); }*/ + int expectedPlayers = MatchmakerAcceptPatches.HostExpectedNumberOfPlayers; + if (isServer) { SetStatusModel status = new(coopHandler.MyPlayer.ProfileId, LobbyEntry.ELobbyStatus.IN_GAME); - Task updateStatus = FikaRequestHandler.UpdateSetStatus(status); + Task updateStatus = FikaRequestHandler.UpdateSetStatus(status); while (!updateStatus.IsCompleted) { @@ -621,7 +622,7 @@ private IEnumerator WaitForOtherPlayers() do { yield return null; - } while (coopHandler.HumanPlayers < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart); + } while (coopHandler.HumanPlayers < expectedPlayers); FikaServer server = Singleton.Instance; server.ReadyClients++; @@ -635,8 +636,9 @@ private IEnumerator WaitForOtherPlayers() do { - yield return null; - } while (Singleton.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart); + MatchmakerAcceptPatches.GClass3182.ChangeStatus("Waiting for other players to finish loading...", server.ReadyClients / expectedPlayers); + yield return new WaitForEndOfFrame(); + } while (server.ReadyClients < expectedPlayers); foreach (CoopPlayer player in coopHandler.Players.Values) { @@ -656,7 +658,7 @@ private IEnumerator WaitForOtherPlayers() do { yield return null; - } while (coopHandler.HumanPlayers < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart); + } while (coopHandler.HumanPlayers < expectedPlayers); FikaClient client = Singleton.Instance; InformationPacket packet = new(true) @@ -668,8 +670,9 @@ private IEnumerator WaitForOtherPlayers() do { - yield return null; - } while (Singleton.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart); + MatchmakerAcceptPatches.GClass3182.ChangeStatus("Waiting for other players to finish loading...", client.ReadyClients / expectedPlayers); + yield return new WaitForEndOfFrame(); + } while (client.ReadyClients < expectedPlayers); } /*if (fikaStartButton != null) @@ -1035,7 +1038,7 @@ private async Task WaitForPlayers() Logger.LogError("WaitForPlayers::GClass3163 was null!"); } await Task.Delay(100); - } while (numbersOfPlayersToWaitFor > 0 && !forceStart); + } while (numbersOfPlayersToWaitFor > 0); } else { @@ -1092,7 +1095,7 @@ private async Task WaitForPlayers() writer.Reset(); client.SendData(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); await Task.Delay(1000); - } while (numbersOfPlayersToWaitFor > 0 && !forceStart); + } while (numbersOfPlayersToWaitFor > 0); } } @@ -1219,16 +1222,20 @@ public override IEnumerator vmethod_4(BotControllerSettings controllerSettings, yield return WaitForOtherPlayers(); + + int expectedPlayers = MatchmakerAcceptPatches.HostExpectedNumberOfPlayers; if (isServer) { - while (Singleton.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart) + FikaServer server = Singleton.Instance; + while (server.ReadyClients < expectedPlayers) { yield return new WaitForEndOfFrame(); } } else { - while (Singleton.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart) + FikaClient client = Singleton.Instance; + while (client.ReadyClients < expectedPlayers) { yield return new WaitForEndOfFrame(); }