diff --git a/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll b/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll index 4d654af..0099970 100644 --- a/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll +++ b/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ef0d986b42a1e5d7d498a61a2581c529981967d5586dcd1b7a6b49253204b7dc +oid sha256:d0cc403c45e28f2452702441c05eb75301540ec586d0f94eabbef2445befb7f8 size 79360 diff --git a/Project/Source/Gasa/AbilitySystem/EffectProperties.cpp b/Project/Source/Gasa/AbilitySystem/EffectProperties.cpp new file mode 100644 index 0000000..59e84e8 --- /dev/null +++ b/Project/Source/Gasa/AbilitySystem/EffectProperties.cpp @@ -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(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); + } +} diff --git a/Project/Source/Gasa/AbilitySystem/EffectProperties.h b/Project/Source/Gasa/AbilitySystem/EffectProperties.h new file mode 100644 index 0000000..eecf2a1 --- /dev/null +++ b/Project/Source/Gasa/AbilitySystem/EffectProperties.h @@ -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); +}; diff --git a/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent_Inlines.h b/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent_Inlines.h index 907c2f2..30f4e22 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent_Inlines.h +++ b/Project/Source/Gasa/AbilitySystem/GasaAbilitySystemComponent_Inlines.h @@ -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; diff --git a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp index ff24001..b14ebfe 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp +++ b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp @@ -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( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) ); - GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Health, PrevHealth ); + static FProperty* UGasaAttributeSetProperty = FindFieldChecked(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( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) ); - GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), MaxHealth, PrevMaxHealth ); + static FProperty* UGasaAttributeSetProperty = FindFieldChecked(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( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) ); - GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Mana, PrevMana ); + static FProperty* UGasaAttributeSetProperty = FindFieldChecked(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( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) ); - GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), MaxMana, PrevMaxMana ); + static FProperty* UGasaAttributeSetProperty = FindFieldChecked(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& 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& 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); } diff --git a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h index 4a83286..04d6c63 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h +++ b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h @@ -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( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) ); + static FProperty* Prop = FindFieldChecked(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Health)); return Prop; } + static FGameplayAttribute GetMaxHealthAttribute() { - static FProperty* Prop = FindFieldChecked( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) ); + static FProperty* Prop = FindFieldChecked(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, MaxHealth)); return Prop; } + static FGameplayAttribute GetManaAttribute() { - static FProperty* Prop = FindFieldChecked( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) ); + static FProperty* Prop = FindFieldChecked(UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UGasaAttributeSet, Mana)); return Prop; } + static FGameplayAttribute GetMaxManaAttribute() { - static FProperty* Prop = FindFieldChecked( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) ); + static FProperty* Prop = FindFieldChecked(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& OutLifetimeProps ) const override; + void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; #pragma endregion UObject }; diff --git a/Project/Source/Gasa/GasaCommon.h b/Project/Source/Gasa/GasaCommon.h index 7edf149..a6577fa 100644 --- a/Project/Source/Gasa/GasaCommon.h +++ b/Project/Source/Gasa/GasaCommon.h @@ -21,6 +21,8 @@ #pragma region Engine Forwards struct FInputActionValue; +struct FGameplayEffectContextHandle; +struct FGameplayEffectModCallbackData; struct FOnAttributeChangeData; struct FReplicationFlags; diff --git a/Project/Source/GasaGen/GasaGen_UGasaAttributeSet.cpp b/Project/Source/GasaGen/GasaGen_UGasaAttributeSet.cpp index 2c591d8..d0b8847 100644 --- a/Project/Source/GasaGen/GasaGen_UGasaAttributeSet.cpp +++ b/Project/Source/GasaGen/GasaGen_UGasaAttributeSet.cpp @@ -104,7 +104,7 @@ void gen_UGasaAttributeSet() body.append( def_pragma( txt("region AttributeSet"))); body.append( code_str( 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(fmt_newline); @@ -170,6 +170,7 @@ void gen_UGasaAttributeSet() header.print(fmt_newline); source.print( def_include( txt("GasaAttributeSet.h"))); source.print( def_include( txt("GasaAttributeSet_Inlines.h"))); + source.print( def_include( txt("EffectProperties.h"))); source.print(fmt_newline); source.print( def_include( txt("AbilitySystemComponent.h"))); source.print( def_include( txt("Net/UnrealNetwork.h"))); @@ -191,6 +192,17 @@ void gen_UGasaAttributeSet() 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; { 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( void UGasaAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) { @@ -230,6 +244,7 @@ void gen_UGasaAttributeSet() ))); } body.append(PreAttributeChange); + body.append(fmt_newline); CodeFn GetLifetimeOfReplicatedProps; {