From caae7fd758e604b4d797b51d3c2fe9027c8d239b Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 24 Apr 2024 11:58:40 -0400 Subject: [PATCH] 43. Instant and Duration Application Policy --- .../Gasa/AbilitySystem/GasaEffectActor.cpp | 82 +++++++++++++++++++ .../Gasa/AbilitySystem/GasaEffectActor.h | 4 +- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Project/Source/Gasa/AbilitySystem/GasaEffectActor.cpp b/Project/Source/Gasa/AbilitySystem/GasaEffectActor.cpp index 2fc65af..f52d498 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaEffectActor.cpp +++ b/Project/Source/Gasa/AbilitySystem/GasaEffectActor.cpp @@ -28,8 +28,90 @@ void AGasaEffectActor::ApplyEffectToActor(AActor* Actor, TSubclassOfMakeEffectContext(); + 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 ); + } + } } 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 ); + } + } } diff --git a/Project/Source/Gasa/AbilitySystem/GasaEffectActor.h b/Project/Source/Gasa/AbilitySystem/GasaEffectActor.h index 989992b..5976110 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaEffectActor.h +++ b/Project/Source/Gasa/AbilitySystem/GasaEffectActor.h @@ -12,13 +12,11 @@ enum class EEffectUsagePolicy : uint8 None = 0 UMETA(Hidden), ApplyOnOverlap = bit(0), ApplyOnEndOverlap = bit(1), - DoNotApply = bit(2), RemoveOnOverlap = bit(3), RemoveOnEndOverlap = bit(4), - DoNotRemove = bit(5), }; -constexpr int32 DefaultEffectUsagePolicy = (int32(EEffectUsagePolicy::DoNotApply) | int32(EEffectUsagePolicy::RemoveOnEndOverlap)); +constexpr int32 DefaultEffectUsagePolicy = (int32(EEffectUsagePolicy::RemoveOnEndOverlap)); UCLASS() class GASA_API AGasaEffectActor : public AGasaActor