Space Plunder
Loading...
Searching...
No Matches
CharacterHealthComponent.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "NiagaraComponent.h"
8#include "Data/HealthData.h"
9#include "CharacterHealthComponent.generated.h"
10
11DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnCharacterDeathEvent, AActor*, OwningActor, EDeathType, DeathType, AActor*, DeathCauser, AController*, DeathInstigator);
12
13// On Shield Break sets off blueprint event
15DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnNonLethalKnockOut, const class UDamageType* ,DamageType, const float, WaitTime);
17// DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnCriticalHit, float, TotalDamage, const class UDamageType*, DamageType, bool, bKillingHit, bool, bInjuredPart);
18
19DECLARE_DYNAMIC_MULTICAST_DELEGATE_SevenParams(FOnDamageHit, AController*, InstigatedBy, const float, TotalDamage, const class UDamageType*, DamageType, const FName&, HitBone, const FVector&, HitLocation, const bool, bKillingHit, const bool, bInjuredPart);
20DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams(FOnHitReaction, const float, Damage, const FVector&, HitLocation, const FName&, BoneName, const FVector&, ShotFromDirection, const UDamageType*, DamageType);
21DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnInjuredBodyPart, const EBodyPartName, InjuredBodyPart, const FVector&, HitLocation, const TArray<FBodyPart>&, AllBodyParts);
22DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams(FOnHealthAndShieldChanged,const float, Health, const float, MaxHealth, const float, ShieldHealth, const float, MaxShieldHealth, const class UDamageType*, DamageType);
23
24
25UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent) )
26class HEALTH_API UCharacterHealthComponent : public UCharacterComponent
27{
28 GENERATED_BODY()
29
30public:
31 UCharacterHealthComponent();
32
33 //- Use this if the Character has a shield //
34 UPROPERTY(BlueprintAssignable, Category = "Health")
35 FOnHealthAndShieldChanged OnHealthAndShieldChanged;
36 UPROPERTY(BlueprintAssignable, Category = "Health")
37 FOnCharacterDeathEvent OnDeath;
38 UPROPERTY(BlueprintAssignable, Category = "Health")
39 FOnInjuredBodyPart OnInjuredBodyPart;
40 UPROPERTY(BlueprintAssignable, Category = "Health")
41 FOnShieldBreak OnShieldBreak;
42 UPROPERTY(BlueprintAssignable, Category = "Health")
43 FOnNonLethalKnockOut OnNonLethalKnockOut;
44 UPROPERTY(BlueprintAssignable, Category = "Health")
45 FOnWakeUp OnWakeUp;
46 //- The total Amount of Damage done After Calculations, use for Hit markers etc. //
47 UPROPERTY(BlueprintAssignable, Category = "Health")
48 FOnDamageHit OnDamageHit;
49 UPROPERTY(BlueprintAssignable, Category = "Health")
50 FOnHitReaction OnHitReaction;
51
52
53
54 //- Save / Load //
55 virtual bool LoadComponentData(const FString& SlotName) override;
56 virtual bool SaveComponentData(const FString& SlotName) override;
57
58 virtual void SetupComponentWidgets() override;
59 virtual void SetupComponent(USkeletalMeshComponent* SkeletalMesh, UAnimInstance* AnimationInstance, AController* Controller, AActor* HUDReference, const bool bNPC, const bool bDead) override;
60
61 //- Getters/Setters //
62 UFUNCTION(BlueprintCallable, Category = "Health")
63 FORCEINLINE float GetHealth() const { return Health;}
64 UFUNCTION(BlueprintCallable, Category= "Health")
65 FORCEINLINE float GetMaxHealth() const { return MaxHealth;};
66 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Health")
67 FORCEINLINE float GetShieldHealth() const { return ShieldHealth;}
68 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Health")
69 FORCEINLINE float GetMaxShieldHealth() const { return MaxShieldHealth;}
70 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Health")
71 FORCEINLINE TArray<FBodyPart> GetBodyParts() const { return BodyParts;}
72 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Health")
73 FORCEINLINE bool GetIsKnockedOut() const { return bIsKnockedOut;}
74
75 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Health")
76 TArray<FBodyPart> GetInjuredBodyParts() const;
77 //- Returns true if new Injured Body part //
78 UFUNCTION(BlueprintCallable, Category = "Health")
79 bool LimbDamage(const float Damage, const FName& HitBone, const UDamageType* DamageType, const FVector& HitLocation);
80
81 UFUNCTION(BlueprintCallable, Category="Health|KO")
82 void ForceWakeUp();
83
84 UFUNCTION()
85 void ShieldRegen();
86 UFUNCTION(BlueprintCallable)
87 void UpdateShieldAndHealth(const UDamageType* DamageType = nullptr);
88
89 //- Body Parts //
90 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "!bALSSkeleton && !bUnrealSkeleton && !bUseCustomBones"))
91 bool bSyntySkeleton;
92 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "!bSyntySkeleton && !bUnrealSkeleton && !bUseCustomBones"))
93 bool bALSSkeleton;
94 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "!bALSSkeleton && !bSyntySkeleton && !bUseCustomBones"))
95 bool bUnrealSkeleton;
96 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "!bALSSkeleton && !bSyntySkeleton && !bUnrealSkeleton"))
97 bool bUseCustomBones;
98 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
99 TArray<FName> HeadBones;
100 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
101 TArray<FName> SpineBones;
102 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
103 TArray<FName> RightArmBones;
104 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
105 TArray<FName> LeftArmBones;
106 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
107 TArray<FName> RightLegBones;
108 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
109 TArray<FName> LeftLegBones;
110 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
111 TArray<FName> RightHandBones;
112 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs", meta = (EditCondition = "bUseCustomBones"))
113 TArray<FName> LeftHandBones;
114 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs")
115 float BodyPartMaxHealth = 50.0f;
116 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Limbs")
117 float BodyPartInjuredHealthLevel = 25.0f;
118 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|KO")
119 bool bCanBeKnockedOut = false;
120
121 UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite, Category = "Health|Shield")
122 bool bHasShield = false;
123protected:
124 virtual void BeginPlay() override;
125 virtual void ComponentSetupComplete() override;
126
127 UFUNCTION()
128 virtual void TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatedBy, AActor* DamageCauser);
129 UFUNCTION()
130 virtual void TakePointDamage(AActor* DamagedActor, float Damage, class AController* InstigatedBy, FVector HitLocation, class UPrimitiveComponent* FHitComponent, FName BoneName, FVector ShotFromDirection, const class UDamageType* DamageType, AActor* DamageCauser);
131 UFUNCTION()
132 virtual void TakeRadialDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, FVector Origin, const FHitResult& HitInfo, class AController* InstigatedBy, AActor* DamageCauser);
133
134 virtual void Death(AActor* Causer, AController* DeathInstigator, const UDamageType* DamageType);
135 UFUNCTION()
136 void OnDeathReplicated();
137 UFUNCTION()
138 void OnRep_Shield();
139 UFUNCTION()
140 void OnRep_Health();
141
142 UFUNCTION(BlueprintCallable, Category="Health|KO")
143 void KnockedOutSleep();
144
145 //- Effects //
146 UFUNCTION(BlueprintCallable, Category="Heath|Effects")
147 void ImpactEffects(const EBodyPartName BodyPartName, const FVector& HitLocation, const bool bIsNonLethal = false, const FVector& ShotFromDirection = FVector::ZeroVector, const float Damage = 10.0f);
148 UFUNCTION(NetMulticast, Unreliable, BlueprintCallable, Category="Heath|Effects")
149 void MulticastImpactEffects(const EBodyPartName BodyPartName, const FVector& HitLocation, const bool bIsNonLethal, const FVector& ShotFromDirection, const float Damage);
150
151 UFUNCTION(BlueprintCallable, Category="Heath|Effects")
152 void BleedingEffects(const EBodyPartName BodyPartName, const FVector& HitLocation);
153 UFUNCTION(NetMulticast, Unreliable, BlueprintCallable, Category="Heath|Effects")
154 void MulticastBleedingEffects(const EBodyPartName BodyPartName, const FVector& HitLocation);
155
156 UPROPERTY(ReplicatedUsing=OnRep_Health)
157 float Health;
158 UPROPERTY(ReplicatedUsing=OnRep_Health, EditAnywhere, BlueprintReadWrite, Category = "Health|General")
159 float MaxHealth = 100.0f;
160
161 // UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Health|HUD")
162 // class UUserWidget* HealthHUDWidget = nullptr;
163 class IHealthInterface* HealthHUDWidget = nullptr;
164
165 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Shield")
166 const UDamageType* ShieldDamageType;
167 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Shield")
168 bool bShieldBroken = false;
169 UPROPERTY(ReplicatedUsing=OnRep_Shield, EditAnywhere, BlueprintReadWrite, Category = "Health|Shield", meta = (EditCondition = "bHasShield"))
170 float MaxShieldHealth = 100.0f;
171 //- Initial Delay for the regen time
172 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Shield", meta = (EditCondition = "bHasShield"))
173 float ShieldTimeToRegen = 5.0f;
174 //- How fast it goes up while recharging
175 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Shield", meta = (EditCondition = "bHasShield"))
176 float AmountToRecharge = 0.1f;
177
178 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Traits")
179 float EnduranceMaxHealthMultiplier = 2.0f;
180
181 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Health|KO")
182 bool bIsKnockedOut = false;
183 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Health|KO")
184 float KnockOutHealth = 50.0f;
185 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Health|KO")
186 float KnockOutTimeToWakeUp = 0.0f;
187 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|KO")
188 float KnockOutTimeToWakeUpDefault = 20.0f;
189 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Health|KO")
190 float KnockOutMaxHealth = 50.0f;
191
192 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Health|Damage Multiplier")
193 float HeadDamageMultiplier = 2.5f;
194 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Health|Damage Multiplier")
195 float SpineDamageMultiplier = 1.5f;
196 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Health|Damage Multiplier")
197 float ArmDamageMultiplier = 1.0f;
198 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Health|Damage Multiplier")
199 float HandDamageMultiplier = 0.5f;
200 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Health|Damage Multiplier")
201 float LegDamageMultiplier = 0.8f;
202
203 //- Shield += Level * Base
204 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Traits")
205 float IntelligenceMaxShieldMultiplierBase = 10.0f;
206 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Traits")
207 float EnduranceMaxKnockedOutHealthMultiplier = 5.0f;
208 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Traits")
209 float LuckMultiplier = 2.0f;
210
211
212 //- Particle Systems //
213 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Health|Effects")
214 class UNiagaraSystem* BloodImpact;
215 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Health|Effects")
216 class UNiagaraSystem* DamageShieldImpact;
217 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Health|Effects")
218 class UNiagaraSystem* DamageNonLethalImpact;
219 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Health|Effects")
220 class UNiagaraSystem* BleedingParticles;
221 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Health|Effects")
222 TArray<UNiagaraComponent* > BleedingSystems;
223
224 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Effects")
225 float BloodSpamWaitTime = 0.5f;
226 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Effects")
227 int32 BloodAmountMultiplier = 3;
228 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Effects")
229 int32 BloodAmountMin = 5;
230 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Effects")
231 int32 BloodAmountMax = 250;
232
233 UPROPERTY(ReplicatedUsing=OnDeathReplicated)
234 bool bDeathOnce = false;
235
236 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Debugging", meta=(EditCondition="bCheatsEnabled"))
237 bool bInfiniteHealth = false;
238 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Health|Debugging", meta=(EditCondition="bCheatsEnabled"))
239 bool bInfiniteShield = false;
240
241
242private:
243 UFUNCTION(BlueprintCallable, Category = "Health")
244 void LoadHealthAndShieldFromSave(const float LoadedHealth, const float LoadedShield, const TArray<FBodyPart>& LoadedBodyParts);
245
246 void InjuredBodyPart(const EBodyPartName BodyPart, const FVector& HitLocation);
247
248 void SetupSyntySkeleton();
249 void SetupALSSkeleton();
250 void SetupCustomSkeleton();
251
252 void SetupLimbs();
253 virtual void HealthDamage(const float Damage);
254 void ShieldDamage(const float Damage);
255 void NonLethalDamage(const float Damage);
256 float HitBodyPartDamageBonus(const EBodyPartName BodyPartName = EBodyPartName::Spine, const int32 Luck = 1) const;
257
258 void ShieldBreak() const;
259
260
261 //- HUD //
262 UFUNCTION()
263 void UpdateHealthAndShieldHUDElement(const float InHealth, const float InMaxHealth, const float InShieldHealth, const float InMaxShieldHealth, const class UDamageType* InDamageType);
264 UFUNCTION()
265 void UpdateHealthHUDElement(const float InHealth, const float InMaxHealth,const class UDamageType* InDamageType);
266
267 UPROPERTY(EditAnywhere, Category="HUD|Health")
268 TSoftClassPtr<class UUserWidget> HealthHUDWidgetClass;
269
270 UPROPERTY(ReplicatedUsing=OnRep_Shield, meta = (EditCondition = "bHasShield"))
271 float ShieldHealth = 100.0f;
272
273 UPROPERTY()
274 const UDamageType* LastDamageType;
275 void CheckShieldRegen();
276 void PreventBloodSpam();
277 bool bCanSpawnBlood = true;
278 bool bKillingHitOnce = true;
279
280 TArray<FBodyPart> BodyParts;
289
290
291 FTimerHandle ShieldTimerHandle;
292 FTimerHandle KnockOutTimerHandle;
293 FTimerHandle BloodPreventSpamTimerHandle;
294};
295
EBodyPartName
Definition BaseData.h:133
EDeathType
Definition BaseData.h:53
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnShieldBreak)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_SevenParams(FOnDamageHit, AController *, InstigatedBy, const float, TotalDamage, const class UDamageType *, DamageType, const FName &, HitBone, const FVector &, HitLocation, const bool, bKillingHit, const bool, bInjuredPart)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnInjuredBodyPart, const EBodyPartName, InjuredBodyPart, const FVector &, HitLocation, const TArray< FBodyPart > &, AllBodyParts)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnNonLethalKnockOut, const class UDamageType *, DamageType, const float, WaitTime)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams(FOnHitReaction, const float, Damage, const FVector &, HitLocation, const FName &, BoneName, const FVector &, ShotFromDirection, const UDamageType *, DamageType)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FOnCharacterDeathEvent, AActor *, OwningActor, EDeathType, DeathType, AActor *, DeathCauser, AController *, DeathInstigator)
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
Definition Health.Build.cs:6
Definition HealthInterface.h:19
Represents a character component that can be added to an actor.
Definition HealthData.h:26