第一次提交
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AttributeSet.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "NativeGameplayTags.h"
|
||||
|
||||
#include "AS_Combat.generated.h"
|
||||
|
||||
namespace AS_Combat
|
||||
{
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Damage)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(DamageNegation)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(GuardDamageNegation)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(StaminaDamage)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(StaminaDamageNegation)
|
||||
|
||||
|
||||
}
|
||||
|
||||
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
|
||||
|
||||
UCLASS()
|
||||
class GENERICGAMEPLAYATTRIBUTES_API UAS_Combat : public UAttributeSet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
|
||||
UAS_Combat();
|
||||
|
||||
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||
|
||||
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
|
||||
|
||||
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
|
||||
|
||||
virtual bool PreGameplayEffectExecute(struct FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
// The damage that will apply to target
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Damage, Category = "Attribute|CombatSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData Damage{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, Damage)
|
||||
|
||||
// The damage reduction(percentage) for incoming health damage
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_DamageNegation, Category = "Attribute|CombatSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData DamageNegation{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, DamageNegation)
|
||||
|
||||
// The damage reduction(percentage) for incoming health damage while guarding
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_GuardDamageNegation, Category = "Attribute|CombatSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData GuardDamageNegation{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, GuardDamageNegation)
|
||||
|
||||
// The stamina damage that will apply to target
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_StaminaDamage, Category = "Attribute|CombatSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData StaminaDamage{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, StaminaDamage)
|
||||
|
||||
// The damage reduction(percentage) for incoming stamina damage
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_StaminaDamageNegation, Category = "Attribute|CombatSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData StaminaDamageNegation{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, StaminaDamageNegation)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetDamageAttribute"), Category = "Attribute|CombatSet")
|
||||
static FGameplayAttribute Bp_GetDamageAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetDamage"), Category = "Attribute|CombatSet")
|
||||
float Bp_GetDamage() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetDamage"), Category = "Attribute|CombatSet")
|
||||
void Bp_SetDamage(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitDamage"), Category = "Attribute|CombatSet")
|
||||
void Bp_InitDamage(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetDamageNegationAttribute"), Category = "Attribute|CombatSet")
|
||||
static FGameplayAttribute Bp_GetDamageNegationAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetDamageNegation"), Category = "Attribute|CombatSet")
|
||||
float Bp_GetDamageNegation() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetDamageNegation"), Category = "Attribute|CombatSet")
|
||||
void Bp_SetDamageNegation(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitDamageNegation"), Category = "Attribute|CombatSet")
|
||||
void Bp_InitDamageNegation(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetGuardDamageNegationAttribute"), Category = "Attribute|CombatSet")
|
||||
static FGameplayAttribute Bp_GetGuardDamageNegationAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetGuardDamageNegation"), Category = "Attribute|CombatSet")
|
||||
float Bp_GetGuardDamageNegation() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetGuardDamageNegation"), Category = "Attribute|CombatSet")
|
||||
void Bp_SetGuardDamageNegation(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitGuardDamageNegation"), Category = "Attribute|CombatSet")
|
||||
void Bp_InitGuardDamageNegation(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetStaminaDamageAttribute"), Category = "Attribute|CombatSet")
|
||||
static FGameplayAttribute Bp_GetStaminaDamageAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetStaminaDamage"), Category = "Attribute|CombatSet")
|
||||
float Bp_GetStaminaDamage() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetStaminaDamage"), Category = "Attribute|CombatSet")
|
||||
void Bp_SetStaminaDamage(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitStaminaDamage"), Category = "Attribute|CombatSet")
|
||||
void Bp_InitStaminaDamage(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetStaminaDamageNegationAttribute"), Category = "Attribute|CombatSet")
|
||||
static FGameplayAttribute Bp_GetStaminaDamageNegationAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetStaminaDamageNegation"), Category = "Attribute|CombatSet")
|
||||
float Bp_GetStaminaDamageNegation() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetStaminaDamageNegation"), Category = "Attribute|CombatSet")
|
||||
void Bp_SetStaminaDamageNegation(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitStaminaDamageNegation"), Category = "Attribute|CombatSet")
|
||||
void Bp_InitStaminaDamageNegation(float NewValue);
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Helper function to proportionally adjust the value of an attribute when it's associated max attribute changes. (i.e. When MaxHealth increases, Health increases by an amount that maintains the same percentage as before) */
|
||||
virtual void AdjustAttributeForMaxChange(FGameplayAttributeData& AffectedAttribute, const FGameplayAttributeData& MaxAttribute, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_Damage(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_DamageNegation(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_GuardDamageNegation(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_StaminaDamage(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_StaminaDamageNegation(const FGameplayAttributeData& OldValue);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,135 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AttributeSet.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "NativeGameplayTags.h"
|
||||
|
||||
#include "AS_Health.generated.h"
|
||||
|
||||
namespace AS_Health
|
||||
{
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Health)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(MaxHealth)
|
||||
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(IncomingHealing)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(IncomingDamage)
|
||||
|
||||
}
|
||||
|
||||
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
|
||||
|
||||
UCLASS()
|
||||
class GENERICGAMEPLAYATTRIBUTES_API UAS_Health : public UAttributeSet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
|
||||
UAS_Health();
|
||||
|
||||
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||
|
||||
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
|
||||
|
||||
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
|
||||
|
||||
virtual bool PreGameplayEffectExecute(struct FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
// Current health of an actor.(actor的当前生命值)
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Attribute|HealthSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData Health{ 100 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, Health)
|
||||
|
||||
// Max health value of an actor.(actor的最大生命值)
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxHealth, Category = "Attribute|HealthSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData MaxHealth{ 100 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, MaxHealth)
|
||||
|
||||
|
||||
|
||||
// Incoming healing. This is mapped directly to +Health.(即将到来的恢复值,映射为+Health)
|
||||
UPROPERTY(BlueprintReadOnly,Category = "Attribute|HealthSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData IncomingHealing{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, IncomingHealing)
|
||||
|
||||
// Incoming damage. This is mapped directly to -Health(即将到来的伤害值,映射为-Health)
|
||||
UPROPERTY(BlueprintReadOnly,Category = "Attribute|HealthSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData IncomingDamage{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, IncomingDamage)
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetHealthAttribute"), Category = "Attribute|HealthSet")
|
||||
static FGameplayAttribute Bp_GetHealthAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetHealth"), Category = "Attribute|HealthSet")
|
||||
float Bp_GetHealth() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetHealth"), Category = "Attribute|HealthSet")
|
||||
void Bp_SetHealth(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitHealth"), Category = "Attribute|HealthSet")
|
||||
void Bp_InitHealth(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetMaxHealthAttribute"), Category = "Attribute|HealthSet")
|
||||
static FGameplayAttribute Bp_GetMaxHealthAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetMaxHealth"), Category = "Attribute|HealthSet")
|
||||
float Bp_GetMaxHealth() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetMaxHealth"), Category = "Attribute|HealthSet")
|
||||
void Bp_SetMaxHealth(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitMaxHealth"), Category = "Attribute|HealthSet")
|
||||
void Bp_InitMaxHealth(float NewValue);
|
||||
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetIncomingHealingAttribute"), Category = "Attribute|HealthSet")
|
||||
static FGameplayAttribute Bp_GetIncomingHealingAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetIncomingHealing"), Category = "Attribute|HealthSet")
|
||||
float Bp_GetIncomingHealing() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetIncomingHealing"), Category = "Attribute|HealthSet")
|
||||
void Bp_SetIncomingHealing(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetIncomingDamageAttribute"), Category = "Attribute|HealthSet")
|
||||
static FGameplayAttribute Bp_GetIncomingDamageAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetIncomingDamage"), Category = "Attribute|HealthSet")
|
||||
float Bp_GetIncomingDamage() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetIncomingDamage"), Category = "Attribute|HealthSet")
|
||||
void Bp_SetIncomingDamage(float NewValue);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Helper function to proportionally adjust the value of an attribute when it's associated max attribute changes. (i.e. When MaxHealth increases, Health increases by an amount that maintains the same percentage as before) */
|
||||
virtual void AdjustAttributeForMaxChange(FGameplayAttributeData& AffectedAttribute, const FGameplayAttributeData& MaxAttribute, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_Health(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_MaxHealth(const FGameplayAttributeData& OldValue);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,101 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AttributeSet.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "NativeGameplayTags.h"
|
||||
|
||||
#include "AS_Mana.generated.h"
|
||||
|
||||
namespace AS_Mana
|
||||
{
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Mana)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(MaxMana)
|
||||
|
||||
|
||||
}
|
||||
|
||||
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
|
||||
|
||||
UCLASS()
|
||||
class GENERICGAMEPLAYATTRIBUTES_API UAS_Mana : public UAttributeSet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
|
||||
UAS_Mana();
|
||||
|
||||
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||
|
||||
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
|
||||
|
||||
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
|
||||
|
||||
virtual bool PreGameplayEffectExecute(struct FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
// Current mana of an actor.(actor的当前魔法值)
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Mana, Category = "Attribute|ManaSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData Mana{ 100 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, Mana)
|
||||
|
||||
// Max mana value of an actor.(actor的最大魔法值)
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxMana, Category = "Attribute|ManaSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData MaxMana{ 100 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, MaxMana)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetManaAttribute"), Category = "Attribute|ManaSet")
|
||||
static FGameplayAttribute Bp_GetManaAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetMana"), Category = "Attribute|ManaSet")
|
||||
float Bp_GetMana() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetMana"), Category = "Attribute|ManaSet")
|
||||
void Bp_SetMana(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitMana"), Category = "Attribute|ManaSet")
|
||||
void Bp_InitMana(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetMaxManaAttribute"), Category = "Attribute|ManaSet")
|
||||
static FGameplayAttribute Bp_GetMaxManaAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetMaxMana"), Category = "Attribute|ManaSet")
|
||||
float Bp_GetMaxMana() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetMaxMana"), Category = "Attribute|ManaSet")
|
||||
void Bp_SetMaxMana(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitMaxMana"), Category = "Attribute|ManaSet")
|
||||
void Bp_InitMaxMana(float NewValue);
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Helper function to proportionally adjust the value of an attribute when it's associated max attribute changes. (i.e. When MaxHealth increases, Health increases by an amount that maintains the same percentage as before) */
|
||||
virtual void AdjustAttributeForMaxChange(FGameplayAttributeData& AffectedAttribute, const FGameplayAttributeData& MaxAttribute, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_Mana(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_MaxMana(const FGameplayAttributeData& OldValue);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,135 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AttributeSet.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "NativeGameplayTags.h"
|
||||
|
||||
#include "AS_Stamina.generated.h"
|
||||
|
||||
namespace AS_Stamina
|
||||
{
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Stamina)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(MaxStamina)
|
||||
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(IncomingHealing)
|
||||
|
||||
GENERICGAMEPLAYATTRIBUTES_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(IncomingDamage)
|
||||
|
||||
}
|
||||
|
||||
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
|
||||
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
|
||||
|
||||
UCLASS()
|
||||
class GENERICGAMEPLAYATTRIBUTES_API UAS_Stamina : public UAttributeSet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
|
||||
UAS_Stamina();
|
||||
|
||||
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||
|
||||
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
|
||||
|
||||
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
|
||||
|
||||
virtual bool PreGameplayEffectExecute(struct FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
|
||||
|
||||
// Current stamina of an actor.(actor的当前生命值)
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Stamina, Category = "Attribute|StaminaSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData Stamina{ 100 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, Stamina)
|
||||
|
||||
// Max stamina value of an actor.(actor的最大生命值)
|
||||
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxStamina, Category = "Attribute|StaminaSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData MaxStamina{ 100 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, MaxStamina)
|
||||
|
||||
|
||||
|
||||
// Incoming healing. This is mapped directly to +Stamina.(即将到来的恢复值,映射为+Stamina)
|
||||
UPROPERTY(BlueprintReadOnly,Category = "Attribute|StaminaSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData IncomingHealing{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, IncomingHealing)
|
||||
|
||||
// Incoming damage. This is mapped directly to -Stamina(即将到来的伤害值,映射为-Stamina)
|
||||
UPROPERTY(BlueprintReadOnly,Category = "Attribute|StaminaSet", Meta = (AllowPrivateAccess = true))
|
||||
FGameplayAttributeData IncomingDamage{ 0.0 };
|
||||
ATTRIBUTE_ACCESSORS(ThisClass, IncomingDamage)
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetStaminaAttribute"), Category = "Attribute|StaminaSet")
|
||||
static FGameplayAttribute Bp_GetStaminaAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetStamina"), Category = "Attribute|StaminaSet")
|
||||
float Bp_GetStamina() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetStamina"), Category = "Attribute|StaminaSet")
|
||||
void Bp_SetStamina(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitStamina"), Category = "Attribute|StaminaSet")
|
||||
void Bp_InitStamina(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetMaxStaminaAttribute"), Category = "Attribute|StaminaSet")
|
||||
static FGameplayAttribute Bp_GetMaxStaminaAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetMaxStamina"), Category = "Attribute|StaminaSet")
|
||||
float Bp_GetMaxStamina() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetMaxStamina"), Category = "Attribute|StaminaSet")
|
||||
void Bp_SetMaxStamina(float NewValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="InitMaxStamina"), Category = "Attribute|StaminaSet")
|
||||
void Bp_InitMaxStamina(float NewValue);
|
||||
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetIncomingHealingAttribute"), Category = "Attribute|StaminaSet")
|
||||
static FGameplayAttribute Bp_GetIncomingHealingAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetIncomingHealing"), Category = "Attribute|StaminaSet")
|
||||
float Bp_GetIncomingHealing() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetIncomingHealing"), Category = "Attribute|StaminaSet")
|
||||
void Bp_SetIncomingHealing(float NewValue);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable,BlueprintPure,meta=(DisplayName="GetIncomingDamageAttribute"), Category = "Attribute|StaminaSet")
|
||||
static FGameplayAttribute Bp_GetIncomingDamageAttribute();
|
||||
|
||||
UFUNCTION(BlueprintPure,meta=(DisplayName="GetIncomingDamage"), Category = "Attribute|StaminaSet")
|
||||
float Bp_GetIncomingDamage() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable,meta=(DisplayName="SetIncomingDamage"), Category = "Attribute|StaminaSet")
|
||||
void Bp_SetIncomingDamage(float NewValue);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Helper function to proportionally adjust the value of an attribute when it's associated max attribute changes. (i.e. When MaxHealth increases, Health increases by an amount that maintains the same percentage as before) */
|
||||
virtual void AdjustAttributeForMaxChange(FGameplayAttributeData& AffectedAttribute, const FGameplayAttributeData& MaxAttribute, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_Stamina(const FGameplayAttributeData& OldValue);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnRep_MaxStamina(const FGameplayAttributeData& OldValue);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user