LEAP Documentation 40220
Documentation for the LEAP project
DestroyableObjective.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2021. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
10#include "DestroyableObjective.generated.h"
11
12DECLARE_DYNAMIC_MULTICAST_DELEGATE_SixParams(FObjectiveDamagedSignature, class ADestroyableObjective*, Objective, const float, Damage, struct FDamageEvent const&, DamageEvent, class AController*, EventInstigator, class AActor*, DamageCauser, class APlayerState*, InstigatorPlayerState);
13DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FObjectiveEventSignature, class ADestroyableObjective*, Objective);
14DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FObjectivePointTeamChangedSignature, int32, TeamOwner, ADestroyableObjective*, Objective);
15
16class UAfflictionComponent;
17class UAfflictionInstance;
18
19#define NOT_INITIALIZED_HEALTH -MAX_FLT
20
21UCLASS()
22class PROJECTX_API ADestroyableObjective : public AActor, public IHealthInterface, public ITeamInterface
23{
24 GENERATED_BODY()
25
26public:
27 // Sets default values for this component's properties
29
30 virtual void ToggleActivation(bool bToggle);
31
32 virtual void Tick(float DeltaTime) override;
33 virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, AActor* DamageCauser) override;
34
35 UFUNCTION(BlueprintPure, Category = "Destroyable Objective")
36 FORCEINLINE bool IsObjectiveActive() const { return bIsActive; }
37 UFUNCTION(BlueprintPure, Category = "Destroyable Objective")
38 FORCEINLINE bool IsObjectiveProperlyInitialized() const { return bHasTeamProperlyInitialized && bHasHealthProperlyInitialized; }
39
40 virtual int32 GetTeam() const override;
41 virtual int32 SetTeam(int32 NewTeam) override;
42
43 /* Returns true if the health has been properly initialized and is < 0 */
44 virtual bool IsDead() const override { return GetHealth() <= 0 && GetHealth() > NOT_INITIALIZED_HEALTH; }
45 virtual float GetHealth() const override { return Health; }
46 virtual float GetMaxHealth() const override { return MaxHealth; }
47 virtual void SetHealth(const float NewHealth) override;
48 virtual void SetHealthRegenRate(float NewRate) override { HealthRegenRate = NewRate; }
49 virtual float GetTimeSinceLastDamage() const override;
50 virtual UAfflictionComponent* GetAfflictionComponent() const override { return AfflictionComponent; }
51
52 UPROPERTY(BlueprintAssignable, Category = "Destroyable Objective|Events")
53 FObjectiveDamagedSignature OnObjectiveDamaged;
54 UPROPERTY(BlueprintAssignable, Category = "Destroyable Objective|Events")
55 FObjectiveDamagedSignature OnObjectiveDestroyed;
56 UPROPERTY(BlueprintAssignable, Category = "Destroyable Objective|Events")
57 FObjectiveEventSignature OnObjectiveOwnerChanged;
58 UPROPERTY(BlueprintAssignable, Category = "Destroyable Objective|Events")
59 FObjectiveEventSignature OnObjectiveActivationChanged;
60 UPROPERTY(BlueprintAssignable, Category = "Destroyable Objective|Events")
61 FObjectiveEventSignature OnObjectiveProperlyInitialized;
62 UPROPERTY(BlueprintAssignable, Category = "Destroyable Objective|Events")
63 FObjectivePointTeamChangedSignature OnTeamChangedEvent;
64
65protected:
66 virtual void BeginPlay() override;
67 virtual void EndPlay(const EEndPlayReason::Type EndplayReason) override;
68 virtual void OnRep_Owner() override;
69 virtual void Die(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser, const FHitResult& HitResult, APlayerState* InstigatorPlayerState);
70
71 /* Starts the wait on the passive regeneration delay before enabling the Passive Regen */
72 virtual void StartPassiveRegenDelay();
73 /* Fully starts our passive regeneration */
74 virtual void BeginPassiveRegen();
75 virtual void StopPassiveRegen();
76 virtual void CheckForInitialization();
77
78 UFUNCTION(BlueprintImplementableEvent)
79 void OnObjectiveInitialized();
80
81 UFUNCTION()
82 virtual void OnRep_Health(float PreviousHealth);
83 UFUNCTION()
84 virtual void OnRep_Activation();
85 UFUNCTION()
86 virtual void OnRep_Team();
87 UFUNCTION(Reliable, NetMulticast)
88 void Multicast_Die(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser, const FHitResult& Hit, APlayerState* InstigatorPlayerState);
89
90 UPROPERTY(EditAnywhere, Category = "Destroyable Objective|Health", meta = (AllowPrivateAccess = true))
91 float MaxHealth = 1000.f;
92 /* Should this objective's health passively recharge when it hasn't taken damage recently ? */
93 UPROPERTY(GlobalConfig, EditDefaultsOnly, BlueprintReadOnly, Category = "Destroyable Objective|Health|Regen")
94 bool bUsePassiveHealthRegen = true;
95 /* How long to wait after damage is taken before we start recharging our health */
96 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Destroyable Objective|Health|Regen", meta = (EditCondition = "bUsePassiveHealthRegen"))
97 float PassiveHealthRegenDelay = 5.f;
98 /* How much health do we regenerate / s when passive health regen is active ? */
99 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Destroyable Objective|Health|Regen", meta = (EditCondition = "bUsePassiveHealthRegen"))
100 float PassiveHealthRegenRate = 10.f;
101 /* Should this point get its team from its owner*/
102 UPROPERTY(EditAnywhere, Category = "Destroyable Objective|Health", meta = (AllowPrivateAccess = true))
103 bool bUserOwnerTeam = true;
104 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Destroyable Objective|XP")
106 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Destroyable Objective|XP")
108 /* should this be targetedable on begin play*/
109 UPROPERTY(EditDefaultsOnly)
110 bool bRegisterTargetOnBeginPlay = true;
111private:
112
113 float HealthRegenRate = 0.f;
114 float LastDamageTime = -MAX_FLT;
115 UAfflictionComponent* AfflictionComponent = nullptr;
116 TWeakObjectPtr<UAfflictionInstance> PassiveRegenAffliction = nullptr;
117 FTimerHandle PassiveHealthRegenTimer;
118
119 UPROPERTY(ReplicatedUsing = OnRep_Health)
121 UPROPERTY(ReplicatedUsing = OnRep_Team)
122 int Team = UINT8_MAX;
123 UPROPERTY(ReplicatedUsing = OnRep_Activation)
124 bool bIsActive = false;
125 bool bIsProperlyInitialized = false;
126 bool bHasTeamProperlyInitialized = false;
127 bool bHasHealthProperlyInitialized = false;
128};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_SixParams(FObjectiveDamagedSignature, class ADestroyableObjective *, Objective, const float, Damage, struct FDamageEvent const &, DamageEvent, class AController *, EventInstigator, class AActor *, DamageCauser, class APlayerState *, InstigatorPlayerState)
#define NOT_INITIALIZED_HEALTH
Definition: DestroyableObjective.h:19
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FObjectiveEventSignature, class ADestroyableObjective *, Objective)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FObjectivePointTeamChangedSignature, int32, TeamOwner, ADestroyableObjective *, Objective)
EXPEventType
Definition: PlayerStats.h:13
Definition: DestroyableObjective.h:23
virtual bool IsDead() const override
Definition: DestroyableObjective.h:44
virtual float GetHealth() const override
Definition: DestroyableObjective.h:45
virtual void SetHealthRegenRate(float NewRate) override
Definition: DestroyableObjective.h:48
virtual float GetMaxHealth() const override
Definition: DestroyableObjective.h:46
virtual UAfflictionComponent * GetAfflictionComponent() const override
Definition: DestroyableObjective.h:50
Definition: HealthInterface.h:28
Definition: TeamInterface.h:26