Files
Cog/Source/CogSample/CogSampleFunctionLibrary_Gameplay.cpp
T
Arnaud Jamin 1aabdb5c4e First Submit
2023-10-02 01:32:41 -04:00

24 lines
1004 B
C++

#include "CogSampleFunctionLibrary_Gameplay.h"
#include "AbilitySystemComponent.h"
#include "GameplayEffectTypes.h"
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleFunctionLibrary_Gameplay::AdjustAttributeForMaxChange(UAbilitySystemComponent* AbilityComponent, FGameplayAttributeData& AffectedAttribute, float OldValue, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty)
{
if (AbilityComponent == nullptr)
{
return;
}
if (FMath::IsNearlyEqual(OldValue, NewMaxValue))
{
return;
}
// Change current value to maintain the current Val / Max percent
const float CurrentValue = AffectedAttribute.GetCurrentValue();
const float NewDelta = (OldValue > 0.f) ? (CurrentValue * NewMaxValue / OldValue) - CurrentValue : NewMaxValue;
AbilityComponent->ApplyModToAttributeUnsafe(AffectedAttributeProperty, EGameplayModOp::Additive, NewDelta);
}