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

#pragma once

#include "CoreMinimal.h"
#include "AC_PlayerDialogueInterpreter.h"
#include "DialogueTree.h"
#include "Components/ActorComponent.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "Kismet/GameplayStatics.h"
#include "AC_Dialogue.generated.h"


UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class ENDLESSVENDETTA_API UAC_Dialogue : public UActorComponent
{
	GENERATED_BODY()

public:
	void Interact() const;

	UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue")
	UDialogueTree* DialogueTree;
};

inline void UAC_Dialogue::Interact() const
{
	GLog->Log("Interacting with dialogue");
	if (!IsValid(DialogueTree)) return;
	AEndlessVendettaCharacter* Character = Cast<AEndlessVendettaCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
	if (!IsValid(Cast<UAC_PlayerDialogueInterpreter>(Character->GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass())))) return;
	Cast<UAC_PlayerDialogueInterpreter>(Character->GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass()))->StartDialogue(DialogueTree);
	Character->bIsInDialogue = true;
}
