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


#include "AC_PlayerStats.h"
#include "AC_PlayerInventory.h"
#include "EpicEnumsAndStructs.h"

// Sets default values for this component's properties
UAC_PlayerStats::UAC_PlayerStats()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


void UAC_PlayerStats::InitializePlayerStats()
{
	CurrentHealth = MaxHealth;
	CurrentStamina = MaxStamina;
	CurrentMana = MaxMana;
	UpdateCurrentCarryWeight();

}

void UAC_PlayerStats::UpdateCurrentCarryWeight()
{
	APawn* PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
	float LocCarryWeight = 0.f;

	if (PlayerPawn)
	{
		TArray<FBaseItemInfo> PlayerInventory = PlayerPawn->FindComponentByClass<UAC_PlayerInventory>()->GetPlayerInventory();

		for (const FBaseItemInfo& InventoryItem : PlayerInventory)
		{
			LocCarryWeight += InventoryItem.ItemWeight;
		}
		CurrentCarryWeight = LocCarryWeight;
	}

}

// Called when the game starts
void UAC_PlayerStats::BeginPlay()
{
	Super::BeginPlay();

	InitializePlayerStats();

	// ...
	
}


// Called every frame
void UAC_PlayerStats::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

