// Multiplayer By Caleb


#include "GAS/CAbilitySystemComponent.h"


void UCAbilitySystemComponent::ApplyInitialEffects()
{
	if (!GetOwner() || !GetOwner()->HasAuthority()) return;

	for (const auto& EffectClass : InitialEffects)
	{
		/**
		 * this will work as well
		 * const auto Effect{EffectClass->GetDefaultObject<UGameplayEffect>()};
		 * ApplyGameplayEffectToSelf(Effect, 0.f, MakeEffectContext());
		**/
		auto GameplayEffectSpecHandle{MakeOutgoingSpec(EffectClass, 1, MakeEffectContext())};
		ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get());
	}
}

void UCAbilitySystemComponent::GiveInitialAbilities()
{
	if (!GetOwner() || !GetOwner()->HasAuthority()) return;

	for (const auto& AbilityPairClass : Abilities)
	{
		GiveAbility(FGameplayAbilitySpec(
			AbilityPairClass.Value,
			0,
			static_cast<int32>(AbilityPairClass.Key),
			nullptr
		));
	}
	for (const auto& AbilityPairClass : BasicAbilities)
	{
		GiveAbility(FGameplayAbilitySpec(
			AbilityPairClass.Value,
			1,
			static_cast<int32>(AbilityPairClass.Key),
			nullptr
		));
	}
}
