Skip to content

Commit

Permalink
Fix loading in
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Dec 18, 2024
1 parent 06a7d09 commit 2fe1157
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
13 changes: 9 additions & 4 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,10 @@ private void SyncTransitControllers()
/// This task ensures that all players are joined and loaded before continuing
/// </summary>
/// <returns></returns>
private async Task WaitForOtherPlayers()
private async Task WaitForOtherPlayersToLoad()
{
#if DEBUG
Logger.LogWarning("Starting " + nameof(WaitForOtherPlayers));
Logger.LogWarning("Starting " + nameof(WaitForOtherPlayersToLoad));
#endif
if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
Expand Down Expand Up @@ -955,7 +955,7 @@ private GameObject CreateStartButton()
if (isServer)
{
RaidStarted = true;
FikaBackendUtils.HostExpectedNumberOfPlayers = Singleton<FikaServer>.Instance.NetServer.ConnectedPeersCount;
FikaBackendUtils.HostExpectedNumberOfPlayers = Singleton<FikaServer>.Instance.NetServer.ConnectedPeersCount + 1;
return;
}

Expand Down Expand Up @@ -1410,6 +1410,11 @@ private async Task WaitForHostToStart()
Destroy(startButton);
}

InformationPacket continuePacket = new()
{
AmountOfPeers = server.NetServer.ConnectedPeersCount + 1
};
server.SendDataToAll(ref continuePacket, DeliveryMethod.ReliableOrdered);
SetStatusModel status = new(FikaBackendUtils.GroupId, LobbyEntry.ELobbyStatus.IN_GAME);
await FikaRequestHandler.UpdateSetStatus(status);
return;
Expand Down Expand Up @@ -1523,7 +1528,7 @@ public override async Task vmethod_1(BotControllerSettings controllerSettings, I
DynamicAI = gameObject.AddComponent<FikaDynamicAI>();
}

await WaitForOtherPlayers();
await WaitForOtherPlayersToLoad();

SetMatchmakerStatus(LocaleUtils.UI_FINISHING_RAID_INIT.Localized());
Logger.LogInfo("All players are loaded, continuing...");
Expand Down
5 changes: 4 additions & 1 deletion Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,14 @@ private void OnInformationPacketReceived(InformationPacket packet)
if (coopGame != null)
{
coopGame.RaidStarted = packet.RaidStarted;
FikaBackendUtils.HostExpectedNumberOfPlayers = packet.ReadyPlayers;
}
ReadyClients = packet.ReadyPlayers;
HostReady = packet.HostReady;
HostLoaded = packet.HostLoaded;
if (packet.AmountOfPeers > 0)
{
FikaBackendUtils.HostExpectedNumberOfPlayers = packet.AmountOfPeers;
}

if (packet.HostReady)
{
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private void OnSideEffectPacketReceived(SideEffectPacket packet, NetPeer peer)
if (item.TryGetItemComponent(out SideEffectComponent sideEffectComponent))
{
sideEffectComponent.Value = packet.Value;
item.RaiseRefreshEvent(false, false);
item.RaiseRefreshEvent(true, false);
}
}

Expand Down
3 changes: 3 additions & 0 deletions Fika.Core/Networking/Packets/Backend/InformationPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public struct InformationPacket : INetSerializable
public bool RaidStarted;
public bool RequestStart;
public int ReadyPlayers;
public int AmountOfPeers;
public bool HostReady;
public bool HostLoaded;
public DateTime GameTime;
Expand All @@ -20,6 +21,7 @@ public void Deserialize(NetDataReader reader)
RaidStarted = reader.GetBool();
RequestStart = reader.GetBool();
ReadyPlayers = reader.GetInt();
AmountOfPeers = reader.GetInt();
HostReady = reader.GetBool();
if (HostReady)
{
Expand All @@ -34,6 +36,7 @@ public void Serialize(NetDataWriter writer)
writer.Put(RaidStarted);
writer.Put(RequestStart);
writer.Put(ReadyPlayers);
writer.Put(AmountOfPeers);
writer.Put(HostReady);
if (HostReady)
{
Expand Down

0 comments on commit 2fe1157

Please sign in to comment.