This code demonstrates the implementation of the the Nimbus cloud testing the heart of the person who tries to ride it. It checks if the player's heart is pure and grants them the ability to ride the Nimbus if they pass the test.
bool ANimbus::GivePureHeartTest(AActor* PlayerToTest)
{
bool bHeartIsPure = false;
// Check if the player is valid
if (PlayerToTest && bCanGiveAway)
{
// Cast to the player's class which should be Goku
Goku = dynamic_cast<AGokuCharacter*>(PlayerToTest);
if (Goku)
{
// Call the function to check the player's heart
bHeartIsPure = Goku->IsHeartPure();
if (bHeartIsPure) {
// Call the function to give the player the ability to fly
UNimbusRide* NimbusRide = Cast<UNimbusRide>(Goku->GetComponentByClass(UNimbusRide::StaticClass()));
if (NimbusRide)
{
if (bOnNimbus)
{
GiveFlyAbility();
NimbusRide->Ride();
UE_LOG(LogTemp, Warning, TEXT("You ARE on the nimbus!"));
UE_LOG(LogTemp, Warning, TEXT("OnNimbus value is: %d"), bOnNimbus);
return bHeartIsPure;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("You are NOT on the nimbus!"));
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("NimbusRide component not found!"));
}
UE_LOG(LogTemp, Warning, TEXT("You have passed the test!"));
return bHeartIsPure;
}
else {
// Give the player a message that they failed the test
// TODO: Add message to UI after it's been set up
UE_LOG(LogTemp, Warning, TEXT("You have failed the test of heart. You suck!"));
return bHeartIsPure;
}
}
}
return bHeartIsPure;
}