void ASGameMode::DefaultTimer() { /* Immediately start the match while playing in editor */ //if (GetWorld()->IsPlayInEditor()) { if (GetMatchState() == MatchState::WaitingToStart) { StartMatch(); } } /* Only increment time of day while game is active */ if (IsMatchInProgress()) { ASGameState* MyGameState = Cast<ASGameState>(GameState); if (MyGameState) { /* Increment our time of day */ MyGameState->ElapsedGameMinutes += MyGameState->GetTimeOfDayIncrement(); /* Determine our state */ MyGameState->GetAndUpdateIsNight(); /* Trigger events when night starts or ends */ bool CurrentIsNight = MyGameState->GetIsNight(); if (CurrentIsNight != LastIsNight) { EHUDMessage MessageID = CurrentIsNight ? EHUDMessage::Game_SurviveStart : EHUDMessage::Game_SurviveEnded; MyGameState->BroadcastGameMessage(MessageID); /* The night just ended, respawn all dead players */ if (!CurrentIsNight) { OnNightEnded(); } /* Update bot states */ if (CurrentIsNight) { WakeAllBots(); } else { PassifyAllBots(); } } LastIsNight = MyGameState->bIsNight; } } }
void ASPlayerController::UnFreeze() { Super::UnFreeze(); // Check if match is ending or has ended. ASGameState* MyGameState = Cast<ASGameState>(GetWorld()->GameState); if (MyGameState && MyGameState->HasMatchEnded()) { /* Don't allow spectating or respawns */ return; } /* Respawn or spectate */ if (bRespawnImmediately) { ServerRestartPlayer(); } else { StartSpectating(); } }
void ASGameMode::SpawnBotHandler() { if (!bSpawnZombiesAtNight) return; ASGameState* MyGameState = Cast<ASGameState>(GameState); if (MyGameState) { /* Only spawn bots during night time */ if (MyGameState->GetIsNight()) { /* This could be any dynamic number based on difficulty (eg. increasing after having survived a few nights) */ const int32 MaxPawns = 10; /* Check number of available pawns (players included) */ if (GetWorld()->GetNumPawns() < MaxPawns) { SpawnNewBot(); } } } }
void ASGameMode::DefaultTimer() { /* This function is called every 1 second. */ Super::DefaultTimer(); /* Immediately start the match while playing in editor */ //if (GetWorld()->IsPlayInEditor()) { if (GetMatchState() == MatchState::WaitingToStart) { StartMatch(); } } /* Only increment time of day while game is active */ if (IsMatchInProgress()) { ASGameState* MyGameState = Cast<ASGameState>(GameState); if (MyGameState) { /* Increment our time of day */ MyGameState->ElapsedGameMinutes += MyGameState->GetTimeOfDayIncrement(); /* Determine our state */ MyGameState->GetAndUpdateIsNight(); /* Trigger events when night starts or ends */ bool CurrentIsNight = MyGameState->GetIsNight(); if (CurrentIsNight != LastIsNight) { FString MessageText = CurrentIsNight ? "SURVIVE!" : "You Survived! Now prepare for the coming night!"; ASGameState* MyGameState = Cast<ASGameState>(GameState); if (MyGameState) { MyGameState->BroadcastGameMessage(MessageText); } /* The night just ended, respawn all dead players */ if (!CurrentIsNight) { /* Respawn spectating players that died during the night */ for (FConstPlayerControllerIterator It = GetWorld()->GetPlayerControllerIterator(); It; It++) { /* Look for all players that are spectating */ ASPlayerController* MyController = Cast<ASPlayerController>(*It); if (MyController) { if (MyController->PlayerState->bIsSpectator) { RestartPlayer(MyController); MyController->ClientHUDStateChanged(EHUDState::Playing); } else { /* Player still alive, award him some points */ ASCharacter* MyPawn = Cast<ASCharacter>(MyController->GetPawn()); if (MyPawn && MyPawn->IsAlive()) { ASPlayerState* PS = Cast<ASPlayerState>(MyController->PlayerState); if (PS) { PS->ScorePoints(NightSurvivedScore); } } } } } } /* Update bot states */ if (CurrentIsNight) { WakeAllBots(); } else { PassifyAllBots(); } } LastIsNight = MyGameState->bIsNight; } } }