LEAP Documentation 40220
Documentation for the LEAP project
Projectile.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"
8#include "Projectile.generated.h"
9
12class UMeshComponent;
13
14DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FImpactSignature, const FHitResult&, Hit);
15
16UCLASS()
17class PROJECTX_API AProjectile : public AWeaponInstanceActor, public IObjectPoolInterface
18{
19 GENERATED_UCLASS_BODY()
20
21protected:
22 virtual void BeginPlay() override;
23 virtual void OnSpawnedFromObjectPool() override;
24 virtual void OnReleasedToObjectPool() override;
25 virtual void Tick(float DeltaTime) override;
26
27 UFUNCTION()
28 virtual void InitializeMovementComponent();
29
30 UFUNCTION()
31 virtual void OnHit(AActor* SelfActor, AActor* OtherActor, FVector NormalImpulse, const FHitResult& Hit);
32
33 UFUNCTION()
34 virtual void GenerateHitRequest(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit, const FRotator& CustomRotator = FRotator::ZeroRotator, const TArray<AActor*> DamagedActors = TArray<AActor*>());
35
36 UFUNCTION()
37 void UpdateProjectilePath();
38
39 UFUNCTION(NetMulticast, Reliable)
40 void Multicast_OnHit(AActor* SelfActor, AActor* OtherActor, const FVector& NormalImpulse, const FHitResult& Hit);
41
42 UFUNCTION()
43 void OnAccelerationTowardsHomingTargetNotify(bool bIsAccelerating);
44
45 virtual void SpawnImpactEffect(const FHitResult& Hit, AActor* OtherActor, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser);
46
47public:
48 void Init(const int32 ID, const uint8 InShotID, class UWeaponInstanceProjectile* Weapon);
49 void AddIgnoredActor(AActor* ActorToIgnore);
50
51 UFUNCTION()
52 FVector GetStartLocation() const { return StartLocation; }
53
54 UFUNCTION()
55 int32 GetProjectileID() const { return ProjectileID; }
56
57 bool ShouldSpawnActorOnHit() const { return bSpawnActorOnHit; }
58 UFUNCTION(BlueprintCallable)
59 TSubclassOf<AActor> GetActorToSpawnOnHit() const { return ActorClassToSpawn; }
60
61 UFUNCTION()
62 const TArray<FVector_NetQuantize>& GetProjectilePath() const { return ProjectilePath; }
63
64 UFUNCTION()
65 virtual int32 GetTicketUsageCount() const;
66
67 FORCEINLINE class UDataTable* GetImpactEffectTable() const { return ImpactEffectTable; }
68 void UpdateDamageModifier(float DamageModifierIn) { DamageModifier = DamageModifierIn; }
69
70 UFUNCTION(BlueprintPure)
71 FORCEINLINE float GetDamageModifier() const { return DamageModifier; }
72 virtual bool Destroy(bool bNetForce = false, bool bShouldModifyLevel = true) override;
73
74 bool IsReflectedProjectile() const { return bReflectedProjectile; }
75 void SetReflectedProjectile(bool const bInReflectedProjectile);
76
77 UPROPERTY(BlueprintAssignable)
78 FImpactSignature OnImpact;
79
80 FTransform CosmeticTransform = FTransform::Identity;
81
82protected:
83 /* (3P) How long to allow the projectile to exist after a hit, in order to clean up cosmetics before being destroyed */
84 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
85 float LingerTime3P = 0.2f;
86 /* (1P) How long to allow the projectile to exist after a hit, in order to clean up cosmetics before being destroyed */
87 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
88 float LingerTime1P = 0.05f;
89 /* Rate at which projectile smoothing accelerates 3P*/
90 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
91 float StartingCosmeticScaleMultiplier3P = 0.05f;
92 /* Rate at which to smooth the projectile from muzzle to projectile path 3P*/
93 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
94 float SmoothInterpSpeed3P = 3.0f;
95 /* Rate at which to scale the projectile from the multiplier to its original size 3P*/
96 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
97 float ScaleLerpSpeed3P = 5.0f;
98 /* Rate at which projectile smoothing accelerates*/
99 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
100 float StartingCosmeticScaleMultiplier1P = 0.05f;
101 /* Rate at which to smooth the projectile from muzzle to projectile path */
102 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
103 float SmoothInterpSpeed1P = 1.0f;
104 /* Rate at which to scale the projectile from the multiplier to its original size */
105 UPROPERTY(EditDefaultsOnly, Category = Cosmetics)
106 float ScaleLerpSpeed1P = 2.0f;
107 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
108 int32 MaxBounces = 0;
109 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
110 bool bSpawnedActorMatchesProjectileOrientation = false;
111 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
112 bool bSpawnActorOnHit = false;
113 UPROPERTY(VisibleDefaultsOnly, Category = ClientProjectile)
114 class UMovementComponent* ProjectileMovement = NULL;
115 //Time between point collections
116 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
117 float PathPointRate = 0.5f;
118 /* Impact effects table. */
119 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
120 class UDataTable* ImpactEffectTable = NULL;
121 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
122 class UParticleSystem* TrailParticle = NULL;
123 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
124 FRotator TrailRotation = FRotator::ZeroRotator;
125 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile)
126 FVector TrailLocation = FVector::ZeroVector;
127 UPROPERTY(EditDefaultsOnly, Category = ClientProjectile, meta = (EditCondition = bSpawnActorOnHit))
128 TSubclassOf<AActor> ActorClassToSpawn;
129
130 TArray<TWeakObjectPtr<AActor>> IgnoredActors;
131 TWeakObjectPtr<AActor> HomingTarget = nullptr;
132 TWeakObjectPtr<AActor> AimTarget = nullptr;
133 float AimTargetFalloff = 1.0f;
134 bool bLocallyOwnedProjectile = false;
135 int32 CurrentBounces = 0;
136 float LingerTime = 0.0f;
137 bool bDestroyOnHit = false;
138 bool bReflectedProjectile = false;
139 float DamageModifier = 1.0f;
140 FVector StartLocation = FVector(0);
141 TArray<FVector_NetQuantize> ProjectilePath = TArray<FVector_NetQuantize>();
142 FTimerHandle PathCollectionTimer;
143 int32 ProjectileID = INDEX_NONE;
144 uint8 ShotID;
145 float InitialSpeed = 0.0f;
146 class UParticleSystemComponent* TrailParticleSystem = NULL;
147 class TArray<TWeakObjectPtr<UMeshComponent>> MeshComponents;
148 UPXProjectileMovementComponent* MovementComponent = nullptr;
149 class ULightComponent* LightComponent = NULL;
150
151 friend class UTurretComponent;
152
153private:
154 bool bWantsToDestroy = false;
155 bool bIgnoreHits = false;
156 bool bIsAcceleratingTowardsHomingTarget = false;
157 float TimeSinceHomingTargetLost = -1.f;
158 float CachedActorLifeSpan = INDEX_NONE;
159 FVector OriginalScale = FVector::ZeroVector;
160 float InterpLerpVal = 0.0f;
161 float ScaleLerpVal = 0.0f;
162
163 TMap<UMeshComponent*, FVector> MeshOffsets;
164};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FImpactSignature, const FHitResult &, Hit)
Definition: ProjectileExplosive.h:11
Definition: Projectile.h:18
bool IsReflectedProjectile() const
Definition: Projectile.h:74
void UpdateDamageModifier(float DamageModifierIn)
Definition: Projectile.h:68
bool ShouldSpawnActorOnHit() const
Definition: Projectile.h:57
Definition: WeaponInstanceActor.h:16
Definition: ObjectPoolInterface.h:16
Definition: PXProjectileMovementComponent.h:25
Definition: TurretComponent.h:21
Definition: WeaponInstanceProjectile.h:36