Seperates new properties and behaviours associated with only the main bounties and not any other bounties
130 lines
4.4 KiB
C++
130 lines
4.4 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "BountyDirector.h"
|
|
|
|
#include "Components/ArrowComponent.h"
|
|
|
|
// Sets default values
|
|
ABountyDirector::ABountyDirector()
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
}
|
|
|
|
// Called every frame
|
|
void ABountyDirector::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
|
|
}
|
|
// Called when the game starts or when spawned
|
|
void ABountyDirector::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
PlayerChar = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter());
|
|
if (!IsValid(PlayerChar)) UE_LOG(LogTemp, Fatal, TEXT("Players Character isn't being loaded in BeginPlay() in BountyDirector"));
|
|
|
|
// Setup a component for bounties to attach to on the player
|
|
for (UActorComponent* ActorComp : PlayerChar->GetComponentsByTag(UArrowComponent::StaticClass(), FName("Bounty")))
|
|
{
|
|
BountyAttachmentPoint = Cast<UArrowComponent>(ActorComp);
|
|
if (!IsValid(BountyAttachmentPoint)) UE_LOG(LogTemp, Fatal, TEXT("There's no Bounty Attachment UArrowComponent on Players Char "));
|
|
break;
|
|
}
|
|
|
|
SpawnBountyAndItsSideBounties();
|
|
UpdateBountyDisplay();
|
|
}
|
|
|
|
void ABountyDirector::SpawnBountyAndItsSideBounties()
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("Spawning Bounty..."));
|
|
|
|
if (BountyClassArray.IsEmpty()) return;
|
|
if (!IsValid(BountyClassArray[CurrentBountyIndex])) UE_LOG(LogTemp, Fatal, TEXT("Missing Bounty at Index: %d"), CurrentBountyIndex);
|
|
|
|
// Spawn Main Bounty which the current bounty index is pointing to
|
|
FActorSpawnParameters SpawnParams;
|
|
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
|
|
AActor* BountyActor = GetWorld()->SpawnActor<AActor>(BountyClassArray[CurrentBountyIndex], PlayerChar->GetActorLocation(), PlayerChar->GetActorRotation(), SpawnParams);
|
|
const FAttachmentTransformRules AttachmentTransformRules(EAttachmentRule::SnapToTarget, true);
|
|
BountyActor->AttachToComponent(BountyAttachmentPoint, AttachmentTransformRules);
|
|
|
|
ActiveBounty = Cast<AMainBountyClass>(BountyActor);
|
|
if (!IsValid(ActiveBounty)) UE_LOG(LogTemp, Fatal, TEXT("Failed to Cast to Bounty class"));
|
|
|
|
// WHEN MARCEL STOPS PLAYING WITH THE CHARACTER, ADD THIS BOUNTY TO PLAYERS ARRAY OF ACTIVE BOUNTIES!!!!!
|
|
ActiveBounty->CompletedFirstCheckpoint.AddDynamic(this, &ABountyDirector::DestroyActiveSideBounties);
|
|
ActiveSideBounties.Reset();
|
|
for (TSubclassOf<ASideBountyClass> SideBountyClass : ActiveBounty->GetSideBountiesToSpawn())
|
|
{
|
|
if (!IsValid(SideBountyClass)) continue;
|
|
AActor* SideBountyActor = GetWorld()->SpawnActor<AActor>(SideBountyClass, PlayerChar->GetActorLocation(), PlayerChar->GetActorRotation(), SpawnParams);
|
|
SideBountyActor->AttachToComponent(BountyAttachmentPoint, AttachmentTransformRules);
|
|
ASideBountyClass* SideBounty = Cast<ASideBountyClass>(SideBountyActor);
|
|
if (!IsValid(SideBounty)) UE_LOG(LogTemp, Fatal, TEXT("A SideBounty for %s has been set to a wrong type"), *ActiveBounty->GetBountyTitle());
|
|
int i = ActiveSideBounties.Add(SideBounty);
|
|
ActiveSideBounties[i]->CompletedSideBounty.AddDynamic(this, &ABountyDirector::EarnFavours);
|
|
// ONCE AGAIN WHEN MARCEL STOPS PLAYING WITH THE CHARACTER, ADD THIS SIDE BOUNTY TO PLAYERS ARRAY OF ACTIVE BOUNTIES!!!!!
|
|
}
|
|
}
|
|
|
|
void ABountyDirector::UpdateBountyProgression()
|
|
{
|
|
if (!IsValid(ActiveBounty)) return;
|
|
|
|
if (ActiveBounty->IsCompleted()) FinishActiveBounty();
|
|
}
|
|
|
|
void ABountyDirector::FinishActiveBounty()
|
|
{
|
|
ActiveBounty->CollectRewards();
|
|
|
|
// Destroy old Bounties
|
|
ActiveBounty->Destroy();
|
|
DestroyActiveSideBounties();
|
|
|
|
// Increment Main and Side Bounty Indexes
|
|
CurrentBountyIndex++;
|
|
|
|
// Game Completion Check
|
|
if (CurrentBountyIndex >= BountyClassArray.Num())
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("Finished all bounties currently available in the game :)"));
|
|
ActiveBounty = nullptr;
|
|
UpdateBountyDisplay();
|
|
return;
|
|
}
|
|
|
|
SpawnBountyAndItsSideBounties();
|
|
UpdateBountyDisplay();
|
|
}
|
|
|
|
void ABountyDirector::DestroyActiveSideBounties()
|
|
{
|
|
for (ASideBountyClass* SideBounty : ActiveSideBounties)
|
|
{
|
|
if (!IsValid(SideBounty)) continue;
|
|
|
|
// WHEN MARCEL STOPS PLAYING WITH PLAYERS CHARACTER, REMOVE THIS SIDE BOUNTY FROM ACTIVE BOUNTIES
|
|
|
|
SideBounty->DestroyCheckpoints();
|
|
SideBounty->Destroy();
|
|
}
|
|
|
|
UpdateBountyDisplay();
|
|
}
|
|
|
|
void ABountyDirector::EarnFavours(int FavoursEarned)
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("Earned %d favours"), FavoursEarned);
|
|
}
|
|
|
|
|
|
|
|
|