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

Represents a weapon pickup in the game. More...

#include <WeaponPickup.h>

Inheritance diagram for AWeaponPickup:
AInteractableActorWithPrompt IWeaponPickupInterface AInteractableActor AActorBase IBaseInterface ISaveLoad

Public Member Functions

 AWeaponPickup (const FObjectInitializer &ObjectInitializer)
 
virtual void WeaponDroppedEvent (const FWeaponData_T &DroppedWeaponData) override
 
virtual void AddImpulseToWeapon (const FVector &Impulse, const FName &BoneName=NAME_None, const bool bVelChange=false) override
 
virtual void OnFinishSpawning () override
 
virtual void MulticastOnFinishSpawning ()
 
- Public Member Functions inherited from AInteractableActorWithPrompt
 AInteractableActorWithPrompt ()
 
- Public Member Functions inherited from AInteractableActor
 AInteractableActor ()
 
virtual void ReceiveStartFocus (AActor *Caller)
 
virtual void ReceiveEndFocus (AActor *Caller)
 
virtual void ReceiveOnInteract (AActor *Caller, const EInteractionType InteractionType)
 
virtual void ReceiveOnEndInteract (AActor *Caller)
 
virtual void ReceiveOnOverlap (AActor *Caller)
 
virtual void ReceiveOnEndOverlap (AActor *Caller)
 
virtual void ReceiveToggleSwitch (AActor *Caller, const bool bOn)
 
- Public Member Functions inherited from AActorBase
 AActorBase ()
 
virtual bool SaveGame () override
 
virtual bool LoadGame () override
 
void SetGravityEnabledEvent (const bool bValue)
 

Protected Member Functions

virtual void OnConstruction (const FTransform &Transform) override
 
virtual void BeginPlay () override
 
void SetMesh () const
 
void SetAttachments ()
 
void AddAttachment (const FString &AttachmentID)
 
virtual void Multicast_WeaponDroppedEvent (const FWeaponData_T &DroppedWeaponData)
 
virtual void OnInteract (AActor *Caller, const int32 InteractionType) override
 
virtual void InteractionComplete () override
 
virtual void OnEndInteract (AActor *Caller) override
 
virtual bool OnOverlap (AActor *Caller) override
 
virtual void StartFocus () override
 
virtual void EndFocus () override
 
virtual void ToggleSwitch (AActor *Caller, bool bOn) override
 
virtual FVector GetInteractionLocation () const override
 
virtual UPrimitiveComponent * GetGrabComponent () const override
 
- Protected Member Functions inherited from AInteractableActorWithPrompt
void OnInteractionComplete (AActor *Caller)
 
void HideButtonPrompt ()
 
- Protected Member Functions inherited from AInteractableActor
virtual void Tick (float DeltaTime) override
 
virtual void SetMeshOutline (const bool bValue)
 
- Protected Member Functions inherited from AActorBase
void LogDebugError (const FString &Message) const
 
void LogDebugError (const FString &Message, const int32 Value) const
 
void LogDebugError (const FString &Message, const float Value) const
 
void LogDebugWarning (const FString &Message) const
 
void LogDebugWarning (const FString &Message, const int32 Value) const
 
void LogDebugWarning (const FString &Message, const float Value) const
 
void LogDebugMessage (const FString &Message, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const int32 Value, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const float Value, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const bool bValue, const bool bWarning, const bool bError) const
 
void LogOnScreenMessage (const int32 Key, const FString &Message, FColor Color=FColor::Green) const
 
void SetCategoryName (const FLogCategoryBase &Category)
 

Protected Attributes

bool bManuallySpawned = true
 
FString WeaponID = "DefaultWeapon"
 
bool bOverrideWeaponData = false
 
FWeaponData_T WeaponPickupData
 
class USkeletalMeshComponent * GunMesh
 
class UCapsuleComponent * CapsuleComponent
 
- Protected Attributes inherited from AInteractableActorWithPrompt
class UInteractionPromptComponent * InteractionPromptComponent
 
class USphereComponent * InteractionPromptCollision
 
class USceneComponent * SceneRootComponent
 
bool bHasProgress = true
 
float PromptHeight = 75.0f
 
AActor * CurrentInteractCaller = nullptr
 
float HidePromptTime = 2.5f
 
- Protected Attributes inherited from AInteractableActor
class UInteractableActorComponent * InteractableActorComponent
 
class UAudioReactionComponent * AudioReactionComponent
 
class UAIPerceptionStimuliSourceComponent * PerceptionStimuliComponent
 
- Protected Attributes inherited from AActorBase
FString DisplayName = "Display Name"
 
bool bDebuggingMode = false
 

Detailed Description

Represents a weapon pickup in the game.

This class inherits from AActor and implements several interfaces for interaction and pickup functionality.

See also
WeaponPickup

Constructor & Destructor Documentation

◆ AWeaponPickup()

AWeaponPickup::AWeaponPickup ( const FObjectInitializer & ObjectInitializer)
explicit
20 : AInteractableActorWithPrompt(ObjectInitializer
21 .DoNotCreateDefaultSubobject(TEXT("Scene Root"))
22 .DoNotCreateDefaultSubobject(TEXT("Interaction Prompt")))
23{
24 bReplicates = true;
25 SetReplicatingMovement(true);
26 GunMesh = CreateDefaultSubobject<USkeletalMeshComponent>("Gun Mesh");
27 GunMesh->SetGenerateOverlapEvents(true);
28 GunMesh->SetCollisionProfileName(TEXT("DefaultPickup"));
29 GunMesh->SetSimulatePhysics(true);
30 GunMesh->SetRenderCustomDepth(true);
31 RootComponent = GunMesh;
32
33 GunMesh->bRenderCustomDepth = false;
34 CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>("Capsule Component");
35 CapsuleComponent->SetupAttachment(GunMesh);
36 CapsuleComponent->SetWorldRotation(FRotator(0,0,90));
37 FWalkableSlopeOverride WalkableSlopeOverride;
38 WalkableSlopeOverride.WalkableSlopeBehavior = EWalkableSlopeBehavior::WalkableSlope_Unwalkable;
39 CapsuleComponent->SetWalkableSlopeOverride(WalkableSlopeOverride);
40
42 InteractionPromptCollision->SetupAttachment(GunMesh);
43 bLoseFocusAfterInteract = true;
44}
AInteractableActorWithPrompt()
Definition InteractableActorWithPrompt.cpp:8
class USphereComponent * InteractionPromptCollision
Definition InteractableActorWithPrompt.h:32
class UCapsuleComponent * CapsuleComponent
Definition WeaponPickup.h:75
class USkeletalMeshComponent * GunMesh
Definition WeaponPickup.h:73
Definition BaseData.h:420

Member Function Documentation

◆ AddAttachment()

void AWeaponPickup::AddAttachment ( const FString & AttachmentID)
protected
108{
109 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
110 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::AddAttachment);
111 bool bSuccess = false;
112 const FWeaponAttachment WeaponAttachment = UWeaponBPLib::GetWeaponAttachment(this, AttachmentID, bSuccess);
113 if(!bSuccess){return;}
114 if(!WeaponAttachment.IsValid()){return;}
115 if(!GunMesh->DoesSocketExist(WeaponAttachment.AttachmentTypeName())){return;}
116
117 const FWeaponStats_T WeaponStats = UWeaponBPLib::GetWeaponStats(this, WeaponPickupData.WeaponID, bSuccess);
118 if(!bSuccess){return;}
119 if(!WeaponStats.GetIsAttachmentCompatible(AttachmentID, WeaponAttachment.AttachmentType)){return;}
120
121 UStaticMeshComponent* AttachmentComponent = NewObject<UStaticMeshComponent>(this);
122 if(AttachmentComponent == nullptr){return;}
123 AttachmentComponent->RegisterComponent();
124 AttachmentComponent->SetStaticMesh(WeaponAttachment.StaticMesh);
125 AttachmentComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
126 AttachmentComponent->AttachToComponent(GunMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, WeaponAttachment.AttachmentTypeName());
127 AttachmentComponent->ComponentTags.Add(FName(WeaponAttachment.WeaponAttachmentID));
128 AttachmentComponent->ComponentTags.Add(WeaponAttachment.AttachmentTypeName());
129 AttachmentComponent->SetRelativeLocation(WeaponAttachment.AttachmentOffset);
130 AttachmentComponent->SetRelativeRotation(WeaponAttachment.AttachmentRotationOffset);
131}
void AddAttachment(const FString &AttachmentID)
Definition WeaponPickup.cpp:107
FWeaponData_T WeaponPickupData
Definition WeaponPickup.h:68
static FWeaponAttachment GetWeaponAttachment(const UObject *WorldContextObject, const FString &WeaponAttachmentID, bool &bSuccess, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:235
static FWeaponStats_T GetWeaponStats(const UObject *WorldContextObject, const FString &WeaponID, bool &bSuccess, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:176
Definition WeaponStructs.h:501
FString WeaponID
Definition WeaponStructs.h:866
Represents statistics for a weapon.
Definition WeaponStructs.h:622
bool GetIsAttachmentCompatible(const FString &AttachmentID, const EAttachmentType AttachmentType) const
Definition WeaponStructs.h:772

◆ AddImpulseToWeapon()

void AWeaponPickup::AddImpulseToWeapon ( const FVector & Impulse,
const FName & BoneName = NAME_None,
const bool bVelChange = false )
overridevirtual

Implements IWeaponPickupInterface.

163{
164 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
165 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::AddImpulseToWeapon);
166 GunMesh->AddImpulse(Impulse, BoneName, bVelChange);
167}
virtual void AddImpulseToWeapon(const FVector &Impulse, const FName &BoneName=NAME_None, const bool bVelChange=false) override
Definition WeaponPickup.cpp:162

◆ BeginPlay()

void AWeaponPickup::BeginPlay ( )
overrideprotectedvirtual

Reimplemented from AInteractableActorWithPrompt.

56{
57 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
58 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::BeginPlay);
59 Super::BeginPlay();
62 {
65 {
68 }
69 }
70 else
71 {
72 bool bSuccess = false;
74 if(bSuccess == false)
75 {
76 UE_LOG(LogWeaponSystem, Error, TEXT("AWeaponPickup::BeginPlay Weapon Data Failed "));
77 Destroy();
78 return;
79 }
80 }
81 SetMesh();
83}
FString DisplayName
Definition ActorBase.h:51
bool bManuallySpawned
Definition WeaponPickup.h:58
FString WeaponID
Definition WeaponPickup.h:62
virtual void BeginPlay() override
Definition WeaponPickup.cpp:55
void SetAttachments()
Definition WeaponPickup.cpp:97
void SetMesh() const
Definition WeaponPickup.cpp:85
bool bOverrideWeaponData
Definition WeaponPickup.h:65
static bool GetDoesWeaponHaveBurstMode(const UObject *WorldContextObject, const FString &WeaponID, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:331
static FWeaponData_T GetDefaultWeaponData(const UObject *WorldContextObject, const FString &WeaponID, bool &bSuccess, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:154
static bool GetDoesWeaponHaveAutoMode(const UObject *WorldContextObject, const FString &WeaponID, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:321
static FString GetWeaponDisplayName(const UObject *WorldContextObject, const FString &WeaponID, UDataTable *DataTable=nullptr)
Definition WeaponBPLib.cpp:275
EWeaponFireMode FireMode
Definition WeaponStructs.h:870

◆ EndFocus()

void AWeaponPickup::EndFocus ( )
overrideprotectedvirtual
296{
297 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
298 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::EndFocus);
299 Super::EndFocus();
300 if(GunMesh != nullptr)
301 {
302 GunMesh->SetRenderCustomDepth(false);
303 }
304}
virtual void EndFocus() override
Definition WeaponPickup.cpp:295

◆ GetGrabComponent()

virtual UPrimitiveComponent * AWeaponPickup::GetGrabComponent ( ) const
inlineoverrideprotectedvirtual
88{return Cast<UPrimitiveComponent>(RootComponent);};

◆ GetInteractionLocation()

FVector AWeaponPickup::GetInteractionLocation ( ) const
overrideprotectedvirtual
314{
315 return GetActorLocation();
316}

◆ InteractionComplete()

void AWeaponPickup::InteractionComplete ( )
overrideprotectedvirtual

Reimplemented from AInteractableActorWithPrompt.

222{
223 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
224 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::InteractionComplete);
225 if(CurrentInteractCaller == nullptr){return;}
226 ICharacterWeaponPickups* CharacterInteracting = Cast<ICharacterWeaponPickups>(CurrentInteractCaller);
227 IBaseServer* ServerCharacterInteracting = Cast<IBaseServer>(CurrentInteractCaller);
228 if(CharacterInteracting != nullptr)
229 {
230 const int32 RemainingAmmo = CharacterInteracting->PickupGunEvent(WeaponPickupData);
231 if(RemainingAmmo)
232 {
233 WeaponPickupData.TotalAmmoCount = RemainingAmmo;
234 }
235 else
236 {
237 if(ServerCharacterInteracting != nullptr)
238 {
239 ServerCharacterInteracting->DestroyActor(this);
240 }
241 }
242 }
243 Super::InteractionComplete();
244}
AActor * CurrentInteractCaller
Definition InteractableActorWithPrompt.h:60
virtual void InteractionComplete() override
Definition WeaponPickup.cpp:221
Definition BaseServer.h:16
virtual void DestroyActor(AActor *ActorToDestroy)
Definition CharacterWeaponPickups.h:17
virtual int32 PickupGunEvent(const FWeaponData_T In_WeaponData)=0
int32 TotalAmmoCount
Definition WeaponStructs.h:883

◆ Multicast_WeaponDroppedEvent()

virtual void AWeaponPickup::Multicast_WeaponDroppedEvent ( const FWeaponData_T & DroppedWeaponData)
protectedvirtual

◆ MulticastOnFinishSpawning()

virtual void AWeaponPickup::MulticastOnFinishSpawning ( )
virtual

◆ OnConstruction()

void AWeaponPickup::OnConstruction ( const FTransform & Transform)
overrideprotectedvirtual
48{
49 Super::OnConstruction(Transform);
50 if(GunMesh != nullptr && GunMesh->GetSkeletalMeshAsset() == nullptr)
51 {
52 SetMesh();
53 }
54}

◆ OnEndInteract()

void AWeaponPickup::OnEndInteract ( AActor * Caller)
overrideprotectedvirtual
247{
248 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
249 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::OnEndInteract);
250 Super::OnEndInteract(Caller);
251
252 // if(InteractionPromptComponent != nullptr)
253 // {
254 // InteractionPromptComponent->SetAvailable();
255 // }
256
257
258 // ICharacterWeaponPickups* CharacterInteracting = Cast<ICharacterWeaponPickups>(Caller);
259 // IBaseServer* ServerCharacterInteracting = Cast<IBaseServer>(Caller);
260 // if(CharacterInteracting != nullptr)
261 // {
262 // const int32 RemainingAmmo = CharacterInteracting->PickupGunEvent(WeaponPickupData);
263 // if(RemainingAmmo)
264 // {
265 // WeaponPickupData.TotalAmmoCount = RemainingAmmo;
266 // }
267 // else
268 // {
269 // if(ServerCharacterInteracting != nullptr)
270 // {
271 // ServerCharacterInteracting->DestroyActor(this);
272 // }
273 // }
274 // }
275}
virtual void OnEndInteract(AActor *Caller) override
Definition WeaponPickup.cpp:246

◆ OnFinishSpawning()

void AWeaponPickup::OnFinishSpawning ( )
overridevirtual
170{
171 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
172 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::OnFinishSpawning);
176 SetMesh();
178}
virtual void MulticastOnFinishSpawning()
virtual void OnFinishSpawning() override
Definition WeaponPickup.cpp:169

◆ OnInteract()

void AWeaponPickup::OnInteract ( AActor * Caller,
const int32 InteractionType )
overrideprotectedvirtual
192{
193 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
194 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::OnInteract);
195 Super::OnInteract(Caller, InteractionType);
196 if(Caller == nullptr){UE_LOG(LogWeaponSystem, Warning, TEXT("AWeaponPickup::OnInteract Caller NULLPTR "));return;}
197 if(bDebuggingMode){UE_LOG(LogWeaponSystem, Warning, TEXT("AWeaponPickup::OnInteract %s %i "), *Caller->GetHumanReadableName(), InteractionType);}
198 ICharacterWeaponPickups* CharacterInteracting = Cast<ICharacterWeaponPickups>(Caller);
199 if(CharacterInteracting == nullptr){if(bDebuggingMode){UE_LOG(LogWeaponSystem, Warning, TEXT("AWeaponPickup::OnInteract CharacterInteracting"));}return;}
200 if(!WeaponPickupData.IsValid()){if(bDebuggingMode){UE_LOG(LogWeaponSystem, Warning, TEXT("AWeaponPickup::OnInteract WeaponPickupData INVALID"));}return;}
201
202 SetOwner(Caller);
203 const bool bCanPickup = CharacterInteracting->PickupGunCheck(WeaponPickupData);
204 if(bCanPickup)
205 {
207 // if(InteractionPromptComponent != nullptr)
208 // {
209 // InteractionPromptComponent->SetAvailable();
210 // }
211 }
212 else
213 {
214 // if(InteractionPromptComponent != nullptr)
215 // {
216 // InteractionPromptComponent->SetUnavailable();
217 // }
218 }
219}
bool bDebuggingMode
Definition ActorBase.h:53
virtual void OnInteract(AActor *Caller, const int32 InteractionType) override
Definition WeaponPickup.cpp:191
virtual bool PickupGunCheck(const FWeaponData_T &In_WeaponData)=0
bool IsValid() const
Definition WeaponStructs.h:896

◆ OnOverlap()

bool AWeaponPickup::OnOverlap ( AActor * Caller)
overrideprotectedvirtual
278{
279 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
280 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::OnOverlap);
281 return Super::OnOverlap(Caller);
282}
virtual bool OnOverlap(AActor *Caller) override
Definition WeaponPickup.cpp:277

◆ SetAttachments()

void AWeaponPickup::SetAttachments ( )
protected
98{
99 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
100 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::SetAttachments);
101 for(const FString& WeaponAttachmentID : WeaponPickupData.CurrentWeaponAttachments)
102 {
103 AddAttachment(WeaponAttachmentID);
104 }
105}

◆ SetMesh()

void AWeaponPickup::SetMesh ( ) const
protected
86{
87 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
88 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::SetMesh);
89 bool bSuccess = false;
90 const FWeaponStats_T WeaponStats = UWeaponBPLib::GetWeaponStats(this, WeaponID, bSuccess);
91 if(bSuccess && WeaponStats.IsValid() && WeaponStats.MeshForPickup != nullptr)
92 {
93 GunMesh->SetSkeletalMesh(WeaponStats.MeshForPickup);
94 }
95}
bool IsValid() const
Definition WeaponStructs.h:842
class USkeletalMesh * MeshForPickup
Definition WeaponStructs.h:740

◆ StartFocus()

void AWeaponPickup::StartFocus ( )
overrideprotectedvirtual
285{
286 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
287 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::StartFocus);
288 Super::StartFocus();
289 if(GunMesh != nullptr)
290 {
291 GunMesh->SetRenderCustomDepth(true);
292 }
293}
virtual void StartFocus() override
Definition WeaponPickup.cpp:284

◆ ToggleSwitch()

void AWeaponPickup::ToggleSwitch ( AActor * Caller,
bool bOn )
overrideprotectedvirtual
307{
308 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
309 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::ToggleSwitch);
310 UE_LOG(LogWeaponSystem,Warning,TEXT("Toggle Switch, Weapon pickup"));
311}
virtual void ToggleSwitch(AActor *Caller, bool bOn) override
Definition WeaponPickup.cpp:306

◆ WeaponDroppedEvent()

void AWeaponPickup::WeaponDroppedEvent ( const FWeaponData_T & DroppedWeaponData)
overridevirtual

Implements IWeaponPickupInterface.

135{
136 SCOPE_CYCLE_COUNTER(STATGROUP_WeaponSystem_Weapons);
137 TRACE_CPUPROFILER_EVENT_SCOPE(AWeaponPickup::WeaponDroppedEvent);
138 if(!DroppedWeaponData.IsValid()){UE_LOG(LogWeaponSystem, Error, TEXT("No WeaponClass Was Set in Weapon Pickup"));return;}
139 bOverrideWeaponData = true;
140 WeaponID = DroppedWeaponData.WeaponID;
141 WeaponPickupData = DroppedWeaponData;
143 SetMesh();
146}
virtual void Multicast_WeaponDroppedEvent(const FWeaponData_T &DroppedWeaponData)
virtual void WeaponDroppedEvent(const FWeaponData_T &DroppedWeaponData) override
Definition WeaponPickup.cpp:134

Member Data Documentation

◆ bManuallySpawned

bool AWeaponPickup::bManuallySpawned = true
protected

If the weapon has been placed in the world, false if a player is dropping a weapon

◆ bOverrideWeaponData

bool AWeaponPickup::bOverrideWeaponData = false
protected

If we want it to spawn with custom weapon data, used for player dropped weapons and custom spawns

◆ CapsuleComponent

class UCapsuleComponent* AWeaponPickup::CapsuleComponent
protected

◆ GunMesh

class USkeletalMeshComponent* AWeaponPickup::GunMesh
protected

◆ WeaponID

FString AWeaponPickup::WeaponID = "DefaultWeapon"
protected

What Weapon it is, Will get the Default Weapon data from a DataTable

◆ WeaponPickupData

FWeaponData_T AWeaponPickup::WeaponPickupData
protected

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