GASATHON/Project/Source/Gasa/AbilitySystem/GasaEffectActor.cpp

118 lines
3.9 KiB
C++
Raw Normal View History

2024-04-13 16:29:25 -07:00
#include "GasaEffectActor.h"
2024-04-22 09:01:30 -07:00
#include "GasaAbilitySystemComponent_Inlines.h"
using namespace Gasa;
2024-04-13 16:29:25 -07:00
AGasaEffectActor::AGasaEffectActor()
{
PrimaryActorTick.bCanEverTick = false;
2024-04-22 09:01:30 -07:00
RootComponent = CreateDefaultSubobject<USceneComponent>("Root");
2024-04-24 08:48:07 -07:00
InstantEffectUsage = DefaultEffectUsagePolicy;
DurationEffectUsage = DefaultEffectUsagePolicy;
InfiniteEffectUsage = DefaultEffectUsagePolicy;
2024-04-13 16:29:25 -07:00
}
void AGasaEffectActor::ApplyEffectToActor(AActor* Actor, TSubclassOf<UGameplayEffect> EffectClass)
2024-04-13 16:29:25 -07:00
{
UGasaAbilitySystemComp* AS = GetAbilitySystem(Actor, true);
2024-04-13 16:29:25 -07:00
2024-04-22 09:01:30 -07:00
FGameplayEffectContextHandle
Context = AS->MakeEffectContext();
Context.AddSourceObject(Actor);
2024-04-24 07:59:48 -07:00
2024-04-22 09:01:30 -07:00
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( EffectClass, 1.0f, Context );
2024-04-24 07:59:48 -07:00
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
2024-04-13 16:29:25 -07:00
}
2024-04-24 08:48:07 -07:00
void AGasaEffectActor::OnOverlap(AActor* Actor)
{
UGasaAbilitySystemComp* AS = GetAbilitySystem(Actor, true);
FGameplayEffectContextHandle
Context = AS->MakeEffectContext();
Context.AddSourceObject(Actor);
if (InstantEffectClass.Get())
{
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::ApplyOnOverlap))
{
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InstantEffectClass, 1.0f, Context );
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
}
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::RemoveOnOverlap))
{
AS->RemoveActiveGameplayEffectBySourceEffect( InstantEffectClass, AS );
}
}
if (DurationEffectClass.Get())
{
if (Bitfield_IsSet(DurationEffectUsage, (int32)EEffectUsagePolicy::ApplyOnOverlap))
{
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InstantEffectClass, 1.0f, Context );
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
}
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::RemoveOnOverlap))
{
AS->RemoveActiveGameplayEffectBySourceEffect( DurationEffectClass, AS );
}
}
if (InfiniteEffectClass.Get())
{
if (Bitfield_IsSet(InfiniteEffectUsage, (int32)EEffectUsagePolicy::ApplyOnOverlap))
{
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InstantEffectClass, 1.0f, Context );
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
}
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::RemoveOnOverlap))
{
AS->RemoveActiveGameplayEffectBySourceEffect( InfiniteEffectClass, AS );
}
}
2024-04-24 08:48:07 -07:00
}
void AGasaEffectActor::OnEndOverlap(AActor* Actor)
{
UGasaAbilitySystemComp* AS = GetAbilitySystem(Actor, true);
FGameplayEffectContextHandle
Context = AS->MakeEffectContext();
Context.AddSourceObject(Actor);
if (InstantEffectClass.Get())
{
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::ApplyOnEndOverlap))
{
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InstantEffectClass, 1.0f, Context );
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
}
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::RemoveOnEndOverlap))
{
AS->RemoveActiveGameplayEffectBySourceEffect( InstantEffectClass, AS );
}
}
if (DurationEffectClass.Get())
{
if (Bitfield_IsSet(DurationEffectUsage, (int32)EEffectUsagePolicy::ApplyOnEndOverlap))
{
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InstantEffectClass, 1.0f, Context );
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
}
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::RemoveOnEndOverlap))
{
AS->RemoveActiveGameplayEffectBySourceEffect( DurationEffectClass, AS );
}
}
if (InfiniteEffectClass.Get())
{
if (Bitfield_IsSet(InfiniteEffectUsage, (int32)EEffectUsagePolicy::ApplyOnEndOverlap))
{
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InstantEffectClass, 1.0f, Context );
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
}
if (Bitfield_IsSet(InstantEffectUsage, (int32)EEffectUsagePolicy::RemoveOnEndOverlap))
{
AS->RemoveActiveGameplayEffectBySourceEffect( InfiniteEffectClass, AS );
}
}
2024-04-24 08:48:07 -07:00
}