@ -49,31 +49,6 @@ namespace Unity.BossRoom.Gameplay.GameState
}
}
}
}
// void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
// {
// int idx = FindLobbyPlayerIdx(clientId);
// if (idx == -1)
// {
// throw new Exception($"OnClientChangedSeat: client ID {clientId} is not a lobby player and cannot change seats! Shouldn't be here!");
// }
/ /
// if (networkCharSelection.IsLobbyClosed.Value)
// {
// // The user tried to change their class after everything was locked in... too late! Discard this choice
// return;
// }
/ /
// // Allow multiple players to select the same character without restrictions
// networkCharSelection.LobbyPlayers[idx] = new NetworkCharSelection.LobbyPlayerState(clientId,
// networkCharSelection.LobbyPlayers[idx].PlayerName,
// networkCharSelection.LobbyPlayers[idx].PlayerNumber,
// lockedIn ? NetworkCharSelection.SeatState.LockedIn : NetworkCharSelection.SeatState.Active,
// newSeatIdx,
// Time.time);
// Debug.Log("CloseLobbyIfReady");
// CloseLobbyIfReady();
// }
void OnClientChangedSeat ( ulong clientId , int newSeatIdx , bool lockedIn )
void OnClientChangedSeat ( ulong clientId , int newSeatIdx , bool lockedIn )
{
{
int idx = FindLobbyPlayerIdx ( clientId ) ;
int idx = FindLobbyPlayerIdx ( clientId ) ;
@ -88,31 +63,7 @@ namespace Unity.BossRoom.Gameplay.GameState
return ;
return ;
}
}
if ( newSeatIdx = = - 1 )
// Allow multiple players to select the same character without restrictions
{
// we can't lock in with no seat
lockedIn = false ;
}
else
{
// see if someone has already locked-in that seat! If so, too late... discard this choice
foreach ( NetworkCharSelection . LobbyPlayerState playerInfo in networkCharSelection . LobbyPlayers )
{
if ( playerInfo . ClientId ! = clientId & & playerInfo . SeatIdx = = newSeatIdx & & playerInfo . SeatState = = NetworkCharSelection . SeatState . LockedIn )
{
// somebody already locked this choice in. Stop!
// Instead of granting lock request, change this player to Inactive state.
networkCharSelection . LobbyPlayers [ idx ] = new NetworkCharSelection . LobbyPlayerState ( clientId ,
networkCharSelection . LobbyPlayers [ idx ] . PlayerName ,
networkCharSelection . LobbyPlayers [ idx ] . PlayerNumber ,
NetworkCharSelection . SeatState . Inactive ) ;
// then early out
return ;
}
}
}
networkCharSelection . LobbyPlayers [ idx ] = new NetworkCharSelection . LobbyPlayerState ( clientId ,
networkCharSelection . LobbyPlayers [ idx ] = new NetworkCharSelection . LobbyPlayerState ( clientId ,
networkCharSelection . LobbyPlayers [ idx ] . PlayerName ,
networkCharSelection . LobbyPlayers [ idx ] . PlayerName ,
networkCharSelection . LobbyPlayers [ idx ] . PlayerNumber ,
networkCharSelection . LobbyPlayers [ idx ] . PlayerNumber ,
@ -120,24 +71,6 @@ namespace Unity.BossRoom.Gameplay.GameState
newSeatIdx ,
newSeatIdx ,
Time . time ) ;
Time . time ) ;
if ( lockedIn )
{
// to help the clients visually keep track of who's in what seat, we'll "kick out" any other players
// who were also in that seat. (Those players didn't click "Ready!" fast enough, somebody else took their seat!)
for ( int i = 0 ; i < networkCharSelection . LobbyPlayers . Count ; + + i )
{
if ( networkCharSelection . LobbyPlayers [ i ] . SeatIdx = = newSeatIdx & & i ! = idx )
{
// change this player to Inactive state.
networkCharSelection . LobbyPlayers [ i ] = new NetworkCharSelection . LobbyPlayerState (
networkCharSelection . LobbyPlayers [ i ] . ClientId ,
networkCharSelection . LobbyPlayers [ i ] . PlayerName ,
networkCharSelection . LobbyPlayers [ i ] . PlayerNumber ,
NetworkCharSelection . SeatState . Inactive ) ;
}
}
}
CloseLobbyIfReady ( ) ;
CloseLobbyIfReady ( ) ;
}
}
@ -153,15 +86,9 @@ namespace Unity.BossRoom.Gameplay.GameState
}
}
return - 1 ;
return - 1 ;
}
}
public void StartGame ( )
{
networkCharSelection . IsLobbyClosed . Value = true ;
SaveLobbyResults ( ) ;
m_WaitToEndLobbyCoroutine = StartCoroutine ( WaitToEndLobby ( ) ) ;
}
void CloseLobbyIfReady ( )
void CloseLobbyIfReady ( )
{
{
// If dedicated server, leave char select open if there's no one left
if ( DedicatedServerUtilities . IsServerBuildTarget & & networkCharSelection . LobbyPlayers . Count = = 0 )
if ( DedicatedServerUtilities . IsServerBuildTarget & & networkCharSelection . LobbyPlayers . Count = = 0 )
{
{
return ;
return ;
@ -170,42 +97,15 @@ namespace Unity.BossRoom.Gameplay.GameState
foreach ( NetworkCharSelection . LobbyPlayerState playerInfo in networkCharSelection . LobbyPlayers )
foreach ( NetworkCharSelection . LobbyPlayerState playerInfo in networkCharSelection . LobbyPlayers )
{
{
if ( playerInfo . SeatState ! = NetworkCharSelection . SeatState . LockedIn )
if ( playerInfo . SeatState ! = NetworkCharSelection . SeatState . LockedIn )
return ; // nope, at least one player isn't locked in yet!
return ; // at least one player isn't locked in yet!
}
}
// everybody's ready at the same time! Lock it down!
networkCharSelection . IsLobbyClosed . Value = true ;
networkCharSelection . IsLobbyClosed . Value = true ;
// remember our choices so the next scene can use the info
SaveLobbyResults ( ) ;
SaveLobbyResults ( ) ;
// Delay a few seconds to give the UI time to react, then switch scenes
IEnumerator WaitToEndLobby ( )
{
yield return new WaitForSeconds ( 3 ) ;
SceneLoaderWrapper . Instance . LoadScene ( "BossRoom" , useNetworkSceneManager : true ) ;
}
m_WaitToEndLobbyCoroutine = StartCoroutine ( WaitToEndLobby ( ) ) ;
m_WaitToEndLobbyCoroutine = StartCoroutine ( WaitToEndLobby ( ) ) ;
}
}
// void CloseLobbyIfReady()
// {
// // If dedicated server, leave char select open if there's no one left
// if (DedicatedServerUtilities.IsServerBuildTarget && networkCharSelection.LobbyPlayers.Count == 0)
// {
// return;
// }
//
// startButtonScipt.InteractableTruer(false);
// foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)
// {
// if (playerInfo.SeatState != NetworkCharSelection.SeatState.LockedIn)
// return; // at least one player isn't locked in yet!
// }
// startButtonScipt.InteractableTruer(true);
// }
public StartButtonScipt startButtonScipt ;
void CancelCloseLobby ( )
void CancelCloseLobby ( )
{
{
if ( m_WaitToEndLobbyCoroutine ! = null )
if ( m_WaitToEndLobbyCoroutine ! = null )
@ -340,12 +240,12 @@ namespace Unity.BossRoom.Gameplay.GameState
}
}
}
}
//using System;
//using System;
//using System.Collections;
//using System.Collections;
//using Unity.BossRoom.ConnectionManagement;
//using Unity.BossRoom.ConnectionManagement;
//using Unity.BossRoom.Gameplay.GameplayObjects;
//using Unity.BossRoom.Gameplay.GameplayObjects;
//using Unity.BossRoom.Infrastructure;
//using Unity.BossRoom.Infrastructure;
//using Unity.Multiplayer.Samples;
//using Unity.Multiplayer.Samples.BossRoom;
//using Unity.Multiplayer.Samples.BossRoom;
//using Unity.Multiplayer.Samples.Utilities;
//using Unity.Multiplayer.Samples.Utilities;
//using Unity.Netcode;
//using Unity.Netcode;
@ -365,7 +265,7 @@ namespace Unity.BossRoom.Gameplay.GameState
// public override GameState ActiveState => GameState.CharSelect;
// public override GameState ActiveState => GameState.CharSelect;
// public NetworkCharSelection networkCharSelection { get; private set; }
// public NetworkCharSelection networkCharSelection { get; private set; }
// //public static int numOfPlayers;
// Coroutine m_WaitToEndLobbyCoroutine;
// Coroutine m_WaitToEndLobbyCoroutine;
// [Inject]
// [Inject]
@ -391,6 +291,31 @@ namespace Unity.BossRoom.Gameplay.GameState
// }
// }
// }
// }
// // void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
// // {
// // int idx = FindLobbyPlayerIdx(clientId);
// // if (idx == -1)
// // {
// // throw new Exception($"OnClientChangedSeat: client ID {clientId} is not a lobby player and cannot change seats! Shouldn't be here!");
// // }
// //
// // if (networkCharSelection.IsLobbyClosed.Value)
// // {
// // // The user tried to change their class after everything was locked in... too late! Discard this choice
// // return;
// // }
// //
// // // Allow multiple players to select the same character without restrictions
// // networkCharSelection.LobbyPlayers[idx] = new NetworkCharSelection.LobbyPlayerState(clientId,
// // networkCharSelection.LobbyPlayers[idx].PlayerName,
// // networkCharSelection.LobbyPlayers[idx].PlayerNumber,
// // lockedIn ? NetworkCharSelection.SeatState.LockedIn : NetworkCharSelection.SeatState.Active,
// // newSeatIdx,
// // Time.time);
// // Debug.Log("CloseLobbyIfReady");
// // CloseLobbyIfReady();
// // }
// void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
// void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
// {
// {
// int idx = FindLobbyPlayerIdx(clientId);
// int idx = FindLobbyPlayerIdx(clientId);
@ -470,13 +395,20 @@ namespace Unity.BossRoom.Gameplay.GameState
// }
// }
// return -1;
// return -1;
// }
// }
// public void StartGame()
// /// <summary>
// {
// /// Looks through all our connections and sees if everyone has locked in their choice;
// networkCharSelection.IsLobbyClosed.Value = true;
// /// if so, we lock in the whole lobby, save state, and begin the transition to gameplay
// SaveLobbyResults();
// /// </summary>
// m_WaitToEndLobbyCoroutine = StartCoroutine(WaitToEndLobby());
// }
// void CloseLobbyIfReady()
// void CloseLobbyIfReady()
// {
// {
// // If dedicated server, leave char select open if there's no one left
// if (DedicatedServerUtilities.IsServerBuildTarget && networkCharSelection.LobbyPlayers.Count == 0)
// {
// return;
// }
// foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)
// foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)
// {
// {
// if (playerInfo.SeatState != NetworkCharSelection.SeatState.LockedIn)
// if (playerInfo.SeatState != NetworkCharSelection.SeatState.LockedIn)
@ -490,12 +422,32 @@ namespace Unity.BossRoom.Gameplay.GameState
// SaveLobbyResults();
// SaveLobbyResults();
// // Delay a few seconds to give the UI time to react, then switch scenes
// // Delay a few seconds to give the UI time to react, then switch scenes
// IEnumerator WaitToEndLobby()
// {
// yield return new WaitForSeconds(3);
// SceneLoaderWrapper.Instance.LoadScene("BossRoom", useNetworkSceneManager: true);
// }
// m_WaitToEndLobbyCoroutine = StartCoroutine(WaitToEndLobby());
// m_WaitToEndLobbyCoroutine = StartCoroutine(WaitToEndLobby());
// }
// }
// /// <summary>
// /// Cancels the process of closing the lobby, so that if a new player joins, they are able to chose a character.
// // void CloseLobbyIfReady()
// /// </summary>
// // {
// // // If dedicated server, leave char select open if there's no one left
// // if (DedicatedServerUtilities.IsServerBuildTarget && networkCharSelection.LobbyPlayers.Count == 0)
// // {
// // return;
// // }
// //
// // startButtonScipt.InteractableTruer(false);
// // foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)
// // {
// // if (playerInfo.SeatState != NetworkCharSelection.SeatState.LockedIn)
// // return; // at least one player isn't locked in yet!
// // }
// // startButtonScipt.InteractableTruer(true);
// // }
// public StartButtonScipt startButtonScipt;
// void CancelCloseLobby()
// void CancelCloseLobby()
// {
// {
// if (m_WaitToEndLobbyCoroutine != null)
// if (m_WaitToEndLobbyCoroutine != null)
@ -508,7 +460,6 @@ namespace Unity.BossRoom.Gameplay.GameState
// void SaveLobbyResults()
// void SaveLobbyResults()
// {
// {
// int numofPlayersInLobby = networkCharSelection.LobbyPlayers.Count;
// int numofPlayersInLobby = networkCharSelection.LobbyPlayers.Count;
// //numOfPlayers = numofPlayersInLobby;
// PlayerPrefs.SetInt("NumberOfLobbyPlayers", numofPlayersInLobby);
// PlayerPrefs.SetInt("NumberOfLobbyPlayers", numofPlayersInLobby);
// Debug.Log("Number of Players in lobby are: " + numofPlayersInLobby);
// Debug.Log("Number of Players in lobby are: " + numofPlayersInLobby);
// foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)
// foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)
@ -517,8 +468,6 @@ namespace Unity.BossRoom.Gameplay.GameState
// if (playerNetworkObject && playerNetworkObject.TryGetComponent(out PersistentPlayer persistentPlayer))
// if (playerNetworkObject && playerNetworkObject.TryGetComponent(out PersistentPlayer persistentPlayer))
// {
// {
// // pass avatar GUID to PersistentPlayer
// // it'd be great to simplify this with something like a NetworkScriptableObjects :(
// persistentPlayer.NetworkAvatarGuidState.AvatarGuid.Value =
// persistentPlayer.NetworkAvatarGuidState.AvatarGuid.Value =
// networkCharSelection.AvatarConfiguration[playerInfo.SeatIdx].Guid.ToNetworkGuid();
// networkCharSelection.AvatarConfiguration[playerInfo.SeatIdx].Guid.ToNetworkGuid();
// }
// }
@ -561,9 +510,7 @@ namespace Unity.BossRoom.Gameplay.GameState
// void OnSceneEvent(SceneEvent sceneEvent)
// void OnSceneEvent(SceneEvent sceneEvent)
// {
// {
// // We need to filter out the event that are not a client has finished loading the scene
// if (sceneEvent.SceneEventType != SceneEventType.LoadComplete) return;
// if (sceneEvent.SceneEventType != SceneEventType.LoadComplete) return;
// // When the client finishes loading the Lobby Map, we will need to Seat it
// SeatNewPlayer(sceneEvent.ClientId);
// SeatNewPlayer(sceneEvent.ClientId);
// }
// }
@ -576,28 +523,23 @@ namespace Unity.BossRoom.Gameplay.GameState
// return possiblePlayerNumber;
// return possiblePlayerNumber;
// }
// }
// }
// }
// // we couldn't get a Player# for this person... which means the lobby is full!
// return -1;
// return -1;
// }
// }
// bool IsPlayerNumberAvailable(int playerNumber)
// bool IsPlayerNumberAvailable(int playerNumber)
// {
// {
// bool found = false;
// foreach (NetworkCharSelection.LobbyPlayerState playerState in networkCharSelection.LobbyPlayers)
// foreach (NetworkCharSelection.LobbyPlayerState playerState in networkCharSelection.LobbyPlayers)
// {
// {
// if (playerState.PlayerNumber == playerNumber)
// if (playerState.PlayerNumber == playerNumber)
// {
// {
// found = true;
// return false;
// break;
// }
// }
// }
// }
// return true;
// return !found;
// }
// }
// void SeatNewPlayer(ulong clientId)
// void SeatNewPlayer(ulong clientId)
// {
// {
// // If lobby is closing and waiting to start the game, cancel to allow that new player to select a character
// if (networkCharSelection.IsLobbyClosed.Value)
// if (networkCharSelection.IsLobbyClosed.Value)
// {
// {
// CancelCloseLobby();
// CancelCloseLobby();
@ -609,13 +551,11 @@ namespace Unity.BossRoom.Gameplay.GameState
// var playerData = sessionPlayerData.Value;
// var playerData = sessionPlayerData.Value;
// if (playerData.PlayerNumber == -1 || !IsPlayerNumberAvailable(playerData.PlayerNumber))
// if (playerData.PlayerNumber == -1 || !IsPlayerNumberAvailable(playerData.PlayerNumber))
// {
// {
// // If no player num already assigned or if player num is no longer available, get an available one.
// playerData.PlayerNumber = GetAvailablePlayerNumber();
// playerData.PlayerNumber = GetAvailablePlayerNumber();
// }
// }
// if (playerData.PlayerNumber == -1)
// if (playerData.PlayerNumber == -1)
// {
// {
// // Sanity check. We ran out of seats... there was no room!
// throw new Exception($"No available player number for client ID {clientId}");
// throw new Exception($"we shouldn't be here, connection approval should have refused this connection already for client ID {clientId} and player num {playerData.PlayerNumber}");
// }
// }
// networkCharSelection.LobbyPlayers.Add(new NetworkCharSelection.LobbyPlayerState(clientId, playerData.PlayerName, playerData.PlayerNumber, NetworkCharSelection.SeatState.Inactive));
// networkCharSelection.LobbyPlayers.Add(new NetworkCharSelection.LobbyPlayerState(clientId, playerData.PlayerName, playerData.PlayerNumber, NetworkCharSelection.SeatState.Inactive));
@ -625,7 +565,6 @@ namespace Unity.BossRoom.Gameplay.GameState
// void OnClientDisconnectCallback(ulong clientId)
// void OnClientDisconnectCallback(ulong clientId)
// {
// {
// // clear this client's PlayerNumber and any associated visuals (so other players know they're gone).
// for (int i = 0; i < networkCharSelection.LobbyPlayers.Count; ++i)
// for (int i = 0; i < networkCharSelection.LobbyPlayers.Count; ++i)
// {
// {
// if (networkCharSelection.LobbyPlayers[i].ClientId == clientId)
// if (networkCharSelection.LobbyPlayers[i].ClientId == clientId)
@ -637,9 +576,9 @@ namespace Unity.BossRoom.Gameplay.GameState
// if (!networkCharSelection.IsLobbyClosed.Value)
// if (!networkCharSelection.IsLobbyClosed.Value)
// {
// {
// // If the lobby is not already closing, close if the remaining players are all ready
// CloseLobbyIfReady();
// CloseLobbyIfReady();
// }
// }
// }
// }
// }
// }
//}
//}