Space Plunder
Loading...
Searching...
No Matches
WeaponFramework.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"
6#include "GameFramework/Actor.h"
7#include "Interfaces/Weapon.h"
8#include "WeaponFramework.generated.h"
9
10class UProjectileWeaponComponent;
11class UHitscanWeaponComponent;
12DECLARE_LOG_CATEGORY_EXTERN(LogWeaponFramework, Display, All);
13
14
24// class USpotLightComponent;
25
26UCLASS()
27class WEAPONSYSTEM_API AWeaponFramework : public AActor, public IWeapon
28{
29 GENERATED_BODY()
30
31public:
33
34 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
35 bool bDebuggingMode = false;
36 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
37 bool bInfiniteAmmo = false;
38 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
39 bool bBottomlessClip = false;
40 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
41 float DrawDebugTime = 2.0f;
42 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
43 float DrawDebugColorDarkMultiplier = 0.1f;
44 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
45 float DrawDebugColorLightMultiplier = 2.0f;
46 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
47 float DrawDebugPointSize = 16.0f;
48 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
49 FLinearColor MainTraceColor = FLinearColor(0.9f, 0.1f, 0.1f);
50 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon|Debugging")
51 FLinearColor BlindFireTraceColor = FLinearColor(0.1f, 0.9f, 0.1f);
52
53 UPROPERTY(EditAnywhere, Category = "Weapon|Trace|Debugging")
54 bool bTraceComplex = false;
55 UPROPERTY(EditAnywhere, Category = "Weapon|Trace|Debugging")
56 bool bReturnPhysicalMaterial = false;
57 //@TODO Get the "too close" number right
58 UPROPERTY(EditAnywhere, Category = "Weapon|Trace|Debugging")
59 float TraceDistanceTooClose = 0.075f;
60protected:
61 virtual void BeginPlay() override;
62 virtual void SetupWeaponEffects();
63
64 UFUNCTION(BlueprintCallable, Category="Weapon|Debugging")
65 void LogDebugMessage(const FString& Message, const bool bError = false) const;
66
67 UFUNCTION(Server, Reliable, Category="Weapon")
68 void Server_InitWeapon();
69
70 //~ Weapon Interface Functions ~//
71 virtual void InitWeapon() override;
72
73 virtual void Fire(const FVector Location, const FRotator Rotation, const AActor* ActorToIgnore, const float Accuracy) override;
74 virtual void Reload(const float ReloadTime) override;
75 virtual void CancelReload() override;
76 virtual void SwitchAutoMode() override;
77 virtual void BlindFireWeapon(const FVector Location,const FRotator Rotation, const AActor* ActorToIgnore, const float Accuracy) override;
78
79 virtual void AddAttachment(const FString& AttachmentID) override;
80 virtual void ToggleAttachment(const EAttachmentType& AttachmentType) override;
81
82 virtual void MoveUMG(bool bIsRightShoulder) override;
83 virtual void Aiming(bool bIsAiming) override;
84
85 virtual FWeaponData_T GetWeaponData() const override {return WeaponData;};
86 virtual FWeaponStats_T GetWeaponStats() const override;
87 virtual EWeaponType GetWeaponType() const override{return WeaponType;};
88 virtual EWeaponFireMode GetFireMode() const override {return WeaponData.FireMode;};
89
90 virtual FTransform GetPivotPoint() const override {return RecoilPivotPoint->GetRelativeTransform();};
91 virtual FTransform GetAimDownSightSocket() const override;
92 virtual float GetWeaponFOV() const override;
93
94 virtual bool IsClipEmpty() const override {return WeaponData.CurrentAmmo <= 0;};
95
96 virtual void SetWeaponData(const FWeaponData_T NewWeaponData) override {WeaponData = NewWeaponData;};
97 virtual void SetWeaponShouldAutoReload(const bool bValue) override;
98 virtual void SetWeaponMesh(USkeletalMesh* SkeletalMesh) override;
99 virtual void SetMuzzleOffset(const FVector& Location, const FRotator& Rotation) override;
100 virtual void SetRecoilPivotPoint(const FVector& Location, const FRotator& Rotation) override;
101
102 virtual void SetWeaponMeshHidden(const bool bValue) override;
103 UFUNCTION(NetMulticast, Reliable)
104 void Multicast_SetWeaponMeshHidden(const bool bValue);
105
106 virtual void SetDebuggingStats(const bool bDebug, const bool bInfinite, const bool bBottomless) override {bDebuggingMode = bDebug; bInfiniteAmmo = bInfinite, bBottomlessClip = bBottomless;};
107
108 //~ Weapon Interface Functions ~//
109
110 UFUNCTION(BlueprintCallable, Category="Weapons")
111 virtual void ToggleLaser(const bool bForceOff = false);
112
113
114 //- Blueprint Functions //
115 UFUNCTION(BlueprintImplementableEvent, Category = "Weapon", meta=(DisplayName = "Fire"))
116 void ReceiveFire(FHitResult Hit, APawn* InstigatorPawn);
117
118
120 UFUNCTION(BlueprintCallable, Category = "Weapon|Attachments")
121 TArray<FWeaponModifiers> GetAllWeaponAttachmentModifiers() const;
122 UFUNCTION(BlueprintCallable, Category = "Weapon|Attachments")
123 TArray<FWeaponAttachment> GetAllWeaponAttachments() const;
124 UFUNCTION(BlueprintCallable, Category = "Weapon|Attachments")
125 FWeaponAttachment GetWeaponAttachment(const FString& AttachmentID) const;
126 UFUNCTION(BlueprintCallable, Category = "Weapon|Attachments")
127 bool RemoveAttachment(const FString AttachmentID, const EAttachmentType AttachmentType);
128 UFUNCTION(BlueprintCallable, Category = "Weapon|Attachments")
129 void RemoveAllAttachments();
130
131
132 bool CanShoot() const;
133 float GetAccuracyMultiplier() const {return AccuracyMultiplier;};
134
135
136 void ApplyDamageToActor(const FHitResult& Hit, FVector ShotDirection, float Multiplier = 1.0f);
137
138 //- Multiplayer //
139 UFUNCTION(Server, Reliable)
140 void ServerFire(const FVector Location,const FRotator Rotation, const AActor* ActorToIgnore, const float Accuracy);
141 UFUNCTION(Server, Reliable, WithValidation)
142 virtual void ServerShoot();
143 UFUNCTION(Server, Reliable)
144 void ServerSetReloading(const bool bReloading);
145 UFUNCTION(Server, Reliable)
146 void ServerReload();
147 UFUNCTION(Server, Reliable, Category = "Weapons|ADS")
148 virtual void Server_SetWeaponShouldAutoReload(const bool bValue);
149
150 void CalculateBulletSpread(FVector& NewBulletSpread) const;
151
152 //@ MOVE TO HITSCAN //
153 virtual float CalculateDistanceDamage(const float Distance) const;
154 virtual FHitResult BlindFireWeaponTrace(const float Accuracy, const AActor* ActorToIgnore = nullptr);
155 virtual bool LineTrace(FHitResult& Hit, FVector& ShotDirection, const FLinearColor& Color = FLinearColor::Green, const FVector& CustomLineEnd = FVector::ZeroVector) const;
156
157
158 UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadOnly, Category="Weapon|Components")
159 UHitscanWeaponComponent* HitscanWeaponComponent;
160 UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadOnly, Category="Weapon|Components")
161 UProjectileWeaponComponent* ProjectileWeaponComponent;
162
163 UPROPERTY()
164 FVector TraceLocation;
165 FRotator TraceRotation;
166
167 UPROPERTY()
168 const AActor* TraceActorToIgnore;
169 UPROPERTY()
170 TArray<AActor*> ActorsToIgnore;
171
172 UPROPERTY()
173 APawn* OwnerPawn;
174
175 UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadOnly, Category="Weapon|Weapon Data")
176 FWeaponData_T WeaponData;
177 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Weapon|General")
179
180
181 //- Gun Visual Components //
182 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
183 USceneComponent* SceneRoot;
184 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
185 USkeletalMeshComponent* GunMeshComponent;
186 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
187 USceneComponent* Muzzle;
188 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
189 USceneComponent* RecoilPivotPoint;
190 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
191 TArray<UStaticMeshComponent*> AttachmentComponents;
192 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
193 class UWeaponEffectsComponent* WeaponEffects;
194
195 UFUNCTION()
196 void OnMeshReplicated();
197
198 UFUNCTION()
199 void OnRep_WeaponStats();
200
201 UPROPERTY(ReplicatedUsing=OnMeshReplicated, VisibleAnywhere, BlueprintReadOnly, Category = "Weapon|Components")
202 USkeletalMesh* WeaponMesh;
203
204 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Projectile")
205 TSubclassOf<class AActor> ProjectileClass;
206
207
208private:
209 void SetWeaponFireMode();
210 void AddWeaponAttachments();
211
212 void ShootHitScan();
213 void ShootProjectile();
214 UPROPERTY(ReplicatedUsing=OnRep_WeaponStats, VisibleAnywhere, Category = "Weapon|Status")
215 FWeaponStats_T CurrentWeaponStats;
216
217
218 bool bWeaponEffectsSetup = false;
219 float AccuracyMultiplier = 1.0f;
220 bool bLaserOn = false;
221
222 bool bIsBeingReloaded;
223 FTimerHandle ReloadTimerHandle;
224};
225
226
227
228
229
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
DECLARE_LOG_CATEGORY_EXTERN(LogWeaponFramework, Display, All)
EWeaponType
Represents the types of weapons available in the game.
Definition WeaponStructs.h:83
EWeaponFireMode
Enum class representing the different fire modes for a weapon.
Definition WeaponStructs.h:99
EAttachmentType
Enum class representing different types of weapon attachments.
Definition WeaponStructs.h:150
A weapon base class.
Definition WeaponFramework.h:28
virtual EWeaponFireMode GetFireMode() const override
Definition WeaponFramework.h:88
virtual EWeaponType GetWeaponType() const override
Definition WeaponFramework.h:87
virtual FTransform GetPivotPoint() const override
Definition WeaponFramework.h:90
virtual void SetWeaponData(const FWeaponData_T NewWeaponData) override
Definition WeaponFramework.h:96
virtual bool IsClipEmpty() const override
Definition WeaponFramework.h:94
Definition Weapon.h:18
Definition WeaponStructs.h:501
Struct representing data of a weapon that changes.
Definition WeaponStructs.h:861
Definition WeaponStructs.h:433
Represents statistics for a weapon.
Definition WeaponStructs.h:622