Resource.cpp :
#include "BacASable.h"
#include "Resource.h"
UResource::UResource()
{
ValueMax = 100;
Regeneration = 1;
ValueInit = 100;
}
void UResource::PostInitProperties()
{
Super::PostInitProperties();
ValueInit = FMath::Clamp(ValueInit, 0.0f, ValueMax);
ActualValue = ValueInit;
}
void UResource::Tick(float DeltaTime)
{
Add(DeltaTime * Regeneration);
}
bool UResource::IsTickable() const
{
return true;
}
TStatId UResource::GetStatId() const
{
return Super::GetStatID();
}
void UResource::Add(float Value)
{
ActualValue = FMath::Clamp(ActualValue + Value, 0.0f, ValueMax);
}
bool UResource::IsEmpty() const
{
return (ActualValue == 0);
}
bool UResource::IsFull() const
{
return (ActualValue == ValueMax);
}
void UResource::ResetValueMax(float NewMax)
{
if (ValueInit == ValueMax) {
ValueInit = NewMax;
}
ValueMax = NewMax;
ActualValue = ValueInit;
}
void UResource::MakeAsCooldown(float NewMax)
{
if (NewMax != 0.0f)
{
ValueMax = NewMax;
}
ValueInit = 0;
ActualValue = 0;
Regeneration = -1;
}
Edit - I marked the topic as unresolved for this issue (I don’t know if it’s accepted)