void FGAGameEffectContainer::InternalApplyDuration(const FGAGameEffectHandle& HandleIn)
{
	FTimerDelegate delDuration = FTimerDelegate::CreateUObject(HandleIn.GetContext().TargetComp.Get(), &UGAAttributeComponent::ExpireEffect, HandleIn);
	FTimerManager& timerDuration = HandleIn.GetEffectRef().Context.TargetComp->GetWorld()->GetTimerManager();

	timerDuration.SetTimer(HandleIn.GetEffectRef().DurationTimerHandle, delDuration,
		HandleIn.GetEffectSpec()->Duration, false, HandleIn.GetEffectSpec()->Duration);

	TArray<FGAEffectMod> Modifiers = HandleIn.GetEffectRef().GetAttributeModifiers();
	EGAEffectStacking Stacking = HandleIn.GetEffectSpec()->EffectStacking;
	InternalApplyEffectTags(HandleIn);
	for (FGAEffectMod& Modifier : Modifiers)
	{
		if (Modifier.Attribute.IsValid())
		{
			UGAAttributesBase* attr = HandleIn.GetContextRef().GetTargetAttributes();
			FGAAttributeBase* Attribute = attr->GetAttribute(Modifier.Attribute);

			if (Attribute)
			{
				Attribute->AddBonus(FGAModifier(Modifier.AttributeMod, Modifier.Value), HandleIn, Stacking);
			}
		}
	}
}
void FGAGameEffectContainer::InternalApplyModifiers(const FGAGameEffectHandle& HandleIn)
{
	TArray<FGAGameEffectModifier>& Modifiers = HandleIn.GetEffectSpec()->Modifiers;
	EGAEffectStacking Stacking = HandleIn.GetEffectSpec()->EffectStacking;
	for (FGAGameEffectModifier& Modifier : Modifiers)
	{
		if (Modifier.Attribute.IsValid())
		{
			UGAAttributesBase* attr = HandleIn.GetContextRef().GetTargetAttributes();
			FGAAttributeBase* Attribute = attr->GetAttribute(Modifier.Attribute);

			if (Attribute)
			{
				Attribute->AddBonus(FGAModifier(Modifier.ModType, Modifier.Value), HandleIn, Stacking);
			}
		}
	}
}
Exemple #3
0
void FGAActiveDuration::OnApplied()
{
	TArray<FGAAttributeData> InitialModifiers = EffectSpec->GetInitialAttribute(Context);
	for (const FGAAttributeData& data : InitialModifiers)
	{
		//FGAAttributeData data = InitialAttribute;
		if (Context.InstigatorComp.IsValid())
			Context.InstigatorComp->ModifyAttributesOnTarget(data, Context, OwnedTags, MyHandle);
	}
	TArray<FGAAttributeData> AttributeModifiers = EffectSpec->GetDurationAttribute(Context);
	for (const FGAAttributeData& data : AttributeModifiers)
	{
		FGAAttributeBase* attr = Context.TargetComp->GetAttribute(data.Attribute);
		if (attr)
		{
			TSharedPtr<FGAActiveDuration> temp = AsShared();
			attr->AddBonus(FGAModifier(data.Mod, data.Value, temp), MyHandle);
		}
	}
}
void FGAActiveDuration::OnApplied()
{
	for (const FGAAttributeData& data : PeriodModifiers)
	{
		//FGAAttributeData data = InitialAttribute;
		if (Context.InstigatorComp.IsValid())
			Context.InstigatorComp->ModifyAttributesOnTarget(data, Context, OwnedTags, MyHandle);
	}	
	/*
		If stacking is StrongerOverride, we first check if attribute is already modified by anything.
		If it is, we remove any applicable mods which are weaker than ours.

		We do not make any checks for tags or other effects, They are of no concern to us, when it comes
		to modifing complex attribute.
	*/
	if (Stacking == EGAEffectStacking::StrongerOverride)
	{
		for (const FGAAttributeData& data : DurationAttribute)
		{
			FGAAttributeBase* AtrPtr = Context.TargetComp->GetAttribute(data.Attribute);
			if (AtrPtr)
			{
				AtrPtr->RemoveWeakerBonus(data.Mod, data.Value);
			}
		}
	}

	for (const FGAAttributeData& data : DurationAttribute)
	{
		FGAAttributeBase* attr = Context.TargetComp->GetAttribute(data.Attribute);
		if (attr)
		{
			TSharedPtr<FGAActiveDuration> temp = AsShared();
			attr->AddBonus(FGAModifier(data.Mod, data.Value, temp), MyHandle);
		}
	}
}