// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Components/ActorComponent.h" #include "MHealthComponent.generated.h" class UMHealthComponent; DECLARE_DYNAMIC_MULTICAST_DELEGATE_SixParams(FOnHealthChangedSignature, UMHealthComponent*, HealthComp, float, Health, float, HealthDelta, const class UDamageType*, DamageType, class AController*, InstigatedBy, AActor*, DamageCauser); DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnActorDeath, UMHealthComponent*, HealthComponent, AActor*, DeadActor, AActor*, KillerActor); UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) class MECHDEFENCE_API UMHealthComponent : public UActorComponent { GENERATED_BODY() public: UMHealthComponent(); protected: virtual void BeginPlay() override; bool bIsDead; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "HealthComponent") float Health; UPROPERTY(EditDefaultsOnly, Category = "HealthComponent", meta = (ClampMin = 0.f)) float DefaultHealth; UFUNCTION() void HandleTakeAnyDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser); public: UFUNCTION(BlueprintCallable) float GetHealth() const { return Health; } UFUNCTION(BlueprintCallable) float GetHealthRemappedInRange(float Min = 0.f, float Max = 1.f); UFUNCTION(BlueprintCallable) float GetDefaultHealth() const { return DefaultHealth; } UFUNCTION(BlueprintCallable) bool IsAtMaxHealth() const { return Health == DefaultHealth; } UFUNCTION(BlueprintCallable) bool IsDead() const { return bIsDead; }; UPROPERTY(BlueprintAssignable, Category = "Events") FOnHealthChangedSignature OnHealthChanged; UPROPERTY(BlueprintAssignable, Category = "Events") FOnActorDeath OnActorDeath; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HealthComponent") bool bIsInvincible; UFUNCTION(BlueprintCallable, Category = "HealthComponent") void Heal(float HealAmount); };