Skip to content

Commit

Permalink
Clean up CoopGame and improve "Waiting for X..."
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 5, 2024
1 parent f172e65 commit cf91143
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal sealed class CoopGame : BaseLocalGame<EftGamePlayerOwner>, 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;
Expand Down Expand Up @@ -599,7 +599,6 @@ private IEnumerator WaitForOtherPlayers()
}

NetDataWriter writer = new();
forceStart = false;

MatchmakerAcceptPatches.GClass3182.ChangeStatus("Waiting for other players to finish loading...");

Expand All @@ -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)
{
Expand All @@ -621,7 +622,7 @@ private IEnumerator WaitForOtherPlayers()
do
{
yield return null;
} while (coopHandler.HumanPlayers < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
} while (coopHandler.HumanPlayers < expectedPlayers);

FikaServer server = Singleton<FikaServer>.Instance;
server.ReadyClients++;
Expand All @@ -635,8 +636,9 @@ private IEnumerator WaitForOtherPlayers()

do
{
yield return null;
} while (Singleton<FikaServer>.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)
{
Expand All @@ -656,7 +658,7 @@ private IEnumerator WaitForOtherPlayers()
do
{
yield return null;
} while (coopHandler.HumanPlayers < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
} while (coopHandler.HumanPlayers < expectedPlayers);

FikaClient client = Singleton<FikaClient>.Instance;
InformationPacket packet = new(true)
Expand All @@ -668,8 +670,9 @@ private IEnumerator WaitForOtherPlayers()

do
{
yield return null;
} while (Singleton<FikaClient>.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)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -1219,16 +1222,20 @@ public override IEnumerator vmethod_4(BotControllerSettings controllerSettings,

yield return WaitForOtherPlayers();


int expectedPlayers = MatchmakerAcceptPatches.HostExpectedNumberOfPlayers;
if (isServer)
{
while (Singleton<FikaServer>.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart)
FikaServer server = Singleton<FikaServer>.Instance;
while (server.ReadyClients < expectedPlayers)
{
yield return new WaitForEndOfFrame();
}
}
else
{
while (Singleton<FikaClient>.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart)
FikaClient client = Singleton<FikaClient>.Instance;
while (client.ReadyClients < expectedPlayers)
{
yield return new WaitForEndOfFrame();
}
Expand Down

0 comments on commit cf91143

Please sign in to comment.