Update HealthComponent Functionality

This commit is contained in:
Louis Hobbs 2023-02-03 01:30:24 +00:00
parent 7a7f158816
commit e06e724c0c
2 changed files with 36 additions and 15 deletions

View File

@ -13,20 +13,21 @@ UHealthComponent::UHealthComponent()
// ...
}
void UHealthComponent::TakeDamage()
void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser)
{
if (damagedActor == nullptr || IsDead || !CanDamage)
{
return;
}
void UHealthComponent::DecrementHealth(float value)
{
value *= !CanDamage;
CurrentHealth -= damage;
CurrentHealth -= value;
OnDamaged.ExecuteIfBound({ damagedActor, damage, damageType, instigatedBy, damageCauser });
if (CurrentHealth <= 0.0f)
{
// TODO: Call some death logic here
OnDeath.ExecuteIfBound();
IsDead = true;
OnDeath.ExecuteIfBound({ damagedActor, damage, damageType, instigatedBy, damageCauser });
}
}
@ -102,7 +103,7 @@ void UHealthComponent::BeginPlay()
{
Super::BeginPlay();
// ...
ResetHealth();
}

View File

@ -6,7 +6,29 @@
#include "Components/ActorComponent.h"
#include "HealthComponent.generated.h"
DECLARE_DELEGATE(FOnDeathDelegate)
USTRUCT()
struct FDamageInfo
{
GENERATED_BODY()
UPROPERTY()
AActor* DamagedActor;
UPROPERTY()
float Damage;
UPROPERTY()
const class UDamageType* DamageType;
UPROPERTY()
class AController* InstigatedBy;
UPROPERTY()
AActor* DamageCauser;
};
DECLARE_DELEGATE_OneParam(FOnDamageDelegate, FDamageInfo)
DECLARE_DELEGATE_OneParam(FOnDeathDelegate, FDamageInfo)
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class NAKATOMI_API UHealthComponent : public UActorComponent
@ -15,6 +37,7 @@ class NAKATOMI_API UHealthComponent : public UActorComponent
public:
FOnDamageDelegate OnDamaged;
FOnDeathDelegate OnDeath;
private:
@ -27,7 +50,7 @@ private:
bool IsDead = false;
bool CanDamage;
bool CanDamage = true;
public:
@ -35,10 +58,7 @@ public:
UHealthComponent();
UFUNCTION()
void TakeDamage();
UFUNCTION()
void DecrementHealth(float value);
void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser);
UFUNCTION()
void IncrementHealth(float value);