Extra checks in SetCurrentHealth
This commit is contained in:
parent
49fab1bf38
commit
d93127a74e
@ -59,12 +59,26 @@ float UHealthComponent::GetCurrentHealth()
|
||||
|
||||
void UHealthComponent::SetCurrentHealth(float Value)
|
||||
{
|
||||
CurrentHealth = Value;
|
||||
|
||||
if (CurrentHealth > MaxHealth)
|
||||
if (Value > MaxHealth)
|
||||
{
|
||||
CurrentHealth = MaxHealth;
|
||||
}
|
||||
else if (Value <= 0.0f)
|
||||
{
|
||||
IsDead = true;
|
||||
OnDeath.Broadcast({GetOwner(), CurrentHealth - Value, nullptr, nullptr, nullptr});
|
||||
CurrentHealth = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Value < CurrentHealth)
|
||||
{
|
||||
OnDamaged.Broadcast({GetOwner(), CurrentHealth - Value, nullptr, nullptr, nullptr});
|
||||
}
|
||||
|
||||
CurrentHealth = Value;
|
||||
}
|
||||
}
|
||||
|
||||
void UHealthComponent::ResetHealth()
|
||||
@ -75,8 +89,10 @@ void UHealthComponent::ResetHealth()
|
||||
|
||||
void UHealthComponent::RecoverHealth(float value)
|
||||
{
|
||||
// TODO: We might want to add some extra checking here
|
||||
IncrementHealth(value);
|
||||
if (value > 0)
|
||||
{
|
||||
IncrementHealth(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool UHealthComponent::GetIsDead()
|
||||
|
@ -47,6 +47,7 @@ protected:
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
float CurrentHealth;
|
||||
|
||||
private:
|
||||
bool IsDead = false;
|
||||
|
||||
bool CanDamage = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user