-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLyraHealthComponent.h
More file actions
139 lines (100 loc) · 4.15 KB
/
LyraHealthComponent.h
File metadata and controls
139 lines (100 loc) · 4.15 KB
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
137
138
139
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Components/GameFrameworkComponent.h"
#include "LyraHealthComponent.generated.h"
class ULyraHealthComponent;
class ULyraAbilitySystemComponent;
class ULyraHealthSet;
class UObject;
struct FFrame;
struct FGameplayEffectSpec;
struct FOnAttributeChangeData;
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(Blueprintable, Meta=(BlueprintSpawnableComponent))
class LYRAGAME_API ULyraHealthComponent : public UGameFrameworkComponent
{
GENERATED_BODY()
public:
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")
void InitializeWithAbilitySystem(ULyraAbilitySystemComponent* InASC);
// Uninitialize the component, clearing any references to the ability system.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
void UninitializeFromAbilitySystem();
// Returns the current health value.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
float GetHealth() const;
// Returns the current maximum health value.
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
float GetMaxHealth() const;
// Returns the current health in the range [0.0, 1.0].
UFUNCTION(BlueprintCallable, Category = "Lyra|Health")
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.
virtual void StartDeath();
// Ends the death sequence for the owner.
virtual void FinishDeath();
// Applies enough damage to kill the owner.
virtual void DamageSelfDestruct(bool bFellOutOfWorld = false);
// @TangoAlphaDev
// Fall damage function
virtual void ApplyFallDamage(float Velocity, int VelocityLimit, float FallDamageMultiplier);
// @TangoAlphaDev
public:
// Delegate fired when the health value has changed.
UPROPERTY(BlueprintAssignable)
FLyraHealth_AttributeChanged OnHealthChanged;
// Delegate fired when the max health value has changed.
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:
virtual void OnUnregister() override;
void ClearGameplayTags();
virtual void HandleHealthChanged(const FOnAttributeChangeData& ChangeData);
virtual void HandleMaxHealthChanged(const FOnAttributeChangeData& ChangeData);
virtual void HandleOutOfHealth(AActor* DamageInstigator, AActor* DamageCauser, const FGameplayEffectSpec& DamageEffectSpec, float DamageMagnitude);
UFUNCTION()
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;
};