25. Attribut accessors complete
There is some jank, with the ability system init on character (I'll fix later). Cog replaces the usuals showdebug command
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
#include "GasaAbilitySystemComponent.generated.h"
|
||||
|
||||
|
||||
UCLASS()
|
||||
UCLASS(BlueprintType)
|
||||
class GASA_API UGasaAbilitySystemComp : public UAbilitySystemComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
@ -7,6 +7,10 @@
|
||||
|
||||
UGasaAttributeSet::UGasaAttributeSet()
|
||||
{
|
||||
InitHealth( 100.f );
|
||||
InitMaxHealth( 100.f );
|
||||
InitMana( ( 50.f ) );
|
||||
InitMaxMana( 50.f );
|
||||
}
|
||||
|
||||
void UGasaAttributeSet::Client_OnRep_Health( FGameplayAttributeData& PrevHealth )
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This was generated by GasaGen/GasaGen.cpp
|
||||
|
||||
#include "AttributeSet.h"
|
||||
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "GasaAttributeSet.generated.h"
|
||||
|
||||
UCLASS() class GASA_API UGasaAttributeSet : public UAttributeSet
|
||||
@ -11,13 +11,13 @@ public:
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
FGameplayAttributeData Health;
|
||||
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
FGameplayAttributeData MaxHealth;
|
||||
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_Mana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
FGameplayAttributeData Mana;
|
||||
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
|
||||
FGameplayAttributeData MaxMana;
|
||||
|
||||
UGasaAttributeSet();
|
||||
@ -31,6 +31,117 @@ public:
|
||||
UFUNCTION()
|
||||
void Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana );
|
||||
|
||||
#pragma region Getters
|
||||
|
||||
static FGameplayAttribute GetHealthAttribute()
|
||||
{
|
||||
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) );
|
||||
return Prop;
|
||||
}
|
||||
|
||||
static FGameplayAttribute GetMaxHealthAttribute()
|
||||
{
|
||||
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) );
|
||||
return Prop;
|
||||
}
|
||||
|
||||
static FGameplayAttribute GetManaAttribute()
|
||||
{
|
||||
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) );
|
||||
return Prop;
|
||||
}
|
||||
|
||||
static FGameplayAttribute GetMaxManaAttribute()
|
||||
{
|
||||
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) );
|
||||
return Prop;
|
||||
}
|
||||
|
||||
FORCEINLINE float GetHealth() const
|
||||
{
|
||||
return Health.GetCurrentValue();
|
||||
}
|
||||
|
||||
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 region Setters
|
||||
FORCEINLINE void SetHealth( float NewVal )
|
||||
{
|
||||
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
|
||||
if ( ensure( AbilityComp ) )
|
||||
{
|
||||
AbilityComp->SetNumericAttributeBase( GetHealthAttribute(), NewVal );
|
||||
};
|
||||
}
|
||||
|
||||
FORCEINLINE void SetMaxHealth( float NewVal )
|
||||
{
|
||||
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
|
||||
if ( ensure( AbilityComp ) )
|
||||
{
|
||||
AbilityComp->SetNumericAttributeBase( GetMaxHealthAttribute(), NewVal );
|
||||
};
|
||||
}
|
||||
|
||||
FORCEINLINE void SetMana( float NewVal )
|
||||
{
|
||||
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
|
||||
if ( ensure( AbilityComp ) )
|
||||
{
|
||||
AbilityComp->SetNumericAttributeBase( GetManaAttribute(), NewVal );
|
||||
};
|
||||
}
|
||||
|
||||
FORCEINLINE void SetMaxMana( float NewVal )
|
||||
{
|
||||
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
|
||||
if ( ensure( AbilityComp ) )
|
||||
{
|
||||
AbilityComp->SetNumericAttributeBase( GetMaxManaAttribute(), NewVal );
|
||||
};
|
||||
}
|
||||
|
||||
FORCEINLINE void InitHealth( float NewVal )
|
||||
{
|
||||
Health.SetBaseValue( NewVal );
|
||||
Health.SetCurrentValue( NewVal );
|
||||
}
|
||||
|
||||
FORCEINLINE void InitMaxHealth( float NewVal )
|
||||
{
|
||||
MaxHealth.SetBaseValue( NewVal );
|
||||
MaxHealth.SetCurrentValue( NewVal );
|
||||
}
|
||||
|
||||
FORCEINLINE void InitMana( float NewVal )
|
||||
{
|
||||
Mana.SetBaseValue( NewVal );
|
||||
Mana.SetCurrentValue( NewVal );
|
||||
}
|
||||
|
||||
FORCEINLINE void InitMaxMana( float NewVal )
|
||||
{
|
||||
MaxMana.SetBaseValue( NewVal );
|
||||
MaxMana.SetCurrentValue( NewVal );
|
||||
}
|
||||
|
||||
#pragma endregion Setters
|
||||
|
||||
#pragma region UObject
|
||||
|
||||
void GetLifetimeReplicatedProps( TArray< FLifetimeProperty >& OutLifetimeProps ) const override;
|
||||
|
@ -3,4 +3,6 @@
|
||||
AEnemyCharacter::AEnemyCharacter()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
bAutoAbilitySystem = true;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
|
||||
#include "AbilitySystem/GasaAbilitySystemComponent.h"
|
||||
#include "AbilitySystem/GasaAttributeSet.h"
|
||||
#include "Game/GasaLevelScriptActor.h"
|
||||
|
||||
void AGasaCharacter::SetHighlight(EHighlight Desired)
|
||||
@ -45,7 +46,7 @@ AGasaCharacter::AGasaCharacter()
|
||||
AbilitySystem->SetIsReplicated(true);
|
||||
AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);
|
||||
|
||||
Attributes = CreateDefaultSubobject<UAttributeSet>("Attributes");
|
||||
Attributes = CreateDefaultSubobject<UGasaAttributeSet>("Attributes");
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,6 +72,12 @@ void AGasaCharacter::OnRep_PlayerState()
|
||||
void AGasaCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (bAutoAbilitySystem)
|
||||
{
|
||||
// TODO(Ed): Do we need to do this for enemies?
|
||||
AbilitySystem->InitAbilityActorInfo(this, this);
|
||||
}
|
||||
}
|
||||
|
||||
void AGasaCharacter::Tick(float DeltaSeconds)
|
||||
|
@ -9,6 +9,19 @@ APlayerCharacter::APlayerCharacter()
|
||||
bAutoAbilitySystem = false;
|
||||
}
|
||||
|
||||
void APlayerCharacter::PossessedBy(AController* NewController)
|
||||
{
|
||||
Super::PossessedBy(NewController);
|
||||
|
||||
AGasaPlayerState* PS = GetGasaPlayerState();
|
||||
// Server setup ability system (character side)
|
||||
{
|
||||
AbilitySystem = PS->AbilitySystem;
|
||||
Attributes = PS->Attributes;
|
||||
AbilitySystem->InitAbilityActorInfo(PS, this);
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerCharacter::OnRep_PlayerState()
|
||||
{
|
||||
Super::OnRep_PlayerState();
|
||||
|
@ -13,6 +13,8 @@ public:
|
||||
APlayerCharacter();
|
||||
|
||||
#pragma region Pawn
|
||||
void PossessedBy(AController* NewController) override;
|
||||
|
||||
void OnRep_PlayerState() override;
|
||||
#pragma endregion Pawn
|
||||
};
|
||||
|
@ -73,6 +73,7 @@ void AGasaPlayerController::OnPossess(APawn* InPawn)
|
||||
AGasaPlayerState* PS = GetPlayerState();
|
||||
AGasaCharacter* character = Cast<AGasaCharacter>(InPawn);
|
||||
// Net Owner setup ability system
|
||||
if (0)
|
||||
{
|
||||
character->AbilitySystem = PS->AbilitySystem;
|
||||
character->Attributes = PS->Attributes;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "GasaPlayerState.h"
|
||||
|
||||
#include "AbilitySystem/GasaAbilitySystemComponent.h"
|
||||
#include "AbilitySystem/GasaAttributeSet.h"
|
||||
|
||||
AGasaPlayerState::AGasaPlayerState()
|
||||
{
|
||||
@ -8,7 +9,7 @@ AGasaPlayerState::AGasaPlayerState()
|
||||
AbilitySystem->SetIsReplicated(true);
|
||||
AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
|
||||
|
||||
Attributes = CreateDefaultSubobject<UAttributeSet>("Attributes");
|
||||
Attributes = CreateDefaultSubobject<UGasaAttributeSet>("Attributes");
|
||||
|
||||
// Replication
|
||||
NetUpdateFrequency = 100.f;
|
||||
|
Reference in New Issue
Block a user