Last active
November 19, 2023 06:53
-
-
Save glinesbdev/8f1d6bdd08039688db2fe394ef63fb68 to your computer and use it in GitHub Desktop.
AuraEffectActor Side Quest (From Udemy Course)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void AAuraEffectActor::OnOverlap(AActor* TargetActor) | |
{ | |
// ... original code here... | |
// For each of the EEffectApplicationPolicy::ApplyOnOverlap, apply effect to the target | |
for (const auto& EffectPolicy : FilterApplicationGameplayEffects(EEffectApplicationPolicy::ApplyOnOverlap)) | |
{ | |
ApplyEffectToTarget(TargetActor, EffectPolicy.Key); | |
} | |
} | |
void AAuraEffectActor::OnEndOverlap(AActor* TargetActor) | |
{ | |
// ... original code here... | |
if (InfiniteEffectRemovalPolicy == EEffectRemovalPolicy::RemoveOnEndOverlap) | |
{ | |
RemoveInfiniteEffectFromTarget(TargetActor); | |
} | |
// For each of the EEffectApplicationPolicy::ApplyOnEndOverlap, apply effect to the target | |
for (const auto& EffectPolicy : FilterApplicationGameplayEffects(EEffectApplicationPolicy::ApplyOnEndOverlap)) | |
{ | |
ApplyEffectToTarget(TargetActor, EffectPolicy.Key); | |
} | |
// For each of the EEffectRemovalPolicy::RemoveOnEndOverlap, remove any infinite effects on the target | |
// Any non-infinite duration effects automatically remove themselves | |
for (const auto& _ : FilterRemovalGameplayEffects(EEffectRemovalPolicy::RemoveOnEndOverlap)) | |
{ | |
RemoveInfiniteEffectFromTarget(TargetActor); | |
} | |
} | |
void AAuraEffectActor::RemoveInfiniteEffectFromTarget(AActor* TargetActor) | |
{ | |
UAbilitySystemComponent* TargetAsc = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(TargetActor); | |
if (!IsValid(TargetAsc)) return; | |
TArray<FActiveGameplayEffectHandle> HandlesToRemove; | |
for (const auto& HandlePair : ActiveEffectHandles) | |
{ | |
if (HandlePair.Value == TargetAsc) | |
{ | |
TargetAsc->RemoveActiveGameplayEffect(HandlePair.Key, 1); | |
HandlesToRemove.Add(HandlePair.Key); | |
} | |
} | |
for (const auto& Handle : HandlesToRemove) | |
{ | |
ActiveEffectHandles.FindAndRemoveChecked(Handle); | |
} | |
} | |
TMap<TSubclassOf<UGameplayEffect>, EEffectApplicationPolicy> AAuraEffectActor::FilterApplicationGameplayEffects(EEffectApplicationPolicy ApplicationPolicy) const | |
{ | |
return ApplicationGameplayEffects.FilterByPredicate( | |
[&ApplicationPolicy](const TTuple<TSubclassOf<UGameplayEffect>, EEffectApplicationPolicy>& EffectPolicy) | |
{ | |
return EffectPolicy.Value == ApplicationPolicy; | |
}); | |
} | |
TMap<TSubclassOf<UGameplayEffect>, EEffectRemovalPolicy> AAuraEffectActor::FilterRemovalGameplayEffects(EEffectRemovalPolicy RemovalPolicy) const | |
{ | |
return RemovalGameplayEffects.FilterByPredicate( | |
[&RemovalPolicy](const TTuple<TSubclassOf<UGameplayEffect>, EEffectRemovalPolicy>& EffectPolicy) | |
{ | |
return EffectPolicy.Value == RemovalPolicy; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Protected | |
// These are the effects that take effect on Application | |
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Applied Effects") | |
TMap<TSubclassOf<UGameplayEffect>, EEffectApplicationPolicy> ApplicationGameplayEffects; | |
// These are the effects that take effect on Removal | |
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Applied Effects") | |
TMap<TSubclassOf<UGameplayEffect>, EEffectRemovalPolicy> RemovalGameplayEffects; | |
// Private | |
void RemoveInfiniteEffectFromTarget(AActor* TargetActor); | |
TMap<TSubclassOf<UGameplayEffect>, EEffectApplicationPolicy> FilterApplicationGameplayEffects(EEffectApplicationPolicy ApplicationPolicy) const; | |
TMap<TSubclassOf<UGameplayEffect>, EEffectRemovalPolicy> FilterRemovalGameplayEffects(EEffectRemovalPolicy RemovalPolicy) const; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment