46. PostGameplayEffectExecute
This commit is contained in:
		
							
								
								
									
										38
									
								
								Project/Source/Gasa/AbilitySystem/EffectProperties.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Project/Source/Gasa/AbilitySystem/EffectProperties.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| #include "EffectProperties.h" | ||||
|  | ||||
| #include "AbilitySystemComponent.h" | ||||
| #include "AbilitySystemGlobals.h" | ||||
| #include "GameplayEffect.h" | ||||
| #include "GameplayEffectExtension.h" | ||||
| #include "GameFramework/Pawn.h" | ||||
| #include "GameFramework/PlayerController.h" | ||||
|  | ||||
| void FEffectProperties::Populate(FGameplayEffectModCallbackData const& Data) | ||||
| { | ||||
| 	Context             = Data.EffectSpec.GetContext(); | ||||
| 	SourceAbilitySystem = Context.GetOriginalInstigatorAbilitySystemComponent(); | ||||
|  | ||||
| 	if (IsValid(SourceAbilitySystem) | ||||
| 		&& SourceAbilitySystem->AbilityActorInfo.IsValid() | ||||
| 		&& SourceAbilitySystem->AbilityActorInfo->AvatarActor.IsValid()) | ||||
| 	{ | ||||
| 		FGameplayAbilityActorInfo* AbilityInfo = SourceAbilitySystem->AbilityActorInfo.Get(); | ||||
| 		SourceAvatar     = AbilityInfo->AvatarActor.Get(); | ||||
| 		SourceController = AbilityInfo->PlayerController.Get(); | ||||
|  | ||||
| 		if (SourceController == nullptr && SourceAvatar) | ||||
| 		{ | ||||
| 			APawn* Pawn = Cast<APawn>(SourceAvatar); | ||||
| 			if (Pawn) | ||||
| 				SourceController = Pawn->GetController(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (Data.Target.AbilityActorInfo.IsValid() && Data.Target.AbilityActorInfo->AvatarActor.IsValid()) | ||||
| 	{ | ||||
| 		FGameplayAbilityActorInfo* AbilityInfo = Data.Target.AbilityActorInfo.Get(); | ||||
| 		TargetAvatar        = AbilityInfo->AvatarActor.Get(); | ||||
| 		TargetController    = AbilityInfo->PlayerController.Get(); | ||||
| 		TargetAbilitySystem = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(TargetAvatar); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										34
									
								
								Project/Source/Gasa/AbilitySystem/EffectProperties.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Project/Source/Gasa/AbilitySystem/EffectProperties.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "GameplayEffectTypes.h" | ||||
| #include "GasaCommon.h" | ||||
|  | ||||
| #include "EffectProperties.generated.h" | ||||
|  | ||||
| USTRUCT() | ||||
| struct GASA_API FEffectProperties | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| 	FGameplayEffectContextHandle Context; | ||||
|  | ||||
| 	UPROPERTY(VisibleAnywhere) | ||||
| 	UAbilitySystemComponent* SourceAbilitySystem; | ||||
| 	 | ||||
| 	UPROPERTY(VisibleAnywhere) | ||||
| 	AActor* SourceAvatar; | ||||
|  | ||||
| 	UPROPERTY(VisibleAnywhere) | ||||
| 	AController* SourceController; | ||||
| 	 | ||||
| 	UPROPERTY(VisibleAnywhere) | ||||
| 	UAbilitySystemComponent* TargetAbilitySystem; | ||||
| 	 | ||||
| 	UPROPERTY(VisibleAnywhere) | ||||
| 	AActor* TargetAvatar; | ||||
|  | ||||
| 	UPROPERTY(VisibleAnywhere) | ||||
| 	APlayerController* TargetController; | ||||
|  | ||||
| 	void Populate(FGameplayEffectModCallbackData const& Data); | ||||
| }; | ||||
| @@ -18,7 +18,7 @@ namespace Gasa | ||||
|  | ||||
| 	// From: UAbilitySystemGlobals::GetAbilitySystemComponentFromActor | ||||
| 	inline | ||||
| 	UGasaAbilitySystemComp* GetAbilitySystem(AActor* Actor, bool LookForComponent = false) | ||||
| 	UGasaAbilitySystemComp* GetAbilitySystem(AActor* Actor, bool LookForComponent = true) | ||||
| 	{ | ||||
| 		if (Actor == nullptr) | ||||
| 			return nullptr; | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| // Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp | ||||
| #include "GasaAttributeSet.h" | ||||
| #include "GasaAttributeSet_Inlines.h" | ||||
| #include "EffectProperties.h" | ||||
|  | ||||
| #include "AbilitySystemComponent.h" | ||||
| #include "Net/UnrealNetwork.h" | ||||
| @@ -8,66 +9,79 @@ | ||||
|  | ||||
| UGasaAttributeSet::UGasaAttributeSet() | ||||
| { | ||||
| 	InitHealth( 100.f ); | ||||
| 	InitMaxHealth( 100.f ); | ||||
| 	InitMana( 50.f ); | ||||
| 	InitMaxMana( 50.f ); | ||||
| 	InitHealth(100.f); | ||||
| 	InitMaxHealth(100.f); | ||||
| 	InitMana(50.f); | ||||
| 	InitMaxMana(50.f); | ||||
| } | ||||
|  | ||||
| #pragma region Rep Notifies | ||||
| void UGasaAttributeSet::Client_OnRep_Health( FGameplayAttributeData& PrevHealth ) | ||||
| void UGasaAttributeSet::Client_OnRep_Health(FGameplayAttributeData& PrevHealth) | ||||
| { | ||||
| 	// From GAMEPLAYATTRIBUTE_REPNOTIFY | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) ); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Health, PrevHealth ); | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Health)); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), Health, PrevHealth); | ||||
| } | ||||
| void UGasaAttributeSet::Client_OnRep_MaxHealth( FGameplayAttributeData& PrevMaxHealth ) | ||||
|  | ||||
| void UGasaAttributeSet::Client_OnRep_MaxHealth(FGameplayAttributeData& PrevMaxHealth) | ||||
| { | ||||
| 	// From GAMEPLAYATTRIBUTE_REPNOTIFY | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) ); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), MaxHealth, PrevMaxHealth ); | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxHealth)); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), MaxHealth, | ||||
| 	                                                                               PrevMaxHealth); | ||||
| } | ||||
| void UGasaAttributeSet::Client_OnRep_Mana( FGameplayAttributeData& PrevMana ) | ||||
|  | ||||
| void UGasaAttributeSet::Client_OnRep_Mana(FGameplayAttributeData& PrevMana) | ||||
| { | ||||
| 	// From GAMEPLAYATTRIBUTE_REPNOTIFY | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) ); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Mana, PrevMana ); | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Mana)); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), Mana, PrevMana); | ||||
| } | ||||
| void UGasaAttributeSet::Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana ) | ||||
|  | ||||
| void UGasaAttributeSet::Client_OnRep_MaxMana(FGameplayAttributeData& PrevMaxMana) | ||||
| { | ||||
| 	// From GAMEPLAYATTRIBUTE_REPNOTIFY | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) ); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), MaxMana, PrevMaxMana ); | ||||
| 	static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxMana)); | ||||
| 	GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), MaxMana, | ||||
| 	                                                                               PrevMaxMana); | ||||
| } | ||||
| #pragma endregion Rep Notifies | ||||
|  | ||||
| void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute, float& NewValue ) | ||||
| void UGasaAttributeSet::PostGameplayEffectExecute(FGameplayEffectModCallbackData const& Data) | ||||
| { | ||||
| 	Super::PreAttributeChange( Attribute, NewValue ); | ||||
| 	Super::PostGameplayEffectExecute(Data); | ||||
| 	FEffectProperties Props; | ||||
| 	Props.Populate(Data); | ||||
| } | ||||
|  | ||||
| 	if ( Attribute == GetHealthAttribute() ) | ||||
| void UGasaAttributeSet::PreAttributeChange(FGameplayAttribute const& Attribute, float& NewValue) | ||||
| { | ||||
| 	Super::PreAttributeChange(Attribute, NewValue); | ||||
|  | ||||
| 	if (Attribute == GetHealthAttribute()) | ||||
| 	{ | ||||
| 		NewValue = FMath::Clamp( NewValue, 0, GetMaxHealth() ); | ||||
| 		NewValue = FMath::Clamp(NewValue, 0, GetMaxHealth()); | ||||
| 	} | ||||
| 	if ( Attribute == GetMaxHealthAttribute() ) | ||||
| 	if (Attribute == GetMaxHealthAttribute()) | ||||
| 	{ | ||||
| 		NewValue = FMath::Clamp( NewValue, 0, 99999.000000 ); | ||||
| 		NewValue = FMath::Clamp(NewValue, 0, 99999.000000); | ||||
| 	} | ||||
| 	if ( Attribute == GetManaAttribute() ) | ||||
| 	if (Attribute == GetManaAttribute()) | ||||
| 	{ | ||||
| 		NewValue = FMath::Clamp( NewValue, 0, GetMaxMana() ); | ||||
| 		NewValue = FMath::Clamp(NewValue, 0, GetMaxMana()); | ||||
| 	} | ||||
| 	if ( Attribute == GetMaxManaAttribute() ) | ||||
| 	if (Attribute == GetMaxManaAttribute()) | ||||
| 	{ | ||||
| 		NewValue = FMath::Clamp( NewValue, 0, 99999.000000 ); | ||||
| 		NewValue = FMath::Clamp(NewValue, 0, 99999.000000); | ||||
| 	} | ||||
| } | ||||
| void UGasaAttributeSet::GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const | ||||
| { | ||||
| 	Super::GetLifetimeReplicatedProps( OutLifetimeProps ); | ||||
|  | ||||
| 	DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Health ); | ||||
| 	DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, MaxHealth ); | ||||
| 	DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Mana ); | ||||
| 	DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, MaxMana ); | ||||
| void UGasaAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const | ||||
| { | ||||
| 	Super::GetLifetimeReplicatedProps(OutLifetimeProps); | ||||
|  | ||||
| 	DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, Health); | ||||
| 	DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, MaxHealth); | ||||
| 	DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, Mana); | ||||
| 	DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, MaxMana); | ||||
| } | ||||
|   | ||||
| @@ -8,46 +8,50 @@ UCLASS() | ||||
| class GASA_API UGasaAttributeSet : public UAttributeSet | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
| 	UGasaAttributeSet(); | ||||
|  | ||||
| 	UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) | ||||
| 	UPROPERTY(ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData Health; | ||||
| 	UPROPERTY( ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) | ||||
| 	UPROPERTY(ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData MaxHealth; | ||||
| 	UPROPERTY( ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) | ||||
| 	UPROPERTY(ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData Mana; | ||||
| 	UPROPERTY( ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) | ||||
| 	UPROPERTY(ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes") | ||||
| 	FGameplayAttributeData MaxMana; | ||||
|  | ||||
| 	UFUNCTION() | ||||
| 	void Client_OnRep_Health( FGameplayAttributeData& PrevHealth ); | ||||
| 	void Client_OnRep_Health(FGameplayAttributeData& PrevHealth); | ||||
| 	UFUNCTION() | ||||
| 	void Client_OnRep_MaxHealth( FGameplayAttributeData& PrevMaxHealth ); | ||||
| 	void Client_OnRep_MaxHealth(FGameplayAttributeData& PrevMaxHealth); | ||||
| 	UFUNCTION() | ||||
| 	void Client_OnRep_Mana( FGameplayAttributeData& PrevMana ); | ||||
| 	void Client_OnRep_Mana(FGameplayAttributeData& PrevMana); | ||||
| 	UFUNCTION() | ||||
| 	void Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana ); | ||||
| 	void Client_OnRep_MaxMana(FGameplayAttributeData& PrevMaxMana); | ||||
|  | ||||
| #pragma region Getters | ||||
| 	static FGameplayAttribute GetHealthAttribute() | ||||
| 	{ | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) ); | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Health)); | ||||
| 		return Prop; | ||||
| 	} | ||||
|  | ||||
| 	static FGameplayAttribute GetMaxHealthAttribute() | ||||
| 	{ | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) ); | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxHealth)); | ||||
| 		return Prop; | ||||
| 	} | ||||
|  | ||||
| 	static FGameplayAttribute GetManaAttribute() | ||||
| 	{ | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) ); | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Mana)); | ||||
| 		return Prop; | ||||
| 	} | ||||
|  | ||||
| 	static FGameplayAttribute GetMaxManaAttribute() | ||||
| 	{ | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) ); | ||||
| 		static FProperty* Prop = FindFieldChecked<FProperty>(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxMana)); | ||||
| 		return Prop; | ||||
| 	} | ||||
|  | ||||
| @@ -55,41 +59,45 @@ public: | ||||
| 	FORCEINLINE float GetMaxHealth() const { return MaxHealth.GetCurrentValue(); } | ||||
| 	FORCEINLINE float GetMana() const { return Mana.GetCurrentValue(); } | ||||
| 	FORCEINLINE float GetMaxMana() const { return MaxMana.GetCurrentValue(); } | ||||
| 	#pragma endregion Getters | ||||
| #pragma endregion Getters | ||||
|  | ||||
| #pragma region Setters | ||||
| 	FORCEINLINE void SetHealth( float NewVal ); | ||||
| 	FORCEINLINE void SetMaxHealth( float NewVal ); | ||||
| 	FORCEINLINE void SetMana( float NewVal ); | ||||
| 	FORCEINLINE void SetMaxMana( float NewVal ); | ||||
| 	FORCEINLINE void SetHealth(float NewVal); | ||||
| 	FORCEINLINE void SetMaxHealth(float NewVal); | ||||
| 	FORCEINLINE void SetMana(float NewVal); | ||||
| 	FORCEINLINE void SetMaxMana(float NewVal); | ||||
|  | ||||
| 	FORCEINLINE void InitHealth( float NewVal ) | ||||
| 	FORCEINLINE void InitHealth(float NewVal) | ||||
| 	{ | ||||
| 		Health.SetBaseValue( NewVal ); | ||||
| 		Health.SetCurrentValue( NewVal ); | ||||
| 		Health.SetBaseValue(NewVal); | ||||
| 		Health.SetCurrentValue(NewVal); | ||||
| 	} | ||||
| 	FORCEINLINE void InitMaxHealth( float NewVal ) | ||||
|  | ||||
| 	FORCEINLINE void InitMaxHealth(float NewVal) | ||||
| 	{ | ||||
| 		MaxHealth.SetBaseValue( NewVal ); | ||||
| 		MaxHealth.SetCurrentValue( NewVal ); | ||||
| 		MaxHealth.SetBaseValue(NewVal); | ||||
| 		MaxHealth.SetCurrentValue(NewVal); | ||||
| 	} | ||||
| 	FORCEINLINE void InitMana( float NewVal ) | ||||
|  | ||||
| 	FORCEINLINE void InitMana(float NewVal) | ||||
| 	{ | ||||
| 		Mana.SetBaseValue( NewVal ); | ||||
| 		Mana.SetCurrentValue( NewVal ); | ||||
| 		Mana.SetBaseValue(NewVal); | ||||
| 		Mana.SetCurrentValue(NewVal); | ||||
| 	} | ||||
| 	FORCEINLINE void InitMaxMana( float NewVal ) | ||||
|  | ||||
| 	FORCEINLINE void InitMaxMana(float NewVal) | ||||
| 	{ | ||||
| 		MaxMana.SetBaseValue( NewVal ); | ||||
| 		MaxMana.SetCurrentValue( NewVal ); | ||||
| 		MaxMana.SetBaseValue(NewVal); | ||||
| 		MaxMana.SetCurrentValue(NewVal); | ||||
| 	} | ||||
| 	#pragma endregion Setters | ||||
| #pragma endregion Setters | ||||
|  | ||||
| #pragma region AttributeSet | ||||
| 	    void PreAttributeChange( const FGameplayAttribute& Attribute, float& NewValue ) override; | ||||
| 	void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override; | ||||
| 	void PostGameplayEffectExecute(FGameplayEffectModCallbackData const& Data) override; | ||||
| #pragma endregion AttributeSet | ||||
|  | ||||
| #pragma region UObject | ||||
| 	    void GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override; | ||||
| 	void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; | ||||
| #pragma endregion UObject | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user