LEAP Documentation 40220
Documentation for the LEAP project
SpottingComponent.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 "Components/ActorComponent.h"
7#include "SpottingComponent.generated.h"
8
9class ACharacter;
10class AController;
11class UAfflictionInstance;
12
14DECLARE_DYNAMIC_MULTICAST_DELEGATE(FEnemyUniqueEnemySpottedSignature);
15
16UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), Blueprintable)
17class PROJECTX_API USpottingComponent : public UActorComponent
18{
19 GENERATED_BODY()
20
21public:
22 USpottingComponent();
23 virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
24 bool IsEnabled() const { return bSpottingComponentEnabled; }
25 float GetCachedSpottingRange() const { return CachedSpottingDistance; }
26
27 UFUNCTION(BlueprintCallable)
28 void SetDotMultiplier(float NewMultipler) { MaxDotMultiplier = NewMultipler;}
29 UFUNCTION(BlueprintCallable, Category = "Spotting Component")
30 void SetOwningCharacter(ACharacter* const InOwningCharacter);
31 UFUNCTION(BlueprintCallable, Category = "Spotting Component")
32 void PerformRadialScan(float ScanRange, bool bIgnoreObstacles = false, bool bRevealStealthTargets = false);
33 UFUNCTION(BlueprintCallable, Category = "Spotting Component")
34 void UpdateSpottingRange(float NewRange) { SpottingRange = NewRange; }
35 UFUNCTION(BlueprintCallable, Category = "Spotting Component")
36 void UpdateUseDotProductCheck(bool bNewCheckDotProduct) { bCheckDotProduct = bNewCheckDotProduct;}
37
38 FEnemySpottedSignature OnEnemySpotted;
39 FEnemyUniqueEnemySpottedSignature OnUniqueEnemySpotted;
40
41protected:
42 UFUNCTION(BlueprintPure, Category = "Spotting Component")
43 virtual ACharacter* GetOwningCharacter() const;
44 UFUNCTION(BlueprintPure, Category = "Spotting Component")
45 AController* GetOwningController() const;
46
47 // Called when the game starts
48 virtual void BeginPlay() override;
49 //UPROPERTY(ReplicatedUsing = OnRep_SpottingEnabled)
50 bool bSpottingComponentEnabled = true;
51 /* affliction appled to affected players */
52 UPROPERTY(EditDefaultsOnly, Category = Radar)
53 TSubclassOf<UAfflictionInstance> SpottedAffliction = NULL;
54 /* Time in seconds required while holding the cursor on top of an actor to spot it */
55 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
56 float SpottingRequiredTime = 3.f;
57 /* The max range at which this component will scan for spotting in cms*/
58 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
59 float SpottingRange = 1000000.f;
60 /* A curve that lays out the max dot a target can be from the spotter based on distance. As the distance grows so does your vision cone, this helps you to tighten up that dot so you can remain precise even when testing against distant targets*/
61 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
62 UCurveFloat* MaxDotPerDistanceCurve = nullptr;
63 /* A multiplier that can be set to the dot check at runtime */
64 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
65 float MaxDotMultiplier = 1.f;
66 /* Should we run the target finder on the server ? */
67 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
68 bool bTickTargetFinderOnServer = false;
69 /* Should the spotted character be revelead if he is invisible ? */
70 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
71 bool bRevealInvisibleTargets = false;
72 /* Can this spotting component spot multiple targets at once? Have in mind that Multispots don't use SpottingRequiredTime but are rather spotted instantly to avoid keeping track of multiple possible targets at once. Multiple spot events can only occur when
73 this component ticks on the server*/
74 UPROPERTY(EditDefaultsOnly, Category = "Spotting Component")
75 bool bCanMultispot = false;
76
77 TWeakObjectPtr<AActor> SpottingTarget = NULL;
78 UPROPERTY()
79 ACharacter* OwningCharacter = NULL;
80
81 void TickTargetFinder(float DeltaTime);
82 void TickTargetMaintain(float DeltaTime);
83 void SpotTarget(AActor* SpottedActor, int& UniqueSpots);
84
85 UFUNCTION(Server, Reliable, WithValidation)
86 void Server_SpotTarget(AActor* SpottedActor);
87
88 UFUNCTION(BlueprintNativeEvent, Category = "Spotting Component")
89 void GetSpottingViewPoint(FVector& OutLocation, FRotator& OutRotation) const;
90private:
91 UPROPERTY(Transient)
92 float SpottingTime = 0.f;
93
94 bool bCheckDotProduct = true;
95 float CachedSpottingDistance = 0.0f;
96};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FEnemySpottedSignature, AActor *, EnemySpotted)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FEnemyUniqueEnemySpottedSignature)