bool AGameState::HasMatchEnded() const { if (GetMatchState() == MatchState::WaitingPostMatch || GetMatchState() == MatchState::LeavingMap) { return true; } return false; }
bool AGameState::HasMatchStarted() const { if (GetMatchState() == MatchState::EnteringMap || GetMatchState() == MatchState::WaitingToStart) { return false; } return true; }
void ALabyrinthGameMode::DefaultTimer() { Super::DefaultTimer(); // don't update timers for play in editor mode, it's not a real match if (GetWorld()->IsPlayInEditor()) { // start the match if necessary if (GetMatchState() == MatchState::WaitingToStart) { StartMatch(); } return; } ALGameState* const MyGameState = Cast<ALGameState>(GameState); if (MyGameState && MyGameState->RemainingTime > 0 && !MyGameState->bIsTimerPaused) { MyGameState->RemainingTime--; if (MyGameState->RemainingTime <= 0) { if (GetMatchState() == MatchState::WaitingPostMatch) { RestartGame(); } else if (GetMatchState() == MatchState::InProgress) { FinishMatch(); // Send end round events ALGameState* const MyGameState = Cast<ALGameState>(GameState); for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; It++) { ALPlayerController* PlayerController = Cast<ALPlayerController>(*It); if (PlayerController && MyGameState) { ALPlayerState* PlayerState = Cast<ALPlayerState>((*It)->PlayerState); const bool bIsWinner = IsWinner(PlayerState); // TO-DO: Add this to the Player controller //PlayerController->ClientSendRoundEndEvent(bIsWinner, MyGameState->ElapsedTime); } } } else if (GetMatchState() == MatchState::WaitingToStart) { StartMatch(); } } } }
void AShooterGameMode::DefaultTimer() { // don't update timers for Play In Editor mode, it's not real match if (GetWorld()->IsPlayInEditor()) { // start match if necessary. if (GetMatchState() == MatchState::WaitingToStart) { StartMatch(); } return; } AShooterGameState* const MyGameState = Cast<AShooterGameState>(GameState); if (MyGameState && MyGameState->RemainingTime > 0 && !MyGameState->bTimerPaused) { MyGameState->RemainingTime--; if (MyGameState->RemainingTime <= 0) { if (GetMatchState() == MatchState::WaitingPostMatch) { RestartGame(); } else if (GetMatchState() == MatchState::InProgress) { FinishMatch(); // Send end round events for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; ++It) { AShooterPlayerController* PlayerController = Cast<AShooterPlayerController>(*It); if (PlayerController && MyGameState) { AShooterPlayerState* PlayerState = Cast<AShooterPlayerState>((*It)->PlayerState); const bool bIsWinner = IsWinner(PlayerState); PlayerController->ClientSendRoundEndEvent(bIsWinner, MyGameState->ElapsedTime); } } } else if (GetMatchState() == MatchState::WaitingToStart) { StartMatch(); } } } }
bool AGameState::IsMatchInProgress() const { if (GetMatchState() == MatchState::InProgress) { return true; } return false; }
void AOnlineArenaGameMode::DefaultTimer() { const auto World = GetWorld(); if (nullptr != World && World->IsPlayInEditor()) { //!< PIE ‚Ì�ê�‡ if (MatchState::WaitingToStart == GetMatchState()) { StartMatch(); } } else { const auto MatchSteate = GetMatchState(); const auto GS = Cast<AOnlineGameState>(GameState); if (nullptr != GS) { --GS->RemainingTime; if (GS->RemainingTime <= 0) { GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, TEXT("TIME UP")); if (MatchState::WaitingPostMatch == MatchState) { RestartGame(); } else if (MatchState::InProgress == MatchState) { EndMatch(); } } else { GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, FString::FromInt(GS->RemainingTime)); if (MatchState::WaitingToStart == MatchState) { StartMatch(); } } } } }
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 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; } } }