163 - Pickup Spawn Point

This commit is contained in:
Kingsmedia 2022-05-23 23:45:28 +02:00
parent 5c4a41202f
commit 6e741fc764
17 changed files with 169 additions and 99 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,19 +6,13 @@
#include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/CombatComponent.h" #include "Blaster/Components/CombatComponent.h"
void AAmmoPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, void AAmmoPickup::OnOverlap(ABlasterCharacter* BlasterCharacter)
bool bFromSweep, const FHitResult& SweepResult)
{ {
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); Super::OnOverlap(BlasterCharacter);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor); if (UCombatComponent* Combat = BlasterCharacter->GetCombat())
if (BlasterCharacter)
{ {
UCombatComponent* Combat = BlasterCharacter->GetCombat(); Combat->PickupAmmo(WeaponType, AmmoAmount);
if (Combat)
{
Combat->PickupAmmo(WeaponType, AmmoAmount);
}
} }
Destroy(); Destroy();

View File

@ -16,14 +16,7 @@ class BLASTER_API AAmmoPickup : public APickup
GENERATED_BODY() GENERATED_BODY()
protected: protected:
virtual void OnSphereOverlap( virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override;
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
) override;
private: private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)

View File

@ -11,19 +11,13 @@ AHealthPickup::AHealthPickup()
bReplicates = true; bReplicates = true;
} }
void AHealthPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, void AHealthPickup::OnOverlap(ABlasterCharacter* BlasterCharacter)
bool bFromSweep, const FHitResult& SweepResult)
{ {
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); Super::OnOverlap(BlasterCharacter);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor); if (UBuffComponent* Buff = BlasterCharacter->GetBuff())
if (BlasterCharacter)
{ {
UBuffComponent* Buff = BlasterCharacter->GetBuff(); Buff->Heal(HealAmount, HealingTime);
if (Buff)
{
Buff->Heal(HealAmount, HealingTime);
}
} }
Destroy(); Destroy();

View File

@ -18,14 +18,7 @@ public:
AHealthPickup(); AHealthPickup();
protected: protected:
virtual void OnSphereOverlap( virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override;
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
) override;
private: private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)

View File

@ -6,21 +6,14 @@
#include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/BuffComponent.h" #include "Blaster/Components/BuffComponent.h"
void AJumpPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, void AJumpPickup::OnOverlap(ABlasterCharacter* BlasterCharacter)
bool bFromSweep, const FHitResult& SweepResult)
{ {
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); Super::OnOverlap(BlasterCharacter);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor); if (UBuffComponent* Buff = BlasterCharacter->GetBuff())
if (BlasterCharacter)
{ {
UBuffComponent* Buff = BlasterCharacter->GetBuff(); Buff->BuffJump(JumpZVelocity, JumpBuffTime);
if (Buff)
{
Buff->BuffJump(JumpZVelocity, JumpBuffTime);
}
} }
Destroy(); Destroy();
} }

View File

@ -15,14 +15,7 @@ class BLASTER_API AJumpPickup : public APickup
GENERATED_BODY() GENERATED_BODY()
protected: protected:
virtual void OnSphereOverlap( virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override;
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
) override;
private: private:

View File

@ -42,14 +42,44 @@ void APickup::BeginPlay()
if (HasAuthority()) if (HasAuthority())
{ {
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);
}
}
OverlapSphere->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnSphereOverlap); OverlapSphere->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnSphereOverlap);
} }
} }
void APickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, void APickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult) bool bFromSweep, const FHitResult& SweepResult)
{ {
if (ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor))
{
OnOverlap(BlasterCharacter);
}
} }
void APickup::Tick(float DeltaTime) void APickup::Tick(float DeltaTime)
@ -84,4 +114,3 @@ void APickup::Destroyed()
); );
} }
} }

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "Pickup.generated.h" #include "Pickup.generated.h"
@ -15,7 +16,7 @@ public:
APickup(); APickup();
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
virtual void Destroyed() override; virtual void Destroyed() override;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
@ -29,9 +30,16 @@ protected:
const FHitResult& SweepResult const FHitResult& SweepResult
); );
virtual void OnOverlap(ABlasterCharacter* BlasterCharacter);
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float BaseTurnRate = 45.f; float BaseTurnRate = 45.f;
FTimerHandle BindOverlapTimer;
float BindOverlapTime = 0.25f;
void BindOverlapTimerFinished();
private: private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
class USphereComponent* OverlapSphere; class USphereComponent* OverlapSphere;
@ -41,11 +49,10 @@ private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
UStaticMeshComponent* PickupMesh; UStaticMeshComponent* PickupMesh;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* PickupEffectComponent; class UNiagaraComponent* PickupEffectComponent;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
class UNiagaraSystem* PickupEffect; class UNiagaraSystem* PickupEffect;
}; };

View File

@ -0,0 +1,59 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "PickupSpawnPoint.h"
#include "Pickup.h"
#include "Kismet/GameplayStatics.h"
APickupSpawnPoint::APickupSpawnPoint()
{
PrimaryActorTick.bCanEverTick = true;
bReplicates = true;
}
void APickupSpawnPoint::BeginPlay()
{
Super::BeginPlay();
StartSpawnPickupTimer(nullptr);
}
void APickupSpawnPoint::SpawnPickup()
{
if (const int32 NumPickupClasses = PickupClasses.Num(); NumPickupClasses > 0)
{
const int32 Selection = FMath::RandRange(0, NumPickupClasses - 1);
SpawnedPickup = GetWorld()->SpawnActor<APickup>(
PickupClasses[Selection],
GetActorTransform()
);
if (HasAuthority() && SpawnedPickup)
{
SpawnedPickup->OnDestroyed.AddDynamic(this, &APickupSpawnPoint::StartSpawnPickupTimer);
}
}
}
void APickupSpawnPoint::StartSpawnPickupTimer(AActor* Destroyed)
{
const float SpawnTime = FMath::RandRange(SpawnPickupTimeMin, SpawnPickupTimeMax);
GetWorldTimerManager().SetTimer(
SpawnPickupTimer,
this,
&APickupSpawnPoint::SpawnPickupTimerFinished,
SpawnTime
);
}
void APickupSpawnPoint::SpawnPickupTimerFinished()
{
if (HasAuthority())
{
SpawnPickup();
}
}
void APickupSpawnPoint::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -0,0 +1,41 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PickupSpawnPoint.generated.h"
UCLASS()
class BLASTER_API APickupSpawnPoint : public AActor
{
GENERATED_BODY()
public:
APickupSpawnPoint();
virtual void Tick(float DeltaTime) override;
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere)
TArray<TSubclassOf<class APickup>> PickupClasses;
UPROPERTY()
APickup* SpawnedPickup;
UPROPERTY(EditAnywhere)
float SpawnPickupTimeMin;
UPROPERTY(EditAnywhere)
float SpawnPickupTimeMax;
void SpawnPickup();
UFUNCTION()
void StartSpawnPickupTimer(AActor* Destroyed);
void SpawnPickupTimerFinished();
private:
FTimerHandle SpawnPickupTimer;
};

View File

@ -6,19 +6,13 @@
#include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/BuffComponent.h" #include "Blaster/Components/BuffComponent.h"
void AShieldPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, void AShieldPickup::OnOverlap(ABlasterCharacter* BlasterCharacter)
bool bFromSweep, const FHitResult& SweepResult)
{ {
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); Super::OnOverlap(BlasterCharacter);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor); if (UBuffComponent* Buff = BlasterCharacter->GetBuff())
if (BlasterCharacter)
{ {
UBuffComponent* Buff = BlasterCharacter->GetBuff(); Buff->ReplenishShield(ShieldReplenishAmount, ShieldReplenishTime);
if (Buff)
{
Buff->ReplenishShield(ShieldReplenishAmount, ShieldReplenishTime);
}
} }
Destroy(); Destroy();

View File

@ -16,14 +16,7 @@ class BLASTER_API AShieldPickup : public APickup
protected: protected:
virtual void OnSphereOverlap( virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override;
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
) override;
private: private:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)

View File

@ -6,20 +6,14 @@
#include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/BuffComponent.h" #include "Blaster/Components/BuffComponent.h"
void ASpeedPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, void ASpeedPickup::OnOverlap(ABlasterCharacter* BlasterCharacter)
bool bFromSweep, const FHitResult& SweepResult)
{ {
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); Super::OnOverlap(BlasterCharacter);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor); if (UBuffComponent* Buff = BlasterCharacter->GetBuff())
if (BlasterCharacter)
{ {
UBuffComponent* Buff = BlasterCharacter->GetBuff(); Buff->BuffSpeed(BaseSpeedBuff, CrouchSpeedBuff, SpeedBuffTime);
if (Buff)
{
Buff->BuffSpeed(BaseSpeedBuff, CrouchSpeedBuff, SpeedBuffTime);
}
} }
Destroy(); Destroy();
} }

View File

@ -15,14 +15,7 @@ class BLASTER_API ASpeedPickup : public APickup
GENERATED_BODY() GENERATED_BODY()
protected: protected:
virtual void OnSphereOverlap( virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override;
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
) override;
private: private: