Space Plunder
Loading...
Searching...
No Matches
AWeaponFramework Class Reference

A weapon base class. More...

#include <WeaponFramework.h>

Inheritance diagram for AWeaponFramework:
IWeapon AHitscanWeaponFramework AMeleeWeaponFramework AProjectileWeaponFramework

Public Member Functions

 AWeaponFramework ()
 

Public Attributes

bool bDebuggingMode = false
 
bool bInfiniteAmmo = false
 
bool bBottomlessClip = false
 
float DrawDebugTime = 2.0f
 
float DrawDebugColorDarkMultiplier = 0.1f
 
float DrawDebugColorLightMultiplier = 2.0f
 
float DrawDebugPointSize = 16.0f
 
FLinearColor MainTraceColor = FLinearColor(0.9f, 0.1f, 0.1f)
 
FLinearColor BlindFireTraceColor = FLinearColor(0.1f, 0.9f, 0.1f)
 
bool bTraceComplex = false
 
bool bReturnPhysicalMaterial = false
 
float TraceDistanceTooClose = 0.075f
 

Protected Member Functions

virtual void BeginPlay () override
 
virtual void SetupWeaponEffects ()
 
void LogDebugMessage (const FString &Message, const bool bError=false) const
 
void Server_InitWeapon ()
 
virtual void InitWeapon () override
 
virtual void Fire (const FVector Location, const FRotator Rotation, const AActor *ActorToIgnore, const float Accuracy) override
 
virtual void Reload (const float ReloadTime) override
 
virtual void CancelReload () override
 
virtual void SwitchAutoMode () override
 
virtual void BlindFireWeapon (const FVector Location, const FRotator Rotation, const AActor *ActorToIgnore, const float Accuracy) override
 
virtual void AddAttachment (const FString &AttachmentID) override
 
virtual void ToggleAttachment (const EAttachmentType &AttachmentType) override
 
virtual void MoveUMG (bool bIsRightShoulder) override
 
virtual void Aiming (bool bIsAiming) override
 
virtual FWeaponData_T GetWeaponData () const override
 
virtual FWeaponStats_T GetWeaponStats () const override
 
virtual EWeaponType GetWeaponType () const override
 
virtual EWeaponFireMode GetFireMode () const override
 
virtual FTransform GetPivotPoint () const override
 
virtual FTransform GetAimDownSightSocket () const override
 
virtual float GetWeaponFOV () const override
 
virtual bool IsClipEmpty () const override
 
virtual void SetWeaponData (const FWeaponData_T NewWeaponData) override
 
virtual void SetWeaponShouldAutoReload (const bool bValue) override
 
virtual void SetWeaponMesh (USkeletalMesh *SkeletalMesh) override
 
virtual void SetMuzzleOffset (const FVector &Location, const FRotator &Rotation) override
 
virtual void SetRecoilPivotPoint (const FVector &Location, const FRotator &Rotation) override
 
virtual void SetWeaponMeshHidden (const bool bValue) override
 
void Multicast_SetWeaponMeshHidden (const bool bValue)
 
virtual void SetDebuggingStats (const bool bDebug, const bool bInfinite, const bool bBottomless) override
 
virtual void ToggleLaser (const bool bForceOff=false)
 
void ReceiveFire (FHitResult Hit, APawn *InstigatorPawn)
 
TArray< FWeaponModifiersGetAllWeaponAttachmentModifiers () const
 
TArray< FWeaponAttachmentGetAllWeaponAttachments () const
 
FWeaponAttachment GetWeaponAttachment (const FString &AttachmentID) const
 
bool RemoveAttachment (const FString AttachmentID, const EAttachmentType AttachmentType)
 
void RemoveAllAttachments ()
 
bool CanShoot () const
 
float GetAccuracyMultiplier () const
 
void ApplyDamageToActor (const FHitResult &Hit, FVector ShotDirection, float Multiplier=1.0f)
 
void ServerFire (const FVector Location, const FRotator Rotation, const AActor *ActorToIgnore, const float Accuracy)
 
virtual void ServerShoot ()
 
void ServerSetReloading (const bool bReloading)
 
void ServerReload ()
 
virtual void Server_SetWeaponShouldAutoReload (const bool bValue)
 
void CalculateBulletSpread (FVector &NewBulletSpread) const
 
virtual float CalculateDistanceDamage (const float Distance) const
 
virtual FHitResult BlindFireWeaponTrace (const float Accuracy, const AActor *ActorToIgnore=nullptr)
 
virtual bool LineTrace (FHitResult &Hit, FVector &ShotDirection, const FLinearColor &Color=FLinearColor::Green, const FVector &CustomLineEnd=FVector::ZeroVector) const
 
void OnMeshReplicated ()
 
void OnRep_WeaponStats ()
 

Protected Attributes

UHitscanWeaponComponent * HitscanWeaponComponent
 
UProjectileWeaponComponent * ProjectileWeaponComponent
 
FVector TraceLocation
 
FRotator TraceRotation
 
const AActor * TraceActorToIgnore
 
TArray< AActor * > ActorsToIgnore
 
APawn * OwnerPawn
 
FWeaponData_T WeaponData
 
EWeaponType WeaponType = EWeaponType::Default
 
USceneComponent * SceneRoot
 
USkeletalMeshComponent * GunMeshComponent
 
USceneComponent * Muzzle
 
USceneComponent * RecoilPivotPoint
 
TArray< UStaticMeshComponent * > AttachmentComponents
 
class UWeaponEffectsComponent * WeaponEffects
 
USkeletalMesh * WeaponMesh
 
TSubclassOf< class AActor > ProjectileClass
 

Private Member Functions

void SetWeaponFireMode ()
 
void AddWeaponAttachments ()
 
void ShootHitScan ()
 
void ShootProjectile ()
 

Private Attributes

FWeaponStats_T CurrentWeaponStats
 
bool bWeaponEffectsSetup = false
 
float AccuracyMultiplier = 1.0f
 
bool bLaserOn = false
 
bool bIsBeingReloaded
 
FTimerHandle ReloadTimerHandle
 

Detailed Description

A weapon base class.

This class represents a weapon in the game. It inherits from AActor, IWeapon, and IBaseInterface. It provides functionality for firing, reloading, switching fire mode, aiming, and other weapon-related actions.

See also
WeaponFramework

Constructor & Destructor Documentation

◆ AWeaponFramework()

AWeaponFramework::AWeaponFramework ( )
21{
22 PrimaryActorTick.bCanEverTick = false;
23 bReplicates = true;
24
25 SceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Scene Root"));
26 RootComponent = SceneRoot;
27 GunMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Gun Mesh"));
28 GunMeshComponent->SetupAttachment(SceneRoot);
29 // RootComponent = GunMeshComponent;
30 Muzzle = CreateDefaultSubobject<USceneComponent>(TEXT("Muzzle Location"));
31 Muzzle->SetupAttachment(GunMeshComponent);
32 RecoilPivotPoint = CreateDefaultSubobject<USceneComponent>(TEXT("Recoil Pivot Point"));
33 RecoilPivotPoint->SetupAttachment(GunMeshComponent);
34
35 WeaponEffects = CreateDefaultSubobject<UWeaponEffectsComponent>(TEXT("Weapon Effects"));
36 HitscanWeaponComponent = CreateDefaultSubobject<UHitscanWeaponComponent>(TEXT("Hit Scan"));
37 ProjectileWeaponComponent = CreateDefaultSubobject<UProjectileWeaponComponent>(TEXT("Projectiles"));
38
39 ProjectileClass = UBaseHelpersBPLib::GetDefaultActorBPClass("/WeaponSystem/Weapons/Projectiles/BP_ProjectileBase");
40}
UHitscanWeaponComponent * HitscanWeaponComponent
Definition WeaponFramework.h:159
USceneComponent * RecoilPivotPoint
Definition WeaponFramework.h:189
USkeletalMeshComponent * GunMeshComponent
Definition WeaponFramework.h:185
UProjectileWeaponComponent * ProjectileWeaponComponent
Definition WeaponFramework.h:161
USceneComponent * SceneRoot
Definition WeaponFramework.h:183
class UWeaponEffectsComponent * WeaponEffects
Definition WeaponFramework.h:193
TSubclassOf< class AActor > ProjectileClass
Definition WeaponFramework.h:205
USceneComponent * Muzzle
Definition WeaponFramework.h:187
static TSubclassOf< AActor > GetDefaultActorBPClass(const FString &Location)
Definition BaseHelpersBPLib.cpp:217

Member Function Documentation

◆ AddAttachment()

void AWeaponFramework::AddAttachment ( const FString & AttachmentID)
overrideprotectedvirtual

Attachments

Implements IWeapon.

205{
206 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
207 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::AddAttachment);
208 bool bSuccess = false;
209 const FWeaponAttachment WeaponAttachment = UWeaponBPLib::GetWeaponAttachment(this, AttachmentID, bSuccess);
210 if(!bSuccess){return;}
211 if(!WeaponAttachment.IsValid()){return;}
212 if(!GunMeshComponent->DoesSocketExist(WeaponAttachment.AttachmentTypeName())){return;}
213 if(!GetWeaponStats().GetIsAttachmentCompatible(AttachmentID, WeaponAttachment.AttachmentType))
214 {
215 RemoveAttachment(AttachmentID, WeaponAttachment.AttachmentType);
216 return;
217 }
218 UStaticMeshComponent* AttachmentComponent = NewObject<UStaticMeshComponent>(this);
219 if(AttachmentComponent == nullptr){return;}
220 AttachmentComponent->RegisterComponent();
221 AttachmentComponent->SetStaticMesh(WeaponAttachment.StaticMesh);
222 AttachmentComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
223 AttachmentComponent->AttachToComponent(GunMeshComponent, FAttachmentTransformRules::SnapToTargetIncludingScale, WeaponAttachment.AttachmentTypeName());
224 AttachmentComponent->ComponentTags.Add(FName(WeaponAttachment.WeaponAttachmentID));
225 AttachmentComponent->ComponentTags.Add(WeaponAttachment.AttachmentTypeName());
226 AttachmentComponent->SetRelativeLocation(WeaponAttachment.AttachmentOffset);
227 AttachmentComponent->SetRelativeRotation(WeaponAttachment.AttachmentRotationOffset);
228 if(WeaponAttachment.bModifyMuzzleLocation && Muzzle != nullptr)
229 {
230 Muzzle->SetRelativeLocation(WeaponAttachment.MuzzleOffset);
231 }
232 WeaponData.AddAttachment(AttachmentID);
233 ToggleAttachment(WeaponAttachment.AttachmentType);
234
235 AttachmentComponents.Add(AttachmentComponent);
236}
virtual void AddAttachment(const FString &AttachmentID) override
Definition WeaponFramework.cpp:204
bool RemoveAttachment(const FString AttachmentID, const EAttachmentType AttachmentType)
Definition WeaponFramework.cpp:254
virtual FWeaponStats_T GetWeaponStats() const override
Definition WeaponFramework.cpp:900
TArray< UStaticMeshComponent * > AttachmentComponents
Definition WeaponFramework.h:191
FWeaponData_T WeaponData
Definition WeaponFramework.h:176
virtual void ToggleAttachment(const EAttachmentType &AttachmentType) override
Definition WeaponFramework.cpp:238
static FWeaponAttachment GetWeaponAttachment(const UObject *WorldContextObject, const FString &WeaponAttachmentID, bool &bSuccess, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:235
Definition WeaponStructs.h:501
void AddAttachment(const FString &AttachmentID)
Definition WeaponStructs.h:920

◆ AddWeaponAttachments()

void AWeaponFramework::AddWeaponAttachments ( )
private
111{
112 // RemoveAllAttachments();
113 for(const FString& WeaponAttachmentID : WeaponData.CurrentWeaponAttachments)
114 {
115 AddAttachment(WeaponAttachmentID);
116 }
117}

◆ Aiming()

void AWeaponFramework::Aiming ( bool bIsAiming)
overrideprotectedvirtual

Implements IWeapon.

Reimplemented in AProjectileWeaponFramework.

896{
897 // LogDebugMessage("Aiming Function");
898}

◆ ApplyDamageToActor()

void AWeaponFramework::ApplyDamageToActor ( const FHitResult & Hit,
FVector ShotDirection,
float Multiplier = 1.0f )
protected
704{
705 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::ApplyDamageToActor);
706 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
707 LogDebugMessage(FString::Printf(TEXT("Damage Multipler %f"), Multiplier));
708 //- Multiplier should never be 0 //
709 if(Multiplier <= 0.0f){Multiplier = 1.0f;}
710 //? FVector TracerEndPoint = Hit.TraceEnd;
711 //? EPhysicalSurface SurfaceType;
712 //? int SurfaceIndex;
713 //? FVector TracerEndPoint = Hit.ImpactPoint;
714 //? PlayImpactEffects(SurfaceIndex, TracerEndPoint);
715
716 if(Hit.GetActor() == nullptr){return;}
717 //? Hit.ImpactNormal * -1; - not as Realistic, but it's more satisfying, i.e. you shoot a box, the force will come from the face it was hit
718 ShotDirection *= -1;
719 AController* EventInstigator = nullptr;
720 if(TraceActorToIgnore != nullptr)
721 {
722 EventInstigator = TraceActorToIgnore->GetInstigatorController();
723 }
724 UGameplayStatics::ApplyPointDamage(Hit.GetActor(), (GetWeaponStats().DefaultDamage * Multiplier), ShotDirection, Hit, EventInstigator, this, GetWeaponStats().DamageType);
725 WeaponEffects->WeaponDamageEvent(Hit.GetActor(), GetWeaponStats().DefaultDamage, GetActorLocation(), Hit.Location, FName("WeaponDamage"));
726}
const AActor * TraceActorToIgnore
Definition WeaponFramework.h:168
void LogDebugMessage(const FString &Message, const bool bError=false) const
Definition WeaponFramework.cpp:323
void ApplyDamageToActor(const FHitResult &Hit, FVector ShotDirection, float Multiplier=1.0f)
Definition WeaponFramework.cpp:703

◆ BeginPlay()

void AWeaponFramework::BeginPlay ( )
overrideprotectedvirtual

Reimplemented in AProjectileWeaponFramework.

43{
44 Super::BeginPlay();
45}

◆ BlindFireWeapon()

void AWeaponFramework::BlindFireWeapon ( const FVector Location,
const FRotator Rotation,
const AActor * ActorToIgnore,
const float Accuracy )
overrideprotectedvirtual

Implements IWeapon.

332{
333 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
334 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::BlindFireWeapon);
335 //@ TODO This should call a different function, or set something, currently does the same as Fire?
336 Fire(Location, Rotation, ActorToIgnore, Accuracy);
337}
virtual void BlindFireWeapon(const FVector Location, const FRotator Rotation, const AActor *ActorToIgnore, const float Accuracy) override
Definition WeaponFramework.cpp:331

◆ BlindFireWeaponTrace()

FHitResult AWeaponFramework::BlindFireWeaponTrace ( const float Accuracy,
const AActor * ActorToIgnore = nullptr )
protectedvirtual

Reimplemented in AHitscanWeaponFramework.

340{
341 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
342 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::BlindFireWeaponTrace);
343 // //- Linetrace but from the MuzzleLocation //
344 // //- V2 has the LineEnd calculated from the Muzzle Location //
345 TraceLocation = Muzzle->GetComponentLocation();
346 FHitResult BlindFireHit;
347 FVector ShotDirection;
348 LineTrace(BlindFireHit, ShotDirection, BlindFireTraceColor);
349 //- Apply Damage //
350 if(BlindFireHit.GetActor() != nullptr)
351 {
352 ApplyDamageToActor(BlindFireHit, ShotDirection, CalculateDistanceDamage(BlindFireHit.Distance));
353 }
354 return BlindFireHit;
355}
FLinearColor BlindFireTraceColor
Definition WeaponFramework.h:51
virtual bool LineTrace(FHitResult &Hit, FVector &ShotDirection, const FLinearColor &Color=FLinearColor::Green, const FVector &CustomLineEnd=FVector::ZeroVector) const
Definition WeaponFramework.cpp:658
virtual FHitResult BlindFireWeaponTrace(const float Accuracy, const AActor *ActorToIgnore=nullptr)
Definition WeaponFramework.cpp:339
virtual float CalculateDistanceDamage(const float Distance) const
Definition WeaponFramework.cpp:770
FVector TraceLocation
Definition WeaponFramework.h:164

◆ CalculateBulletSpread()

void AWeaponFramework::CalculateBulletSpread ( FVector & NewBulletSpread) const
protected
730{
731 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::CalculateBulletSpread);
732 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
733
734 if(GetOwner() == nullptr){NewBulletSpread = FVector::ZeroVector; return;}
735 float OwnerSpeed = GetOwner()->GetVelocity().Size();
736 //- Still //
737 if(OwnerSpeed < 10)
738 {
739 //@ TODO Add these Number to WeaponData Struct
740 //- If Full Auto Weapon is in Single Mode, Apply Bonus //
741 if(GetWeaponStats().bHasAutoMode && WeaponData.FireMode == EWeaponFireMode::Single) {OwnerSpeed = 0.65f;}
742 //- if Auto Weapon is in Burst Mode //
743 else if(GetWeaponStats().bHasAutoMode && WeaponData.FireMode == EWeaponFireMode::Burst) {OwnerSpeed = 0.85f;}
744 //- If Burst Weapon is in single Apply Bonus //
745 else if(GetWeaponStats().bHasBurstMode && WeaponData.FireMode == EWeaponFireMode::Single){OwnerSpeed = 0.75f;}
746 else{OwnerSpeed = 1.0f;}
747 }
748 //- Moving //
749 else
750 {
751 //- If Full Auto Weapon is in Single Mode, Apply Bonus //
752 if(GetWeaponStats().bHasAutoMode && WeaponData.FireMode == EWeaponFireMode::Single) {OwnerSpeed = 1.25f;}
753 //- if Auto Weapon is in Burst Mode //
754 else if(GetWeaponStats().bHasAutoMode && WeaponData.FireMode == EWeaponFireMode::Burst) {OwnerSpeed = 1.45f;}
755 //- If Burst Weapon is in single Apply Bonus //
756 else if(GetWeaponStats().bHasBurstMode && WeaponData.FireMode == EWeaponFireMode::Single){OwnerSpeed = 1.35f;}
757
758 else{OwnerSpeed = 1.75f;}
759 }
760 OwnerSpeed = (OwnerSpeed / AccuracyMultiplier);
761
762 // - Random Variation to X and Y axis //
763 const float Spread = GetWeaponStats().BulletSpread * OwnerSpeed;
764 const float BulletX = FMath::RandRange((Spread * -1), Spread);
765 const float BulletY = FMath::RandRange((Spread * -1), Spread);
766 const float BulletZ = FMath::RandRange((Spread * -1), Spread);
767 NewBulletSpread = FVector(BulletX,BulletY,BulletZ);
768}
void CalculateBulletSpread(FVector &NewBulletSpread) const
Definition WeaponFramework.cpp:729
float AccuracyMultiplier
Definition WeaponFramework.h:219
EWeaponFireMode FireMode
Definition WeaponStructs.h:870
float BulletSpread
Definition WeaponStructs.h:673

◆ CalculateDistanceDamage()

float AWeaponFramework::CalculateDistanceDamage ( const float Distance) const
protectedvirtual

Reimplemented in AHitscanWeaponFramework.

771{
772 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
773 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::CalculateDistanceDamage);
774 const float MaxDamageMultiplier = GetWeaponStats().MaxDamageMultiplier;
775 const float MinDamageMultiplier = GetWeaponStats().MinDamageMultiplier;
776 const float WeaponRangeMin = GetWeaponStats().WeaponRangeMin;
777 const float WeaponRangeMax = GetWeaponStats().WeaponRangeMax;
778 //- Full damage up to WeaponRangeMin
779 if (Distance <= WeaponRangeMin)
780 {
781 LogDebugMessage(FString::Printf(TEXT("Weapon Distance %.2f Multiplier: %.2f (BELOW MIN DISTANCE = MAX Multiplier)"), Distance, MaxDamageMultiplier));
782 return MaxDamageMultiplier;
783 }
784 //- Damage decreases linearly between WeaponRangeMin and WeaponRangeMax
785 if (Distance <= WeaponRangeMax)
786 {
787 const float Alpha = (Distance - WeaponRangeMin) / (WeaponRangeMax - WeaponRangeMin);
788 LogDebugMessage(FString::Printf(TEXT("Weapon Distance %.2f Multiplier: %.2f (IN BETWEEN DISTANCE)"), Distance, FMath::Lerp(MaxDamageMultiplier, MinDamageMultiplier, Alpha)));
789 return FMath::Lerp(MaxDamageMultiplier, MinDamageMultiplier, Alpha);
790 }
791 //- Constant minimum damage beyond WeaponRangeMax
792 LogDebugMessage(FString::Printf(TEXT("Weapon Distance %.2f Multiplier: %.2f (FATHER THAN MAX DISTANCE = MIN MULTIPLIER)"), Distance, MinDamageMultiplier));
793 return MinDamageMultiplier;
794 return 0.0f;
795}
float MaxDamageMultiplier
Definition WeaponStructs.h:685
float WeaponRangeMax
Definition WeaponStructs.h:682
float MinDamageMultiplier
Definition WeaponStructs.h:688
float WeaponRangeMin
Definition WeaponStructs.h:679

◆ CancelReload()

void AWeaponFramework::CancelReload ( )
overrideprotectedvirtual

Implements IWeapon.

845{
846 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
847 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::CancelReload);
848 ServerSetReloading(false);
849}
void ServerSetReloading(const bool bReloading)
virtual void CancelReload() override
Definition WeaponFramework.cpp:844

◆ CanShoot()

bool AWeaponFramework::CanShoot ( ) const
protected
966{
967 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
968 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::CanShoot);
969 if(bIsBeingReloaded) return false;
970 if(WeaponData.CurrentAmmo <= 0) return false;
971 return true;
972}
bool CanShoot() const
Definition WeaponFramework.cpp:965
bool bIsBeingReloaded
Definition WeaponFramework.h:222
int32 CurrentAmmo
Definition WeaponStructs.h:880

◆ Fire()

void AWeaponFramework::Fire ( const FVector Location,
const FRotator Rotation,
const AActor * ActorToIgnore,
const float Accuracy )
overrideprotectedvirtual

Shooting

Implements IWeapon.

358{
359 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::Fire);
360 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
361
363 if(OwnerPawn != nullptr && OwnerPawn->GetController() != nullptr)
364 {
365 APlayerController* OwnerController = Cast<APlayerController>(OwnerPawn->GetController());
366 //- only camera shake and vibrate if we got ammo
367 if(CanShoot() && OwnerController != nullptr && OwnerController->IsLocalController())
368 {
369 WeaponEffects->PlayFeedbackEffects(OwnerController, WeaponData.FireMode, Accuracy);
370 }
371 }
372 ServerFire(Location, Rotation, ActorToIgnore, Accuracy);
373}
virtual void Fire(const FVector Location, const FRotator Rotation, const AActor *ActorToIgnore, const float Accuracy) override
Definition WeaponFramework.cpp:357
void ServerFire(const FVector Location, const FRotator Rotation, const AActor *ActorToIgnore, const float Accuracy)
bool bWeaponEffectsSetup
Definition WeaponFramework.h:218
APawn * OwnerPawn
Definition WeaponFramework.h:173
virtual void SetupWeaponEffects()
Definition WeaponFramework.cpp:310

◆ GetAccuracyMultiplier()

float AWeaponFramework::GetAccuracyMultiplier ( ) const
inlineprotected
133{return AccuracyMultiplier;};

◆ GetAimDownSightSocket()

FTransform AWeaponFramework::GetAimDownSightSocket ( ) const
overrideprotectedvirtual

Implements IWeapon.

920{
921 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
922 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::GetAimDownSightSocket);
923 if(GunMeshComponent == nullptr){return FTransform(FVector(1));}
924 if(GunMeshComponent->DoesSocketExist(FName("ADS_Socket")) == false){return FTransform(FVector(1));}
925 return GunMeshComponent->GetSocketTransform(FName("ADS_Socket"));
926}
virtual FTransform GetAimDownSightSocket() const override
Definition WeaponFramework.cpp:919

◆ GetAllWeaponAttachmentModifiers()

TArray< FWeaponModifiers > AWeaponFramework::GetAllWeaponAttachmentModifiers ( ) const
protected

Weapon Attachments

168{
169 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
170 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::GetAllWeaponAttachmentModifiers);
171 TArray<FWeaponModifiers> Modifiers;
172 for(const auto& Attachment : GetAllWeaponAttachments())
173 {
174 Modifiers.Add(Attachment.WeaponStatModifiers);
175 }
176 return Modifiers;
177}
TArray< FWeaponAttachment > GetAllWeaponAttachments() const
Definition WeaponFramework.cpp:179
TArray< FWeaponModifiers > GetAllWeaponAttachmentModifiers() const
Definition WeaponFramework.cpp:167

◆ GetAllWeaponAttachments()

TArray< FWeaponAttachment > AWeaponFramework::GetAllWeaponAttachments ( ) const
protected
180{
181 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
182 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::GetAllWeaponAttachments);
183 TArray<FWeaponAttachment> Attachments;
184 for(const FString& WeaponAttachmentID : WeaponData.CurrentWeaponAttachments)
185 {
186 Attachments.Add(GetWeaponAttachment(WeaponAttachmentID));
187 }
188 return Attachments;
189}
FWeaponAttachment GetWeaponAttachment(const FString &AttachmentID) const
Definition WeaponFramework.cpp:191

◆ GetFireMode()

virtual EWeaponFireMode AWeaponFramework::GetFireMode ( ) const
inlineoverrideprotectedvirtual

Implements IWeapon.

88{return WeaponData.FireMode;};

◆ GetPivotPoint()

virtual FTransform AWeaponFramework::GetPivotPoint ( ) const
inlineoverrideprotectedvirtual

Implements IWeapon.

90{return RecoilPivotPoint->GetRelativeTransform();};

◆ GetWeaponAttachment()

FWeaponAttachment AWeaponFramework::GetWeaponAttachment ( const FString & AttachmentID) const
protected
192{
193 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
194 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::GetWeaponAttachment);
195 bool bSuccess = false;
197 if(bSuccess)
198 {
199 return WeaponAttachment;
200 }
202}
static FWeaponAttachment Empty()
Definition WeaponStructs.h:538

◆ GetWeaponData()

virtual FWeaponData_T AWeaponFramework::GetWeaponData ( ) const
inlineoverrideprotectedvirtual

Get Weapon infos

Implements IWeapon.

85{return WeaponData;};

◆ GetWeaponFOV()

float AWeaponFramework::GetWeaponFOV ( ) const
overrideprotectedvirtual

Implements IWeapon.

929{
930 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
931 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::GetWeaponFOV);
932 const FWeaponStats_T WeaponStats = GetWeaponStats();
933 if(WeaponStats.IsValid() == false){return 0.0f;}
934 return WeaponStats.FOV;
935}
virtual float GetWeaponFOV() const override
Definition WeaponFramework.cpp:928
Represents statistics for a weapon.
Definition WeaponStructs.h:622
bool IsValid() const
Definition WeaponStructs.h:842
float FOV
Definition WeaponStructs.h:647

◆ GetWeaponStats()

FWeaponStats_T AWeaponFramework::GetWeaponStats ( ) const
overrideprotectedvirtual

Implements IWeapon.

901{
902 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
903 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::GetWeaponStats);
904 FWeaponStats_T WeaponStats;
905 if(CurrentWeaponStats.IsValid() == false)
906 {
907 bool bSuccess = false;
908 WeaponStats = UWeaponBPLib::GetWeaponStats(this, WeaponData.WeaponID, bSuccess);
909 if(!bSuccess){LogDebugMessage("AWeaponFramework::GetWeaponStats WeaponStats", true);}
910 }
911 else
912 {
913 WeaponStats = CurrentWeaponStats;
914 }
915 WeaponStats = WeaponStats.AddModifiers(GetAllWeaponAttachmentModifiers());
916 return WeaponStats;
917}
FWeaponStats_T CurrentWeaponStats
Definition WeaponFramework.h:215
static FWeaponStats_T GetWeaponStats(const UObject *WorldContextObject, const FString &WeaponID, bool &bSuccess, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:176
FString WeaponID
Definition WeaponStructs.h:866
FWeaponStats_T AddModifiers(const TArray< FWeaponModifiers > &Modifiers)
Definition WeaponStructs.h:793

◆ GetWeaponType()

virtual EWeaponType AWeaponFramework::GetWeaponType ( ) const
inlineoverrideprotectedvirtual

Implements IWeapon.

87{return WeaponType;};
EWeaponType WeaponType
Definition WeaponFramework.h:178

◆ InitWeapon()

void AWeaponFramework::InitWeapon ( )
overrideprotectedvirtual

Implements IWeapon.

48{
49 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::InitWeapon);
50 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
51 if(HasAuthority())
52 {
53 bool bSuccess = false;
55 if(!bSuccess){LogDebugMessage("AWeaponFramework::InitWeapon CurrentWeaponStats", true);}
59 ActorsToIgnore.Emplace(this);
60 ActorsToIgnore.Emplace(GetOwner());
61 if(GunMeshComponent != nullptr)
62 {
65 LogDebugMessage(FString::Printf(TEXT("InitWeapon Set Relative LocatioN: %s"), *CurrentWeaponStats.RotationOffset.ToString()));
66 }
68 }
70}
void AddWeaponAttachments()
Definition WeaponFramework.cpp:110
void SetWeaponFireMode()
Definition WeaponFramework.cpp:96
virtual void InitWeapon() override
Definition WeaponFramework.cpp:47
void Server_InitWeapon()
TArray< AActor * > ActorsToIgnore
Definition WeaponFramework.h:170
void OnRep_WeaponStats()
Definition WeaponFramework.cpp:84
FVector WeaponOffset
Definition WeaponStructs.h:718
FRotator RotationOffset
Definition WeaponStructs.h:720

◆ IsClipEmpty()

virtual bool AWeaponFramework::IsClipEmpty ( ) const
inlineoverrideprotectedvirtual

Implements IWeapon.

94{return WeaponData.CurrentAmmo <= 0;};

◆ LineTrace()

bool AWeaponFramework::LineTrace ( FHitResult & Hit,
FVector & ShotDirection,
const FLinearColor & Color = FLinearColor::Green,
const FVector & CustomLineEnd = FVector::ZeroVector ) const
protectedvirtual

Reimplemented in AHitscanWeaponFramework.

659{
660 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::LineTrace);
661 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
662 const FVector ForwardVector = (FRotationMatrix(TraceRotation).GetScaledAxis( EAxis::X ));
663 FVector BulletSpread;
664 CalculateBulletSpread(BulletSpread);
665 ShotDirection = -TraceRotation.Vector();
666 const FVector LineEnd = ((ForwardVector * GetWeaponStats().GunRange) + TraceLocation) + BulletSpread;
667
668 const ECollisionChannel CollisionChannel = UEngineTypes::ConvertToCollisionChannel(UEngineTypes::ConvertToTraceType(ECC_GameTraceChannel4));
669 static const FName LineTraceSingleName(TEXT("LineTraceSingle"));
670 FCollisionQueryParams Params;// = ConfigureCollisionParams(LineTraceSingleName, bTraceComplex, ActorsToIgnore, bIgnoreSelf, WorldContextObject);
671 // Params.bDebugQuery
672 Params.bTraceComplex = bTraceComplex;
673 Params.bReturnPhysicalMaterial = bReturnPhysicalMaterial;
674 Params.AddIgnoredActor(OwnerPawn);
675 Params.AddIgnoredActor(GetOwner());
676 bool const bHit = GetWorld() ? GetWorld()->LineTraceSingleByChannel(Hit, TraceLocation, LineEnd, CollisionChannel, Params) : false;
677
678 if(UBaseHelpersBPLib::GetDrawDebugType(bDebuggingMode) != EDrawDebugTrace::None)
679 {
680 const bool bPersistent = UBaseHelpersBPLib::GetDrawDebugType(bDebuggingMode) == EDrawDebugTrace::Persistent;
681 const float LifeTime = (UBaseHelpersBPLib::GetDrawDebugType(bDebuggingMode) == EDrawDebugTrace::ForDuration) ? DrawDebugTime : 0.f;
682
683 if (bHit && Hit.bBlockingHit)
684 {
685 const FLinearColor DarkerColor = FLinearColor(Color.R * DrawDebugColorDarkMultiplier, Color.G * DrawDebugColorDarkMultiplier, Color.B * DrawDebugColorDarkMultiplier, Color.A);
686 const FLinearColor LighterColor = FLinearColor((Color.R + 0.1f) * DrawDebugColorLightMultiplier, (Color.G + 0.1f) * DrawDebugColorLightMultiplier, (Color.B + 0.1f) * DrawDebugColorLightMultiplier, Color.A);
687 // Red up to the blocking hit, green thereafter
688 DrawDebugLine(GetWorld(), TraceLocation, Hit.ImpactPoint, Color.ToFColor(true), bPersistent, LifeTime);
689 DrawDebugLine(GetWorld(), Hit.ImpactPoint, LineEnd, LighterColor.ToFColor(true), bPersistent, LifeTime);
690 DrawDebugPoint(GetWorld(), Hit.ImpactPoint, DrawDebugPointSize, DarkerColor.ToFColor(true), bPersistent, LifeTime);
691 }
692 else
693 {
694 // no hit means all red
695 DrawDebugLine(GetWorld(), TraceLocation, LineEnd, Color.ToFColor(true), bPersistent, LifeTime);
696 }
697 }
698 return bHit;
699 return false;
700}
bool bDebuggingMode
Definition WeaponFramework.h:35
float DrawDebugColorLightMultiplier
Definition WeaponFramework.h:45
float DrawDebugColorDarkMultiplier
Definition WeaponFramework.h:43
float DrawDebugTime
Definition WeaponFramework.h:41
FRotator TraceRotation
Definition WeaponFramework.h:165
bool bTraceComplex
Definition WeaponFramework.h:54
float DrawDebugPointSize
Definition WeaponFramework.h:47
bool bReturnPhysicalMaterial
Definition WeaponFramework.h:56
static EDrawDebugTrace::Type GetDrawDebugType(const bool bDebuggingMode)
Definition BaseHelpersBPLib.cpp:910
float GunRange
Definition WeaponStructs.h:676

◆ LogDebugMessage()

void AWeaponFramework::LogDebugMessage ( const FString & Message,
const bool bError = false ) const
protected
324{
325 if(bDebuggingMode == false){return;}
326 const FString FullMessage = FString::Printf(TEXT(" %s - in %s of %s"), ToCStr(Message), ToCStr(GetName()), GetOwner() ? ToCStr(GetOwner()->GetName()) : ToCStr("Invalid Owner"));
327 UBaseHelpersBPLib::PrintToLogWithCategory(GetWorld(), LogWeaponFramework, FullMessage, true, bError);
328}
static void PrintToLogWithCategory(const UObject *WorldContextObject, const FLogCategoryBase &Category, const FString &Message, const bool bWarning=false, const bool bError=false)
Definition BaseHelpersBPLib.cpp:105

◆ MoveUMG()

void AWeaponFramework::MoveUMG ( bool bIsRightShoulder)
overrideprotectedvirtual

Implements IWeapon.

889{
890 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
891 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::MoveUMG);
892}
virtual void MoveUMG(bool bIsRightShoulder) override
Definition WeaponFramework.cpp:888

◆ Multicast_SetWeaponMeshHidden()

void AWeaponFramework::Multicast_SetWeaponMeshHidden ( const bool bValue)
protected

◆ OnMeshReplicated()

void AWeaponFramework::OnMeshReplicated ( )
protected
948{
949 GunMeshComponent->SetSkeletalMesh(WeaponMesh);
950}
USkeletalMesh * WeaponMesh
Definition WeaponFramework.h:202

◆ OnRep_WeaponStats()

void AWeaponFramework::OnRep_WeaponStats ( )
protected
85{
86 if(GunMeshComponent != nullptr)
87 {
90 LogDebugMessage(FString::Printf(TEXT("OnRep Set Relative LocatioN: %s"), *CurrentWeaponStats.RotationOffset.ToString()));
91 }
92}

◆ ReceiveFire()

void AWeaponFramework::ReceiveFire ( FHitResult Hit,
APawn * InstigatorPawn )
protected

◆ Reload()

void AWeaponFramework::Reload ( const float ReloadTime)
overrideprotectedvirtual

Implements IWeapon.

798{
799 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
800 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::Reload);
801
802 if(!GetWeaponStats().IsValid()){return;}
803 if(WeaponData.CurrentAmmo >= GetWeaponStats().ClipSize){return;}
804 if(WeaponData.TotalAmmoCount <= 0){return;}
805 if(bIsBeingReloaded){return;}
806 ServerSetReloading(true);
807 GetWorldTimerManager().SetTimer(ReloadTimerHandle, this, &AWeaponFramework::ServerReload, ReloadTime, false);
808}
virtual void Reload(const float ReloadTime) override
Definition WeaponFramework.cpp:797
FTimerHandle ReloadTimerHandle
Definition WeaponFramework.h:223
int32 TotalAmmoCount
Definition WeaponStructs.h:883

◆ RemoveAllAttachments()

void AWeaponFramework::RemoveAllAttachments ( )
protected
298{
299 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
300 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::RemoveAllAttachments);
301 for(UStaticMeshComponent* Component : AttachmentComponents)
302 {
303 if(Component != nullptr && Component->IsValidLowLevel())
304 {
305 Component->DestroyComponent();
306 }
307 }
308}
void RemoveAllAttachments()
Definition WeaponFramework.cpp:297

◆ RemoveAttachment()

bool AWeaponFramework::RemoveAttachment ( const FString AttachmentID,
const EAttachmentType AttachmentType )
protected
255{
256 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
257 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::RemoveAttachment);
258 if(AttachmentType == EAttachmentType::Laser)
259 {
260 ToggleLaser(true);
261 }
262 for(UStaticMeshComponent* Component : AttachmentComponents)
263 {
264 for(const FName& NameTag : Component->ComponentTags)
265 {
266 if(NameTag == FName(AttachmentID))
267 {
268 if(Component != nullptr && Component->IsValidLowLevel())
269 {
270 LogDebugMessage(FString::Printf(TEXT("Attachemnt %s Destroyed"), *AttachmentID));
271 Component->DestroyComponent();
272 }
273 WeaponData.CurrentWeaponAttachments.Remove(AttachmentID);
274 return true;
275 }
276 }
277 }
278 return false;
279}
virtual void ToggleLaser(const bool bForceOff=false)
Definition WeaponFramework.cpp:134
TArray< FString > CurrentWeaponAttachments
Definition WeaponStructs.h:887

◆ Server_InitWeapon()

void AWeaponFramework::Server_InitWeapon ( )
protected

◆ Server_SetWeaponShouldAutoReload()

virtual void AWeaponFramework::Server_SetWeaponShouldAutoReload ( const bool bValue)
protectedvirtual

◆ ServerFire()

void AWeaponFramework::ServerFire ( const FVector Location,
const FRotator Rotation,
const AActor * ActorToIgnore,
const float Accuracy )
protected

◆ ServerReload()

void AWeaponFramework::ServerReload ( )
protected

◆ ServerSetReloading()

void AWeaponFramework::ServerSetReloading ( const bool bReloading)
protected

◆ ServerShoot()

virtual void AWeaponFramework::ServerShoot ( )
protectedvirtual

◆ SetDebuggingStats()

virtual void AWeaponFramework::SetDebuggingStats ( const bool bDebug,
const bool bInfinite,
const bool bBottomless )
inlineoverrideprotectedvirtual

Implements IWeapon.

106{bDebuggingMode = bDebug; bInfiniteAmmo = bInfinite, bBottomlessClip = bBottomless;};
bool bInfiniteAmmo
Definition WeaponFramework.h:37
bool bBottomlessClip
Definition WeaponFramework.h:39

◆ SetMuzzleOffset()

void AWeaponFramework::SetMuzzleOffset ( const FVector & Location,
const FRotator & Rotation )
overrideprotectedvirtual

Implements IWeapon.

954{
955 Muzzle->SetRelativeLocation(Location);
956 Muzzle->SetRelativeRotation(Rotation);
957}

◆ SetRecoilPivotPoint()

void AWeaponFramework::SetRecoilPivotPoint ( const FVector & Location,
const FRotator & Rotation )
overrideprotectedvirtual

Implements IWeapon.

960{
961 RecoilPivotPoint->SetRelativeLocation(Location);
962 RecoilPivotPoint->SetRelativeRotation(Rotation);
963}

◆ SetupWeaponEffects()

void AWeaponFramework::SetupWeaponEffects ( )
protectedvirtual
311{
312 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
313 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::SetupWeaponEffects);
314 OwnerPawn = Cast<APawn>(GetOwner());
315 if(OwnerPawn == nullptr){LogDebugMessage("OwnerPawn SetupWeaponEffects", true);return;}
316 bWeaponEffectsSetup = WeaponEffects->SetupEffectsComponent(OwnerPawn, Muzzle, GetWeaponStats().WeaponEffectsID);
317 // if(bWeaponEffectsSetup)
318 // {
319 // WeaponEffects->GetWeaponEffectsFromID(WeaponData.WeaponID);
320 // }
321}

◆ SetWeaponData()

virtual void AWeaponFramework::SetWeaponData ( const FWeaponData_T NewWeaponData)
inlineoverrideprotectedvirtual

Implements IWeapon.

96{WeaponData = NewWeaponData;};

◆ SetWeaponFireMode()

void AWeaponFramework::SetWeaponFireMode ( )
private
97{
99 // - Automatic Weapons will always start in Auto Mode //
100 if(GetWeaponStats().bHasAutoMode)
101 {
103 }
104 else if(GetWeaponStats().bHasBurstMode)
105 {
107 }
108}

◆ SetWeaponMesh()

void AWeaponFramework::SetWeaponMesh ( USkeletalMesh * SkeletalMesh)
overrideprotectedvirtual

Implements IWeapon.

938{
939 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
940 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::SetWeaponMesh_Implementation);
941 if(SkeletalMesh == nullptr){LogDebugMessage("SetWeaponMesh Null Mesh");return;}
942 WeaponMesh = SkeletalMesh;
944 GunMeshComponent->SetSkeletalMesh(SkeletalMesh);
945}
void OnMeshReplicated()
Definition WeaponFramework.cpp:947

◆ SetWeaponMeshHidden()

void AWeaponFramework::SetWeaponMeshHidden ( const bool bValue)
overrideprotectedvirtual

Sets the Guns Mesh to be Hidden in Game, Used for Turrets and Ships, Things with invisible Weapons

Implements IWeapon.

151{
152 if(GunMeshComponent != nullptr)
153 {
154 GunMeshComponent->SetHiddenInGame(bValue, true);
155 }
157}
void Multicast_SetWeaponMeshHidden(const bool bValue)

◆ SetWeaponShouldAutoReload()

void AWeaponFramework::SetWeaponShouldAutoReload ( const bool bValue)
overrideprotectedvirtual

Implements IWeapon.

121{
122 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::SetWeaponShouldAutoReload);
123 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
125}
virtual void SetWeaponShouldAutoReload(const bool bValue) override
Definition WeaponFramework.cpp:120
virtual void Server_SetWeaponShouldAutoReload(const bool bValue)

◆ ShootHitScan()

void AWeaponFramework::ShootHitScan ( )
private
461{
462 // if(HitscanWeaponComponent != nullptr)
463 // {
464 // if(bBottomlessClip){WeaponData.CurrentAmmo++;}
465 // WeaponData.CurrentAmmo--;
466 // HitscanWeaponComponent->SetMuzzle(Muzzle);
467 // FHitResult Hit = HitscanWeaponComponent->ServerShoot();
468 // FVector TracerEndPoint = Hit.TraceEnd;
469 // TArray<FVector> HitLocations;
470 // }
473 //- Bullet is only Decreased in fire Function //
474 if(GetWeaponStats().bMultiFire)
475 {
477 }
478 if(!bBottomlessClip){LogDebugMessage(FString::Printf(TEXT("Current Ammo: %i"), WeaponData.CurrentAmmo));}
479
480
481 //- Weapon Effects //
482 WeaponEffects->WeaponFireNoiseEvent(GetWeaponStats().bSilenced);
483 WeaponEffects->MuzzleFlashEvent(GetWeaponStats().MuzzleFlashOffset);
484
485
486 FHitResult Hit;
487 FVector ShotDirection;
488 bool bSuccess = LineTrace(Hit, ShotDirection, MainTraceColor);
489
490 //- Defaults for Impact Effects
491 FVector TracerEndPoint = Hit.TraceEnd;
492 TArray<FVector> HitLocations;
493
494 //- No Hit //
495 if(!bSuccess)
496 {
497 TracerEndPoint = Hit.TraceEnd;
498 HitLocations.Add(Hit.TraceEnd);
499 if(WeaponEffects != nullptr)
500 {
501 WeaponEffects->TracerEvent(HitLocations);
502 }
504 return;
505 }
506
507 //- Check how close the gun is to the hit location
508 FVector MuzzleLocation = Muzzle->GetComponentLocation();
509 FVector NormalVector = (MuzzleLocation - Hit.Location);
510 NormalVector.Normalize(0.0001);
511 FVector ForwardVector = (FRotationMatrix(TraceRotation).GetScaledAxis( EAxis::X ));
512 float VectorDistance = UKismetMathLibrary::Dot_VectorVector(NormalVector,(ForwardVector * -1));
513 if(VectorDistance < TraceDistanceTooClose)
514 {
515 //- If the gun is too close to the Hit location
516 //- eg. gun against the wall
517 FHitResult BlindFireHit = BlindFireWeaponTrace(GetAccuracyMultiplier());
518 if(BlindFireHit.bBlockingHit)
519 {
520 HitLocations.Add(BlindFireHit.Location);
521 ApplyDamageToActor(BlindFireHit, ShotDirection, CalculateDistanceDamage(BlindFireHit.Distance));
522 ReceiveFire(BlindFireHit, OwnerPawn);
523 if(WeaponEffects != nullptr)
524 {
525 WeaponEffects->ImpactEvent(BlindFireHit);
526 }
527 LogDebugMessage(FString::Printf(TEXT("Hit 1: X %f,Y: %f,Z: %f"), BlindFireHit.Location.X, BlindFireHit.Location.Y, BlindFireHit.Location.Z));
528 }
529 else
530 {
531 HitLocations.Add(BlindFireHit.TraceEnd);
532 ApplyDamageToActor(BlindFireHit, ShotDirection, CalculateDistanceDamage(BlindFireHit.Distance));
533 ReceiveFire(BlindFireHit, OwnerPawn);
534 if(WeaponEffects != nullptr)
535 {
536 WeaponEffects->ImpactEvent(BlindFireHit);
537 }
538 LogDebugMessage(FString::Printf(TEXT("Hit 1.5: X %f,Y: %f,Z: %f"), BlindFireHit.TraceEnd.X, BlindFireHit.TraceEnd.Y, BlindFireHit.TraceEnd.Z));
539 }
540 }
541 else
542 {
543 //- Check if Anything is between the player and where they should be shooting //
544 //- i.e. can see someone around the corner but gun is pointed at the wall //
545
546 //todo Change this to Linetrace Function, TraceLocation = Hit.Location
547 // way to change just the end
548 FHitResult HitCheck;
549 ActorsToIgnore.Add(Hit.GetActor());
550
551
552 //- LineTrace, Did we hit something
553 if(UKismetSystemLibrary::LineTraceSingle(this,
554 Hit.Location,
555 MuzzleLocation,
556 UEngineTypes::ConvertToTraceType(ECC_GameTraceChannel4),
558 //~ Debugging
560 true, FLinearColor::Blue,
561 FLinearColor::Blue, DrawDebugTime))
562 {
563 FHitResult BlindFireHit = BlindFireWeaponTrace(GetAccuracyMultiplier());
564 if(BlindFireHit.bBlockingHit)
565 {
566 HitLocations.Add(BlindFireHit.Location);
567 ApplyDamageToActor(BlindFireHit, ShotDirection, CalculateDistanceDamage(BlindFireHit.Distance));
568 ReceiveFire(BlindFireHit, OwnerPawn);
569 if(WeaponEffects != nullptr)
570 {
571 WeaponEffects->ImpactEvent(BlindFireHit);
572 }
573 LogDebugMessage(FString::Printf(TEXT("Hit 2: X %f,Y: %f,Z: %f"), BlindFireHit.Location.X, BlindFireHit.Location.Y, BlindFireHit.Location.Z));
574 }
575 else
576 {
577 HitLocations.Add(BlindFireHit.TraceEnd);
578 ApplyDamageToActor(BlindFireHit, ShotDirection, CalculateDistanceDamage(BlindFireHit.Distance));
579 ReceiveFire(BlindFireHit, OwnerPawn);
580 if(WeaponEffects != nullptr)
581 {
582 WeaponEffects->ImpactEvent(BlindFireHit);
583 }
584 LogDebugMessage(FString::Printf(TEXT("Hit 2.5: X %f,Y: %f,Z: %f"), BlindFireHit.TraceEnd.X, BlindFireHit.TraceEnd.Y, BlindFireHit.TraceEnd.Z));
585 }
586 }
587 else
588 {
589 //- Nothing in the way
590 if(Hit.GetActor() != nullptr)
591 {
592 ApplyDamageToActor(Hit, ShotDirection, CalculateDistanceDamage(Hit.Distance));
593 LogDebugMessage(FString::Printf(TEXT("Hit 3: X %f,Y: %f,Z: %f"), Hit.Location.X, Hit.Location.Y, Hit.Location.Z));
594 HitLocations.Add(Hit.Location);
596 if(WeaponEffects != nullptr)
597 {
598 WeaponEffects->ImpactEvent(Hit);
599 }
600 }
601 }
602 //Remove as the var is kept
603 ActorsToIgnore.Remove(Hit.GetActor());
604 }
605 WeaponEffects->TracerEvent(HitLocations);
606}
FLinearColor MainTraceColor
Definition WeaponFramework.h:49
float GetAccuracyMultiplier() const
Definition WeaponFramework.h:133
void ReceiveFire(FHitResult Hit, APawn *InstigatorPawn)
float TraceDistanceTooClose
Definition WeaponFramework.h:59

◆ ShootProjectile()

void AWeaponFramework::ShootProjectile ( )
private
609{
610 if(!CanShoot()) {return;}
611 if(GetWeaponStats().IsValid() == false){return;}
612 if(HasAuthority())
613 {
614 ActorsToIgnore.Emplace(GetOwner());
617 const FVector MuzzleLocation = Muzzle->GetComponentLocation();
618 const FActorSpawnParameters SpawnParameters;
619 const FTransform SpawnTransform = FTransform(TraceRotation + GetWeaponStats().ProjectileRotationOffset, MuzzleLocation, FVector(1));
620 AActor* SpawnedProjectile = UGameplayStatics::BeginDeferredActorSpawnFromClass(this, ProjectileClass, SpawnTransform, ESpawnActorCollisionHandlingMethod::AlwaysSpawn, this);
621 if(SpawnedProjectile == nullptr){UE_LOG(LogWeaponSystem, Warning,TEXT("Spawn Projectile failed in Projectile Weapon"));return;}
622 IProjectile* Projectile = Cast<IProjectile>(SpawnedProjectile);
623 if(Projectile == nullptr){UE_LOG(LogWeaponSystem, Warning,TEXT("Projectile cast failed in Projectile Weapon"));return;}
624 Projectile->SetProjectileStats(GetWeaponStats().WeaponProjectileStats);
625 Projectile->SetDefaultDamage(GetWeaponStats().DefaultDamage);
626 Projectile->SetActorsToIgnore(ActorsToIgnore);
627 Projectile->SetDebuggingMode(bDebuggingMode);
628 AController* EventInstigator = nullptr;
629 if(TraceActorToIgnore != nullptr)
630 {
631 EventInstigator = TraceActorToIgnore->GetInstigatorController();
632 }
633 Projectile->SetInstigator(EventInstigator);
634 if(GetOwner() != nullptr)
635 {
636 SpawnedProjectile->SetOwner(GetOwner());
637 }
638 else
639 {
640 UE_LOG(LogWeaponSystem, Error, TEXT("Projectile weapon, GetOwner FAILED"));
641 }
642 UGameplayStatics::FinishSpawningActor(SpawnedProjectile, SpawnTransform);
643 }
644 //- Weapon Effects //
645 OwnerPawn = Cast<APawn>(GetOwner());
646 if(OwnerPawn != nullptr)
647 {
648 WeaponEffects->MuzzleFlashEvent(GetWeaponStats().MuzzleFlashOffset);
649 FHitResult HitResult;
650 ReceiveFire(HitResult, OwnerPawn);
651 APlayerController* OwnerController = Cast<APlayerController>(OwnerPawn->GetController());
652 WeaponEffects->PlayFeedbackEffects(OwnerController, WeaponData.FireMode, GetAccuracyMultiplier());
653 }
654 WeaponEffects->WeaponFireNoiseEvent();
655}
Definition Projectile.h:20

◆ SwitchAutoMode()

void AWeaponFramework::SwitchAutoMode ( )
overrideprotectedvirtual

Implements IWeapon.

852{
853 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
854 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::SwitchAutoMode);
855 switch (WeaponData.FireMode)
856 {
858 if(GetWeaponStats().bHasAutoMode)
859 {
861 break;
862 }
863 if(GetWeaponStats().bHasBurstMode)
864 {
866 }
867 break;
870 break;
872 if(GetWeaponStats().bHasBurstMode)
873 {
875 }
876 else
877 {
879 }
880 break;
881 default:
883 break;
884 }
885}
virtual void SwitchAutoMode() override
Definition WeaponFramework.cpp:851

◆ ToggleAttachment()

void AWeaponFramework::ToggleAttachment ( const EAttachmentType & AttachmentType)
overrideprotectedvirtual

Implements IWeapon.

239{
240 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
241 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponFramework::ToggleAttachment);
242 switch (AttachmentType)
243 {
245 break;
247 ToggleLaser();
248 break;
249 default:
250 break;
251 }
252}

◆ ToggleLaser()

void AWeaponFramework::ToggleLaser ( const bool bForceOff = false)
protectedvirtual
135{
136 if(bLaserOn)
137 {
138 bLaserOn = false;
139 }
140 else
141 {
142 bLaserOn = true;
143 }
144 if(bForceOff)
145 {
146 bLaserOn = false;
147 }
148}
bool bLaserOn
Definition WeaponFramework.h:220

Member Data Documentation

◆ AccuracyMultiplier

float AWeaponFramework::AccuracyMultiplier = 1.0f
private

◆ ActorsToIgnore

TArray<AActor*> AWeaponFramework::ActorsToIgnore
protected

◆ AttachmentComponents

TArray<UStaticMeshComponent*> AWeaponFramework::AttachmentComponents
protected

◆ bBottomlessClip

bool AWeaponFramework::bBottomlessClip = false

◆ bDebuggingMode

bool AWeaponFramework::bDebuggingMode = false

◆ bInfiniteAmmo

bool AWeaponFramework::bInfiniteAmmo = false

◆ bIsBeingReloaded

bool AWeaponFramework::bIsBeingReloaded
private

◆ bLaserOn

bool AWeaponFramework::bLaserOn = false
private

◆ BlindFireTraceColor

FLinearColor AWeaponFramework::BlindFireTraceColor = FLinearColor(0.1f, 0.9f, 0.1f)

◆ bReturnPhysicalMaterial

bool AWeaponFramework::bReturnPhysicalMaterial = false

◆ bTraceComplex

bool AWeaponFramework::bTraceComplex = false

◆ bWeaponEffectsSetup

bool AWeaponFramework::bWeaponEffectsSetup = false
private

◆ CurrentWeaponStats

FWeaponStats_T AWeaponFramework::CurrentWeaponStats
private

◆ DrawDebugColorDarkMultiplier

float AWeaponFramework::DrawDebugColorDarkMultiplier = 0.1f

◆ DrawDebugColorLightMultiplier

float AWeaponFramework::DrawDebugColorLightMultiplier = 2.0f

◆ DrawDebugPointSize

float AWeaponFramework::DrawDebugPointSize = 16.0f

◆ DrawDebugTime

float AWeaponFramework::DrawDebugTime = 2.0f

◆ GunMeshComponent

USkeletalMeshComponent* AWeaponFramework::GunMeshComponent
protected

◆ HitscanWeaponComponent

UHitscanWeaponComponent* AWeaponFramework::HitscanWeaponComponent
protected

◆ MainTraceColor

FLinearColor AWeaponFramework::MainTraceColor = FLinearColor(0.9f, 0.1f, 0.1f)

◆ Muzzle

USceneComponent* AWeaponFramework::Muzzle
protected

◆ OwnerPawn

APawn* AWeaponFramework::OwnerPawn
protected

◆ ProjectileClass

TSubclassOf<class AActor> AWeaponFramework::ProjectileClass
protected

◆ ProjectileWeaponComponent

UProjectileWeaponComponent* AWeaponFramework::ProjectileWeaponComponent
protected

◆ RecoilPivotPoint

USceneComponent* AWeaponFramework::RecoilPivotPoint
protected

◆ ReloadTimerHandle

FTimerHandle AWeaponFramework::ReloadTimerHandle
private

◆ SceneRoot

USceneComponent* AWeaponFramework::SceneRoot
protected

◆ TraceActorToIgnore

const AActor* AWeaponFramework::TraceActorToIgnore
protected

◆ TraceDistanceTooClose

float AWeaponFramework::TraceDistanceTooClose = 0.075f

◆ TraceLocation

FVector AWeaponFramework::TraceLocation
protected

◆ TraceRotation

FRotator AWeaponFramework::TraceRotation
protected

◆ WeaponData

FWeaponData_T AWeaponFramework::WeaponData
protected

◆ WeaponEffects

class UWeaponEffectsComponent* AWeaponFramework::WeaponEffects
protected

◆ WeaponMesh

USkeletalMesh* AWeaponFramework::WeaponMesh
protected

◆ WeaponType

EWeaponType AWeaponFramework::WeaponType = EWeaponType::Default
protected

The documentation for this class was generated from the following files: