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

#include <InteractableBox.h>

Inheritance diagram for AInteractableBox:
AInteractableActor AActorBase IBaseInterface ISaveLoad

Public Member Functions

 AInteractableBox ()
 
void OnBoxOpened ()
 
void Server_CalculateRandomNumber ()
 
void Server_OpenBox (const FVector &Force)
 
- Public Member Functions inherited from AInteractableActor
 AInteractableActor ()
 
virtual void ReceiveOnEndInteract (AActor *Caller)
 
virtual void ReceiveOnOverlap (AActor *Caller)
 
virtual void ReceiveOnEndOverlap (AActor *Caller)
 
- 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 BeginPlay () override
 
virtual void ReceiveOnInteract (AActor *Caller, const EInteractionType InteractionType) override
 
virtual void ReceiveToggleSwitch (AActor *Caller, const bool bOn) override
 
virtual void ReceiveStartFocus (AActor *Caller) override
 
virtual void ReceiveEndFocus (AActor *Caller) override
 
void SetMesh ()
 
void OpenBox (const FVector &Force)
 
bool IsValid () const
 
FVector CalculateImpulse (const AActor *Caller) const
 
void OnMeshTypeReplicated ()
 
void OnOpenedReplicated ()
 
void OnBoxDataReplicated ()
 
- 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

UStaticMeshComponent * BaseMeshComponent
 
UStaticMeshComponent * LidMeshComponent
 
class USphereComponent * SphereComponent
 
bool bOpened = false
 
bool bUseBoxData = false
 
bool bUseRandom = false
 
int32 MeshType = 0
 
TArray< UStaticMesh * > BaseMeshes
 
TArray< UStaticMesh * > LidMeshes
 
int32 Credits = 0
 
int32 XP = 0
 
float DirectionalForce = 5200.0f
 
float UpForce = 12500.0f
 
class USoundBase * OpenSound
 
FBoxReplicationData BoxReplicationData
 
- 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
 

Private Member Functions

void DestroyLid ()
 

Private Attributes

bool bLidDestroyed = false
 
float LidDestroyTime = 20.0f
 
FTimerHandle LidDestroyTimerHandle
 

Constructor & Destructor Documentation

◆ AInteractableBox()

AInteractableBox::AInteractableBox ( )
explicit
15{
16 PrimaryActorTick.bCanEverTick = false;
17 BaseMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("Base Mesh");
18 RootComponent = BaseMeshComponent;
19 BaseMeshComponent->SetSimulatePhysics(true);
20 BaseMeshComponent->BodyInstance.bNotifyRigidBodyCollision = true;
21 LidMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("Lid Mesh");
22 LidMeshComponent->SetupAttachment(RootComponent);
23 SphereComponent = CreateDefaultSubobject<USphereComponent>("Sphere");
24 SphereComponent->SetupAttachment(RootComponent);
25 bReplicates = true;
26 SetReplicateMovement(true);
28 OpenInteraction.bHold = true;
29 InteractableActorComponent->InteractionData = FInteractionData(OpenInteraction, EAIStimuliType::Item);
30 InteractableActorComponent->bLoseFocusAfterInteract = true;
31}
class UInteractableActorComponent * InteractableActorComponent
Definition InteractableActor.h:63
UStaticMeshComponent * BaseMeshComponent
Definition InteractableBox.h:88
class USphereComponent * SphereComponent
Definition InteractableBox.h:92
UStaticMeshComponent * LidMeshComponent
Definition InteractableBox.h:90
Definition BaseData.h:420
Definition BaseData.h:333
bool bHold
Definition BaseData.h:339

Member Function Documentation

◆ BeginPlay()

void AInteractableBox::BeginPlay ( )
overrideprotectedvirtual

Reimplemented from AInteractableActor.

43{
44 Super::BeginPlay();
45 if(bUseRandom)
46 {
47 if(HasAuthority())
48 {
51 return;
52 }
53 }
55}
void Server_CalculateRandomNumber()
bool bUseRandom
Definition InteractableBox.h:100
void OnMeshTypeReplicated()
Definition InteractableBox.cpp:289

◆ CalculateImpulse()

FVector AInteractableBox::CalculateImpulse ( const AActor * Caller) const
protected
282{
283 if(Caller == nullptr){return FVector::ZeroVector;}
284 const FRotator LookAtRotation = UKismetMathLibrary::FindLookAtRotation(Caller->GetActorLocation(), GetActorLocation());
285 const FVector ForwardVector = LookAtRotation.Vector();
286 return (ForwardVector * DirectionalForce) + (FVector::UpVector * UpForce);
287}
float UpForce
Definition InteractableBox.h:116
float DirectionalForce
Definition InteractableBox.h:113

◆ DestroyLid()

void AInteractableBox::DestroyLid ( )
private
214{
215 if(LidMeshComponent != nullptr)
216 {
217 bLidDestroyed = true;
218 LidMeshComponent->DestroyComponent();
219 LidMeshComponent = nullptr;
220 }
221}
bool bLidDestroyed
Definition InteractableBox.h:129

◆ IsValid()

bool AInteractableBox::IsValid ( ) const
protected
271{
272 if(BaseMeshes.IsEmpty()){return false;}
273 if(LidMeshes.IsEmpty()){return false;}
274 if(BaseMeshComponent == nullptr){return false;}
275 if(LidMeshComponent == nullptr && bLidDestroyed == false){return false;}
276 if(BaseMeshes.IsValidIndex(MeshType) == false){return false;}
277 if(LidMeshes.IsValidIndex(MeshType) == false){return false;}
278 return true;
279}
TArray< UStaticMesh * > BaseMeshes
Definition InteractableBox.h:104
int32 MeshType
Definition InteractableBox.h:102
TArray< UStaticMesh * > LidMeshes
Definition InteractableBox.h:106

◆ OnBoxDataReplicated()

void AInteractableBox::OnBoxDataReplicated ( )
protected
192{
193 // FInteractionType InteractionType;
194 // if(UBaseHelpersBPLib::GetInteraction(InteractionType, GetInteractionData(), BoxReplicationData.SelectedInteraction))
195 // {
197 {
198 if(HasAuthority())
199 {
201 }
202 InteractableActorComponent->SetInteractionHidden(EInteractionType::Open, true);
203 IInteractionInterface* BaseCaller = Cast<IInteractionInterface>(BoxReplicationData.Caller);
204 if(BaseCaller != nullptr)
205 {
206 BaseCaller->InteractionDataUpdated();
207 }
208 OnBoxOpened();
209 }
210 // }
211}
FVector CalculateImpulse(const AActor *Caller) const
Definition InteractableBox.cpp:281
void OpenBox(const FVector &Force)
Definition InteractableBox.cpp:223
FBoxReplicationData BoxReplicationData
Definition InteractableBox.h:123
Definition InteractionInterface.h:18
virtual void InteractionDataUpdated() const
Definition InteractionInterface.h:57
EInteractionType SelectedInteraction
Definition InteractableBox.h:18
AActor * Caller
Definition InteractableBox.h:16

◆ OnBoxOpened()

void AInteractableBox::OnBoxOpened ( )

◆ OnMeshTypeReplicated()

void AInteractableBox::OnMeshTypeReplicated ( )
protected
290{
291 if(IsValid() == false)
292 {
293 UE_LOG(LogTemp, Warning, TEXT("AInteractableBox::OnMeshTypeReplicated Invalid"));
294 Destroy();
295 return;
296 }
297 SetMesh();
298}
void SetMesh()
Definition InteractableBox.cpp:142
bool IsValid() const
Definition InteractableBox.cpp:270

◆ OnOpenedReplicated()

void AInteractableBox::OnOpenedReplicated ( )
protected
301{
303}
FVector Impulse
Definition InteractableBox.h:19

◆ OpenBox()

void AInteractableBox::OpenBox ( const FVector & Force)
protected
224{
225 UE_LOG(LogTemp, Warning, TEXT("OPEN BOX"));
226 if(IsValid() == false){return;}
227 bOpened = true;
228 LidMeshComponent->SetRenderCustomDepth(false);
229 LidMeshComponent->SetIsReplicated(true);
230 LidMeshComponent->SetSimulatePhysics(true);
231 LidMeshComponent->AddImpulse(Force);
232 InteractableActorComponent->SetInteractionHidden(EInteractionType::Open, true);
233 if(BaseMeshComponent != nullptr && OpenSound != nullptr)
234 {
235 UGameplayStatics::PlaySoundAtLocation(this, OpenSound, BaseMeshComponent->GetComponentLocation());
236 }
237 if(SphereComponent != nullptr)
238 {
239 SphereComponent->DestroyComponent();
240 }
241 GetWorld()->GetTimerManager().SetTimer(LidDestroyTimerHandle, this, &AInteractableBox::DestroyLid, LidDestroyTime);
242}
class USoundBase * OpenSound
Definition InteractableBox.h:118
float LidDestroyTime
Definition InteractableBox.h:132
bool bOpened
Definition InteractableBox.h:95
void DestroyLid()
Definition InteractableBox.cpp:213
FTimerHandle LidDestroyTimerHandle
Definition InteractableBox.h:133

◆ ReceiveEndFocus()

void AInteractableBox::ReceiveEndFocus ( AActor * Caller)
overrideprotectedvirtual

Reimplemented from AInteractableActor.

132{
133 Super::ReceiveEndFocus(Caller);
134 if(IsValid() == false){return;}
135 BaseMeshComponent->SetRenderCustomDepth(false);
136 if(bOpened == false)
137 {
138 LidMeshComponent->SetRenderCustomDepth(false);
139 }
140}

◆ ReceiveOnInteract()

void AInteractableBox::ReceiveOnInteract ( AActor * Caller,
const EInteractionType InteractionType )
overrideprotectedvirtual

Reimplemented from AInteractableActor.

58{
59 Super::ReceiveOnInteract(Caller, InteractionType);
60 SetOwner(Caller);
61 // if(bUseBoxData)
62 // {
63 // BoxReplicationData = FBoxReplicationData(Caller, InteractionType, CalculateImpulse(Caller));
64 // OnBoxDataReplicated();
65 // return;
66 // }
67 // FInteractionType InteractionType;
68 // if(UBaseHelpersBPLib::GetInteraction(InteractionType, GetInteractionData(), InteractionType))
69 // {
70 if(InteractionType == EInteractionType::Open)
71 {
72 // Server_OpenBox(CalculateImpulse(Caller));
73 if(HasAuthority())
74 {
76 }
77 else
78 {
80 }
81 InteractableActorComponent->SetInteractionHidden(EInteractionType::Open, true);
82 const IInteractionInterface* BaseCaller = Cast<IInteractionInterface>(Caller);
83 if(BaseCaller != nullptr)
84 {
85 BaseCaller->InteractionDataUpdated();
86 }
88 }
89 // }
90}
void Server_OpenBox(const FVector &Force)

◆ ReceiveStartFocus()

void AInteractableBox::ReceiveStartFocus ( AActor * Caller)
overrideprotectedvirtual

Reimplemented from AInteractableActor.

121{
122 Super::ReceiveStartFocus(Caller);
123 if(IsValid() == false){return;}
124 BaseMeshComponent->SetRenderCustomDepth(true);
125 if(bOpened == false)
126 {
127 LidMeshComponent->SetRenderCustomDepth(true);
128 }
129}

◆ ReceiveToggleSwitch()

void AInteractableBox::ReceiveToggleSwitch ( AActor * Caller,
const bool bOn )
overrideprotectedvirtual

Reimplemented from AInteractableActor.

93{
94 Super::ReceiveToggleSwitch(Caller, bOn);
95
96}

◆ Server_CalculateRandomNumber()

void AInteractableBox::Server_CalculateRandomNumber ( )

◆ Server_OpenBox()

void AInteractableBox::Server_OpenBox ( const FVector & Force)

◆ SetMesh()

void AInteractableBox::SetMesh ( )
protected
143{
144 if(IsValid() == false)
145 {
146 UE_LOG(LogTemp, Warning, TEXT("AInteractableBox::SetMesh Invalid"));
147 return;
148 }
149 BaseMeshComponent->SetStaticMesh(BaseMeshes[MeshType]);
150 if(bOpened == false)
151 {
152 LidMeshComponent->SetStaticMesh(LidMeshes[MeshType]);
153 }
154}

Member Data Documentation

◆ BaseMeshComponent

UStaticMeshComponent* AInteractableBox::BaseMeshComponent
protected

◆ BaseMeshes

TArray<UStaticMesh*> AInteractableBox::BaseMeshes
protected

◆ bLidDestroyed

bool AInteractableBox::bLidDestroyed = false
private

◆ bOpened

bool AInteractableBox::bOpened = false
protected

◆ BoxReplicationData

FBoxReplicationData AInteractableBox::BoxReplicationData
protected

◆ bUseBoxData

bool AInteractableBox::bUseBoxData = false
protected

◆ bUseRandom

bool AInteractableBox::bUseRandom = false
protected

◆ Credits

int32 AInteractableBox::Credits = 0
protected

◆ DirectionalForce

float AInteractableBox::DirectionalForce = 5200.0f
protected

How much force in the direction from the Character Interacting

◆ LidDestroyTime

float AInteractableBox::LidDestroyTime = 20.0f
private

How Long After opened does the lid last

◆ LidDestroyTimerHandle

FTimerHandle AInteractableBox::LidDestroyTimerHandle
private

◆ LidMeshComponent

UStaticMeshComponent* AInteractableBox::LidMeshComponent
protected

◆ LidMeshes

TArray<UStaticMesh*> AInteractableBox::LidMeshes
protected

◆ MeshType

int32 AInteractableBox::MeshType = 0
protected

◆ OpenSound

class USoundBase* AInteractableBox::OpenSound
protected

◆ SphereComponent

class USphereComponent* AInteractableBox::SphereComponent
protected

◆ UpForce

float AInteractableBox::UpForce = 12500.0f
protected

How much force UP when opened

◆ XP

int32 AInteractableBox::XP = 0
protected

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