LEAP Documentation 40220
Documentation for the LEAP project
AfflictionComponent.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 "CoreMinimal.h"
7#include "Components/ActorComponent.h"
8#include "GameFramework/Controller.h"
9#include "AfflictionComponent.generated.h"
10
11DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAfflictionsUpdatedSignature, UAfflictionInstance*, Affliction);
12
13UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
14class PROJECTX_API UAfflictionComponent : public UActorComponent
15{
16 GENERATED_UCLASS_BODY()
17protected:
18 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
19
20public:
21 virtual float TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser);
22
23 void OwnerDied();
24
25 template <class T>
26 T* AddAffliction(const TSubclassOf<UAfflictionInstance> AfflictionClass, AActor* Instigator, bool bDeferInitialization = false)
27 {
28 return Cast<T>(AddAffliction(AfflictionClass, Instigator, bDeferInitialization));
29 }
30
31 /* Adds an affliction, returns the relevant affliction or null if it cannot/fails. */
32 UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category = Affliction, meta = (DefaultToSelf = Instigator))
33 virtual UAfflictionInstance* AddAffliction(const TSubclassOf<UAfflictionInstance> AfflictionClass, AActor* Instigator, bool bDeferInitialization = false);
34 /* Initializes the affliction, this should only be called if initialization was deferred in AddAffliction*/
35 UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category = Affliction, meta = (DefaultToSelf = Instigator))
36 virtual void InitializeAffliction(UAfflictionInstance* const Affliction, AActor* const Instigator);
37 /* Check to see if the current affliction type is currently applied */
38 UFUNCTION(BlueprintCallable, Category = Affliction)
39 virtual bool HasAffliction(const TSubclassOf<UAfflictionInstance> AfflictionClass, AActor* const Instigator = nullptr) const;
40 /* Gets the number of afflictions of a specified type applied with specific instigator */
41 UFUNCTION(BlueprintCallable, Category = Affliction)
42 virtual int32 GetNumAfflictions(const TSubclassOf<UAfflictionInstance> AfflictionClass, AActor* const Instigator = nullptr) const;
43 /* Check to see if the current affliction type is currently applied */
44 UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category = Affliction)
45 virtual void ResetTimersOnAfflictionsOfType(const TSubclassOf<UAfflictionInstance> AfflictionClass, const AActor* Instigator = nullptr);
46 /* Removes an affliction, returns true if an affliction was removed. */
47 UFUNCTION(BlueprintCallable, Category = Affliction)
48 bool RemoveAfflictionbyType(const TSubclassOf<UAfflictionInstance> AfflictionClass, AActor* Instigator = NULL);
49 UFUNCTION(BlueprintCallable, Category = Affliction)
50 void RemoveAffliction(UAfflictionInstance* Affliction) const;
51 /* Removes all afflictions of a desired type. Note that bCallAfflictionEndEvents only applies to the server. */
52 UFUNCTION(BlueprintCallable, Category = Affliction)
53 void RemoveAfflictionsByType(const TSubclassOf<UAfflictionInstance> AfflictionClass, const AActor* Instigator = NULL, bool bCallAfflictionEndEvents = true);
54
55 /* Note that bCallAfflictionEndEvents only applies to the server. */
56 void RemoveAfflictionsByType(const TSubclassOf<UAfflictionInstance> AfflictionClass, const TArray <TWeakObjectPtr<UAfflictionInstance>>& IgnoredAfflictions, const AActor* Instigator = NULL, bool bCallAfflictionEndEvents = true);
57 void GetAfflictionsByType(const TSubclassOf<UAfflictionInstance> AfflictionClass, TArray<TWeakObjectPtr<UAfflictionInstance>>& FoundAfflictions, const AActor* Instigator = NULL) const;
58 bool OnAfflictionDestroyed(UAfflictionInstance* Affliction);
59
60 UPROPERTY(BlueprintAssignable)
61 FAfflictionsUpdatedSignature AfflictionAddedEvent;
62 UPROPERTY(BlueprintAssignable)
63 FAfflictionsUpdatedSignature AfflictionRemovedEvent;
64
65protected:
66
67 UFUNCTION()
68 virtual void OnRep_AfflictionList();
69
70 UFUNCTION(Client, Reliable)
71 void Client_RemoveAfflictionsByType(TSubclassOf<UAfflictionInstance> AfflictionClass, const TArray <TWeakObjectPtr<UAfflictionInstance>>& IgnoredAfflictions, const AActor* Instigator = NULL, bool bCallAfflictionEndEvents = true);
72
73private:
74 /* An array of currently active afflictions on this pawn. */
75 UPROPERTY(ReplicatedUsing = OnRep_AfflictionList)
76 TArray<TWeakObjectPtr<UAfflictionInstance>> AfflictionList;
77
78};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAfflictionsUpdatedSignature, UAfflictionInstance *, Affliction)