Starting to figure out attribute set more (Part of 65. 65. Initialize Attributes from a Data Table)

Going to move gasagen code to editor module.
This commit is contained in:
2024-10-21 16:10:56 -04:00
parent 067c2f03c5
commit 2522f4df6c
10 changed files with 343 additions and 38 deletions

View File

@ -17,6 +17,34 @@ UGasaAttributeSet::UGasaAttributeSet()
}
#pragma region Rep Notifies
void UGasaAttributeSet::Client_OnRep_Strength( FGameplayAttributeData& PrevStrength )
{
// From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Strength ) );
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Strength, PrevStrength );
}
void UGasaAttributeSet::Client_OnRep_Intelligence( FGameplayAttributeData& PrevIntelligence )
{
// From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Intelligence ) );
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(
FGameplayAttribute( UGasaAttributeSetProperty ), Intelligence, PrevIntelligence
);
}
void UGasaAttributeSet::Client_OnRep_Resilience( FGameplayAttributeData& PrevResilience )
{
// From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Resilience ) );
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(
FGameplayAttribute( UGasaAttributeSetProperty ), Resilience, PrevResilience
);
}
void UGasaAttributeSet::Client_OnRep_Vigor( FGameplayAttributeData& PrevVigor )
{
// From GAMEPLAYATTRIBUTE_REPNOTIFY
static FProperty* UGasaAttributeSetProperty = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Vigor ) );
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication( FGameplayAttribute( UGasaAttributeSetProperty ), Vigor, PrevVigor );
}
void UGasaAttributeSet::Client_OnRep_Health( FGameplayAttributeData& PrevHealth )
{
// From GAMEPLAYATTRIBUTE_REPNOTIFY
@ -49,6 +77,22 @@ void UGasaAttributeSet::PostGameplayEffectExecute( FGameplayEffectModCallbackDat
FEffectProperties Props;
Props.Populate( Data );
if ( Data.EvaluatedData.Attribute == GetStrengthAttribute() )
{
SetStrength( FMath::Clamp( GetStrength(), 0, 999.000000 ) );
}
if ( Data.EvaluatedData.Attribute == GetIntelligenceAttribute() )
{
SetIntelligence( FMath::Clamp( GetIntelligence(), 0, 999.000000 ) );
}
if ( Data.EvaluatedData.Attribute == GetResilienceAttribute() )
{
SetResilience( FMath::Clamp( GetResilience(), 0, 999.000000 ) );
}
if ( Data.EvaluatedData.Attribute == GetVigorAttribute() )
{
SetVigor( FMath::Clamp( GetVigor(), 0, 999.000000 ) );
}
if ( Data.EvaluatedData.Attribute == GetHealthAttribute() )
{
SetHealth( FMath::Clamp( GetHealth(), 0, GetMaxHealth() ) );
@ -65,12 +109,30 @@ void UGasaAttributeSet::PostGameplayEffectExecute( FGameplayEffectModCallbackDat
{
SetMaxMana( FMath::Clamp( GetMaxMana(), 0, 99999.000000 ) );
}
PostAttributeChange_Custom();
}
void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute, float& NewValue )
{
Super::PreAttributeChange( Attribute, NewValue );
if ( Attribute == GetStrengthAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, 999.000000 );
}
if ( Attribute == GetIntelligenceAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, 999.000000 );
}
if ( Attribute == GetResilienceAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, 999.000000 );
}
if ( Attribute == GetVigorAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, 999.000000 );
}
if ( Attribute == GetHealthAttribute() )
{
NewValue = FMath::Clamp( NewValue, 0, GetMaxHealth() );
@ -87,12 +149,18 @@ void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute,
{
NewValue = FMath::Clamp( NewValue, 0, 99999.000000 );
}
PreAttributeChange_Custom();
}
void UGasaAttributeSet::GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const
{
Super::GetLifetimeReplicatedProps( OutLifetimeProps );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Strength );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Intelligence );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Resilience );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Vigor );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Health );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, MaxHealth );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Mana );

View File

@ -11,6 +11,19 @@ class GASA_API UGasaAttributeSet : public UAttributeSet
public:
UGasaAttributeSet();
// Primary Attribute Fields
UPROPERTY( ReplicatedUsing = Client_OnRep_Strength, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Strength;
UPROPERTY( ReplicatedUsing = Client_OnRep_Intelligence, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Intelligence;
UPROPERTY( ReplicatedUsing = Client_OnRep_Resilience, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Resilience;
UPROPERTY( ReplicatedUsing = Client_OnRep_Vigor, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Vigor;
// Vital Attribute Fields
UPROPERTY( ReplicatedUsing = Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData Health;
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxHealth, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
@ -20,6 +33,14 @@ public:
UPROPERTY( ReplicatedUsing = Client_OnRep_MaxMana, EditAnywhere, BlueprintReadWrite, Category = "Attributes" )
FGameplayAttributeData MaxMana;
UFUNCTION()
void Client_OnRep_Strength( FGameplayAttributeData& PrevStrength );
UFUNCTION()
void Client_OnRep_Intelligence( FGameplayAttributeData& PrevIntelligence );
UFUNCTION()
void Client_OnRep_Resilience( FGameplayAttributeData& PrevResilience );
UFUNCTION()
void Client_OnRep_Vigor( FGameplayAttributeData& PrevVigor );
UFUNCTION()
void Client_OnRep_Health( FGameplayAttributeData& PrevHealth );
UFUNCTION()
@ -30,6 +51,26 @@ public:
void Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana );
#pragma region Getters
static FGameplayAttribute GetStrengthAttribute()
{
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Strength ) );
return Prop;
}
static FGameplayAttribute GetIntelligenceAttribute()
{
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Intelligence ) );
return Prop;
}
static FGameplayAttribute GetResilienceAttribute()
{
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Resilience ) );
return Prop;
}
static FGameplayAttribute GetVigorAttribute()
{
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Vigor ) );
return Prop;
}
static FGameplayAttribute GetHealthAttribute()
{
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) );
@ -51,6 +92,10 @@ public:
return Prop;
}
FORCEINLINE float GetStrength() const { return Strength.GetCurrentValue(); }
FORCEINLINE float GetIntelligence() const { return Intelligence.GetCurrentValue(); }
FORCEINLINE float GetResilience() const { return Resilience.GetCurrentValue(); }
FORCEINLINE float GetVigor() const { return Vigor.GetCurrentValue(); }
FORCEINLINE float GetHealth() const { return Health.GetCurrentValue(); }
FORCEINLINE float GetMaxHealth() const { return MaxHealth.GetCurrentValue(); }
FORCEINLINE float GetMana() const { return Mana.GetCurrentValue(); }
@ -59,11 +104,35 @@ public:
#pragma region Setters
FORCEINLINE void
SetHealth( float NewVal );
SetStrength( float NewVal );
FORCEINLINE void SetIntelligence( float NewVal );
FORCEINLINE void SetResilience( float NewVal );
FORCEINLINE void SetVigor( float NewVal );
FORCEINLINE void SetHealth( float NewVal );
FORCEINLINE void SetMaxHealth( float NewVal );
FORCEINLINE void SetMana( float NewVal );
FORCEINLINE void SetMaxMana( float NewVal );
FORCEINLINE void InitStrength( float NewVal )
{
Strength.SetBaseValue( NewVal );
Strength.SetCurrentValue( NewVal );
}
FORCEINLINE void InitIntelligence( float NewVal )
{
Intelligence.SetBaseValue( NewVal );
Intelligence.SetCurrentValue( NewVal );
}
FORCEINLINE void InitResilience( float NewVal )
{
Resilience.SetBaseValue( NewVal );
Resilience.SetCurrentValue( NewVal );
}
FORCEINLINE void InitVigor( float NewVal )
{
Vigor.SetBaseValue( NewVal );
Vigor.SetCurrentValue( NewVal );
}
FORCEINLINE void InitHealth( float NewVal )
{
Health.SetBaseValue( NewVal );

View File

@ -6,6 +6,42 @@
#pragma region Attribute Setters
FORCEINLINE
void UGasaAttributeSet::SetStrength( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetStrengthAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetIntelligence( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetIntelligenceAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetResilience( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetResilienceAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetVigor( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetVigorAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();

View File

@ -64,6 +64,18 @@ AGasaCharacter::AGasaCharacter()
ACharacter::SetReplicateMovement(true);
}
#pragma region Ability System
void AGasaCharacter::InitDefaultAttributes()
{
UAbilitySystemComponent* ASC = GetAbilitySystemComponent();
ensure(ASC);
ensure(DefaultAttributes);
FGameplayEffectContextHandle Context = ASC->MakeEffectContext();
FGameplayEffectSpecHandle Spec = ASC->MakeOutgoingSpec(DefaultAttributes, 1.0f, Context );
ASC->ApplyGameplayEffectSpecToTarget( * Spec.Data, ASC );
}
#pragma endregion Ability System
#pragma region GameFramework
void AGasaCharacter::Controller_OnPawnPossessed()
{
@ -186,6 +198,8 @@ void AGasaCharacter::BeginPlay()
{
AbilitySystem->InitAbilityActorInfo(this, this);
Cast<UGasaAbilitySystemComp>(AbilitySystem)->OnAbilityActorInfoSet();
InitDefaultAttributes();
}
}
@ -233,3 +247,4 @@ void AGasaCharacter::Tick(float DeltaSeconds)
}
}
#pragma endregion Actor

View File

@ -34,6 +34,11 @@ public:
UPROPERTY(EditAnywhere, Category="Ability System")
TObjectPtr<UAttributeSet> Attributes;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Ability System")
TSubclassOf<UGameplayEffect> DefaultAttributes;
void InitDefaultAttributes();
#pragma endregion Ability System
#pragma region Combat