diff --git a/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs b/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs index eae3809..dcb2c69 100644 --- a/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs +++ b/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs @@ -344,7 +344,6 @@ namespace Unity.BossRoom.Gameplay.GameState if (isLobbyClosed) { ConfigureUIForLobbyMode(LobbyMode.LobbyEnding); - } else { @@ -457,3 +456,464 @@ namespace Unity.BossRoom.Gameplay.GameState } } + + +//using System; +//using System.Collections.Generic; +//using Unity.BossRoom.Gameplay.UI; +//using TMPro; +//using Unity.BossRoom.ConnectionManagement; +//using Unity.Multiplayer.Samples.Utilities; +//using Unity.Netcode; +//using UnityEngine; +//using VContainer; +//using Avatar = Unity.BossRoom.Gameplay.Configuration.Avatar; +//using System.Linq; + +//namespace Unity.BossRoom.Gameplay.GameState +//{ +// /// +// /// Client specialization of the Character Select game state. Mainly controls the UI during character-select. +// /// +// [RequireComponent(typeof(NetcodeHooks))] +// public class ClientCharSelectState : GameStateBehaviour +// { +// /// +// /// Reference to the scene's state object so that UI can access state +// /// +// public static ClientCharSelectState Instance { get; private set; } + +// [SerializeField] +// NetcodeHooks m_NetcodeHooks; + +// public override GameState ActiveState { get { return GameState.CharSelect; } } + +// [SerializeField] +// NetworkCharSelection m_NetworkCharSelection; + +// [SerializeField] +// [Tooltip("This is triggered when the player chooses a character")] +// string m_AnimationTriggerOnCharSelect = "BeginRevive"; + +// [SerializeField] +// [Tooltip("This is triggered when the player presses the \"Ready\" button")] +// string m_AnimationTriggerOnCharChosen = "BeginRevive"; + +// [Header("Lobby Seats")] +// [SerializeField] +// [Tooltip("Collection of 8 portrait-boxes, one for each potential lobby member")] +// List m_PlayerSeats; + +// [System.Serializable] +// public class ColorAndIndicator +// { +// public Sprite Indicator; +// public Color Color; +// } +// [Tooltip("Representational information for each player")] +// public ColorAndIndicator[] m_IdentifiersForEachPlayerNumber; + +// [SerializeField] +// [Tooltip("Text element containing player count which updates as players connect")] +// TextMeshProUGUI m_NumPlayersText; + +// [SerializeField] +// [Tooltip("Text element for the Ready button")] +// TextMeshProUGUI m_ReadyButtonText; + +// [Header("UI Elements for different lobby modes")] +// [SerializeField] +// [Tooltip("UI elements to turn on when the player hasn't chosen their seat yet. Turned off otherwise!")] +// List m_UIElementsForNoSeatChosen; + +// [SerializeField] +// [Tooltip("UI elements to turn on when the player has locked in their seat choice (and is now waiting for other players to do the same). Turned off otherwise!")] +// List m_UIElementsForSeatChosen; + +// [SerializeField] +// [Tooltip("UI elements to turn on when the lobby is closed (and game is about to start). Turned off otherwise!")] +// List m_UIElementsForLobbyEnding; + +// [SerializeField] +// [Tooltip("UI elements to turn on when there's been a fatal error (and the client cannot proceed). Turned off otherwise!")] +// List m_UIElementsForFatalError; + +// [Header("Misc")] +// [SerializeField] +// [Tooltip("The controller for the class-info box")] +// UICharSelectClassInfoBox m_ClassInfoBox; + +// [SerializeField] +// Transform m_CharacterGraphicsParent; + +// int m_LastSeatSelected = -1; +// bool m_HasLocalPlayerLockedIn = false; + +// GameObject m_CurrentCharacterGraphics; + +// Animator m_CurrentCharacterGraphicsAnimator; + +// Dictionary m_SpawnedCharacterGraphics = new Dictionary(); + +// /// +// /// Conceptual modes or stages that the lobby can be in. We don't actually +// /// bother to keep track of what LobbyMode we're in at any given time; it's just +// /// an abstraction that makes it easier to configure which UI elements should +// /// be enabled/disabled in each stage of the lobby. +// /// +// enum LobbyMode +// { +// ChooseSeat, // "Choose your seat!" stage +// SeatChosen, // "Waiting for other players!" stage +// LobbyEnding, // "Get ready! Game is starting!" stage +// FatalError, // "Fatal Error" stage +// } + +// Dictionary> m_LobbyUIElementsByMode; + +// [Inject] +// ConnectionManager m_ConnectionManager; + +// protected override void Awake() +// { +// base.Awake(); +// Instance = this; + +// m_NetcodeHooks.OnNetworkSpawnHook += OnNetworkSpawn; +// m_NetcodeHooks.OnNetworkDespawnHook += OnNetworkDespawn; + +// m_LobbyUIElementsByMode = new Dictionary>() +// { +// { LobbyMode.ChooseSeat, m_UIElementsForNoSeatChosen }, +// { LobbyMode.SeatChosen, m_UIElementsForSeatChosen }, +// { LobbyMode.LobbyEnding, m_UIElementsForLobbyEnding }, +// { LobbyMode.FatalError, m_UIElementsForFatalError }, +// }; +// } + +// protected override void OnDestroy() +// { +// if (Instance == this) +// { +// Instance = null; +// } + +// base.OnDestroy(); +// } + +// protected override void Start() +// { +// base.Start(); +// for (int i = 0; i < m_PlayerSeats.Count; ++i) +// { +// m_PlayerSeats[i].Initialize(i); +// } + +// ConfigureUIForLobbyMode(LobbyMode.ChooseSeat); +// UpdateCharacterSelection(NetworkCharSelection.SeatState.Inactive); +// } + +// void OnNetworkDespawn() +// { +// if (m_NetworkCharSelection) +// { +// m_NetworkCharSelection.IsLobbyClosed.OnValueChanged -= OnLobbyClosedChanged; +// m_NetworkCharSelection.LobbyPlayers.OnListChanged -= OnLobbyPlayerStateChanged; +// } +// } + +// void OnNetworkSpawn() +// { +// if (!NetworkManager.Singleton.IsClient) +// { +// enabled = false; +// } +// else +// { +// m_NetworkCharSelection.IsLobbyClosed.OnValueChanged += OnLobbyClosedChanged; +// m_NetworkCharSelection.LobbyPlayers.OnListChanged += OnLobbyPlayerStateChanged; +// } +// } + +// /// +// /// Called when our PlayerNumber (e.g. P1, P2, etc.) has been assigned by the server +// /// +// /// +// void OnAssignedPlayerNumber(int playerNum) +// { +// m_ClassInfoBox.OnSetPlayerNumber(playerNum); +// } + +// void UpdatePlayerCount() +// { +// int count = m_NetworkCharSelection.LobbyPlayers.Count; +// var pstr = (count > 1) ? "players" : "player"; +// m_NumPlayersText.text = "" + count + " " + pstr + " connected"; +// } + +// /// +// /// Called by the server when any of the seats in the lobby have changed. (Including ours!) +// /// +// void OnLobbyPlayerStateChanged(NetworkListEvent changeEvent) +// { +// UpdateSeats(); +// UpdatePlayerCount(); + +// // now let's find our local player in the list and update the character/info box appropriately +// int localPlayerIdx = -1; +// for (int i = 0; i < m_NetworkCharSelection.LobbyPlayers.Count; ++i) +// { +// if (m_NetworkCharSelection.LobbyPlayers[i].ClientId == NetworkManager.Singleton.LocalClientId) +// { +// localPlayerIdx = i; +// break; +// } +// } + +// if (localPlayerIdx == -1) +// { +// // we aren't currently participating in the lobby! +// // this can happen for various reasons, such as the lobby being full and us not getting a seat. +// UpdateCharacterSelection(NetworkCharSelection.SeatState.Inactive); +// } +// else if (m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].SeatState == NetworkCharSelection.SeatState.Inactive) +// { +// // we haven't chosen a seat yet (or were kicked out of our seat by someone else) +// UpdateCharacterSelection(NetworkCharSelection.SeatState.Inactive); +// // make sure our player num is properly set in Lobby UI +// OnAssignedPlayerNumber(m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].PlayerNumber); +// } +// else +// { +// // we have a seat! Note that if our seat is LockedIn, this function will also switch the lobby mode +// UpdateCharacterSelection(m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].SeatState, m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].SeatIdx); +// } +// } + +// /// +// /// Internal utility that sets the character-graphics and class-info box based on +// /// our chosen seat. It also triggers a LobbyMode change when it notices that our seat-state +// /// is LockedIn. +// /// +// /// Our current seat state +// /// Which seat we're sitting in, or -1 if SeatState is Inactive +// void UpdateCharacterSelection(NetworkCharSelection.SeatState state, int seatIdx = -1) +// { +// if (seatIdx < -1 || seatIdx >= m_NetworkCharSelection.AvatarConfiguration.Length) +// { +// Debug.LogError($"Invalid seat index: {seatIdx}. Must be between 0 and {m_NetworkCharSelection.AvatarConfiguration.Length - 1}."); +// return; // Prevent out-of-bounds access. +// } + +// bool isNewSeat = m_LastSeatSelected != seatIdx; +// m_LastSeatSelected = seatIdx; + +// if (state == NetworkCharSelection.SeatState.Inactive) +// { +// // Deactivate current character graphics when unselecting a seat +// if (m_CurrentCharacterGraphics) +// { +// m_CurrentCharacterGraphics.SetActive(false); +// } +// m_ClassInfoBox.ConfigureForNoSelection(); +// m_HasLocalPlayerLockedIn = false; // Reset lock-in status +// ConfigureUIForLobbyMode(LobbyMode.ChooseSeat); +// return; +// } + +// if (seatIdx == -1) +// { +// Debug.LogWarning("Seat index is -1 for an active state. This should not happen."); +// return; +// } + +// // Change character preview when selecting a new seat +// if (isNewSeat) +// { +// var selectedCharacterGraphics = GetCharacterGraphics(m_NetworkCharSelection.AvatarConfiguration[seatIdx]); + +// if (m_CurrentCharacterGraphics) +// { +// m_CurrentCharacterGraphics.SetActive(false); // Deactivate previous graphics +// } + +// selectedCharacterGraphics.SetActive(true); // Activate new character graphics +// m_CurrentCharacterGraphics = selectedCharacterGraphics; +// m_CurrentCharacterGraphicsAnimator = m_CurrentCharacterGraphics.GetComponent(); + +// m_ClassInfoBox.ConfigureForClass(m_NetworkCharSelection.AvatarConfiguration[seatIdx].CharacterClass); +// } + +// // Handle lock-in and active state changes +// if (state == NetworkCharSelection.SeatState.LockedIn && !m_HasLocalPlayerLockedIn) +// { +// // Local player locks in their choice +// ConfigureUIForLobbyMode(m_NetworkCharSelection.IsLobbyClosed.Value ? LobbyMode.LobbyEnding : LobbyMode.SeatChosen); +// m_HasLocalPlayerLockedIn = true; +// // m_CurrentCharacterGraphicsAnimator.SetTrigger(m_AnimationTriggerOnCharChosen); // Optional animation trigger +// } +// else if (state == NetworkCharSelection.SeatState.Active && m_HasLocalPlayerLockedIn) +// { +// // Reset if locked-in choice was unselected +// ConfigureUIForLobbyMode(LobbyMode.ChooseSeat); +// m_ClassInfoBox.SetLockedIn(false); +// m_HasLocalPlayerLockedIn = false; +// } +// else if (state == NetworkCharSelection.SeatState.Active && isNewSeat) +// { +// // Handle animation trigger when actively selecting a new seat +// // m_CurrentCharacterGraphicsAnimator.SetTrigger(m_AnimationTriggerOnCharSelect); // Optional animation trigger +// } +// } + + +// /// +// /// Internal utility that sets the graphics for the eight lobby-seats (based on their current networked state) +// /// +// void UpdateSeats() +// { +// // Players can hop between seats -- and can even SHARE seats -- while they're choosing a class. +// // Once they have chosen their class (by "locking in" their seat), other players in that seat are kicked out. +// // But until a seat is locked in, we need to display each seat as being used by the latest player to choose it. +// // So we go through all players and figure out who should visually be shown as sitting in that seat. +// NetworkCharSelection.LobbyPlayerState[] curSeats = new NetworkCharSelection.LobbyPlayerState[m_PlayerSeats.Count]; +// foreach (NetworkCharSelection.LobbyPlayerState playerState in m_NetworkCharSelection.LobbyPlayers) +// { +// if (playerState.SeatIdx == -1 || playerState.SeatState == NetworkCharSelection.SeatState.Inactive) +// continue; // this player isn't seated at all! +// if (curSeats[playerState.SeatIdx].SeatState == NetworkCharSelection.SeatState.Inactive +// || (curSeats[playerState.SeatIdx].SeatState == NetworkCharSelection.SeatState.Active && curSeats[playerState.SeatIdx].LastChangeTime < playerState.LastChangeTime)) +// { +// // this is the best candidate to be displayed in this seat (so far) +// curSeats[playerState.SeatIdx] = playerState; +// } +// } + +// // now actually update the seats in the UI +// for (int i = 0; i < m_PlayerSeats.Count; ++i) +// { +// m_PlayerSeats[i].SetState(curSeats[i].SeatState, curSeats[i].PlayerNumber, curSeats[i].PlayerName); +// } +// } + +// /// +// /// Called by the server when the lobby closes (because all players are seated and locked in) +// /// +// void OnLobbyClosedChanged(bool wasLobbyClosed, bool isLobbyClosed) +// { +// if (isLobbyClosed) +// { +// ConfigureUIForLobbyMode(LobbyMode.LobbyEnding); + +// } +// else +// { +// if (m_LastSeatSelected == -1) +// { +// ConfigureUIForLobbyMode(LobbyMode.ChooseSeat); +// } +// else +// { +// ConfigureUIForLobbyMode(LobbyMode.SeatChosen); +// m_ClassInfoBox.ConfigureForClass(m_NetworkCharSelection.AvatarConfiguration[m_LastSeatSelected].CharacterClass); +// } +// } +// } + +// /// +// /// Turns on the UI elements for a specified "lobby mode", and turns off UI elements for all other modes. +// /// It can also disable/enable the lobby seats and the "Ready" button if they are inappropriate for the +// /// given mode. +// /// +// void ConfigureUIForLobbyMode(LobbyMode mode) +// { +// // first the easy bit: turn off all the inappropriate ui elements, and turn the appropriate ones on! +// foreach (var list in m_LobbyUIElementsByMode.Values) +// { +// foreach (var uiElement in list) +// { +// uiElement.SetActive(false); +// } +// } + +// foreach (var uiElement in m_LobbyUIElementsByMode[mode]) +// { +// uiElement.SetActive(true); +// } + +// // that finishes the easy bit. Next, each lobby mode might also need to configure the lobby seats and class-info box. +// bool isSeatsDisabledInThisMode = false; +// switch (mode) +// { +// case LobbyMode.ChooseSeat: +// if (m_LastSeatSelected == -1) +// { +// if (m_CurrentCharacterGraphics) +// { +// m_CurrentCharacterGraphics.gameObject.SetActive(false); +// } +// m_ClassInfoBox.ConfigureForNoSelection(); +// } +// m_ReadyButtonText.text = "READY!"; +// break; +// case LobbyMode.SeatChosen: +// isSeatsDisabledInThisMode = true; +// m_ClassInfoBox.SetLockedIn(true); +// m_ReadyButtonText.text = "UNREADY"; +// break; +// case LobbyMode.FatalError: +// isSeatsDisabledInThisMode = true; +// m_ClassInfoBox.ConfigureForNoSelection(); +// break; +// case LobbyMode.LobbyEnding: +// isSeatsDisabledInThisMode = true; +// m_ClassInfoBox.ConfigureForNoSelection(); +// break; +// } + +// // go through all our seats and enable or disable buttons +// foreach (var seat in m_PlayerSeats) +// { +// // disable interaction if seat is already locked or all seats disabled +// seat.SetDisableInteraction(seat.IsLocked() || isSeatsDisabledInThisMode); +// } + +// } + +// /// +// /// Called directly by UI elements! +// /// +// /// +// public void OnPlayerClickedSeat(int seatIdx) +// { +// if (m_NetworkCharSelection.IsSpawned) +// { +// m_NetworkCharSelection.ServerChangeSeatRpc(NetworkManager.Singleton.LocalClientId, seatIdx, false); +// } +// } + +// /// +// /// Called directly by UI elements! +// /// +// public void OnPlayerClickedReady() +// { +// if (m_NetworkCharSelection.IsSpawned) +// { +// // request to lock in or unlock if already locked in +// m_NetworkCharSelection.ServerChangeSeatRpc(NetworkManager.Singleton.LocalClientId, m_LastSeatSelected, !m_HasLocalPlayerLockedIn); +// } +// } + +// GameObject GetCharacterGraphics(Avatar avatar) +// { +// if (!m_SpawnedCharacterGraphics.TryGetValue(avatar.Guid, out GameObject characterGraphics)) +// { +// characterGraphics = Instantiate(avatar.GraphicsCharacterSelect, m_CharacterGraphicsParent); +// m_SpawnedCharacterGraphics.Add(avatar.Guid, characterGraphics); +// } + +// return characterGraphics; +// } + +// } +//} diff --git a/Assets/Scripts/Gameplay/GameState/ServerCharSelectState.cs b/Assets/Scripts/Gameplay/GameState/ServerCharSelectState.cs index 48ccee3..3deb85b 100644 --- a/Assets/Scripts/Gameplay/GameState/ServerCharSelectState.cs +++ b/Assets/Scripts/Gameplay/GameState/ServerCharSelectState.cs @@ -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) { int idx = FindLobbyPlayerIdx(clientId); @@ -81,66 +56,24 @@ namespace Unity.BossRoom.Gameplay.GameState { 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; } - - if (newSeatIdx == -1) - { - // 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; - } - } - } - + + // 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); - - 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(); } - + /// /// Returns the index of a client in the master LobbyPlayer list, or -1 if not found /// @@ -153,59 +86,26 @@ namespace Unity.BossRoom.Gameplay.GameState } return -1; } - public void StartGame() - { - networkCharSelection.IsLobbyClosed.Value = true; - SaveLobbyResults(); - 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; } - + foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers) { 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; - - // remember our choices so the next scene can use the info + 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()); } - - // 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() { if (m_WaitToEndLobbyCoroutine != null) @@ -340,12 +240,12 @@ namespace Unity.BossRoom.Gameplay.GameState } } - //using System; //using System.Collections; //using Unity.BossRoom.ConnectionManagement; //using Unity.BossRoom.Gameplay.GameplayObjects; //using Unity.BossRoom.Infrastructure; +//using Unity.Multiplayer.Samples; //using Unity.Multiplayer.Samples.BossRoom; //using Unity.Multiplayer.Samples.Utilities; //using Unity.Netcode; @@ -365,7 +265,7 @@ namespace Unity.BossRoom.Gameplay.GameState // public override GameState ActiveState => GameState.CharSelect; // public NetworkCharSelection networkCharSelection { get; private set; } -// //public static int numOfPlayers; + // Coroutine m_WaitToEndLobbyCoroutine; // [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) // { // int idx = FindLobbyPlayerIdx(clientId); @@ -470,13 +395,20 @@ namespace Unity.BossRoom.Gameplay.GameState // } // return -1; // } - -// /// -// /// Looks through all our connections and sees if everyone has locked in their choice; -// /// if so, we lock in the whole lobby, save state, and begin the transition to gameplay -// /// +// public void StartGame() +// { +// networkCharSelection.IsLobbyClosed.Value = true; +// SaveLobbyResults(); +// 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; +// } + // foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers) // { // if (playerInfo.SeatState != NetworkCharSelection.SeatState.LockedIn) @@ -490,12 +422,32 @@ namespace Unity.BossRoom.Gameplay.GameState // 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()); // } -// /// -// /// Cancels the process of closing the lobby, so that if a new player joins, they are able to chose a character. -// /// + +// // 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() // { // if (m_WaitToEndLobbyCoroutine != null) @@ -508,7 +460,6 @@ namespace Unity.BossRoom.Gameplay.GameState // void SaveLobbyResults() // { // int numofPlayersInLobby = networkCharSelection.LobbyPlayers.Count; -// //numOfPlayers = numofPlayersInLobby; // PlayerPrefs.SetInt("NumberOfLobbyPlayers", numofPlayersInLobby); // Debug.Log("Number of Players in lobby are: " + numofPlayersInLobby); // foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers) @@ -517,8 +468,6 @@ namespace Unity.BossRoom.Gameplay.GameState // 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 = // networkCharSelection.AvatarConfiguration[playerInfo.SeatIdx].Guid.ToNetworkGuid(); // } @@ -561,9 +510,7 @@ namespace Unity.BossRoom.Gameplay.GameState // 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; -// // When the client finishes loading the Lobby Map, we will need to Seat it // SeatNewPlayer(sceneEvent.ClientId); // } @@ -576,28 +523,23 @@ namespace Unity.BossRoom.Gameplay.GameState // return possiblePlayerNumber; // } // } -// // we couldn't get a Player# for this person... which means the lobby is full! // return -1; // } // bool IsPlayerNumberAvailable(int playerNumber) // { -// bool found = false; // foreach (NetworkCharSelection.LobbyPlayerState playerState in networkCharSelection.LobbyPlayers) // { // if (playerState.PlayerNumber == playerNumber) // { -// found = true; -// break; +// return false; // } // } - -// return !found; +// return true; // } // 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) // { // CancelCloseLobby(); @@ -609,13 +551,11 @@ namespace Unity.BossRoom.Gameplay.GameState // var playerData = sessionPlayerData.Value; // 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(); // } // if (playerData.PlayerNumber == -1) // { -// // Sanity check. We ran out of seats... there was no room! -// 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}"); +// throw new Exception($"No available player number for client ID {clientId}"); // } // 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) // { -// // 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) // { // if (networkCharSelection.LobbyPlayers[i].ClientId == clientId) @@ -637,9 +576,9 @@ namespace Unity.BossRoom.Gameplay.GameState // if (!networkCharSelection.IsLobbyClosed.Value) // { -// // If the lobby is not already closing, close if the remaining players are all ready // CloseLobbyIfReady(); // } // } // } //} +