46. PostGameplayEffectExecute

This commit is contained in:
Edward R. Gonzalez 2024-04-24 20:18:38 -04:00
parent ef002ccf53
commit ae1e28a072
8 changed files with 179 additions and 68 deletions

Binary file not shown.

View 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);
}
}

View 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);
};

View File

@ -18,7 +18,7 @@ namespace Gasa
// From: UAbilitySystemGlobals::GetAbilitySystemComponentFromActor // From: UAbilitySystemGlobals::GetAbilitySystemComponentFromActor
inline inline
UGasaAbilitySystemComp* GetAbilitySystem(AActor* Actor, bool LookForComponent = false) UGasaAbilitySystemComp* GetAbilitySystem(AActor* Actor, bool LookForComponent = true)
{ {
if (Actor == nullptr) if (Actor == nullptr)
return nullptr; return nullptr;

View File

@ -1,6 +1,7 @@
// Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp // Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp
#include "GasaAttributeSet.h" #include "GasaAttributeSet.h"
#include "GasaAttributeSet_Inlines.h" #include "GasaAttributeSet_Inlines.h"
#include "EffectProperties.h"
#include "AbilitySystemComponent.h" #include "AbilitySystemComponent.h"
#include "Net/UnrealNetwork.h" #include "Net/UnrealNetwork.h"
@ -8,66 +9,79 @@
UGasaAttributeSet::UGasaAttributeSet() UGasaAttributeSet::UGasaAttributeSet()
{ {
InitHealth( 100.f ); InitHealth(100.f);
InitMaxHealth( 100.f ); InitMaxHealth(100.f);
InitMana( 50.f ); InitMana(50.f);
InitMaxMana( 50.f ); InitMaxMana(50.f);
} }
#pragma region Rep Notifies #pragma region Rep Notifies
void UGasaAttributeSet::Client_OnRep_Health( FGameplayAttributeData& PrevHealth ) void UGasaAttributeSet::Client_OnRep_Health(FGameplayAttributeData& PrevHealth)
{ {
// From GAMEPLAYATTRIBUTE_REPNOTIFY // From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) ); static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Health));
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Health, PrevHealth ); GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), Health, PrevHealth);
} }
void UGasaAttributeSet::Client_OnRep_MaxHealth( FGameplayAttributeData& PrevMaxHealth )
void UGasaAttributeSet::Client_OnRep_MaxHealth(FGameplayAttributeData& PrevMaxHealth)
{ {
// From GAMEPLAYATTRIBUTE_REPNOTIFY // From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) ); static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxHealth));
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), MaxHealth, PrevMaxHealth ); GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), MaxHealth,
PrevMaxHealth);
} }
void UGasaAttributeSet::Client_OnRep_Mana( FGameplayAttributeData& PrevMana )
void UGasaAttributeSet::Client_OnRep_Mana(FGameplayAttributeData& PrevMana)
{ {
// From GAMEPLAYATTRIBUTE_REPNOTIFY // From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) ); static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Mana));
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Mana, PrevMana ); GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), Mana, PrevMana);
} }
void UGasaAttributeSet::Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana )
void UGasaAttributeSet::Client_OnRep_MaxMana(FGameplayAttributeData& PrevMaxMana)
{ {
// From GAMEPLAYATTRIBUTE_REPNOTIFY // From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) ); static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>(StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxMana));
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), MaxMana, PrevMaxMana ); GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(UGasaAttributeSetProperty), MaxMana,
PrevMaxMana);
} }
#pragma endregion Rep Notifies #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 ); void UGasaAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, MaxHealth ); {
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Mana ); Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, MaxMana );
DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, Health);
DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, MaxHealth);
DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, Mana);
DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, MaxMana);
} }

View File

@ -8,46 +8,50 @@ UCLASS()
class GASA_API UGasaAttributeSet : public UAttributeSet class GASA_API UGasaAttributeSet : public UAttributeSet
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UGasaAttributeSet(); UGasaAttributeSet();
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) UPROPERTY(ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes")
FGameplayAttributeData Health; FGameplayAttributeData Health;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) UPROPERTY(ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes")
FGameplayAttributeData MaxHealth; FGameplayAttributeData MaxHealth;
UPROPERTY( ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) UPROPERTY(ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes")
FGameplayAttributeData Mana; FGameplayAttributeData Mana;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" ) UPROPERTY(ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes")
FGameplayAttributeData MaxMana; FGameplayAttributeData MaxMana;
UFUNCTION() UFUNCTION()
void Client_OnRep_Health( FGameplayAttributeData& PrevHealth ); void Client_OnRep_Health(FGameplayAttributeData& PrevHealth);
UFUNCTION() UFUNCTION()
void Client_OnRep_MaxHealth( FGameplayAttributeData& PrevMaxHealth ); void Client_OnRep_MaxHealth(FGameplayAttributeData& PrevMaxHealth);
UFUNCTION() UFUNCTION()
void Client_OnRep_Mana( FGameplayAttributeData& PrevMana ); void Client_OnRep_Mana(FGameplayAttributeData& PrevMana);
UFUNCTION() UFUNCTION()
void Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana ); void Client_OnRep_MaxMana(FGameplayAttributeData& PrevMaxMana);
#pragma region Getters #pragma region Getters
static FGameplayAttribute GetHealthAttribute() 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; return Prop;
} }
static FGameplayAttribute GetMaxHealthAttribute() 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; return Prop;
} }
static FGameplayAttribute GetManaAttribute() 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; return Prop;
} }
static FGameplayAttribute GetMaxManaAttribute() 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; return Prop;
} }
@ -55,41 +59,45 @@ public:
FORCEINLINE float GetMaxHealth() const { return MaxHealth.GetCurrentValue(); } FORCEINLINE float GetMaxHealth() const { return MaxHealth.GetCurrentValue(); }
FORCEINLINE float GetMana() const { return Mana.GetCurrentValue(); } FORCEINLINE float GetMana() const { return Mana.GetCurrentValue(); }
FORCEINLINE float GetMaxMana() const { return MaxMana.GetCurrentValue(); } FORCEINLINE float GetMaxMana() const { return MaxMana.GetCurrentValue(); }
#pragma endregion Getters #pragma endregion Getters
#pragma region Setters #pragma region Setters
FORCEINLINE void SetHealth( float NewVal ); FORCEINLINE void SetHealth(float NewVal);
FORCEINLINE void SetMaxHealth( float NewVal ); FORCEINLINE void SetMaxHealth(float NewVal);
FORCEINLINE void SetMana( float NewVal ); FORCEINLINE void SetMana(float NewVal);
FORCEINLINE void SetMaxMana( float NewVal ); FORCEINLINE void SetMaxMana(float NewVal);
FORCEINLINE void InitHealth( float NewVal ) FORCEINLINE void InitHealth(float NewVal)
{ {
Health.SetBaseValue( NewVal ); Health.SetBaseValue(NewVal);
Health.SetCurrentValue( NewVal ); Health.SetCurrentValue(NewVal);
} }
FORCEINLINE void InitMaxHealth( float NewVal )
FORCEINLINE void InitMaxHealth(float NewVal)
{ {
MaxHealth.SetBaseValue( NewVal ); MaxHealth.SetBaseValue(NewVal);
MaxHealth.SetCurrentValue( NewVal ); MaxHealth.SetCurrentValue(NewVal);
} }
FORCEINLINE void InitMana( float NewVal )
FORCEINLINE void InitMana(float NewVal)
{ {
Mana.SetBaseValue( NewVal ); Mana.SetBaseValue(NewVal);
Mana.SetCurrentValue( NewVal ); Mana.SetCurrentValue(NewVal);
} }
FORCEINLINE void InitMaxMana( float NewVal )
FORCEINLINE void InitMaxMana(float NewVal)
{ {
MaxMana.SetBaseValue( NewVal ); MaxMana.SetBaseValue(NewVal);
MaxMana.SetCurrentValue( NewVal ); MaxMana.SetCurrentValue(NewVal);
} }
#pragma endregion Setters #pragma endregion Setters
#pragma region AttributeSet #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 endregion AttributeSet
#pragma region UObject #pragma region UObject
void GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override; void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
#pragma endregion UObject #pragma endregion UObject
}; };

View File

@ -21,6 +21,8 @@
#pragma region Engine Forwards #pragma region Engine Forwards
struct FInputActionValue; struct FInputActionValue;
struct FGameplayEffectContextHandle;
struct FGameplayEffectModCallbackData;
struct FOnAttributeChangeData; struct FOnAttributeChangeData;
struct FReplicationFlags; struct FReplicationFlags;

View File

@ -104,7 +104,7 @@ void gen_UGasaAttributeSet()
body.append( def_pragma( txt("region AttributeSet"))); body.append( def_pragma( txt("region AttributeSet")));
body.append( code_str( body.append( code_str(
void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override; void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
// void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override; void PostGameplayEffectExecute(FGameplayEffectModCallbackData const& Data) override;
)); ));
body.append( def_pragma( txt("endregion AttributeSet"))); body.append( def_pragma( txt("endregion AttributeSet")));
body.append(fmt_newline); body.append(fmt_newline);
@ -170,6 +170,7 @@ void gen_UGasaAttributeSet()
header.print(fmt_newline); header.print(fmt_newline);
source.print( def_include( txt("GasaAttributeSet.h"))); source.print( def_include( txt("GasaAttributeSet.h")));
source.print( def_include( txt("GasaAttributeSet_Inlines.h"))); source.print( def_include( txt("GasaAttributeSet_Inlines.h")));
source.print( def_include( txt("EffectProperties.h")));
source.print(fmt_newline); source.print(fmt_newline);
source.print( def_include( txt("AbilitySystemComponent.h"))); source.print( def_include( txt("AbilitySystemComponent.h")));
source.print( def_include( txt("Net/UnrealNetwork.h"))); source.print( def_include( txt("Net/UnrealNetwork.h")));
@ -191,6 +192,17 @@ void gen_UGasaAttributeSet()
impl_attribute_fields( body, class_name, attribute_fields); impl_attribute_fields( body, class_name, attribute_fields);
Code PostGameplayEffectExecute = parse_function( code(
void UGasaAttributeSet::PostGameplayEffectExecute(FGameplayEffectModCallbackData const& Data)
{
Super::PostGameplayEffectExecute(Data);
FEffectProperties Props;
Props.Populate(Data);
}
));
body.append(PostGameplayEffectExecute);
body.append(fmt_newline);
CodeFn PreAttributeChange; CodeFn PreAttributeChange;
{ {
CodeBody attribute_clamps = def_body( CodeT::Function_Body ); CodeBody attribute_clamps = def_body( CodeT::Function_Body );
@ -221,6 +233,8 @@ void gen_UGasaAttributeSet()
} }
))); )));
} }
attribute_clamps.append(fmt_newline);
attribute_clamps.append(fmt_newline);
PreAttributeChange = parse_function( token_fmt( "attribute_clamps", (StrC)attribute_clamps.to_string(), stringize( PreAttributeChange = parse_function( token_fmt( "attribute_clamps", (StrC)attribute_clamps.to_string(), stringize(
void UGasaAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) void UGasaAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{ {
@ -230,6 +244,7 @@ void gen_UGasaAttributeSet()
))); )));
} }
body.append(PreAttributeChange); body.append(PreAttributeChange);
body.append(fmt_newline);
CodeFn GetLifetimeOfReplicatedProps; CodeFn GetLifetimeOfReplicatedProps;
{ {