Files
TG_ARPG/Source/TG_ARPG/Public/TGAttributeSet.h
2023-07-16 21:11:21 +08:00

95 lines
3.3 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "TGAbilitySystemComponent.h"
#include "TGAttributeSet.generated.h"
#define ATTRIBUTE_ACCESSORS(ClassName,PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName,PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
/**
*
*/
struct FGameplayEffectModCallbackData;
//创建代理
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FAttrChangeDelegate,float,Attr,int32,stackCount);
UCLASS()
class TG_ARPG_API UTGAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UTGAttributeSet();
//在生命周期内,将对象设置为网络复制的对象
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
//定义各个参数和对应的OnRep/Notify参数
UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_currentHealth)
FGameplayAttributeData currentHealth;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,currentHealth);
UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_MaxHealth)
FGameplayAttributeData maxHealth;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,maxHealth);
UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_currentMana)
FGameplayAttributeData currentMana;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,currentMana);
UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_MaxMana)
FGameplayAttributeData maxMana;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,maxMana);
UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_attackDamage)
FGameplayAttributeData attackDamage;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,attackDamage);
UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_speedMultiplier)
FGameplayAttributeData speedMultiplier;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,speedMultiplier);
//UPROPERTY(BlueprintReadOnly,Category = "Attribute",ReplicatedUsing = OnRep_Armor)
//FGameplayAttributeData Armor;
//ATTRIBUTE_ACCESSORS(UTengenAttributeSet,Armor);
UPROPERTY(BlueprintReadOnly,Category = "Damage")
FGameplayAttributeData Damage;
ATTRIBUTE_ACCESSORS(UTGAttributeSet,Damage);
//数值变化时,通知所有绑定该代理的类
FAttrChangeDelegate HealthChangeDelegate;
FAttrChangeDelegate ManaChangeDelegate;
FAttrChangeDelegate AttackDamageChangeDelegate;
FAttrChangeDelegate SpeedMultiplierChangeDelegate;
//将返回值固定在合理范围内
void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
//当数值发生变化时,在网络中广播该变化
UFUNCTION()
virtual void OnRep_currentHealth(const FGameplayAttributeData& oldCurrentHealth);
UFUNCTION()
virtual void OnRep_maxHealth(const FGameplayAttributeData& oldMaxHealth);
UFUNCTION()
virtual void OnRep_currentMana(const FGameplayAttributeData& oldCurrentMana);
UFUNCTION()
virtual void OnRep_maxMana(const FGameplayAttributeData& oldMaxMana);
UFUNCTION()
virtual void OnRep_attackDamage(const FGameplayAttributeData& oldAttackDamage);
UFUNCTION()
virtual void OnRep_speedMultiplier(const FGameplayAttributeData& oldSpeedMultiplier);
//UFUNCTION()
//virtual void OnRep_Armor(const FGameplayAttributeData& oldArmor);
};