43. Instant and Duration Application Policy

This commit is contained in:
Edward R. Gonzalez 2024-04-24 11:58:40 -04:00
parent f17c53a1a9
commit a604117e95
2 changed files with 83 additions and 3 deletions

View File

@ -28,8 +28,90 @@ void AGasaEffectActor::ApplyEffectToActor(AActor* Actor, TSubclassOf<UGameplayEf
void AGasaEffectActor::OnOverlap(AActor* Actor) 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 );
}
}
} }
void AGasaEffectActor::OnEndOverlap(AActor* Actor) 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 );
}
}
} }

View File

@ -12,13 +12,11 @@ enum class EEffectUsagePolicy : uint8
None = 0 UMETA(Hidden), None = 0 UMETA(Hidden),
ApplyOnOverlap = bit(0), ApplyOnOverlap = bit(0),
ApplyOnEndOverlap = bit(1), ApplyOnEndOverlap = bit(1),
DoNotApply = bit(2),
RemoveOnOverlap = bit(3), RemoveOnOverlap = bit(3),
RemoveOnEndOverlap = bit(4), RemoveOnEndOverlap = bit(4),
DoNotRemove = bit(5),
}; };
constexpr int32 DefaultEffectUsagePolicy = (int32(EEffectUsagePolicy::DoNotApply) | int32(EEffectUsagePolicy::RemoveOnEndOverlap)); constexpr int32 DefaultEffectUsagePolicy = (int32(EEffectUsagePolicy::RemoveOnEndOverlap));
UCLASS() UCLASS()
class GASA_API AGasaEffectActor : public AGasaActor class GASA_API AGasaEffectActor : public AGasaActor