Added Meta values(cost, restore) to the mana attribute set

This commit is contained in:
Nyx
2025-10-01 22:54:52 -06:00
parent 76a504ae17
commit 9f964a7ffa
7 changed files with 54 additions and 14 deletions

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:27dc90d2b01df9b74f14227a10842dfc55f78a5e1af7986f7596cc669c706168
size 14069

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:68579ffd5ae20e4bc73b9d80f6ea694979bff438e50b67b7070ef2f9f12c1b93 oid sha256:06b71d6a239970fcd94b119f44eaef12da72a100ad82fb18add01140924bde35
size 16339 size 54477

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:8d155a69cbf2a3ed1ccd4d6d25506bfc2b1f13bf52c950496195cf0d639e8208 oid sha256:445697eff3a0e04eb94e500ac1629c15f73d9fe3c491abdf6aaeba762a180be0
size 660120 size 667254

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:47222fe715c49e49a439014fc8837724d78864387d34346b1dfc5d00a3ac486d oid sha256:4a996dfec5784ee27e90543e0cd8a5a72052aca5876f411d7b8c383b6b1659ca
size 1459479 size 1461608

View File

@@ -1,6 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "ManaAttributeSet.h" #include "ManaAttributeSet.h"
UManaAttributeSet::UManaAttributeSet() UManaAttributeSet::UManaAttributeSet()
@@ -32,3 +31,36 @@ void UManaAttributeSet::OnRep_MaxMana(const FGameplayAttributeData& OldValue)
const float NewMaxMana = GetMaxMana(); const float NewMaxMana = GetMaxMana();
OnMaxManaChanged.Broadcast(this, OldMaxMana, NewMaxMana); OnMaxManaChanged.Broadcast(this, OldMaxMana, NewMaxMana);
} }
void UManaAttributeSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
if (Data.EvaluatedData.Attribute == GetManaAttribute())
{
SetMana(FMath::Clamp(GetMana(), 0.0f, GetMaxMana()));
}
if (Data.EvaluatedData.Attribute == GetCostAttribute())
{
const float CostValue = GetCost();
const float OldMana = GetMana();
const float ManaMax = GetMaxMana();
const float NewMana = FMath::Clamp(OldMana-CostValue,0.0f, ManaMax);
if (OldMana!=NewMana)
{
SetMana(NewMana);
}
SetCost(0.0f);
}
if (Data.EvaluatedData.Attribute==GetMaxManaAttribute())
{
const float RestoreValue = GetMaxMana();
const float OldMana = GetMana();
const float ManaMax = GetMaxMana();
const float NewMana = FMath::Clamp(OldMana+RestoreValue,0.0f, ManaMax);
if (OldMana!=NewMana)
{
SetMana(NewMana);
}
SetRestore(0.0f);
}
}

View File

@@ -6,6 +6,7 @@
#include "AttributeSet.h" #include "AttributeSet.h"
#include "AbilitySystemComponent.h" #include "AbilitySystemComponent.h"
#include "Net/UnrealNetwork.h" #include "Net/UnrealNetwork.h"
#include "GameplayEffectExtension.h"
#include "ManaAttributeSet.generated.h" #include "ManaAttributeSet.generated.h"
/** /**
@@ -28,16 +29,26 @@ class ELISTRIA_CALLING_API UManaAttributeSet : public UAttributeSet
public: public:
UManaAttributeSet(); UManaAttributeSet();
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnRep_Mana) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnRep_Mana, meta = (HideFromModifiers))
FGameplayAttributeData Mana; FGameplayAttributeData Mana;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnRep_MaxMana) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnRep_MaxMana)
FGameplayAttributeData MaxMana; FGameplayAttributeData MaxMana;
UPROPERTY(VisibleAnywhere)
FGameplayAttributeData Cost;
UPROPERTY(VisibleAnywhere)
FGameplayAttributeData Restore;
ATTRIBUTE_ACCESSORS(UManaAttributeSet, Mana) ATTRIBUTE_ACCESSORS(UManaAttributeSet, Mana)
ATTRIBUTE_ACCESSORS(UManaAttributeSet, MaxMana) ATTRIBUTE_ACCESSORS(UManaAttributeSet, MaxMana)
ATTRIBUTE_ACCESSORS(UManaAttributeSet, Cost)
ATTRIBUTE_ACCESSORS(UManaAttributeSet, Restore)
UFUNCTION() UFUNCTION()
void OnRep_Mana(const FGameplayAttributeData& OldValue); void OnRep_Mana(const FGameplayAttributeData& OldValue);