// Fill out your copyright notice in the Description page of Project Settings.


#include "BaseGadgetTutorial.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"

// Sets default values
ABaseGadgetTutorial::ABaseGadgetTutorial()
{
 	// 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;
	bAllowTickBeforeBeginPlay = false;

}

// Called when the game starts or when spawned
void ABaseGadgetTutorial::BeginPlay()
{
	Super::BeginPlay();
	SetupTutorial();
	SetActorTickInterval(0.2);
}

void ABaseGadgetTutorial::SpawnNewWaypoint(FVector Loc, FString Desc)
{
	if (IsValid(WaypointActor)) WaypointActor->Destroy();

	FActorSpawnParameters SpawnParams;
	SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	WaypointActor = Cast<AWaypointActor>(GetWorld()->SpawnActor<AActor>(WaypointClass, Loc, GetActorRotation(), SpawnParams));
	WaypointActor->SetupWaypoint(WaypointIcon, Desc);
}

void ABaseGadgetTutorial::FinishedTutorial()
{
	if (IsValid(WaypointActor)) WaypointActor->Destroy();
	CompletedGadgetTutorial.Broadcast();
}

void ABaseGadgetTutorial::DestroyTutorial()
{
	if (IsValid(WaypointActor)) WaypointActor->Destroy();
	DespawnEnemies();
	Destroy();
}
