// Project Lab - NHTV Igad

#include "UnrealProject.h"
#include "MainCharacterAnimation.h"
#include "NetworkCharacter.h"
#include "Animation/AnimNodeBase.h"
#include "AnimationProxy.h"

UMainCharacterAnimation::UMainCharacterAnimation(const FObjectInitializer& init)
	: Super(init)
{
	m_mainAnimProxy = nullptr;
	character = nullptr;
	attacking = false;
	charCustomization = FCharacterCustomization();
	m_swingAnimationSequence = 0;
}
void UMainCharacterAnimation::NativeInitializeAnimation()
{
	attacking = false;
	Super::NativeInitializeAnimation();
	character = Cast<ANetworkCharacter>(this->GetOwningActor());
	if (character)
	{
		m_swingAnimationSequence = character->swingAnimationSequence;
	}
}
void UMainCharacterAnimation::NativeUpdateAnimation(float DeltaSeconds)
{
	if(character && character->swingAnimationSequence > m_swingAnimationSequence)
	{
		attacking = true;
		m_swingAnimationSequence = character->swingAnimationSequence;
	}
}
void UMainCharacterAnimation::SetCharacterCustomization(const FCharacterCustomization& characterCustomization)
{
	charCustomization = characterCustomization;
	if(m_mainAnimProxy)
	{
		m_mainAnimProxy->charCustomization = charCustomization;
	}
}
FAnimInstanceProxy* UMainCharacterAnimation::CreateAnimInstanceProxy()
{
	check(!m_mainAnimProxy);
	m_mainAnimProxy = new FMainAnimProxy();

	m_mainAnimProxy->boneNames[0] = "Slave_Head_Ctrl_Jnt";
	m_mainAnimProxy->boneNames[1] = "Slave_L_Hip_Ctrl_Jnt";
	m_mainAnimProxy->boneNames[2] = "Slave_R_Hip_Ctrl_Jnt";
	m_mainAnimProxy->boneNames[3] = "Slave_L_Result_Shoulder_Ctrl_Jnt";
	m_mainAnimProxy->boneNames[4] = "Slave_R_Result_Shoulder_Ctrl_Jnt";
	m_mainAnimProxy->boneNames[5] = "Slave_Result_Spine06";
	m_mainAnimProxy->boneNames[6] = "skeleton";


	return m_mainAnimProxy;
}
void UMainCharacterAnimation::DestroyAnimInstanceProxy(FAnimInstanceProxy* InProxy)
{
	check(InProxy == m_mainAnimProxy);
	delete InProxy;
	m_mainAnimProxy = nullptr;
}
void UMainCharacterAnimation::OnSwingAnimation_Implementation()
{
}

