LEAP Documentation 40220
Documentation for the LEAP project
DamageHistoryComponent.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "ProjectX.h"
6#include "CoreMinimal.h"
7#include "Components/ActorComponent.h"
9#include "DamageHistoryComponent.generated.h"
10
11class AActor;
12struct FDamageEvent;
13class APlayerState;
14
15USTRUCT(BlueprintType)
17{
18 GENERATED_USTRUCT_BODY()
19public:
21 {
22 }
23
24 FKillHistory(APlayerState* InKilled, const float InTime);
25
26 float GetKillTime() const { return KillTime; }
27 TWeakObjectPtr<APlayerState> GetKillHistoryPlayer() const { return KillHistoryPlayer; }
28
29protected:
30 float KillTime = 0.0f;
31 TWeakObjectPtr<APlayerState> KillHistoryPlayer = NULL;
32};
33
34USTRUCT(Blueprintable)
36{
37 GENERATED_USTRUCT_BODY()
38
39public:
41 {
42
43 }
44
45 FHistoryEntry(const float InDamage, const AController* InInstigator, const float InLastHitTime, TSubclassOf<UProjectXDamageType> InDamageType)
46 {
47 Damage = InDamage;
48 Instigator = const_cast<AController*>(InInstigator);
49 LastHitTime = InLastHitTime;
50 MostRecentDamage = InDamageType;
51 UpdateMostRecentDamage(InDamage, InDamageType);
52 }
53
54 void UpdateMostRecentDamage(const float InDamage,const TSubclassOf<UProjectXDamageType>& InDamageType)
55 {
56 if (InDamageType == NULL)
57 {
58 return;
59 }
60 if (DamageTypesMap.Contains(InDamageType))
61 {
62 DamageTypesMap[InDamageType] += Damage;
63 }
64 else
65 {
66 DamageTypesMap.Add(InDamageType, Damage);
67 }
68 MostRecentDamage = InDamageType;
69 }
70
71 TSubclassOf<UProjectXDamageType> GetHighestDamageType() const
72 {
73 float HighestDamage = 0;
74 TSubclassOf<UProjectXDamageType> DamageTypeOut = NULL;
75 for (auto& Elem : DamageTypesMap)
76 {
77 if (Elem.Value > HighestDamage)
78 {
79 HighestDamage = Elem.Value;
80 DamageTypeOut = Elem.Key;
81 }
82 }
83 return DamageTypeOut;
84 }
85
86 //The damage event associated with this entry
87 FDamageEvent DamageEvent;
88
89 //Total damage this player has caused
90 float Damage = 0.f;
91
92 //The damage instigator
93 TWeakObjectPtr<AController> Instigator = NULL;
94
95 TMap<TSubclassOf<UProjectXDamageType>, float> DamageTypesMap;
96
97 //The damage type
98 TSubclassOf<UProjectXDamageType> MostRecentDamage = NULL;
99
100 //The last time this player caused damage
101 float LastHitTime = 0.f;
102
103 //Was this player responsible for the kill?
104 bool bKiller = false;
105
107
108 FORCEINLINE bool IsValid() const { return Instigator != NULL; }
109};
110
111UCLASS( ClassGroup=(Custom), HideCategories = (ComponentTick, Collision, Tags, Variable, Activation, ComponentReplication, Cooking), meta=(BlueprintSpawnableComponent) )
112class PROJECTX_API UDamageHistoryComponent : public UActorComponent
113{
114 GENERATED_UCLASS_BODY()
115
116public:
117 UFUNCTION(BlueprintPure)
118 float GetKillHistoryDuration() { return KillHistoryDuration; }
119
120 /* returns false if there is no event for this instigator */
121 virtual FHistoryEntry& GetEventForInstigator(const AController* Instigator);
122 /* returns false if there is no event for this instigator */
123 virtual FHistoryEntry& GetDamageDoneEventForInstigator(const AController* Instigator);
124
125 /* return false if we cannot find an event */
126 virtual FHistoryEntry& GetHighestDamageEvent();
127
128 virtual void AddNewKillHistory(APlayerState* Kill);
129 const TArray<FKillHistory>& GetKillHistory() { return KillHistory; }
130 int32 GetKillCount() const { return KillHistory.Num(); }
131
132 UFUNCTION()
133 virtual void Die(AActor* Victim, const float Damage, struct FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser, bool bFromHeadshot = false);
134 UFUNCTION()
135 virtual void DamageDone(class AActor* Victim, const float Damage, struct FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser);
136
137protected:
138 virtual void BeginPlay() override;
139
140 UFUNCTION()
141 virtual void TakeDamage(class AActor* Victim, const float Damage, struct FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser, const APlayerState* InstigatorPlayerState);
142
143
144 virtual void BroadcastParticipation();
145 virtual void BroadcastKillModifiers(AActor* Victim, float Damage, FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser);
146
147 UFUNCTION()
148 void ClearKillHistory();
149
150protected:
151 UPROPERTY()
152 TArray<FHistoryEntry> DamageHistory;
153 TArray<FHistoryEntry> DamageDoneHistory;
154
155 FTimerHandle KillHistoryClearHandle;
156
157 UPROPERTY()
158 TArray<FKillHistory> KillHistory;
159
160 UPROPERTY(EditDefaultsOnly, Category = DamageHistory)
161 float KillHistoryDuration = 1.0f;
162
163 UPROPERTY(EditDefaultsOnly, Category = DamageHistory)
164 float ParticipationDuration = 15.f;
165 //The max time an entry will be considered for awarding the Saviour bonus.
166 UPROPERTY(EditDefaultsOnly, Category = DamageHistory)
167 float SaviourMaxDuration = 2.f;
168
169 FString Saviour = "VO_Saviour";
170 FString Avenger = "VO_Avenger";
171 FString HeadShot = "VO_HeadshotKill";
172};
Definition: DamageHistoryComponent.h:36
void UpdateMostRecentDamage(const float InDamage, const TSubclassOf< UProjectXDamageType > &InDamageType)
Definition: DamageHistoryComponent.h:54
FORCEINLINE bool IsValid() const
Definition: DamageHistoryComponent.h:108
FHistoryEntry()
Definition: DamageHistoryComponent.h:40
TMap< TSubclassOf< UProjectXDamageType >, float > DamageTypesMap
Definition: DamageHistoryComponent.h:95
FHistoryEntry(const float InDamage, const AController *InInstigator, const float InLastHitTime, TSubclassOf< UProjectXDamageType > InDamageType)
Definition: DamageHistoryComponent.h:45
static FHistoryEntry InvalidEntry
Definition: DamageHistoryComponent.h:106
FDamageEvent DamageEvent
Definition: DamageHistoryComponent.h:87
TSubclassOf< UProjectXDamageType > GetHighestDamageType() const
Definition: DamageHistoryComponent.h:71
Definition: DamageHistoryComponent.h:17
FKillHistory()
Definition: DamageHistoryComponent.h:20
float GetKillTime() const
Definition: DamageHistoryComponent.h:26
TWeakObjectPtr< APlayerState > GetKillHistoryPlayer() const
Definition: DamageHistoryComponent.h:27