File size: 4,716 Bytes
1e67697 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | // Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Components/GameFrameworkComponent.h"
#include "LyraHealthComponent.generated.h"
#define UE_API LYRAGAME_API
class ULyraHealthComponent;
class ULyraAbilitySystemComponent;
class ULyraHealthSet;
class UObject;
struct FFrame;
struct FGameplayEffectSpec;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLyraHealth_DeathEvent, AActor*, OwningActor);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FLyraHealth_AttributeChanged, ULyraHealthComponent*, HealthComponent, float, OldValue, float, NewValue, AActor*, Instigator);
/**
* ELyraDeathState
*
* Defines current state of death.
*/
UENUM(BlueprintType)
enum class ELyraDeathState : uint8
{
NotDead = 0,
DeathStarted,
DeathFinished
};
/**
* ULyraHealthComponent
*
* An actor component used to handle anything related to health.
*/
UCLASS(MinimalAPI, Blueprintable, Meta=(BlueprintSpawnableComponent))
class ULyraHealthComponent : public UGameFrameworkComponent
{
GENERATED_BODY()
public:
UE_API ULyraHealthComponent(const FObjectInitializer& ObjectInitializer);
// Returns the health component if one exists on the specified actor.
UFUNCTION(BlueprintPure, Category = "Lyra|Health")
static ULyraHealthComponent* FindHealthComponent(const AActor* Actor) { return (Actor ? Actor->FindComponentByClass<ULyraHealthComponent>() : nullptr); }
// Initialize the component using an ability system component.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
UE_API void InitializeWithAbilitySystem(ULyraAbilitySystemComponent* InASC);
// Uninitialize the component, clearing any references to the ability system.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
UE_API void UninitializeFromAbilitySystem();
// Returns the current health value.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
UE_API float GetHealth() const;
// Returns the current maximum health value.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
UE_API float GetMaxHealth() const;
// Returns the current health in the range [0.0, 1.0].
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
UE_API float GetHealthNormalized() const;
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
ELyraDeathState GetDeathState() const { return DeathState; }
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "Lyra|Health", Meta = (ExpandBoolAsExecs = "ReturnValue"))
bool IsDeadOrDying() const { return (DeathState > ELyraDeathState::NotDead); }
// Begins the death sequence for the owner.
UE_API virtual void StartDeath();
// Ends the death sequence for the owner.
UE_API virtual void FinishDeath();
// Applies enough damage to kill the owner.
UE_API virtual void DamageSelfDestruct(bool bFellOutOfWorld = false);
public:
// Delegate fired when the health value has changed. This is called on the client but the instigator may not be valid
UPROPERTY(BlueprintAssignable)
FLyraHealth_AttributeChanged OnHealthChanged;
// Delegate fired when the max health value has changed. This is called on the client but the instigator may not be valid
UPROPERTY(BlueprintAssignable)
FLyraHealth_AttributeChanged OnMaxHealthChanged;
// Delegate fired when the death sequence has started.
UPROPERTY(BlueprintAssignable)
FLyraHealth_DeathEvent OnDeathStarted;
// Delegate fired when the death sequence has finished.
UPROPERTY(BlueprintAssignable)
FLyraHealth_DeathEvent OnDeathFinished;
protected:
UE_API virtual void OnUnregister() override;
UE_API void ClearGameplayTags();
UE_API virtual void HandleHealthChanged(AActor* DamageInstigator, AActor* DamageCauser, const FGameplayEffectSpec* DamageEffectSpec, float DamageMagnitude, float OldValue, float NewValue);
UE_API virtual void HandleMaxHealthChanged(AActor* DamageInstigator, AActor* DamageCauser, const FGameplayEffectSpec* DamageEffectSpec, float DamageMagnitude, float OldValue, float NewValue);
UE_API virtual void HandleOutOfHealth(AActor* DamageInstigator, AActor* DamageCauser, const FGameplayEffectSpec* DamageEffectSpec, float DamageMagnitude, float OldValue, float NewValue);
UFUNCTION()
UE_API virtual void OnRep_DeathState(ELyraDeathState OldDeathState);
protected:
// Ability system used by this component.
UPROPERTY()
TObjectPtr<ULyraAbilitySystemComponent> AbilitySystemComponent;
// Health set used by this component.
UPROPERTY()
TObjectPtr<const ULyraHealthSet> HealthSet;
// Replicated state used to handle dying.
UPROPERTY(ReplicatedUsing = OnRep_DeathState)
ELyraDeathState DeathState;
};
#undef UE_API
|