2022-05-22 15:04:10 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "Pickup.h"
|
|
|
|
|
2022-05-22 23:06:42 +00:00
|
|
|
#include "NiagaraComponent.h"
|
|
|
|
#include "NiagaraFunctionLibrary.h"
|
2022-05-22 20:56:28 +00:00
|
|
|
#include "Blaster/Weapon/WeaponTypes.h"
|
2022-05-22 15:04:10 +00:00
|
|
|
#include "Components/SphereComponent.h"
|
|
|
|
#include "Kismet/GameplayStatics.h"
|
|
|
|
#include "Sound/SoundCue.h"
|
|
|
|
|
|
|
|
APickup::APickup()
|
|
|
|
{
|
|
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
bReplicates = true;
|
|
|
|
|
|
|
|
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
|
|
|
|
|
|
|
|
OverlapSphere = CreateDefaultSubobject<USphereComponent>(TEXT("OverlapSphere"));
|
|
|
|
OverlapSphere->SetupAttachment(RootComponent);
|
|
|
|
OverlapSphere->SetSphereRadius(150.f);
|
|
|
|
OverlapSphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
|
|
OverlapSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
|
|
|
OverlapSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
|
2022-05-22 20:56:28 +00:00
|
|
|
OverlapSphere->AddLocalOffset(FVector(0.f, 0.f, 85.f));
|
2022-05-22 15:04:10 +00:00
|
|
|
|
|
|
|
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
|
|
|
|
PickupMesh->SetupAttachment(OverlapSphere);
|
|
|
|
PickupMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
2022-05-22 20:56:28 +00:00
|
|
|
PickupMesh->SetRelativeScale3D(FVector(5.f, 5.f, 5.f));
|
|
|
|
PickupMesh->SetRenderCustomDepth(true);
|
|
|
|
PickupMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_PURPLE);
|
2022-05-22 23:06:42 +00:00
|
|
|
|
|
|
|
PickupEffectComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("PickupEffectComponent"));
|
|
|
|
PickupEffectComponent->SetupAttachment(RootComponent);
|
2022-05-22 15:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APickup::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
|
|
|
if (HasAuthority())
|
|
|
|
{
|
2022-05-23 21:45:28 +00:00
|
|
|
GetWorldTimerManager().SetTimer(
|
|
|
|
BindOverlapTimer,
|
|
|
|
this,
|
|
|
|
&APickup::BindOverlapTimerFinished,
|
|
|
|
BindOverlapTime
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void APickup::OnOverlap(ABlasterCharacter* BlasterCharacter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void APickup::BindOverlapTimerFinished()
|
|
|
|
{
|
|
|
|
if (HasAuthority())
|
|
|
|
{
|
|
|
|
TArray<AActor*> OverlappingActors;
|
|
|
|
GetOverlappingActors(OverlappingActors, ABlasterCharacter::StaticClass());
|
|
|
|
for (const auto OverlappingActor : OverlappingActors)
|
|
|
|
{
|
|
|
|
if (ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OverlappingActor))
|
|
|
|
{
|
|
|
|
OnOverlap(BlasterCharacter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 15:04:10 +00:00
|
|
|
OverlapSphere->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnSphereOverlap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void APickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
|
2022-05-23 21:45:28 +00:00
|
|
|
bool bFromSweep, const FHitResult& SweepResult)
|
2022-05-22 15:04:10 +00:00
|
|
|
{
|
2022-05-23 21:45:28 +00:00
|
|
|
if (ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor))
|
|
|
|
{
|
|
|
|
OnOverlap(BlasterCharacter);
|
|
|
|
}
|
2022-05-22 15:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APickup::Tick(float DeltaTime)
|
|
|
|
{
|
|
|
|
Super::Tick(DeltaTime);
|
|
|
|
|
2022-05-22 20:56:28 +00:00
|
|
|
if (PickupMesh)
|
|
|
|
{
|
|
|
|
PickupMesh->AddWorldRotation(FRotator(0.f, BaseTurnRate * DeltaTime, 0.f));
|
|
|
|
}
|
2022-05-22 15:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APickup::Destroyed()
|
|
|
|
{
|
|
|
|
Super::Destroyed();
|
|
|
|
|
|
|
|
if (PickupSound)
|
|
|
|
{
|
|
|
|
UGameplayStatics::PlaySoundAtLocation(
|
|
|
|
this,
|
|
|
|
PickupSound,
|
|
|
|
GetActorLocation()
|
|
|
|
);
|
|
|
|
}
|
2022-05-22 23:06:42 +00:00
|
|
|
if (PickupEffect)
|
|
|
|
{
|
|
|
|
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
|
|
|
|
this,
|
|
|
|
PickupEffect,
|
|
|
|
GetActorLocation(),
|
|
|
|
GetActorRotation()
|
|
|
|
);
|
|
|
|
}
|
2022-05-22 15:04:10 +00:00
|
|
|
}
|