|
|
|
|
| #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);
|
|
|
| |
| |
| |
| |
|
|
| UENUM(BlueprintType)
|
| enum class ELyraDeathState : uint8
|
| {
|
| NotDead = 0,
|
| DeathStarted,
|
| DeathFinished
|
| };
|
|
|
|
|
| |
| |
| |
| |
|
|
| UCLASS(MinimalAPI, Blueprintable, Meta=(BlueprintSpawnableComponent))
|
| class ULyraHealthComponent : public UGameFrameworkComponent
|
| {
|
| GENERATED_BODY()
|
|
|
| public:
|
|
|
| UE_API ULyraHealthComponent(const FObjectInitializer& ObjectInitializer);
|
|
|
|
|
| UFUNCTION(BlueprintPure, Category = "Lyra|Health")
|
| static ULyraHealthComponent* FindHealthComponent(const AActor* Actor) { return (Actor ? Actor->FindComponentByClass<ULyraHealthComponent>() : nullptr); }
|
|
|
|
|
| UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
|
| UE_API void InitializeWithAbilitySystem(ULyraAbilitySystemComponent* InASC);
|
|
|
|
|
| UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
|
| UE_API void UninitializeFromAbilitySystem();
|
|
|
|
|
| UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
|
| UE_API float GetHealth() const;
|
|
|
|
|
| UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
|
| UE_API float GetMaxHealth() const;
|
|
|
|
|
| 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); }
|
|
|
|
|
| UE_API virtual void StartDeath();
|
|
|
|
|
| UE_API virtual void FinishDeath();
|
|
|
|
|
| UE_API virtual void DamageSelfDestruct(bool bFellOutOfWorld = false);
|
|
|
| public:
|
|
|
|
|
| UPROPERTY(BlueprintAssignable)
|
| FLyraHealth_AttributeChanged OnHealthChanged;
|
|
|
|
|
| UPROPERTY(BlueprintAssignable)
|
| FLyraHealth_AttributeChanged OnMaxHealthChanged;
|
|
|
|
|
| UPROPERTY(BlueprintAssignable)
|
| FLyraHealth_DeathEvent OnDeathStarted;
|
|
|
|
|
| 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:
|
|
|
|
|
| UPROPERTY()
|
| TObjectPtr<ULyraAbilitySystemComponent> AbilitySystemComponent;
|
|
|
|
|
| UPROPERTY()
|
| TObjectPtr<const ULyraHealthSet> HealthSet;
|
|
|
|
|
| UPROPERTY(ReplicatedUsing = OnRep_DeathState)
|
| ELyraDeathState DeathState;
|
| };
|
|
|
| #undef UE_API
|
|
|