Skip to content

Commit

Permalink
Remove AI players on return (squash this)
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed Jun 8, 2024
1 parent 5c2c597 commit 2bdc099
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Assets/Scripts/Control&Input/Peer2PeerTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,15 @@ private void AddAiPlayers()
}
}

private void RemoveAiPlayers()
{
foreach (var ai in players.Values.Where(p => p.type is PlayerType.AI))
{
NetworkServer.SendToAll(new PlayerLeftMessage(ai.id));
}
}


// Called after shooting rounds (TODO just use the same matchcontroller stuff???)
private static void UpdatePlayerDetailsAfterShootingRound()
{
Expand Down Expand Up @@ -543,7 +552,8 @@ private static void UpdatePlayerInventoryForIdentity(PlayerIdentity identity)

public override void OnServerChangeScene(string newSceneName)
{
var needsExtraAiPlayers = PlayerInputManagerController.Singleton.MatchHasAI && !MatchController.Singleton;
var isAiEnabled = PlayerInputManagerController.Singleton.MatchHasAI;
var needsExtraAiPlayers = isAiEnabled && !MatchController.Singleton;
if (needsExtraAiPlayers)
{
AddAiPlayers();
Expand All @@ -560,6 +570,8 @@ public override void OnServerChangeScene(string newSceneName)
break;
case Scenes.Menu:
isInMatch = false;
if (isAiEnabled)
RemoveAiPlayers();
NetworkServer.RegisterHandler<PlayerConnectedMessage>(OnSpawnPlayerInput);
break;
default:
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/UI/MainMenu/MainMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ private void GoBackToLobby()
SelectControl(playerSelectMenuDefaultButton);
SetStartButtonState();
playerSelectManager.UpdateLobby();
if (playerInputManagerController.MatchHasAI)
aIButton.Toggle();
}
else
{
// Clients should go to their own lobby scene
SceneManager.LoadScene(Scenes.ClientLobby);
if (SceneManager.GetActiveScene().name == Scenes.Menu)
SceneManager.LoadScene(Scenes.ClientLobby);
}
}

Expand Down

0 comments on commit 2bdc099

Please sign in to comment.