45. PreAttributeChange

This commit is contained in:
2024-04-24 18:18:26 -04:00
parent a218d86c23
commit 39f1a1b721
6 changed files with 181 additions and 82 deletions

View File

@ -8,9 +8,9 @@
UGasaAttributeSet::UGasaAttributeSet()
{
InitHealth( 50.f );
InitHealth( 100.f );
InitMaxHealth( 100.f );
InitMana( 25.f );
InitMana( 50.f );
InitMaxMana( 50.f );
}
@ -41,6 +41,27 @@ void UGasaAttributeSet::Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMan
}
#pragma endregion Rep Notifies
void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute, float& NewValue )
{
Super::PreAttributeChange( Attribute, NewValue );
if ( Attribute == GetHealthAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, GetMaxHealth() );
}
if ( Attribute == GetMaxHealthAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, 99999.000000 );
}
if ( Attribute == GetManaAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, GetMaxMana() );
}
if ( Attribute == GetMaxManaAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, 99999.000000 );
}
}
void UGasaAttributeSet::GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const
{
Super::GetLifetimeReplicatedProps( OutLifetimeProps );

View File

@ -9,20 +9,16 @@ class GASA_API UGasaAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Health;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData MaxHealth;
UPROPERTY( ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Mana;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData MaxMana;
UGasaAttributeSet();
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Health;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData MaxHealth;
UPROPERTY( ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Mana;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData MaxMana;
UFUNCTION()
void Client_OnRep_Health( FGameplayAttributeData& PrevHealth );
@ -62,8 +58,7 @@ public:
#pragma endregion Getters
#pragma region Setters
FORCEINLINE void
SetHealth( float NewVal );
FORCEINLINE void SetHealth( float NewVal );
FORCEINLINE void SetMaxHealth( float NewVal );
FORCEINLINE void SetMana( float NewVal );
FORCEINLINE void SetMaxMana( float NewVal );
@ -90,8 +85,11 @@ public:
}
#pragma endregion Setters
#pragma region AttributeSet
void PreAttributeChange( const FGameplayAttribute& Attribute, float& NewValue ) override;
#pragma endregion AttributeSet
#pragma region UObject
void
GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override;
void GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override;
#pragma endregion UObject
};