LEAP Documentation 40220
Documentation for the LEAP project
WeaponInstanceProjectile.h
Go to the documentation of this file.
1
2// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
3
4#pragma once
5
6#include "CoreMinimal.h"
8#include "WeaponInstanceProjectile.generated.h"
9
10class UDamageType;
11class AProjectile;
12class UAdvancedWidgetComponent;
13class UCurveFloat;
14
15UENUM(Blueprintable)
16enum class ELockOnType : uint8
17{
18 TightAimOnly = 0,
19 Always = 1,
20 NONE = MAX_uint8,
21};
22
23UENUM(Blueprintable)
24enum class EProjectileMagnetismType : uint8
25{
26 Always = 0,
27 GamepadOnly = 1,
28 Disabled = MAX_uint8,
29};
30
34UCLASS()
36{
37 GENERATED_BODY()
38
39public:
40 void BeginPlay();
41 virtual TSubclassOf<class UDamageType> GetDamageType() const override;
42 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
43
44 float GetProjectileSpeed() const;
45 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
46 FORCEINLINE AActor* GetHomingTarget() const { return CanLockOn() ? LockOnTarget.Get() : NULL; }
47 FORCEINLINE bool GetShouldProjectilesNotifyTarget() const { return bShouldProjectilesNotifyTarget; }
48 FORCEINLINE float GetTimeBeforeNotifyingHomingTargetLost() const { return TimeBeforeNotifyingHomingTargetLost; }
49 FORCEINLINE AActor* GetAimTarget() const { return AimTarget.Get(); }
50 FORCEINLINE float GetProjectileMagnetismFalloff() const { return MagnetismFalloff; }
51 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
52 FORCEINLINE float GetLockOnStrength() const { return LockOnStrength; }
53 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
54 bool CanLockOn() const;
55 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
56 float CalculateMagnetismFalloff();
57 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
58 float GetWeaponMagnetismConeSize() const;
59 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
60 bool IsWeaponMagnetismEnabled();
61 UFUNCTION(BlueprintPure, Category = "Projectile Weapon")
62 TSubclassOf<AActor> GetProjectileClass() const { return ProjectileClass; }
63 virtual void InitializeWeapon(bool bFromBatchInitialization = false) override;
64 virtual float GetDisplayDamage() const override;
65 virtual void PrimaryFire(uint8 RemainingBurstCount) override;
66
67 virtual bool Equip() override;
68 virtual bool UnEquip(bool bForce = false) override;
69 virtual float GetProjectileDamageModifier();
70
71 virtual void StopAllActions() override;
72
73 UFUNCTION(BlueprintNativeEvent)
74 bool GetProjectileTransform(FTransform& Transform, FTransform& CosmeticTransform);
75
76protected:
77 virtual TArray<AActor*> GetIgnoredActors() { return TArray<AActor*>(); }
78 virtual void FireProjectiles();
79 //deferredly spawns a punch of projectiles at the given transform.
80 TArray<TWeakObjectPtr<AProjectile>> SpawnProjectiles(UClass* Class, const FTransform& Transform, const FTransform& CosmeticTransform);
81
82 virtual void PreSpawnClientProjectile(const uint8 ShotID,AProjectile* Projectile);
83
84 UFUNCTION(Server, Reliable, WithValidation)
85 void Server_AuthenticateTicket(const TArray<int32>& ProjectileIDs, TSubclassOf<AProjectile> UsedProjectileClass, const FVector_NetQuantize& Origin, AActor* PlayerAimTarget = nullptr, const float PlayerMagnetismFalloff = 1.0f);
86
87 UFUNCTION()
88 int32 GetProjectileID() { return ProjectileIDCounter++; }
89
90 virtual void ToggleTightAim(bool bEnable) override;
91 virtual void ToggleLockOn(bool bEnable);
92
93 UFUNCTION(Server, Reliable, WithValidation)
94 void Server_LockOn(AActor* Target);
95 UFUNCTION(Server, Reliable, WithValidation)
96 void Server_SetTentativeLockOn(AActor* Target);
97
98 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
99 virtual void TickTargetFinder(float DeltaTime);
100 virtual void TickTargetLockOn(float DeltaTime);
101 virtual void TickTargetMaintain(float DeltaTime);
102
103 virtual void UpdateLockOn(float DeltaStrength);
104 virtual void SetLockOn(AActor* Target);
105 virtual void SetTentativeLockOn(AActor* Target);
106
107 virtual bool IsValidLockOnTarget(AActor* Target) const;
108
109 UFUNCTION()
110 virtual void OnRep_LockOnTarget();
111 UFUNCTION()
112 virtual void OnRep_TentativeLockOnTarget();
113
114 UFUNCTION()
115 virtual void UpdateLockOnWidget(AActor* Target, TSubclassOf<UAdvancedWidgetComponent> WidgetComponentClass);
116
117public:
118 /* Type of projectile to shoot */
119 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon")
120 TSubclassOf<AActor> ProjectileClass = NULL;
121 /* How fast should the projectile move? */
122 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon")
123 float ProjectileSpeed = 10000.f;
124 /* How many projectiles the weapon shoots. The number of projectiles will divide the total damage dealt. Every projectiles will have to hit to deal full damage. */
125 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon")
126 int32 ProjectileCount = 1;
127 /* Socket on the mesh used as a spawn point for client projectiles. */
128 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon")
129 FName ClientProjectileTransformSocket = FName("Muzzle");
130 /* If this weapon is not managed by the Weapon Component, should we query the ClientProjectileTransformSocket from the equipped weapon anyways? If false, we'll fallback to the 1P or 3P skeletal mesh we're using */
131 UPROPERTY(EditDefaultsOnly, Category = "Weapon", meta = (EditCondition = "bIsManagedByWeaponComponent"))
132 bool bUnmanagedSearchProjectileSocketOnWeapon = false;
133
134 TArray<TWeakObjectPtr<AProjectile>> ProjectileList;
135protected:
136
137 /*Should the characters speed be added to the projectile speed */
138 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon")
139 bool bUseCharacterSpeed = false;
140 /* Should projectile magnetism run gamepad only or with mouse? It can be disabled here as well. */
141 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
143 /* Anything below the first value will be 100% bullet magnetism, the amount of magnetism will drop off until the player's angle reaches the second value. */
144 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
145 FVector2D ProjectileMagnetismFalloffAngle = FVector2D(6.0f, 10.0f);
146 /* Gamepad Only! Anything below the first value will be 100% bullet magnetism, the amount of magnetism will drop off until the player's angle reaches the second value. */
147 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
148 FVector2D ProjectileMagnetismFalloffAngleGamepad = FVector2D(6.0f, 10.0f);
149 /* Same as above but for tight aming. if you have the player on 2x zoom you will want to make the cone 2x tighter */
150 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
151 FVector2D TightAimedProjectileMagnetismFalloffAngle = FVector2D(3.0f, 5.0f);
152 /* Gamepad Only! Same as above but for tight aming. if you have the player on 2x zoom you will want to make the cone 2x tighter */
153 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
154 FVector2D TightAimedProjectileMagnetismFalloffAngleGamepad = FVector2D(3.0f, 5.0f);
155 /* At what distance does magnetism start to fall off? Distance is X and falloff value is Y. If you want a gun that has 100% magnetism up to 1500cm, define a key at (0, 1) and a key at (1500, 1) then taper off the curve over time as X gets > 1500 */
156 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
157 UCurveFloat* ProjectileMagnetismDistanceFalloffCurve = nullptr;
158 /* Gamepad Only! At what distance does magnetism start to fall off? Distance is X and falloff value is Y. If you want a gun that has 100% magnetism up to 1500cm, define a key at (0, 1) and a key at (1500, 1) then taper off the curve over time as X gets > 1500 */
159 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
160 UCurveFloat* ProjectileMagnetismDistanceFalloffCurveGamepad = nullptr;
161 /* Same as above but for tight aiming. If using 2x zoom you'll want to double the distance of the falloff curve */
162 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
163 UCurveFloat* TightAimedProjectileMagnetismDistanceFalloffCurve = nullptr;
164 /* Gamepad Only! Same as above but for tight aiming. If using 2x zoom you'll want to double the distance of the falloff curve */
165 UPROPERTY(EditDefaultsOnly, Category = "Weapon|Aim Assist")
166 UCurveFloat* TightAimedProjectileMagnetismDistanceFalloffCurveGamepad = nullptr;
167 /* Should this weapon have the ability to lock on targets? */
168 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On")
170 /* Should this weapon notify the target it has incoming projectiles when firing homing projectiles towards it? */
171 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On")
172 bool bShouldProjectilesNotifyTarget = false;
173 /* How long, in seconds, should we wait before notifying the target that our projectiles have lost the target.
174 Projectiles can lose/regain acceleration towards the homing target based on an angle between the projectiles velocity and the direction towards the target
175 Having some time in here allows the projectile to not fire a lot of notifications of gained/lost the target when the changes occur too often, which might happen frequently in some cases */
176 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On")
177 float TimeBeforeNotifyingHomingTargetLost = .3f;
178 /* What is the lock-on range? */
179 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
180 float LockOnRange = 10000.f;
181 /* What is the radius of the target finder from within the center of the camera? */
182 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
183 float LockOnRadius = 300.f;
184 /* How long does the player need to hold the button for the lock on to be full initialized and ready */
185 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
186 float LockOnTime = 1.f;
187 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
188 float MinLockOnPercent = 0.75f;
189 /* Max angle the player can be looking (relative to the target) for lock on to work */
190 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
191 float MaxLockOnAngle = 30.f;
192 /* Check this if you want the lock-on to only work if the player manages to keep its cursor inside the Lock-Square */
193 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
194 bool bUsePlaneIntersectionForLock = false;
195
196 UPROPERTY()
197 float MinDotProduct; //Cached version of MaxLockOnAngle
198 UPROPERTY(EditDefaultsOnly, Category = "Projectile Weapon|Lock On", meta = (EditCondition = "bCanLockOn"))
199 TSubclassOf<UAdvancedWidgetComponent> LockOnWidgetComponentClass = NULL;
200 UPROPERTY()
201 TWeakObjectPtr<UAdvancedWidgetComponent> LockOnWidgetComponent = NULL;
202 UPROPERTY(ReplicatedUsing = OnRep_TentativeLockOnTarget)
203 TWeakObjectPtr<AActor> TentativeLockOnTarget = NULL;
204 UPROPERTY(ReplicatedUsing = OnRep_LockOnTarget)
205 TWeakObjectPtr<AActor> LockOnTarget = NULL;
206 UPROPERTY(Replicated)
207 TWeakObjectPtr<AActor> AimTarget = NULL;
208 UPROPERTY(Replicated)
209 float MagnetismFalloff = 0.0f;
210
211 TWeakObjectPtr<AActor> PreviousTarget = NULL;
212 TWeakObjectPtr<AActor> PreviousTentativeTarget = NULL;
213 float LockOnStrength = 0.f;
214 FVector2D TightAimedProjectileMagnetismFalloffInRadians = FVector2D::ZeroVector;
215 FVector2D ProjectileMagnetismFalloffInRadians = FVector2D::ZeroVector;
216 FVector2D TightAimedProjectileMagnetismFalloffInRadiansGamepad = FVector2D::ZeroVector;
217 FVector2D ProjectileMagnetismFalloffInRadiansGamepad = FVector2D::ZeroVector;
218 float ProjectileAuthenticationMaxDistanceFromActorSquared = 500.0f * 500.0f;
219private:
220 /* Internal projectile ID counter for this weapon component. Should never be directly interacted with, use GetProjectileID() instead. */
221 static int32 ProjectileIDCounter;
222
223 friend class UTurretComponent;
224 bool bWantsTick = false;
225 uint16 ProjectileCounter = 0;
226
227};
EProjectileMagnetismType
Definition: WeaponInstanceProjectile.h:25
ELockOnType
Definition: WeaponInstanceProjectile.h:17
Definition: Projectile.h:18
Definition: TurretComponent.h:21
Definition: WeaponInstanceProjectile.h:36
FORCEINLINE float GetTimeBeforeNotifyingHomingTargetLost() const
Definition: WeaponInstanceProjectile.h:48
FORCEINLINE bool GetShouldProjectilesNotifyTarget() const
Definition: WeaponInstanceProjectile.h:47
FORCEINLINE AActor * GetAimTarget() const
Definition: WeaponInstanceProjectile.h:49
FORCEINLINE float GetProjectileMagnetismFalloff() const
Definition: WeaponInstanceProjectile.h:50
Definition: WeaponInstanceRanged.h:27