Update HealthComponent Functionality
This commit is contained in:
		
							parent
							
								
									7a7f158816
								
							
						
					
					
						commit
						e06e724c0c
					
				| @ -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) | 	CurrentHealth -= damage; | ||||||
| { |  | ||||||
| 	value *= !CanDamage; |  | ||||||
| 
 | 
 | ||||||
| 	CurrentHealth -= value; | 	OnDamaged.ExecuteIfBound({ damagedActor, damage, damageType, instigatedBy, damageCauser }); | ||||||
| 
 | 
 | ||||||
| 	if (CurrentHealth <= 0.0f) | 	if (CurrentHealth <= 0.0f) | ||||||
| 	{ | 	{ | ||||||
| 		// TODO: Call some death logic here
 | 		IsDead = true; | ||||||
| 		OnDeath.ExecuteIfBound(); | 		OnDeath.ExecuteIfBound({ damagedActor, damage, damageType, instigatedBy, damageCauser }); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -102,7 +103,7 @@ void UHealthComponent::BeginPlay() | |||||||
| { | { | ||||||
| 	Super::BeginPlay(); | 	Super::BeginPlay(); | ||||||
| 
 | 
 | ||||||
| 	// ...
 | 	ResetHealth(); | ||||||
| 	 | 	 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -6,7 +6,29 @@ | |||||||
| #include "Components/ActorComponent.h" | #include "Components/ActorComponent.h" | ||||||
| #include "HealthComponent.generated.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) ) | UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) | ||||||
| class NAKATOMI_API UHealthComponent : public UActorComponent | class NAKATOMI_API UHealthComponent : public UActorComponent | ||||||
| @ -15,6 +37,7 @@ class NAKATOMI_API UHealthComponent : public UActorComponent | |||||||
| 
 | 
 | ||||||
| public:	 | public:	 | ||||||
| 	 | 	 | ||||||
|  | 	FOnDamageDelegate OnDamaged; | ||||||
| 	FOnDeathDelegate OnDeath; | 	FOnDeathDelegate OnDeath; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| @ -27,7 +50,7 @@ private: | |||||||
| 
 | 
 | ||||||
| 	bool IsDead = false; | 	bool IsDead = false; | ||||||
| 
 | 
 | ||||||
| 	bool CanDamage; | 	bool CanDamage = true; | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
| @ -35,10 +58,7 @@ public: | |||||||
| 	UHealthComponent(); | 	UHealthComponent(); | ||||||
| 
 | 
 | ||||||
| 	UFUNCTION() | 	UFUNCTION() | ||||||
| 	void TakeDamage(); | 	void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser); | ||||||
| 	 |  | ||||||
| 	UFUNCTION() |  | ||||||
| 	void DecrementHealth(float value); |  | ||||||
| 
 | 
 | ||||||
| 	UFUNCTION() | 	UFUNCTION() | ||||||
| 	void IncrementHealth(float value); | 	void IncrementHealth(float value); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user