Newer
Older
SkyFrontier-Project-IADE-UE4-3D / Source / SkyFrontier / Public / HealthSystem.h
@Genexuz Genexuz on 2 Dec 2022 1 KB shield and health
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Components/ActorComponent.h"
  5. #include "HealthSystem.generated.h"
  6. DECLARE_EVENT_OneParam(UCPP_HealthComponent, DamageTakenEvent, float )
  7. DECLARE_EVENT_OneParam(UCPP_HealthComponent, HealDamageEvent, float )
  8. DECLARE_EVENT_OneParam(UCPP_HealthComponent, ShieldReceiveEvent, float )
  9. UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
  10. class SKYFRONTIER_API UHealthSystem : public UActorComponent
  11. {
  12. GENERATED_BODY()
  13. public:
  14. // Sets default values for this component's properties
  15. UHealthSystem();
  16. UFUNCTION(BlueprintPure)
  17. float GetHealth() const;
  18. UFUNCTION(BlueprintPure)
  19. float GetMaxHealth() const;
  20. UFUNCTION(BlueprintPure)
  21. float GetHealthAsPercentage() const;
  22. UFUNCTION(BlueprintPure)
  23. float GetShield() const;
  24. UFUNCTION(BlueprintCallable)
  25. void ModifyHealth(float Amount);
  26. UFUNCTION(BlueprintCallable)
  27. void TakeDamage(float Amount);
  28. UFUNCTION(BlueprintCallable)
  29. void RecoverHealth(float Amount);
  30. UFUNCTION(BlueprintCallable)
  31. void ReceiveShield(float Amount);
  32. UFUNCTION(BlueprintCallable)
  33. void RemoveShield(float Amount);
  34. protected: // Functions
  35. virtual void BeginPlay() override;
  36. public: // Events
  37. DamageTakenEvent OnDamageTakenEvent;
  38. HealDamageEvent OnDamageHealedEvent;
  39. ShieldReceiveEvent OnShieldReceiveEvent;
  40. private: // This can be protected if we want to subclass the Health Component
  41. UPROPERTY(VisibleAnywhere)
  42. float Health;
  43. UPROPERTY(EditAnywhere)
  44. float MaxHealth;
  45. UPROPERTY(VisibleAnywhere)
  46. float Shield;
  47. };