LEAP Documentation 40220
Documentation for the LEAP project
HookshotComponent.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 "PlayerStructs.h"
8#include "HookshotComponent.generated.h"
9
11class UPrimitiveComponent;
12
13DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHookshotUpdateSignature, const UHookshotComponent*, HookshotComponent);
14
15UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent), Blueprintable)
16class PROJECTX_API UHookshotComponent : public UActorComponent
17{
18 GENERATED_UCLASS_BODY()
19
20public:
21 virtual void BeginPlay() override;
22 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
23 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
24
25 virtual void StartHookshot();
26 virtual void StopHookshot();
27 virtual void StartCooldown();
28 virtual void SetHookshot(bool bEnable, bool bForced = false);
29 virtual void OnCooldownFinished();
30 virtual bool IsOnCooldown() const;
31 virtual bool HasEnoughStartStamina() const;
32 virtual void SetupPlayerInputComponent();
33
34 UFUNCTION(BlueprintPure)
35 const FVector& GetHookshotLocation() const { return HookshotLocation; }
36 UFUNCTION(BlueprintPure)
37 UPrimitiveComponent* GetHookedComponent() const { return HookedComponent.IsValid()? HookedComponent.Get() : NULL; }
38
39 UFUNCTION()
40 virtual void OnComponentHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
41
42 UPROPERTY(BlueprintAssignable)
43 FHookshotUpdateSignature OnHookshotStart;
44 UPROPERTY(BlueprintAssignable)
45 FHookshotUpdateSignature OnHookshotStop;
46 UPROPERTY(BlueprintAssignable)
47 FHookshotUpdateSignature OnHookshotTargetAvailable;
48 UPROPERTY(BlueprintAssignable)
49 FHookshotUpdateSignature OnHookshotTargetNotAvailable;
50
51 bool bCanUseHookshot = false;
52
53protected:
54 UFUNCTION()
55 virtual void CheckCustomMovementToggle(ECustomMovementType CustomMovementType, bool bToggledState);
56
57 //Client sends the location it feels it's hookin towards to unreliable to the server so other clients can see it as well
58 UFUNCTION(Server, Unreliable)
59 void Server_Unreliable_SetHookedLocation(const FVector HookedLocation);
60 UFUNCTION()
61 virtual void OnRep_HookedLocation();
62
63protected:
64 /* What is the initial energy cost of the hookshot? */
65 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
66 float HookshootInitialCost = 10.0f;
67 /* How far can the player hookshot */
68 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
69 float HookshotLength = 20000.0f;
70 /* Min deviation from the center of the screen a point can be to be considered as a hookable one? */
71 UPROPERTY(EditDefaultsOnly)
72 float MinDotAllowedOnHook = 0.9f;
73 /* What is the initial energy cost of the hookshot? */
74 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
75 bool bShouldHookshotResetJumpCount = false;
76 /* A list of radial checks to be made from the cursor if we can't find a suitable hookshot placement.
77 [100,200,400] : If we fail to find a placement near the cursor, we're going to try with a 100 radius first, then 200 and then 400 and see if we hit anything */
78 UPROPERTY(EditDefaultsOnly)
79 TArray<float> RangeCheckFailsafes;
80
81 /* Cooldown after using the hookshot in seconds */
82 UPROPERTY(EditDefaultsOnly)
83 float CooldownInSeconds = 0.5f;
84 /* How far from the hooked point to stop pulling the player towards the point */
85 UPROPERTY(EditDefaultsOnly)
86 float HookshotDisengagementDistance = 100.0f;
87 bool bHookshotEnabled = false;
88
89 UPROPERTY()
90 AProjectXCharacter* CharacterOwner = NULL;
91
92private:
93 UPROPERTY(ReplicatedUsing = OnRep_HookedLocation)
94 FVector HookshotLocation = FVector::ZeroVector;
95 TWeakObjectPtr<UPrimitiveComponent> HookedComponent;
96 float HookshotDisengagementDistanceSqrd = 0.0f;
97 float CurrentMaxSpeed = 0.0f;
98 FTimerHandle CooldownTimerHandle;
99};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHookshotUpdateSignature, const UHookshotComponent *, HookshotComponent)
ECustomMovementType
Definition: PlayerStructs.h:15
Definition: ProjectXCharacter.h:128