Zabiju je
This commit is contained in:
@@ -293,7 +293,35 @@ public class GameClient : IDisposable
|
||||
{
|
||||
LobbyId = r.LobbyId;
|
||||
JoinCode = r.JoinCode;
|
||||
CurrentLobbyState = r.LobbyState;
|
||||
// Ensure we always have a valid lobby state with the creator as owner
|
||||
if (r.LobbyState != null)
|
||||
{
|
||||
CurrentLobbyState = r.LobbyState;
|
||||
if (string.IsNullOrEmpty(CurrentLobbyState.OwnerId))
|
||||
CurrentLobbyState.OwnerId = ClientUuid;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentLobbyState = new LobbyState
|
||||
{
|
||||
LobbyId = r.LobbyId ?? "",
|
||||
JoinCode = r.JoinCode ?? "",
|
||||
OwnerId = ClientUuid
|
||||
};
|
||||
}
|
||||
// Make sure creator appears in the player list
|
||||
if (CurrentLobbyState.Players == null)
|
||||
CurrentLobbyState.Players = new System.Collections.Generic.List<PlayerInfo>();
|
||||
if (!CurrentLobbyState.Players.Any(p => p.ClientUuid == ClientUuid))
|
||||
{
|
||||
CurrentLobbyState.Players.Insert(0, new PlayerInfo
|
||||
{
|
||||
ClientUuid = ClientUuid,
|
||||
DisplayName = DisplayName,
|
||||
IsOwner = true,
|
||||
State = PlayerState.Alive
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -303,6 +331,22 @@ public class GameClient : IDisposable
|
||||
LobbyId = r.LobbyId;
|
||||
CurrentLobbyState = r.LobbyState;
|
||||
JoinCode = r.LobbyState?.JoinCode;
|
||||
// Ensure self is in the player list
|
||||
if (CurrentLobbyState != null)
|
||||
{
|
||||
if (CurrentLobbyState.Players == null)
|
||||
CurrentLobbyState.Players = new System.Collections.Generic.List<PlayerInfo>();
|
||||
if (!CurrentLobbyState.Players.Any(p => p.ClientUuid == ClientUuid))
|
||||
{
|
||||
CurrentLobbyState.Players.Add(new PlayerInfo
|
||||
{
|
||||
ClientUuid = ClientUuid,
|
||||
DisplayName = DisplayName,
|
||||
IsOwner = CurrentLobbyState.OwnerId == ClientUuid,
|
||||
State = PlayerState.Alive
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -344,7 +388,6 @@ public class GameClient : IDisposable
|
||||
var joinedPayload = evt.GetPayload<PlayerJoinedPayload>();
|
||||
if (joinedPayload != null && CurrentLobbyState?.Players != null)
|
||||
{
|
||||
// Check if player already exists
|
||||
bool exists = CurrentLobbyState.Players.Any(p => p.ClientUuid == joinedPayload.ClientUuid);
|
||||
if (!exists)
|
||||
{
|
||||
@@ -352,7 +395,7 @@ public class GameClient : IDisposable
|
||||
{
|
||||
ClientUuid = joinedPayload.ClientUuid,
|
||||
DisplayName = joinedPayload.DisplayName,
|
||||
IsOwner = false,
|
||||
IsOwner = joinedPayload.ClientUuid == CurrentLobbyState.OwnerId,
|
||||
IsReady = false,
|
||||
State = PlayerState.Alive
|
||||
});
|
||||
@@ -491,6 +534,7 @@ public class GameClient : IDisposable
|
||||
Send(new LeaveLobby());
|
||||
LobbyId = null;
|
||||
JoinCode = null;
|
||||
CurrentLobbyState = null;
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
|
||||
Reference in New Issue
Block a user