64. Properly Clamping Attributes

This commit is contained in:
2024-10-19 22:34:51 -04:00
parent 3a3f0c0271
commit 067c2f03c5
3 changed files with 62 additions and 21 deletions

View File

@ -6,6 +6,7 @@
#include "AbilitySystemComponent.h"
#include "Net/UnrealNetwork.h"
#include "Networking/GasaNetLibrary.h"
#include "GameplayEffectExtension.h"
UGasaAttributeSet::UGasaAttributeSet()
{
@ -47,6 +48,23 @@ void UGasaAttributeSet::PostGameplayEffectExecute( FGameplayEffectModCallbackDat
Super::PostGameplayEffectExecute( Data );
FEffectProperties Props;
Props.Populate( Data );
if ( Data.EvaluatedData.Attribute == GetHealthAttribute() )
{
SetHealth( FMath::Clamp( GetHealth(), 0, GetMaxHealth() ) );
}
if ( Data.EvaluatedData.Attribute == GetMaxHealthAttribute() )
{
SetMaxHealth( FMath::Clamp( GetMaxHealth(), 0, 99999.000000 ) );
}
if ( Data.EvaluatedData.Attribute == GetManaAttribute() )
{
SetMana( FMath::Clamp( GetMana(), 0, GetMaxMana() ) );
}
if ( Data.EvaluatedData.Attribute == GetMaxManaAttribute() )
{
SetMaxMana( FMath::Clamp( GetMaxMana(), 0, 99999.000000 ) );
}
}
void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute, float& NewValue )

View File

@ -109,12 +109,12 @@ void UGlobeProgressBar::SetPercentage(float CurrentValue, float MaxValue)
UWorld* World = GetWorld();
FTimerManager& TM = World->GetTimerManager();
if ( CurrentValueClamped < PreviousValue )
if ( CurrentValueClamped <= PreviousValue )
{
// Timer will auto-clear previous set delay
TM.SetTimer( GhostPercentChangeTimer, this, & UGlobeProgressBar::GhostPercentUpdateViaTimer, GhostPercentChangeDelay );
}
else
else if ( Bar->GetPercent() >= GhostBar->GetPercent() )
{
if ( TM.TimerExists( GhostPercentChangeTimer ))
TM.ClearTimer( GhostPercentChangeTimer );
@ -179,7 +179,7 @@ void UGlobeProgressBar::NativeTick(const FGeometry& MyGeometry, float InDeltaTim
FTimerManager& TM = World->GetTimerManager();
// Ghost Percent Interpolation
if ( ! TM.TimerExists( GhostPercentChangeTimer ))
if ( ! TM.TimerExists( GhostPercentChangeTimer ) )
{
float NextPercent = FMath::FInterpTo( GhostBar->GetPercent(), GhostTargetPercent, InDeltaTime, GhostPercentInterpolationSpeed );
GhostBar->SetPercent( NextPercent );