// Project Lab - NHTV Igad

#include "UnrealProject.h"
#include "ConeTrigger.h"
#include "ConeComponent.h"
#include "NetworkCharacter.h"
#include "BlueprintAbilityLibrary.h" // For Cone overlap code

AConeTrigger::AConeTrigger()
{
	PrimaryActorTick.bCanEverTick = true; 
	
	m_coneTrigger = CreateDefaultSubobject <UConeComponent>(TEXT("trigger"));
	RootComponent = m_coneTrigger;
	m_coneTrigger->SetCollisionProfileName(TEXT("Triggers"));
}


void AConeTrigger::BeginPlay()
{
	m_coneTrigger->SetWorldTransform(GetTransform());
	if (!delegatesSet)
	{
		m_coneTrigger->OnComponentBeginOverlap.AddDynamic(this, &AConeTrigger::OnOverlapBegin);
		m_coneTrigger->OnComponentEndOverlap.AddDynamic(this, &AConeTrigger::OnOverlapEnd);
		delegatesSet = true;
	}
	SetCone(radius, angle);
	Super::BeginPlay();
}


void AConeTrigger::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
}

void AConeTrigger::SetCone(float inputRadius, float inputAngle)
{
	m_coneTrigger->coneAngle = (inputAngle);
	m_coneTrigger->coneRadius = (inputRadius);
	m_coneTrigger->UpdateCapsule();
}



bool AConeTrigger::CollisionCheck(ANetworkCharacter* otheractor)
{
	return ULib::IsContainedInCone(GetActorLocation(), GetActorForwardVector(), m_coneTrigger->coneAngle, otheractor);
}