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


#include "DoorClass.h"

#include "EndlessVendettaCharacter.h"
#include "Components/ArrowComponent.h"
#include "Kismet/GameplayStatics.h"

// Sets default values
ADoorClass::ADoorClass()
{
 	// 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 when the game starts or when spawned
void ADoorClass::BeginPlay()
{
	Super::BeginPlay();
	
	// Attempt to find the player character
	APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);
	playerInWorld = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter());
	
	endlessVendettaChar = Cast<AEndlessVendettaCharacter>(playerInWorld);

	for (UActorComponent* actorComp : playerInWorld->GetComponentsByTag(UArrowComponent::StaticClass(), FName("FrontOfDoor")))
	{
		FrontOfDoor = Cast<UArrowComponent>(actorComp);
		break;
	}
}

// Called every frame
void ADoorClass::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void ADoorClass::Interact()
{
	if (!IsValid(this)) return;
	if (!bIsDoorOpen)
	{
		DoorOpeningAnim();
		bIsDoorOpen = true;
	}
	else
	{
		DoorCloseAnim();
		bIsDoorOpen = false;
	}
}

void ADoorClass::InteractPrompt()
{
	if(bIsDoorOpen) return;
	DoorPrompt();
}



