// Project Sword & Gun Copyright © 2021 Kevin Poretti


#include "Components/SNGWeaponInventoryComponent.h"

// Sets default values for this component's properties
USNGWeaponInventoryComponent::USNGWeaponInventoryComponent()
{
	// don't tick...for now
	PrimaryComponentTick.bCanEverTick = false;

	// ...
}

ASNGWeaponBase* USNGWeaponInventoryComponent::GetCurrentWeapon()
{
	return CurrWeapon;
}

void USNGWeaponInventoryComponent::SetCurrentWeapon(int WeaponIndex)
{
	if(WeaponIndex > Weapons.Num() - 1 || WeaponIndex < 0)
	{
		UE_LOG(LogTemp, Error, TEXT("SNGWeaponInventoryComponent :: Weapon index %d is not valid"), WeaponIndex);
		return;
	}

	CurrWeapon = Weapons[WeaponIndex];
}


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

	// ...
	for (auto WeaponClass : WeaponClasses)
	{
		AActor* WeaponOwner = GetOwner();
		
		FActorSpawnParameters SpawnParams;
		SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
		SpawnParams.Owner = WeaponOwner;
		ASNGWeaponBase* TempWeapon = GetWorld()->SpawnActor<ASNGWeaponBase>(WeaponClass, WeaponOwner->GetActorLocation(), WeaponOwner->GetActorRotation(), SpawnParams);
		TempWeapon->SetVisibility(false);
		Weapons.Add(TempWeapon);
	}
}

