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


#include "PlayerCharacter.h"

#include "Components/StatForgeComponent.h"
#include "Faye/Components/OrdersComponent.h"
#include "Faye/Inventory/Inventory.h"
#include "Interface/InteractableActorInterface.h"
#include "Kismet/GameplayStatics.h"
#include "Subsystem/InteractionSubsystem.h"


// Sets default values
APlayerCharacter::APlayerCharacter()
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	
	StatForgeComponent = CreateDefaultSubobject<UStatForgeComponent>("Stat Forge Component");
	OrdersComponent = CreateDefaultSubobject<UOrdersComponent>("Orders Component");
}

// Called when the game starts or when spawned
void APlayerCharacter::BeginPlay()
{
	Super::BeginPlay();
	
	Inventory = NewObject<UInventory>(this);
	Inventory->ModifyGold(100);
	
	PlayerController = Cast<AFayePlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
}

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

// Called to bind functionality to input
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}

UInventory* APlayerCharacter::GetInventory_Implementation() const
{
	return Inventory;
}

void APlayerCharacter::InteractWithObject()
{
	if (AActor* ClosestInteractable = UInteractionSubsystem::GetClosestInteractable(this))
	{
		IInteractableActorInterface::Execute_Interact(ClosestInteractable, this);
	}
}

