CodeObjective1CPP

#include "UnrealProject.h"

#include "Objective1.h"

#include "UFOGameMode.h"

 

 

UObjective1::UObjective1()

{

FString newText = TEXT("Kill the Humans");

currentObjectiveText = FText::FromString(newText);

 

humansKilled = 0;

humansKilledNeeded = 150;

 

scoreOnCompletion = 200;

xpOnCompletion = 20.0f;

 

}

 

 

void UObjective1::OnCreation()

{

 

if (gameMode != NULL)

{

gameMode->onHumanKilledDelegate.AddUniqueDynamic(this, &UObjective1::OnHumanKilled);

}

else

{

this->ConditionalBeginDestroy();

}

 

}

 

void UObjective1::OnUpdate(float deltaTime)

{

FString newText;

 

if (!isObjectiveFinished)

{

newText = TEXT("Humans Killed : ") + FString::FromInt(humansKilled) + TEXT(" / ") + FString::FromInt(humansKilledNeeded);

}

else

{

 

newText = TEXT("Objective Completed !");

 

}

 

currentProgressionText = FText::FromString(newText);

 

}

 

void UObjective1::OnHumanKilled()

{

if (!isObjectiveFinished)

{

 

humansKilled++;

 

if (humansKilled >= humansKilledNeeded)

{

 

gameMode->onHumanKilledDelegate.RemoveDynamic(this, &UObjective1::OnHumanKilled);

gameMode->SubObjectiveReached( );

 

//Add Rewards

gameMode->scoreSystem->AddScore(EScoreType::ST_SubObjective, scoreOnCompletion);

gameMode->AddXPToPlayer(xpOnCompletion);

 

isObjectiveFinished = true;

}

}

 

return;

}