2024-04-13 16:29:25 -07:00
|
|
|
|
#include "GasaEffectActor.h"
|
|
|
|
|
|
2024-04-22 09:01:30 -07:00
|
|
|
|
#include "GasaAbilitySystemComponent_Inlines.h"
|
2024-04-24 13:21:22 -07:00
|
|
|
|
#include "GasaContainers.h"
|
2024-04-22 09:01:30 -07:00
|
|
|
|
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
|
|
|
|
|
2024-04-24 21:30:54 -07:00
|
|
|
|
Level = 1.f;
|
|
|
|
|
|
2024-04-24 13:21:22 -07:00
|
|
|
|
InstantEffectUsage = EInstantEffectUsagePolicy::DoNotApply;
|
2024-04-24 08:48:07 -07:00
|
|
|
|
DurationEffectUsage = DefaultEffectUsagePolicy;
|
|
|
|
|
InfiniteEffectUsage = DefaultEffectUsagePolicy;
|
2024-04-24 13:21:22 -07:00
|
|
|
|
|
|
|
|
|
bDestroyOnEffectRemoval = false;
|
2024-04-13 16:29:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 13:21:22 -07:00
|
|
|
|
void AGasaEffectActor::ApplyEffectToActor(AActor* Actor, TSubclassOf<UGameplayEffect> EffectClass, bool bRemoveOnEndOverlap)
|
2024-04-13 16:29:25 -07:00
|
|
|
|
{
|
2024-04-22 22:10:02 -07:00
|
|
|
|
UGasaAbilitySystemComp* AS = GetAbilitySystem(Actor, true);
|
2024-04-22 09:01:30 -07:00
|
|
|
|
FGameplayEffectContextHandle
|
|
|
|
|
Context = AS->MakeEffectContext();
|
2024-04-22 22:10:02 -07:00
|
|
|
|
Context.AddSourceObject(Actor);
|
2024-04-24 07:59:48 -07:00
|
|
|
|
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( EffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
FActiveGameplayEffectHandle ActiveEffect = AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
|
|
|
|
if (bRemoveOnEndOverlap)
|
|
|
|
|
ActiveEffectsToRemove.Add(ActiveEffect, AS);
|
2024-04-13 16:29:25 -07:00
|
|
|
|
}
|
2024-04-24 08:48:07 -07:00
|
|
|
|
|
|
|
|
|
void AGasaEffectActor::OnOverlap(AActor* Actor)
|
|
|
|
|
{
|
2024-04-24 08:58:40 -07:00
|
|
|
|
UGasaAbilitySystemComp* AS = GetAbilitySystem(Actor, true);
|
|
|
|
|
FGameplayEffectContextHandle
|
|
|
|
|
Context = AS->MakeEffectContext();
|
|
|
|
|
Context.AddSourceObject(Actor);
|
|
|
|
|
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (InstantEffectClass && InstantEffectUsage == EInstantEffectUsagePolicy::ApplyOnOverlap)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec= AS->MakeOutgoingSpec( InstantEffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (DurationEffectClass)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (Bitfield_IsSet(DurationEffectUsage, EEffectUsagePolicy::ApplyOnOverlap))
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( DurationEffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
FActiveGameplayEffectHandle ActiveEffect = AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
2024-04-24 21:30:54 -07:00
|
|
|
|
if (Bitfield_IsSet(DurationEffectUsage, EEffectUsagePolicy::RemoveOnEndOverlap))
|
2024-04-24 13:21:22 -07:00
|
|
|
|
ActiveDuration = ActiveEffect;
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (ActiveDuration.IsValid() && Bitfield_IsSet(DurationEffectUsage, EEffectUsagePolicy::RemoveOnOverlap))
|
|
|
|
|
AS->RemoveActiveGameplayEffect(ActiveDuration);
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (InfiniteEffectClass)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 13:21:22 -07:00
|
|
|
|
bool bApplyOnOverlap = Bitfield_IsSet(InfiniteEffectUsage, EEffectUsagePolicy::ApplyOnOverlap);
|
|
|
|
|
if (bApplyOnOverlap)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InfiniteEffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
FActiveGameplayEffectHandle ActiveEffect = AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
2024-04-24 21:30:54 -07:00
|
|
|
|
if (Bitfield_IsSet(InfiniteEffectUsage, EEffectUsagePolicy::RemoveOnEndOverlap))
|
2024-04-24 13:21:22 -07:00
|
|
|
|
ActiveInfinite = ActiveEffect;
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (ActiveInfinite.IsValid() && Bitfield_IsSet(InfiniteEffectUsage, EEffectUsagePolicy::RemoveOnOverlap))
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (ActiveInfinite.IsValid())
|
|
|
|
|
AS->RemoveActiveGameplayEffect(ActiveInfinite);
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-24 08:48:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaEffectActor::OnEndOverlap(AActor* Actor)
|
|
|
|
|
{
|
2024-04-24 08:58:40 -07:00
|
|
|
|
UGasaAbilitySystemComp* AS = GetAbilitySystem(Actor, true);
|
|
|
|
|
FGameplayEffectContextHandle
|
|
|
|
|
Context = AS->MakeEffectContext();
|
|
|
|
|
Context.AddSourceObject(Actor);
|
|
|
|
|
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (InstantEffectClass && InstantEffectUsage == EInstantEffectUsagePolicy::ApplyOnEndOverlap)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec= AS->MakeOutgoingSpec( InstantEffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (DurationEffectClass)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (Bitfield_IsSet(DurationEffectUsage, EEffectUsagePolicy::ApplyOnEndOverlap))
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( DurationEffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
FActiveGameplayEffectHandle ActiveEffect = AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
2024-04-24 21:30:54 -07:00
|
|
|
|
if (Bitfield_IsSet(DurationEffectUsage, EEffectUsagePolicy::RemoveOnOverlap))
|
2024-04-24 13:21:22 -07:00
|
|
|
|
ActiveDuration = ActiveEffect;
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 21:30:54 -07:00
|
|
|
|
if (ActiveDuration.IsValid() && Bitfield_IsSet(DurationEffectUsage, EEffectUsagePolicy::RemoveOnEndOverlap))
|
2024-04-24 13:21:22 -07:00
|
|
|
|
AS->RemoveActiveGameplayEffect(ActiveDuration);
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (InfiniteEffectClass)
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (Bitfield_IsSet(InfiniteEffectUsage, EEffectUsagePolicy::ApplyOnEndOverlap))
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 21:30:54 -07:00
|
|
|
|
FGameplayEffectSpecHandle Spec = AS->MakeOutgoingSpec( InfiniteEffectClass, Level, Context );
|
2024-04-24 13:21:22 -07:00
|
|
|
|
FActiveGameplayEffectHandle ActiveEffect = AS->ApplyGameplayEffectSpecToSelf( * Spec.Data );
|
2024-04-24 21:30:54 -07:00
|
|
|
|
if (Bitfield_IsSet(InfiniteEffectUsage, EEffectUsagePolicy::RemoveOnOverlap))
|
2024-04-24 13:21:22 -07:00
|
|
|
|
ActiveInfinite = ActiveEffect;
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (ActiveInfinite.IsValid() && Bitfield_IsSet(InfiniteEffectUsage, EEffectUsagePolicy::RemoveOnEndOverlap))
|
2024-04-24 08:58:40 -07:00
|
|
|
|
{
|
2024-04-24 13:21:22 -07:00
|
|
|
|
if (ActiveInfinite.IsValid())
|
|
|
|
|
AS->RemoveActiveGameplayEffect(ActiveInfinite);
|
2024-04-24 08:58:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-24 13:21:22 -07:00
|
|
|
|
|
|
|
|
|
TArray<FActiveGameplayEffectHandle> EffectsRemoved;
|
|
|
|
|
for (ActiveEffectEntry ActiveEffect : ActiveEffectsToRemove)
|
|
|
|
|
{
|
|
|
|
|
if (ActiveEffect.Value != AS)
|
|
|
|
|
continue;
|
|
|
|
|
AS->RemoveActiveGameplayEffect(ActiveEffect.Key, 1);
|
|
|
|
|
EffectsRemoved.Add(ActiveEffect.Key);
|
|
|
|
|
}
|
|
|
|
|
RemoveKeys(ActiveEffectsToRemove, EffectsRemoved);
|
2024-04-24 08:48:07 -07:00
|
|
|
|
}
|