Space Plunder
Loading...
Searching...
No Matches
CharacterShootingComponent.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
9#include "CharacterShootingComponent.generated.h"
10
11
12DECLARE_LOG_CATEGORY_EXTERN(LogShootingComponent, Display, All);
13
14DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnWeaponEqiupped,const TArray<FWeaponData_T>&, Weapons, const int32, CurrentWeaponIndex);
15DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnAmmoChangedSignature, const int32, CurrentAmmo, const int32, TotalAmmo);
16DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWeaponStateChanged, const FPlayerWeaponState&, WeaponState);
17DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnBulletShot, const float, RecoilAmount);
18
19
28UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent))
29class WEAPONSYSTEM_API UCharacterShootingComponent : public UCharacterComponent, public IRecoilInterface
30{
31 GENERATED_BODY()
32
33
34public:
36
37 //- Delegates //
38 UPROPERTY(BlueprintAssignable, Category = "Weapons")
39 FOnWeaponEqiupped OnWeaponEquipped;
40 UPROPERTY(BlueprintAssignable, Category = "Ammo")
41 FOnAmmoChangedSignature OnAmmoChanged;
42 UPROPERTY(BlueprintAssignable, Category = "Ammo")
43 FOnWeaponStateChanged OnWeaponStateChanged;
44 UPROPERTY(BlueprintAssignable, Category = "Recoil")
45 FOnBulletShot OnBulletShot;
46
47
48 UFUNCTION(Server, Reliable)
49 void Server_SpawnWeaponActor_NEW();
50
51
52 //- Setup Functions //
53 void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent);
54 void SetThrowStrength(const float Strength){PickupThrowIntensity = Strength;};
55 void SetThrowPoint(USceneComponent* ThrowPointComponent){ThrowPoint = ThrowPointComponent;};
56
57
58 UFUNCTION(Server, Reliable)
59 void Server_SetThrowPoint(USceneComponent* ThrowPointComponent);
60
61
62 //- Main Functions //
63 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
64 void ShootGun();
65 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
66 void PullTrigger();
67 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
68 void StopShootGun();
69 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
70 void SetTargetLocation(const FVector& TargetLocation);
71
72 //- HUD / UMG //
73 // void MoveUMG(bool bRightShoulder);
74
75 //- Input Functions //
76 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
77 void AimPressedAction(const bool bRightShoulder = true);
78 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
79 void AimReleasedAction(const bool bRightShoulder = true);
80 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
81 void ThrowWeaponAction();
82
83 UFUNCTION(Server, Reliable)
84 void ServerSetPlayerWeaponState(const FPlayerWeaponState& PlayerState);
85 UFUNCTION(Client, Reliable)
86 void ClientSetPlayerWeaponState(const FPlayerWeaponState& PlayerState);
87
88
89 //- Reload //
90 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
91 void Reload();
92 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
93 void SwitchAutoMode();
94 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Shooting Component")
95 float GetLastReloadTime() const {return LastReloadDuration;};
96
97
98 //- Swaps / Pickups //
99 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
100 void PickupWeapon(const FWeaponData_T& WeaponToPickup, int32& RemainingAmmo);
101 void EquipWeapon(const FWeaponData_T& WeaponToEquip);
102 void SwapWeaponPressed();
103 void SwapWeaponReleased();
104 void SwapWeapon();
105 void HolsterWeapon();
106
107 //- Throw //
108 void ThrowWeapon(const FWeaponData_T& WeaponToThrow);
109 void DropWeapon(const FWeaponData_T& WeaponToDrop);
110
111 void GetThrowStats(FTransform& OutTransform, FVector& OutThrowForce) const;
112
113 UFUNCTION(Server, Reliable)
114 void Server_AddStartingWeapons(const TArray<FString>& WeaponIDs);
115
116
117 //- Server //
118 UFUNCTION(Server, Reliable)
119 void ServerStopShootGun();
120 UFUNCTION(Server, Reliable)
121 void ServerSwapWeapon();
122
123 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
124 void PickupAttachment(const FString& WeaponAttachmentID);
125
126
127 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
128 bool CanPickupWeapon(const FWeaponData_T& WeaponData);
129 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
130 bool CanPickupAttachment(const FWeaponAttachment& In_WeaponAttachmentData) const;
131
132 UFUNCTION(Server, Reliable)
133 void Server_PickupWeapon(FWeaponData_T WeaponToPickup, int32 RemainingAmmo);
134
135 UFUNCTION(Server, Reliable)
136 void Server_ThrowWeapon(const FWeaponData_T& WeaponToThrow);
137
138 UFUNCTION(Server, Reliable)
139 void Server_ThrowAllWeapons();
140
141 //- Helper Functions //
142 UFUNCTION(Server, Reliable)
143 void ServerHideWeaponModel(const bool bHidden);
144
145 //- Overriden Functions //
146 virtual void SetupComponent(USkeletalMeshComponent* SkeletalMesh, UAnimInstance* AnimationInstance, AController* Controller, AActor* HUDReference, const bool bNPC, const bool bDead) override;
147 virtual void ComponentSetupComplete() override;
148 virtual void OwnerDeath() override;
149 virtual void OnMontageNotifyBegin(FName NotifyName, const FBranchingPointNotifyPayload& BranchingPointPayload) override;
150
151 //Getters
152
153 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Shooting Component")
154 TArray<FWeaponData_T>& GetWeaponInventory() {return WeaponInventory;};
155 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Shooting Component")
156 int32 GetCurrentWeaponIndex() const {return CurrentWeaponIndex;};
157 //- Returns total Ammo Count - For NPCs to check ammo //
158 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Shooting Component")
159 int32 GetCurrentWeaponAmmo(int32& Current) const;
160 UFUNCTION(BlueprintCallable, Category = "Shooting Component")
161 EWeaponFireMode GetWeaponFireMode() const;
162
163 UFUNCTION(BlueprintCallable, Category = "Player Stats")
164 FPlayerWeaponState GetPlayerWeaponState() const{return PlayerWeaponState;};
165
166 //- Save Load Game //
167 UFUNCTION(BlueprintCallable, Category= "Shooting Component|Save Game")
168 void LoadWeaponsFromSave(const TArray<FWeaponData_T>& LoadedWeapons, const FPlayerWeaponState& LoadedState, const int32 LoadedIndex);
169
170 virtual bool LoadComponentData(const FString& SlotName) override;
171 virtual bool SaveComponentData(const FString& SlotName) override;
172
173
174 //- Recoil Interface //
175 UFUNCTION(BlueprintCallable, Category="Recoil")
176 virtual FTransform GetPivotPoint() override;
177 UFUNCTION(BlueprintCallable, Category="Recoil")
178 virtual FTransform GetRecoilTransform() override;
179
180
181 virtual void RecoilTimer();
182 virtual void RecoilRecoveryTimer();
183 virtual void RecoilStart();
184 virtual void RecoilStop();
185 virtual void RecoilRecoveryStart();
186 virtual void RecoilTick(float DeltaTime);
187
188 virtual void GetTraceParams(FVector& Location, FRotator& Rotation);
189
190 UFUNCTION(BlueprintCallable, Category="Shooting")
191 virtual void SetAccuracy(const float Value){Accuracy = Value;};
192
193 struct FWeaponStats_T GetWeaponStats() const;
194
195 float CalculateAccuracy() const;
196 float CalculateRecoil() const;
197
198 //@TODO Add these to Debugger
199 int32 GetBurstBulletsRemaining() const {return BurstBulletRemaining;};
200
201 AActor* GetCurrentWeaponActor() const {return CurrentWeaponActor;};
202 bool GetTriggerMustWait() const {return bTriggerMustWait;}
203protected:
204 virtual void BeginPlay() override;
205
206
207 //- Animations //
208 UFUNCTION(BlueprintCallable, Category = "Animation|Reload")
209 UAnimMontage* GetReloadAnimation(const EWeaponOverlay WeaponType) const;
210 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Melee Combat")
211 UAnimMontage* GetMeleeAnimation(const EWeaponOverlay WeaponOverlay, const EMeleeWeaponAttack MeleeWeaponAttack = EMeleeWeaponAttack::Default) const;
212 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Melee Combat")
213 UAnimMontage* GetRandomAnimationForMeleeAttack(const TArray<FMeleeWeaponAnim>& WeaponAnims,const EMeleeWeaponAttack MeleeAttackType) const;
214
215
216
217 //- Weapon Activated Functions //
218 UFUNCTION(Server, Unreliable)
219 void ServerRecoil();
220 UFUNCTION()
221 virtual void Recoil();
222
223 class IWeapon* GetWeaponInterface() const;
224 struct FWeaponData_T GetWeaponData() const;
225
226 //- Melee //
227 virtual void MeleeWeaponAttackFinished();
228
229 virtual void BurstFire();
230
231
232 UPROPERTY(Replicated, BlueprintReadOnly, Category="Shooting Component|Hit Reactions")
233 class URecoilAnimationComponent* RecoilAnimationComponent;
234 UPROPERTY(ReplicatedUsing=OnRep_CurrentWeapon, BlueprintReadOnly, Category = "Shooting Component|Weapon")
235 AActor* CurrentWeaponActor;
236
237 //- //
238 //- Melee Animations //
239 //- //
240 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Melee")
241 TArray<FMeleeWeaponAnim> SwordAnims;
242 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Melee")
243 TArray<FMeleeWeaponAnim> SwordShieldAnims;
244 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Melee")
245 TArray<FMeleeWeaponAnim> KnifeAnims;
246 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Melee")
247 TArray<FMeleeWeaponAnim> ChainsawAnims;
248
249
250 UPROPERTY(ReplicatedUsing=OnRep_PlayerWeaponState, VisibleAnywhere, BlueprintReadOnly, Category="Shooting Component|Stats")
251 FPlayerWeaponState PlayerWeaponState;
252 UPROPERTY(ReplicatedUsing=OnRep_CurrentWeaponIndex, VisibleAnywhere, BlueprintReadOnly, Category="Shooting Component|Stats")
253 int32 CurrentWeaponIndex = 0;
254 UPROPERTY(ReplicatedUsing=OnRep_WeaponInventory, VisibleAnywhere, BlueprintReadOnly, Category="Shooting Component|Stats")
255 TArray<FWeaponData_T> WeaponInventory;
256
257 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Shooting Component|Debug")
258 bool bInfiniteAmmo = false;
259 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Shooting Component|Debug")
260 bool bBottomlessClip = false;
261
262
263 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Shooting Component|General")
264 bool bStartingWeapons = false;
265 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Shooting Component|General", meta=(EditCondition=bStartingWeapons))
266 TArray<FString> StartingWeaponIDs;
267
268 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|General")
269 bool bUsePlayerTraceOffset = true;
270 //@TODO Balancing
271
272 //- less than 1 is Low, 5 Is Very high //
273 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting Component|Accuracy", meta=(UIMin = "0.1", UIMax = "10.0"))
274 float Accuracy = 1;
275
276 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|Accuracy")
277 float NPCAccuracyMultiplier = 0.25f;
278 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|Accuracy")
279 float BlindFireAccuracyMultiplier = 0.5f;
280 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|Accuracy")
281 float SlowMoAccuracyMultiplier = 2.0f;
282 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|Accuracy")
283 float CrouchingAccuracyMultiplier = 1.5f;
284 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|Accuracy")
285 float MaxSpeedAccuracyMultiplier = 0.5f;
286 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|Accuracy")
287 float MinSpeedAccuracyMultiplier = 1.5f;
288
289 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooting Component|NPC")
290 bool bHiddenWeaponMesh = false;
291
292private:
293
294 //- Weapon Functions //
295 void ReloadDelay();
296 void CancelReload();
297
298 void UpdateCurrentWeaponInInventory();
299
300 UFUNCTION(Server, Reliable)
301 void Server_UpdateCurrentWeaponInInventory();
302
303 //- Spawn Weapon //
304 UFUNCTION(Category = "Spawn Weapon")
305 void SpawnWeaponActor(const FWeaponData_T& In_WeaponData);
306 UFUNCTION(Server, Reliable, Category = "Spawn Weapon")
307 void Server_SpawnWeaponActor(const FWeaponData_T& In_WeaponData);
308 UFUNCTION(Server, Reliable, Category = "Spawn Weapon")
309 void Server_SetTriggerMustWait(const bool bValue);
310
311 //- Weapon Inventory //
312 void AddWeaponToInventory(FWeaponData_T NewWeapon);
313 void RemoveWeaponFromInventory(const int32 WeaponToRemove);
314 UFUNCTION(Server, Reliable, WithValidation)
315 void ServerAddWeaponToInventory(const FWeaponData_T& NewWeapon);
316 UFUNCTION(Server, Reliable, WithValidation)
317 void ServerRemoveWeaponFromInventory(const int32 WeaponToRemove);
318
319 UFUNCTION(Server, Reliable, WithValidation)
320 void Server_SpawnWeapon(const FWeaponData_T& WeaponSpawned);
321
322 UFUNCTION(Server, Reliable)
323 void Server_SetRecoilComponent();
324
325 //- Replicated Stats //
326 UFUNCTION()
327 void OnRep_CurrentWeapon();
328 UFUNCTION()
329 void OnRep_WeaponInventory();
330 UFUNCTION()
331 void OnRep_CurrentWeaponIndex();
332 UFUNCTION()
333 void OnRep_PlayerWeaponState() const;
334
335 void ReleaseTriggerSpam();
336
337
338 // //- Helper Functions //
339 int32 AddAmmo(const int32 AmountToAdd, const int32 WeaponIndex);
340
341 //- //
342 //- Reload Animations //
343 //- //
344 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Reload")
345 UAnimMontage* PistolReloadAnim;
346 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Reload")
347 UAnimMontage* RifleReloadAnim;
348 UPROPERTY(EditAnywhere, Category= "Shooting Component|Animation|Reload")
349 UAnimMontage* ShotgunReloadAnim;
350 //- Reload Animation Blend out time //
351 UPROPERTY(EditDefaultsOnly, Category = "Shooting Component|Animation")
352 float AnimationBlendOutTime = 0.05f;
353
354
355
356 //- AI Shooting at Target //
357 FRotator TargetRotation = FRotator::ZeroRotator;
358
359
360 //- Stored to be able to call function on //
361 UPROPERTY()
362 UAnimMontage* ReloadAnimation;
363 float LastReloadDuration = 0.0f;
364
365 //- Weapons //
366 UPROPERTY(EditDefaultsOnly, Category = "Shooting Component|Weapon")
367 TSubclassOf<AActor> WeaponClass;
368
369 //- Weapon Spawning/ Pickup //
370 UPROPERTY(EditDefaultsOnly, Category = "Shooting Component|Pickup")
371 TSubclassOf<AActor> WeaponToSpawn;
372 UPROPERTY(EditDefaultsOnly, Category = "Shooting Component|Pickup")
373 float PickupThrowIntensity = 500.0f;
374 UPROPERTY(Replicated)
375 USceneComponent* ThrowPoint;
376
377
378 //- Last time the camera action button is pressed //
379 float SwapWeaponPressedTime = 0.0f;
380 UPROPERTY(EditDefaultsOnly, Category = "Shooting Component|Switch Weapons")
381 float SwapWeaponHoldTime = 0.2f;
382 bool bSwapWeaponPressed = false;
383 UPROPERTY(Replicated, VisibleAnywhere, Category = "Shooting Component|Switch Weapons")
384 bool bTriggerMustWait = false;
385
386
387
388
389 //- Timers //
390 //- Automatic Weapon fire //
391 FTimerHandle ShootingTimerHandle;
392 FTimerHandle ShootingSpamTimerHandle;
393 FTimerHandle ReloadTimerHandle;
394 FTimerHandle WeaponSwapTimerHandle;
395 FTimerHandle UpdatedHUDTimerHandle;
396 FTimerHandle MeleeWeaponTimerHandle;
397 FTimerHandle BurstFireTimerHandle;
398
399 int32 BurstBulletRemaining = 0;
400
401};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnWeaponEqiupped, const TArray< FWeaponData_T > &, Weapons, const int32, CurrentWeaponIndex)
DECLARE_LOG_CATEGORY_EXTERN(LogShootingComponent, Display, All)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWeaponStateChanged, const FPlayerWeaponState &, WeaponState)
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
EWeaponOverlay
Specifies the different weapon overlay types.
Definition WeaponStructs.h:27
EWeaponFireMode
Enum class representing the different fire modes for a weapon.
Definition WeaponStructs.h:99
EMeleeWeaponAttack
Enumeration representing different types of melee weapon attacks.
Definition WeaponStructs.h:61
Definition RecoilInterface.h:17
Definition Weapon.h:18
Represents a character component that can be added to an actor.
Component responsible for managing the shooting behavior of a character.
Definition WeaponStructs.h:260
A struct that represents the state of a player's weapon.
Definition WeaponStructs.h:118
Definition WeaponStructs.h:501
Struct representing data of a weapon that changes.
Definition WeaponStructs.h:861
Represents statistics for a weapon.
Definition WeaponStructs.h:622