コード例 #1
0
ファイル: GAEffects.cpp プロジェクト: Irvaxis/ActionRPGGame
FGAEffectHandle	FGAActiveEffectContainer::HandleInstigatorEffectStrongerOverride(FGAEffectSpec& EffectIn, const FGAEffectContext& Ctx)
{
	/*
		How does it work ?
		1. If there effect of the same name active, we find it and remove it.
		WE can safely assume, that effect of the same name is either the same or stronger.
		2. For effect modifiers, we don't check for effect, we just check for it's tag and type.
		If it is weaker, remove it, and replace with new one.
		3. The same goes for attribute modifiers.

		It's bit inconsistent to say at least..
	*/
	FGAInstigatorEffectContainer& instCont = InstigatorEffects.FindOrAdd(Ctx.InstigatorComp);
	FGAEffectHandle foundHandle;
	for (FGAEffectTagHandle& eff : instCont.Effects)
	{
		if (eff.EffectName == EffectIn.EffectName)
		{
			foundHandle = eff.Handle;
			break;
		}
	}

	/*
		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.
	*/

	TArray<FGAAttributeData> AttributeModifiers = EffectIn.EffectSpec->GetDurationAttribute(Ctx);
	for (const FGAAttributeData& data : AttributeModifiers)
	{
		FGAAttributeBase* AtrPtr = Ctx.TargetComp->GetAttribute(data.Attribute);
		if (AtrPtr)
		{
			AtrPtr->RemoveWeakerBonus(data.Mod, data.Value);
		}
	}

	ModifierContainer.RemoveWeakerModifiers(EffectIn.EffectSpec->RequiredTags, EffectIn.EffectSpec->EffectModifiers);

	RemoveActiveEffect(foundHandle);
	FGAEffectHandle handle = AddActiveEffect(EffectIn, Ctx);

	FGAEffectTagHandle nameHandle(EffectIn.EffectName, handle);
	instCont.Effects.Add(nameHandle);
	return handle;
}
コード例 #2
0
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);
		}
	}
}