6#include "CoreMinimal.h"
7#include "Components/ActorComponent.h"
9#include "DamageHistoryComponent.generated.h"
18 GENERATED_USTRUCT_BODY()
24 FKillHistory(APlayerState* InKilled,
const float InTime);
30 float KillTime = 0.0f;
31 TWeakObjectPtr<APlayerState> KillHistoryPlayer = NULL;
37 GENERATED_USTRUCT_BODY()
45 FHistoryEntry(
const float InDamage,
const AController* InInstigator,
const float InLastHitTime, TSubclassOf<UProjectXDamageType> InDamageType)
48 Instigator =
const_cast<AController*
>(InInstigator);
49 LastHitTime = InLastHitTime;
50 MostRecentDamage = InDamageType;
51 UpdateMostRecentDamage(InDamage, InDamageType);
56 if (InDamageType == NULL)
60 if (DamageTypesMap.Contains(InDamageType))
62 DamageTypesMap[InDamageType] +=
Damage;
66 DamageTypesMap.Add(InDamageType,
Damage);
68 MostRecentDamage = InDamageType;
73 float HighestDamage = 0;
74 TSubclassOf<UProjectXDamageType> DamageTypeOut = NULL;
75 for (
auto& Elem : DamageTypesMap)
77 if (Elem.Value > HighestDamage)
79 HighestDamage = Elem.Value;
80 DamageTypeOut = Elem.Key;
93 TWeakObjectPtr<AController> Instigator = NULL;
98 TSubclassOf<UProjectXDamageType> MostRecentDamage = NULL;
101 float LastHitTime = 0.f;
104 bool bKiller =
false;
108 FORCEINLINE
bool IsValid()
const {
return Instigator != NULL; }
111UCLASS( ClassGroup=(
Custom), HideCategories = (ComponentTick, Collision, Tags, Variable, Activation, ComponentReplication, Cooking), meta=(BlueprintSpawnableComponent) )
112class PROJECTX_API UDamageHistoryComponent :
public UActorComponent
114 GENERATED_UCLASS_BODY()
117 UFUNCTION(BlueprintPure)
118 float GetKillHistoryDuration() {
return KillHistoryDuration; }
121 virtual FHistoryEntry& GetEventForInstigator(
const AController* Instigator);
123 virtual FHistoryEntry& GetDamageDoneEventForInstigator(
const AController* Instigator);
128 virtual void AddNewKillHistory(APlayerState*
Kill);
129 const TArray<FKillHistory>& GetKillHistory() {
return KillHistory; }
130 int32 GetKillCount()
const {
return KillHistory.Num(); }
133 virtual
void Die(AActor* Victim, const
float Damage, struct FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser,
bool bFromHeadshot = false);
135 virtual
void DamageDone(class AActor* Victim, const
float Damage, struct FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser);
138 virtual
void BeginPlay() override;
141 virtual
void TakeDamage(class AActor* Victim, const
float Damage, struct FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser, const APlayerState* InstigatorPlayerState);
144 virtual
void BroadcastParticipation();
145 virtual
void BroadcastKillModifiers(AActor* Victim,
float Damage, FDamageEvent const& DamageEvent, const AController* EventInstigator, const AActor* DamageCauser);
148 void ClearKillHistory();
155 FTimerHandle KillHistoryClearHandle;
160 UPROPERTY(EditDefaultsOnly, Category = DamageHistory)
161 float KillHistoryDuration = 1.0f;
163 UPROPERTY(EditDefaultsOnly, Category = DamageHistory)
164 float ParticipationDuration = 15.f;
166 UPROPERTY(EditDefaultsOnly, Category = DamageHistory)
167 float SaviourMaxDuration = 2.f;
169 FString
Saviour = "VO_Saviour";
170 FString
Avenger = "VO_Avenger";
171 FString
HeadShot = "VO_HeadshotKill";
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