diff --git a/Content/Blueprints/Pickups/BP_AmmoSpawnPoint.uasset b/Content/Blueprints/Pickups/BP_AmmoSpawnPoint.uasset new file mode 100644 index 0000000..4ef6dea Binary files /dev/null and b/Content/Blueprints/Pickups/BP_AmmoSpawnPoint.uasset differ diff --git a/Content/Blueprints/Pickups/BP_PickupSpawnPoint.uasset b/Content/Blueprints/Pickups/BP_PickupSpawnPoint.uasset new file mode 100644 index 0000000..af20d3e Binary files /dev/null and b/Content/Blueprints/Pickups/BP_PickupSpawnPoint.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index 0d213bd..3ef44e3 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Pickups/AmmoPickup.cpp b/Source/Blaster/Pickups/AmmoPickup.cpp index 2693fdd..37e68a9 100644 --- a/Source/Blaster/Pickups/AmmoPickup.cpp +++ b/Source/Blaster/Pickups/AmmoPickup.cpp @@ -6,19 +6,13 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Components/CombatComponent.h" -void AAmmoPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, - bool bFromSweep, const FHitResult& SweepResult) +void AAmmoPickup::OnOverlap(ABlasterCharacter* BlasterCharacter) { - Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); + Super::OnOverlap(BlasterCharacter); - ABlasterCharacter* BlasterCharacter = Cast(OtherActor); - if (BlasterCharacter) + if (UCombatComponent* Combat = BlasterCharacter->GetCombat()) { - UCombatComponent* Combat = BlasterCharacter->GetCombat(); - if (Combat) - { - Combat->PickupAmmo(WeaponType, AmmoAmount); - } + Combat->PickupAmmo(WeaponType, AmmoAmount); } Destroy(); diff --git a/Source/Blaster/Pickups/AmmoPickup.h b/Source/Blaster/Pickups/AmmoPickup.h index 7382a5a..d85662c 100644 --- a/Source/Blaster/Pickups/AmmoPickup.h +++ b/Source/Blaster/Pickups/AmmoPickup.h @@ -16,14 +16,7 @@ class BLASTER_API AAmmoPickup : public APickup GENERATED_BODY() protected: - virtual void OnSphereOverlap( - UPrimitiveComponent* OverlappedComponent, - AActor* OtherActor, - UPrimitiveComponent* OtherComp, - int32 OtherBodyIndex, - bool bFromSweep, - const FHitResult& SweepResult - ) override; + virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override; private: UPROPERTY(EditAnywhere) diff --git a/Source/Blaster/Pickups/HealthPickup.cpp b/Source/Blaster/Pickups/HealthPickup.cpp index 4f6518d..f5645c0 100644 --- a/Source/Blaster/Pickups/HealthPickup.cpp +++ b/Source/Blaster/Pickups/HealthPickup.cpp @@ -11,19 +11,13 @@ AHealthPickup::AHealthPickup() bReplicates = true; } -void AHealthPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, - bool bFromSweep, const FHitResult& SweepResult) +void AHealthPickup::OnOverlap(ABlasterCharacter* BlasterCharacter) { - Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); + Super::OnOverlap(BlasterCharacter); - ABlasterCharacter* BlasterCharacter = Cast(OtherActor); - if (BlasterCharacter) + if (UBuffComponent* Buff = BlasterCharacter->GetBuff()) { - UBuffComponent* Buff = BlasterCharacter->GetBuff(); - if (Buff) - { - Buff->Heal(HealAmount, HealingTime); - } + Buff->Heal(HealAmount, HealingTime); } Destroy(); diff --git a/Source/Blaster/Pickups/HealthPickup.h b/Source/Blaster/Pickups/HealthPickup.h index e0da305..34c0257 100644 --- a/Source/Blaster/Pickups/HealthPickup.h +++ b/Source/Blaster/Pickups/HealthPickup.h @@ -18,14 +18,7 @@ public: AHealthPickup(); protected: - virtual void OnSphereOverlap( - UPrimitiveComponent* OverlappedComponent, - AActor* OtherActor, - UPrimitiveComponent* OtherComp, - int32 OtherBodyIndex, - bool bFromSweep, - const FHitResult& SweepResult - ) override; + virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override; private: UPROPERTY(EditAnywhere) diff --git a/Source/Blaster/Pickups/JumpPickup.cpp b/Source/Blaster/Pickups/JumpPickup.cpp index a461153..e497370 100644 --- a/Source/Blaster/Pickups/JumpPickup.cpp +++ b/Source/Blaster/Pickups/JumpPickup.cpp @@ -6,21 +6,14 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Components/BuffComponent.h" -void AJumpPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, - bool bFromSweep, const FHitResult& SweepResult) +void AJumpPickup::OnOverlap(ABlasterCharacter* BlasterCharacter) { - Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); + Super::OnOverlap(BlasterCharacter); - ABlasterCharacter* BlasterCharacter = Cast(OtherActor); - if (BlasterCharacter) + if (UBuffComponent* Buff = BlasterCharacter->GetBuff()) { - UBuffComponent* Buff = BlasterCharacter->GetBuff(); - if (Buff) - { - Buff->BuffJump(JumpZVelocity, JumpBuffTime); - } + Buff->BuffJump(JumpZVelocity, JumpBuffTime); } Destroy(); } - diff --git a/Source/Blaster/Pickups/JumpPickup.h b/Source/Blaster/Pickups/JumpPickup.h index 17a15f8..60d90ea 100644 --- a/Source/Blaster/Pickups/JumpPickup.h +++ b/Source/Blaster/Pickups/JumpPickup.h @@ -15,14 +15,7 @@ class BLASTER_API AJumpPickup : public APickup GENERATED_BODY() protected: - virtual void OnSphereOverlap( - UPrimitiveComponent* OverlappedComponent, - AActor* OtherActor, - UPrimitiveComponent* OtherComp, - int32 OtherBodyIndex, - bool bFromSweep, - const FHitResult& SweepResult - ) override; + virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override; private: diff --git a/Source/Blaster/Pickups/Pickup.cpp b/Source/Blaster/Pickups/Pickup.cpp index 0587919..92fc32f 100644 --- a/Source/Blaster/Pickups/Pickup.cpp +++ b/Source/Blaster/Pickups/Pickup.cpp @@ -42,14 +42,44 @@ void APickup::BeginPlay() if (HasAuthority()) { + GetWorldTimerManager().SetTimer( + BindOverlapTimer, + this, + &APickup::BindOverlapTimerFinished, + BindOverlapTime + ); + } +} + +void APickup::OnOverlap(ABlasterCharacter* BlasterCharacter) +{ +} + +void APickup::BindOverlapTimerFinished() +{ + if (HasAuthority()) + { + TArray OverlappingActors; + GetOverlappingActors(OverlappingActors, ABlasterCharacter::StaticClass()); + for (const auto OverlappingActor : OverlappingActors) + { + if (ABlasterCharacter* BlasterCharacter = Cast(OverlappingActor)) + { + OnOverlap(BlasterCharacter); + } + } + OverlapSphere->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnSphereOverlap); } } 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(OtherActor)) + { + OnOverlap(BlasterCharacter); + } } void APickup::Tick(float DeltaTime) @@ -84,4 +114,3 @@ void APickup::Destroyed() ); } } - diff --git a/Source/Blaster/Pickups/Pickup.h b/Source/Blaster/Pickups/Pickup.h index a8ac628..70df6c8 100644 --- a/Source/Blaster/Pickups/Pickup.h +++ b/Source/Blaster/Pickups/Pickup.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "Blaster/Character/BlasterCharacter.h" #include "GameFramework/Actor.h" #include "Pickup.generated.h" @@ -15,7 +16,7 @@ public: APickup(); virtual void Tick(float DeltaTime) override; virtual void Destroyed() override; - + protected: virtual void BeginPlay() override; @@ -29,9 +30,16 @@ protected: const FHitResult& SweepResult ); + virtual void OnOverlap(ABlasterCharacter* BlasterCharacter); + UPROPERTY(EditAnywhere) float BaseTurnRate = 45.f; - + + FTimerHandle BindOverlapTimer; + float BindOverlapTime = 0.25f; + void BindOverlapTimerFinished(); + + private: UPROPERTY(EditAnywhere) class USphereComponent* OverlapSphere; @@ -41,11 +49,10 @@ private: UPROPERTY(EditAnywhere) UStaticMeshComponent* PickupMesh; - + UPROPERTY(VisibleAnywhere) class UNiagaraComponent* PickupEffectComponent; UPROPERTY(EditAnywhere) class UNiagaraSystem* PickupEffect; - }; diff --git a/Source/Blaster/Pickups/PickupSpawnPoint.cpp b/Source/Blaster/Pickups/PickupSpawnPoint.cpp new file mode 100644 index 0000000..3c49aa7 --- /dev/null +++ b/Source/Blaster/Pickups/PickupSpawnPoint.cpp @@ -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( + 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); +} diff --git a/Source/Blaster/Pickups/PickupSpawnPoint.h b/Source/Blaster/Pickups/PickupSpawnPoint.h new file mode 100644 index 0000000..9ad240e --- /dev/null +++ b/Source/Blaster/Pickups/PickupSpawnPoint.h @@ -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> PickupClasses; + + UPROPERTY() + APickup* SpawnedPickup; + + UPROPERTY(EditAnywhere) + float SpawnPickupTimeMin; + UPROPERTY(EditAnywhere) + float SpawnPickupTimeMax; + + void SpawnPickup(); + UFUNCTION() + void StartSpawnPickupTimer(AActor* Destroyed); + void SpawnPickupTimerFinished(); + +private: + + FTimerHandle SpawnPickupTimer; + +}; diff --git a/Source/Blaster/Pickups/ShieldPickup.cpp b/Source/Blaster/Pickups/ShieldPickup.cpp index e182de0..16cafe3 100644 --- a/Source/Blaster/Pickups/ShieldPickup.cpp +++ b/Source/Blaster/Pickups/ShieldPickup.cpp @@ -6,19 +6,13 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Components/BuffComponent.h" -void AShieldPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, - bool bFromSweep, const FHitResult& SweepResult) +void AShieldPickup::OnOverlap(ABlasterCharacter* BlasterCharacter) { - Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); + Super::OnOverlap(BlasterCharacter); - ABlasterCharacter* BlasterCharacter = Cast(OtherActor); - if (BlasterCharacter) + if (UBuffComponent* Buff = BlasterCharacter->GetBuff()) { - UBuffComponent* Buff = BlasterCharacter->GetBuff(); - if (Buff) - { - Buff->ReplenishShield(ShieldReplenishAmount, ShieldReplenishTime); - } + Buff->ReplenishShield(ShieldReplenishAmount, ShieldReplenishTime); } Destroy(); diff --git a/Source/Blaster/Pickups/ShieldPickup.h b/Source/Blaster/Pickups/ShieldPickup.h index b3132c6..42658f5 100644 --- a/Source/Blaster/Pickups/ShieldPickup.h +++ b/Source/Blaster/Pickups/ShieldPickup.h @@ -16,14 +16,7 @@ class BLASTER_API AShieldPickup : public APickup protected: - virtual void OnSphereOverlap( - UPrimitiveComponent* OverlappedComponent, - AActor* OtherActor, - UPrimitiveComponent* OtherComp, - int32 OtherBodyIndex, - bool bFromSweep, - const FHitResult& SweepResult - ) override; + virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override; private: UPROPERTY(EditAnywhere) diff --git a/Source/Blaster/Pickups/SpeedPickup.cpp b/Source/Blaster/Pickups/SpeedPickup.cpp index 562fc52..09dd640 100644 --- a/Source/Blaster/Pickups/SpeedPickup.cpp +++ b/Source/Blaster/Pickups/SpeedPickup.cpp @@ -6,20 +6,14 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Components/BuffComponent.h" -void ASpeedPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, - bool bFromSweep, const FHitResult& SweepResult) +void ASpeedPickup::OnOverlap(ABlasterCharacter* BlasterCharacter) { - Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); + Super::OnOverlap(BlasterCharacter); - ABlasterCharacter* BlasterCharacter = Cast(OtherActor); - if (BlasterCharacter) + if (UBuffComponent* Buff = BlasterCharacter->GetBuff()) { - UBuffComponent* Buff = BlasterCharacter->GetBuff(); - if (Buff) - { - Buff->BuffSpeed(BaseSpeedBuff, CrouchSpeedBuff, SpeedBuffTime); - } + Buff->BuffSpeed(BaseSpeedBuff, CrouchSpeedBuff, SpeedBuffTime); } - + Destroy(); } diff --git a/Source/Blaster/Pickups/SpeedPickup.h b/Source/Blaster/Pickups/SpeedPickup.h index 6ce3b81..7dcd940 100644 --- a/Source/Blaster/Pickups/SpeedPickup.h +++ b/Source/Blaster/Pickups/SpeedPickup.h @@ -15,14 +15,7 @@ class BLASTER_API ASpeedPickup : public APickup GENERATED_BODY() protected: - virtual void OnSphereOverlap( - UPrimitiveComponent* OverlappedComponent, - AActor* OtherActor, - UPrimitiveComponent* OtherComp, - int32 OtherBodyIndex, - bool bFromSweep, - const FHitResult& SweepResult - ) override; + virtual void OnOverlap(ABlasterCharacter* BlasterCharacter) override; private: