Spawn players during warmup but disable their input until match starts

This commit is contained in:
Kevin Poretti 2023-01-16 13:02:11 -05:00
parent 10a672dc8f
commit a21e7e71c9
4 changed files with 31 additions and 34 deletions

Binary file not shown.

View File

@ -90,7 +90,7 @@ void AGSGameModeBase::RestartPlayer(AController* NewPlayer)
// inform player controller that game has started using client RPC // inform player controller that game has started using client RPC
AGSPlayerController* PC = Cast<AGSPlayerController>(NewPlayer); AGSPlayerController* PC = Cast<AGSPlayerController>(NewPlayer);
if(PC) if(PC && IsMatchInProgress())
{ {
PC->Client_GameStarted(); PC->Client_GameStarted();
} }
@ -113,37 +113,6 @@ bool AGSGameModeBase::CanDamagePlayer(AGSPlayerController* Damager, AGSPlayerCon
void AGSGameModeBase::PickTeam(AGSPlayerState* PlayerState) void AGSGameModeBase::PickTeam(AGSPlayerState* PlayerState)
{ {
/*
// place player on the team with the fewest players, or on the first team if all teams have the same number of players
TArray<int32> NumTeamPlayers;
AGSGameState* GS = GetGameState<AGSGameState>();
NumTeamPlayers.AddZeroed(GS->GetNumTeams());
check(NumTeamPlayers.Num() > 0);
for(int32 PlayerIdx = 0; PlayerIdx < GS->PlayerArray.Num(); ++PlayerIdx)
{
AGSPlayerState* CurrPS = Cast<AGSPlayerState>(GS->PlayerArray[PlayerIdx]);
if(CurrPS && CurrPS->GetTeamNum() >= 0 && CurrPS->GetTeamNum() < NumTeamPlayers.Num())
{
NumTeamPlayers[CurrPS->GetTeamNum()]++;
}
else
{
UE_LOG(LogTemp, Error, TEXT("Player %s is on team number %d but only %d teams exist"), *CurrPS->GetPlayerName(), CurrPS->GetTeamNum(), NumTeamPlayers.Num())
}
}
int32 LowestTeamIdx = 0;
for(int32 TeamIdx = 0; TeamIdx < NumTeamPlayers.Num(); TeamIdx++)
{
if(NumTeamPlayers[TeamIdx] < NumTeamPlayers[LowestTeamIdx])
{
LowestTeamIdx = TeamIdx;
}
}
*/
PlayerState->SetTeamNum(PlayerState->GetPlayerController()->GetLocalPlayer()->GetControllerId()); PlayerState->SetTeamNum(PlayerState->GetPlayerController()->GetLocalPlayer()->GetControllerId());
} }
@ -245,6 +214,28 @@ void AGSGameModeBase::FinishMatch()
} }
} }
void AGSGameModeBase::HandleStartingNewPlayer_Implementation(APlayerController* NewPlayer)
{
// If players should start as spectators, leave them in the spectator state
if (!bStartPlayersAsSpectators && !MustSpectate(NewPlayer))
{
// If match is in progress, start the player
if ((GetMatchState() == MatchState::WaitingToStart || IsMatchInProgress()) && PlayerCanRestart(NewPlayer))
{
RestartPlayer(NewPlayer);
}
// Check to see if we should start right away, avoids a one frame lag in single player games
else if (GetMatchState() == MatchState::WaitingToStart)
{
// Check to see if we should start the match
if (ReadyToStartMatch())
{
StartMatch();
}
}
}
}
void AGSGameModeBase::HandleMatchIsWaitingToStart() void AGSGameModeBase::HandleMatchIsWaitingToStart()
{ {
@ -266,6 +257,7 @@ void AGSGameModeBase::HandleMatchIsWaitingToStart()
AGSPlayerController* PC = Cast<AGSPlayerController>(*It); AGSPlayerController* PC = Cast<AGSPlayerController>(*It);
if(PC) if(PC)
{ {
RestartPlayer(PC);
PC->Client_WarmupStarted(); PC->Client_WarmupStarted();
} }
} }

View File

@ -80,6 +80,8 @@ public:
*/ */
void FinishMatch(); void FinishMatch();
virtual void HandleStartingNewPlayer_Implementation(APlayerController* NewPlayer) override;
/** /**
* Sets up match warmup timer * Sets up match warmup timer
*/ */

View File

@ -30,6 +30,9 @@ void AGSPlayerController::Client_OnDeath_Implementation(AGSPlayerState* KillerPl
void AGSPlayerController::Client_WarmupStarted_Implementation() void AGSPlayerController::Client_WarmupStarted_Implementation()
{ {
// wait for server to tell us we can move
SetIgnoreMoveInput(true);
OnWarmupStarted(); OnWarmupStarted();
} }