46. PostGameplayEffectExecute

This commit is contained in:
Edward R. Gonzalez 2024-04-24 20:18:38 -04:00
parent 39f1a1b721
commit ad14d6b3af
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"
@ -21,26 +22,38 @@ void UGasaAttributeSet::Client_OnRep_Health( FGameplayAttributeData& PrevHealth
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::PostGameplayEffectExecute(FGameplayEffectModCallbackData const& Data)
{
Super::PostGameplayEffectExecute(Data);
FEffectProperties Props;
Props.Populate(Data);
}
void UGasaAttributeSet::PreAttributeChange(FGameplayAttribute const& Attribute, float& NewValue) void UGasaAttributeSet::PreAttributeChange(FGameplayAttribute const& Attribute, float& NewValue)
{ {
Super::PreAttributeChange(Attribute, NewValue); Super::PreAttributeChange(Attribute, NewValue);
@ -62,6 +75,7 @@ void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute,
NewValue = FMath::Clamp(NewValue, 0, 99999.000000); NewValue = FMath::Clamp(NewValue, 0, 99999.000000);
} }
} }
void UGasaAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const void UGasaAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{ {
Super::GetLifetimeReplicatedProps(OutLifetimeProps); Super::GetLifetimeReplicatedProps(OutLifetimeProps);

View File

@ -8,6 +8,7 @@ UCLASS()
class GASA_API UGasaAttributeSet : public UAttributeSet class GASA_API UGasaAttributeSet : public UAttributeSet
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UGasaAttributeSet(); UGasaAttributeSet();
@ -35,16 +36,19 @@ public:
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));
@ -68,16 +72,19 @@ public:
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);
@ -87,6 +94,7 @@ public:
#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

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;
{ {