Skip to content

Commit 8769ede

Browse files
Merge develop into feature/isdebug-flag-for-connection-approval
2 parents 1f6961b + 294d3fb commit 8769ede

File tree

2 files changed

+76
-14
lines changed

2 files changed

+76
-14
lines changed

Assets/BossRoom/Scripts/Client/Game/State/ClientCharSelectState.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ void OnLobbyClosedChanged(bool wasLobbyClosed, bool isLobbyClosed)
332332
{
333333
ConfigureUIForLobbyMode(LobbyMode.LobbyEnding);
334334
}
335+
else
336+
{
337+
if (m_LastSeatSelected == -1)
338+
{
339+
ConfigureUIForLobbyMode(LobbyMode.ChooseSeat);
340+
}
341+
else
342+
{
343+
ConfigureUIForLobbyMode(LobbyMode.SeatChosen);
344+
m_ClassInfoBox.ConfigureForClass(CharSelectData.AvatarConfiguration[m_LastSeatSelected].CharacterClass);
345+
}
346+
}
335347
}
336348

337349
/// <summary>

Assets/BossRoom/Scripts/Server/Game/State/ServerCharSelectState.cs

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ namespace Unity.Multiplayer.Samples.BossRoom.Server
1212
[RequireComponent(typeof(CharSelectData))]
1313
public class ServerCharSelectState : GameStateBehaviour
1414
{
15-
public override GameState ActiveState { get { return GameState.CharSelect; } }
15+
public override GameState ActiveState => GameState.CharSelect;
1616
public CharSelectData CharSelectData { get; private set; }
1717

18-
private ServerGameNetPortal m_ServerNetPortal;
18+
Coroutine m_WaitToEndLobbyCoroutine;
1919

20-
private void Awake()
20+
void Awake()
2121
{
2222
CharSelectData = GetComponent<CharSelectData>();
23-
m_ServerNetPortal = GameObject.FindGameObjectWithTag("GameNetPortal").GetComponent<ServerGameNetPortal>();
2423
}
2524

26-
private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
25+
void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
2726
{
2827
int idx = FindLobbyPlayerIdx(clientId);
2928
if (idx == -1)
@@ -93,7 +92,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
9392
/// <summary>
9493
/// Returns the index of a client in the master LobbyPlayer list, or -1 if not found
9594
/// </summary>
96-
private int FindLobbyPlayerIdx(ulong clientId)
95+
int FindLobbyPlayerIdx(ulong clientId)
9796
{
9897
for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
9998
{
@@ -107,7 +106,7 @@ private int FindLobbyPlayerIdx(ulong clientId)
107106
/// Looks through all our connections and sees if everyone has locked in their choice;
108107
/// if so, we lock in the whole lobby, save state, and begin the transition to gameplay
109108
/// </summary>
110-
private void CloseLobbyIfReady()
109+
void CloseLobbyIfReady()
111110
{
112111
foreach (CharSelectData.LobbyPlayerState playerInfo in CharSelectData.LobbyPlayers)
113112
{
@@ -122,10 +121,42 @@ private void CloseLobbyIfReady()
122121
SaveLobbyResults();
123122

124123
// Delay a few seconds to give the UI time to react, then switch scenes
125-
StartCoroutine(WaitToEndLobby());
124+
m_WaitToEndLobbyCoroutine = StartCoroutine(WaitToEndLobby());
126125
}
127126

128-
private void SaveLobbyResults()
127+
/// <summary>
128+
/// Cancels the process of closing the lobby, so that if a new player joins, they are able to chose a character.
129+
/// </summary>
130+
void CancelCloseLobby()
131+
{
132+
if (m_WaitToEndLobbyCoroutine != null)
133+
{
134+
StopCoroutine(m_WaitToEndLobbyCoroutine);
135+
}
136+
CharSelectData.IsLobbyClosed.Value = false;
137+
// Set all players unready so they can react to this cancellation
138+
SetAllUnready();
139+
}
140+
141+
void SetAllUnready()
142+
{
143+
for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
144+
{
145+
// Set all locked players to active so that they have to confirm their choice again
146+
if (CharSelectData.LobbyPlayers[i].SeatState == CharSelectData.SeatState.LockedIn)
147+
{
148+
CharSelectData.LobbyPlayers[i] = new CharSelectData.LobbyPlayerState(
149+
CharSelectData.LobbyPlayers[i].ClientId,
150+
CharSelectData.LobbyPlayers[i].PlayerName,
151+
CharSelectData.LobbyPlayers[i].PlayerNum,
152+
CharSelectData.SeatState.Active,
153+
CharSelectData.LobbyPlayers[i].SeatIdx,
154+
CharSelectData.LobbyPlayers[i].LastChangeTime);
155+
}
156+
}
157+
}
158+
159+
void SaveLobbyResults()
129160
{
130161
foreach (CharSelectData.LobbyPlayerState playerInfo in CharSelectData.LobbyPlayers)
131162
{
@@ -141,7 +172,7 @@ private void SaveLobbyResults()
141172
}
142173
}
143174

144-
private IEnumerator WaitToEndLobby()
175+
IEnumerator WaitToEndLobby()
145176
{
146177
yield return new WaitForSeconds(3);
147178
NetworkManager.SceneManager.LoadScene("BossRoom", LoadSceneMode.Single);
@@ -177,15 +208,15 @@ public override void OnNetworkSpawn()
177208
}
178209
}
179210

180-
private void OnSceneEvent(SceneEvent sceneEvent)
211+
void OnSceneEvent(SceneEvent sceneEvent)
181212
{
182213
// We need to filter out the event that are not a client has finished loading the scene
183214
if (sceneEvent.SceneEventType != SceneEventType.LoadComplete) return;
184215
// When the client finishes loading the Lobby Map, we will need to Seat it
185216
SeatNewPlayer(sceneEvent.ClientId);
186217
}
187218

188-
private int GetAvailablePlayerNumber()
219+
int GetAvailablePlayerNumber()
189220
{
190221
for (int possiblePlayerNumber = 0; possiblePlayerNumber < CharSelectData.k_MaxLobbyPlayers; ++possiblePlayerNumber)
191222
{
@@ -213,8 +244,14 @@ bool IsPlayerNumberAvailable(int playerNumber)
213244
return !found;
214245
}
215246

216-
private void SeatNewPlayer(ulong clientId)
247+
void SeatNewPlayer(ulong clientId)
217248
{
249+
// If lobby is closing and waiting to start the game, cancel to allow that new player to select a character
250+
if (CharSelectData.IsLobbyClosed.Value)
251+
{
252+
CancelCloseLobby();
253+
}
254+
218255
SessionPlayerData? sessionPlayerData = SessionManager<SessionPlayerData>.Instance.GetPlayerData(clientId);
219256
if (sessionPlayerData.HasValue)
220257
{
@@ -235,7 +272,7 @@ private void SeatNewPlayer(ulong clientId)
235272
}
236273
}
237274

238-
private void OnClientDisconnectCallback(ulong clientId)
275+
void OnClientDisconnectCallback(ulong clientId)
239276
{
240277
// clear this client's PlayerNumber and any associated visuals (so other players know they're gone).
241278
for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
@@ -246,6 +283,19 @@ private void OnClientDisconnectCallback(ulong clientId)
246283
break;
247284
}
248285
}
286+
287+
288+
if (CharSelectData.IsLobbyClosed.Value)
289+
{
290+
// If lobby is closing and waiting to start the game, cancel so that other players can react to it, and
291+
// wait for the player coming back if they want to.
292+
CancelCloseLobby();
293+
}
294+
else
295+
{
296+
// If it is not closing, set everyone as unready for the same reason
297+
SetAllUnready();
298+
}
249299
}
250300
}
251301
}

0 commit comments

Comments
 (0)