Ejemplo n.º 1
0
FGAEffectHandle UGABlueprintLibrary::ApplyEffectSpec(const FHitResult& Target, APawn* Instigator,
	UObject* Causer, TSubclassOf<class UGAEffectSpecification> SpecIn)
{
	FGAEffectHandle ReturnHandle;
	IIGAAttributes* targetAttr = Cast<IIGAAttributes>(Target.Actor.Get());
	IIGAAttributes* instiAttr = Cast<IIGAAttributes>(Instigator);
	if (!targetAttr || !instiAttr)
		return ReturnHandle;

	UGAAttributeComponent* targetComp = targetAttr->GetAttributeComponent();
	UGAAttributeComponent* instiComp = instiAttr->GetAttributeComponent();

	FGAEffectContext context(Target.Location, Target.Actor, Causer,
		Instigator, targetComp, instiComp);
	FName EffectName;
	if (SpecIn.GetDefaultObject()->Policy.Type != EGAEffectType::Instant)
	{
		if (SpecIn.GetDefaultObject()->EffectName.CustomName)
			EffectName = SpecIn.GetDefaultObject()->EffectName.EffectName;
		else
			EffectName = SpecIn->GetFName();// Causer->GetClass()->GetFName();
	}
	ReturnHandle = instiComp->ApplyEffectToTarget(SpecIn, context, EffectName);
	return ReturnHandle;
}
float UGAAttributesBlueprintFunctionLibrary::GetAttributeFloat(AActor* Target, FGAAttribute AttributeIn)
{
	IIGAAttributes* attributeInt = Cast<IIGAAttributes>(Target);
	if (!attributeInt)
		return 0;

	return  attributeInt->GetAttributes()->GetFloatValue(AttributeIn);
}
void UGAAttributesBlueprintFunctionLibrary::AttributesOperation(TArray<FGAAttributeModifier> AttributesIn)
{
	for (const FGAAttributeModifier& attributeMod : AttributesIn)
	{
		IIGAAttributes* attributeInt = Cast<IIGAAttributes>(attributeMod.Target.Get());
		if (!attributeInt)
		{
			return;
		}
		UGAAttributesBase* attributes = attributeInt->GetAttributes();
		float newValue = attributes->AttributeOperation(attributeMod.Attribute, attributeMod.Value, attributeMod.Operation);
		//if (bSetAttribute)
		//{
		attributes->SetFloatValue(attributeMod.Attribute, newValue);
		//}
	}
}
void UGAAttributesBlueprintFunctionLibrary::ModifyAttributes(TArray<FGAAttributeModifier> AttributesIn)
{
	for (FGAAttributeModifier& attributeMod : AttributesIn)
	{
		IIGAAttributes* instAttr = Cast<IIGAAttributes>(attributeMod.Instigator.Get());
		IIGAAttributes* targetAttr = Cast<IIGAAttributes>(attributeMod.Target.Get());
		if (!instAttr || !targetAttr)
		{
			return;
		}
		UGAAttributeComponent* attributes = instAttr->GetAttributeComponent();
		//float newValue = attributes->AttributeOperation(attributeMod.Attribute, attributeMod.Value, attributeMod.Operation);
		//if (bSetAttribute)
		//{
		attributes->ModifyAttributesOnTarget(targetAttr->GetAttributeComponent(), attributeMod);
		//}
	}
}
FGAEffectHandle UGAAttributeComponent::ApplySelfEffect(AActor* Target, APawn* Instigator,
	UObject* Causer, FGAEffectSpec SpecIn)
{
	//this is bad btw. I need to change it. LAter.
	IIGAAttributes* targetAttr = Cast<IIGAAttributes>(Target);
	IIGAAttributes* instiAttr = Cast<IIGAAttributes>(Instigator);
	if (!targetAttr || !instiAttr)
		return FGAEffectHandle();

	UGAAttributeComponent* targetComp = targetAttr->GetAttributeComponent();
	UGAAttributeComponent* instiComp = instiAttr->GetAttributeComponent();
	FGAEffectContext context(Target->GetActorLocation(), Target, Causer,
		Instigator, targetComp, instiComp);

	SpecIn.Context = context;

	//SpecIn.GetModifiers();
	return ActiveEffects.ApplyEffect(SpecIn, context);
}
FGAEffectHandle UGAAttributeComponent::ApplySelfEffect(AActor* Target, APawn* Instigator,
	UObject* Causer, FGAEffectSpec SpecIn)
{
	UE_LOG(GameAttributesEffects, Log, TEXT("Apply effect to self: %f , Effect: %d"), *GetOwner()->GetName(), *SpecIn.GetNameAsString());
	//this is bad btw. I need to change it. LAter.
	IIGAAttributes* targetAttr = Cast<IIGAAttributes>(Target);
	IIGAAttributes* instiAttr = Cast<IIGAAttributes>(Instigator);
	if (!targetAttr || !instiAttr)
		return FGAEffectHandle();

	UGAAttributeComponent* targetComp = targetAttr->GetAttributeComponent();
	UGAAttributeComponent* instiComp = instiAttr->GetAttributeComponent();
	FGAEffectContext context(Target->GetActorLocation(), Target, Causer,
		Instigator, targetComp, instiComp);

	SpecIn.Context = context;

	//SpecIn.GetModifiers();
	return FGAEffectHandle(); // ActiveEffects.ApplyEffect(SpecIn, context);
}
float UGAAttributesBlueprintFunctionLibrary::ChangeAttribute(AActor* Target, FGAAttribute AttributeIn, float ValueIn, EGAAttributeOp Operation, bool bSetAttribute)
{
	//check if actor have interface, if not, then this actor can't interact with attribute system.
	IIGAAttributes* attributeInt = Cast<IIGAAttributes>(Target);
	if (!attributeInt)
	{
		/*
			Probabaly should print some message, like 
			you need to implement proper interface to interact with this system
			and add component.
		*/
		return 0;
	}
	//shouldn't be null if we are past interface stage..
	UGAAttributesBase* attributes = attributeInt->GetAttributes();

	float newValue = attributes->AttributeOperation(AttributeIn, ValueIn, Operation);
	if (bSetAttribute)
	{
		attributes->SetFloatValue(AttributeIn, newValue);
	}

	return newValue;
}