Newer
Older
SkyFrontier-Project-IADE-UE4-3D / Source / SkyFrontier / Private / HealthSystem.cpp
@Genexuz Genexuz on 2 Dec 2022 1 KB Revert "Delete HealthSystem.cpp"
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. #include "HealthSystem.h"
  3. UHealthSystem::UHealthSystem()
  4. {
  5. // This is a component that doesn't need a tick so lets disable it
  6. PrimaryComponentTick.bCanEverTick = false;
  7. PrimaryComponentTick.bStartWithTickEnabled = false;
  8. }
  9. void UHealthSystem::BeginPlay()
  10. {
  11. Super::BeginPlay();
  12. // This is here for now, but if you ever do anything serialization related you might not want this.
  13. Health = MaxHealth;
  14. }
  15. float UHealthSystem::GetHealth() const
  16. {
  17. return Health;
  18. }
  19. float UHealthSystem::GetMaxHealth() const
  20. {
  21. return MaxHealth;
  22. }
  23. float UHealthSystem::GetHealthAsPercentage() const
  24. {
  25. return Health / MaxHealth;
  26. }
  27. void UHealthSystem::ModifyHealth(const float Amount)
  28. {
  29. if(Amount == 0)
  30. return;
  31. Health += Amount;
  32. Amount > 0 ? OnDamageHealedEvent.Broadcast(Amount) : OnDamageTakenEvent.Broadcast(Amount);
  33. }
  34. void UHealthSystem::TakeDamage(const float Amount)
  35. {
  36. if(Amount > 0)
  37. {
  38. Health -= Amount;
  39. OnDamageTakenEvent.Broadcast(Amount);
  40. }
  41. }
  42. void UHealthSystem::RecoverHealth(const float Amount)
  43. {
  44. if(Amount > 0)
  45. {
  46. Health += Amount;
  47. OnDamageHealedEvent.Broadcast(Amount);
  48. }
  49. }