// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action. #include "AbilitySystem/Effects/OLSGameplayEffect.h" #include "AbilitySystemComponent.h" void UOLSGameplayEffect::ApplyDynamicGameplayEffect(const FOLSDynamicGameplayEffectData& data) { // Kick out of the call if data's AbilitySystemComponent is invalid. if (!ensureAlwaysMsgf(data.AbilitySystemComponent.IsValid(), TEXT("%s is called but the passed FTowersDynamicGameplayEffectData's AbilitySystemComponent is null."), ANSI_TO_TCHAR(__func__))) { return; } // Dynamically create the gameplay effect. UGameplayEffect* ge = NewObject(GetTransientPackage(), data.EffectName); // Dynamic gameplay effects must have an instant duration type. ge->DurationPolicy = EGameplayEffectDurationType::Instant; // Add one new modifier to the gameplay effect. const int32 modifierIndex = ge->Modifiers.Num(); ge->Modifiers.SetNum(modifierIndex + 1); // Grab the modifier at the appropriate index and set its data appropriately. FGameplayModifierInfo& modInfo = ge->Modifiers[modifierIndex]; modInfo.ModifierMagnitude = data.EffectMagnitude; modInfo.ModifierOp = data.EffectModifierOpType; modInfo.Attribute = data.AffectedAttribute; // Apply the gameplay effect to the TowersCharacter's ability system component. data.AbilitySystemComponent->ApplyGameplayEffectToSelf(ge, data.EffectLevel, data.AbilitySystemComponent->MakeEffectContext()); }