// Project Lab - NHTV Igad

#include "UnrealProject.h"
#include "SpellInfo.h"
#include "DefaultPlayerController.h"

USpellInfo::USpellInfo(const FObjectInitializer& init)
	: Super(init)
{
	showDuration = 1.0f;
}

void USpellInfo::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
	m_life -= InDeltaTime;
	if(m_life <= 0.0f)
	{
		RemoveFromParent();
	}

	Super::NativeTick(MyGeometry, InDeltaTime);
}

void USpellInfo::Set(class UAbilityInfo* info, int32 level, float power, class USpellInfoDisplay* parent)
{
	m_ability = info;
	m_parent = parent;
	m_life = showDuration;
	m_level = level;
	m_power = power;

	ADefaultPlayerController* pc = Cast<ADefaultPlayerController>(GetOwningPlayer());
	int32 slot;
	bool alt;
	if(pc && pc->GetAbilityButtonLocation(info, slot, alt))
	{
		SetButtonHint(slot, alt);
	}

	int32 lastLevel = pc->GetCurrentAbilityLevel(m_ability);

	OnSetAbility(info, lastLevel == 0);
}

float USpellInfo::GetLifeTimeRate() const
{
	return (float)m_life / (float)showDuration;
}

int32 USpellInfo::GetLevel() const
{
	return m_level;
}
float USpellInfo::GetPower() const
{
	return m_power;
}

void USpellInfo::SetButtonHint_Implementation(int32 buttonSlot, bool alt)
{
}

void USpellInfo::OnSetAbility_Implementation(class UAbilityInfo* info, bool isNew)
{
}
