void UGAAttributeComponent::InternalRemoveEffect(FGAGameEffectHandle& HandleIn) { FTimerManager& timer = GetWorld()->GetTimerManager(); timer.ClearTimer(HandleIn.GetEffectRef().PeriodTimerHandle); timer.ClearTimer(HandleIn.GetEffectRef().DurationTimerHandle); UE_LOG(GameAttributesEffects, Log, TEXT("UGAAttributeComponent:: Reset Timers and Remove Effect")); FGAGameEffect& Effect = HandleIn.GetEffectRef(); TArray<FGAEffectMod> Mods = Effect.GetOnAppliedMods(); for (FGAEffectMod& mod : Mods) { FGAAttributeBase* attr = DefaultAttributes->GetAttribute(mod.Attribute); if (attr) { UE_LOG(GameAttributes, Log, TEXT("Value Before bonus of attribute = %f"), attr->GetFinalValue()); attr->RemoveBonus(HandleIn); UE_LOG(GameAttributes, Log, TEXT("Value After bonus of attribute = %f"), attr->GetFinalValue()); } } GameEffectContainer.RemoveEffect(HandleIn); }
void FGAGameEffectContainer::RemoveEffect(FGAGameEffectHandle& HandleIn) { EGAEffectAggregation aggregatiopn = HandleIn.GetEffectRef().GameEffect->EffectAggregation; UObject* Instigator = HandleIn.GetContextRef().Instigator.Get(); TSharedPtr<FGAGameEffect> effect = ActiveEffects.FindAndRemoveChecked(HandleIn); if (effect.IsValid()) { switch (aggregatiopn) { case EGAEffectAggregation::AggregateByInstigator: { TMap<FGAGameEffectHandle, TSharedPtr<FGAGameEffect>>* effects = InstigatorEffects.Find(Instigator); TMap<FName, TSet<FGAGameEffectHandle>>* EffectByClass = InstigatorEffectHandles.Find(Instigator); if (EffectByClass) { //Probabaly need another path for removing just single effect from stack. EffectByClass->Remove(HandleIn.GetEffectSpec()->GetFName()); } if (effects) { effects->FindAndRemoveChecked(HandleIn); if (effects->Num() == 0) { InstigatorEffects.Remove(Instigator); } } break; } case EGAEffectAggregation::AggregateByTarget: { //TargetEffects.FindAndRemoveChecked(HandleIn); TSet<FGAGameEffectHandle>* Handles = TargetEffectByType.Find(HandleIn.GetEffectSpec()->GetFName()); //check aggregation type to know which effect to remove exactly ? TargetEffectByType.Remove(HandleIn.GetEffectSpec()->GetFName()); break; } } for (FGAGameEffectModifier& Modifier : effect->GameEffect->Modifiers) { if (Modifier.Attribute.IsValid()) { FGAAttributeBase* Attribute = OwningComp->GetAttribute(Modifier.Attribute); if (Attribute) { Attribute->RemoveBonus(HandleIn); } } } UE_LOG(GameAttributesEffects, Log, TEXT("FGAGameEffectContainer:: Removing Effect")) effect.Reset(); } }
void FGAGameEffectContainer::RemoveEffect(FGAGameEffectHandle& HandleIn) { EGAEffectAggregation aggregatiopn = HandleIn.GetEffectRef().GameEffect->EffectAggregation; UObject* Instigator = HandleIn.GetContextRef().Instigator.Get(); TSharedPtr<FGAGameEffect> effect = ActiveEffects.FindAndRemoveChecked(HandleIn); if (effect.IsValid()) { switch (aggregatiopn) { case EGAEffectAggregation::AggregateByInstigator: { TMap<FGAGameEffectHandle, TSharedPtr<FGAGameEffect>>* effects = InstigatorEffects.Find(Instigator); TMap<UClass*, FGAGameEffectHandle>* EffectByClass = InstigatorEffectHandles.Find(Instigator); if (EffectByClass) { EffectByClass->Remove(HandleIn.GetEffectSpec()->StaticClass()); } if (effects) { effects->FindAndRemoveChecked(HandleIn); if (effects->Num() == 0) { InstigatorEffects.Remove(Instigator); } } break; } case EGAEffectAggregation::AggregateByTarget: { TargetEffects.FindAndRemoveChecked(HandleIn); break; } } for (FGAGameEffectModifier& Modifier : effect->GameEffect->Modifiers) { if (Modifier.Attribute.IsValid()) { FGAAttributeBase* Attribute = OwningComp->GetAttribute(Modifier.Attribute); if (Attribute) { Attribute->RemoveBonus(HandleIn); } } } UE_LOG(GameAttributesEffects, Log, TEXT("FGAGameEffectContainer:: Removing Effect")) effect.Reset(); } }
void FGAActiveDuration::FinishEffect() { if (Context.Target.IsValid()) { Context.Target->GetWorldTimerManager().ClearTimer(PeriodTimerHandle); Context.Target->GetWorldTimerManager().ClearTimer(DurationTimerHandle); } if (Context.TargetComp.IsValid()) { for (const FGAAttributeData& data : DurationAttribute) { FGAAttributeBase* attr = Context.TargetComp->GetAttribute(data.Attribute); if (attr) { attr->RemoveBonus(MyHandle); } } } }