Exemplo n.º 1
0
bool AGameState::HasMatchEnded() const
{
	if (GetMatchState() == MatchState::WaitingPostMatch || GetMatchState() == MatchState::LeavingMap)
	{
		return true;
	}

	return false;
}
Exemplo n.º 2
0
bool AGameState::HasMatchStarted() const
{
	if (GetMatchState() == MatchState::EnteringMap || GetMatchState() == MatchState::WaitingToStart)
	{
		return false;
	}

	return true;
}
Exemplo n.º 3
0
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();
			}
		}
	}
}
Exemplo n.º 4
0
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();
			}
		}
	}
}
Exemplo n.º 5
0
bool AGameState::IsMatchInProgress() const
{
	if (GetMatchState() == MatchState::InProgress)
	{
		return true;
	}

	return false;
}
Exemplo n.º 6
0
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();
				}
			}
		}
	}
}
Exemplo n.º 7
0
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;
		}
	}
}
Exemplo n.º 8
0
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;
		}
	}
}