diff --git a/Source/vampires/Projectile.cpp b/Source/vampires/Projectile.cpp index 8fa085b..5b21e92 100644 --- a/Source/vampires/Projectile.cpp +++ b/Source/vampires/Projectile.cpp @@ -69,12 +69,14 @@ void AProjectile::LoadDataFromDataAsset_Implementation(UProjectileDataAsset* pro ProjectileSpeed = projectileDataAsset->ProjectileSpeed; ProjectileMovement->InitialSpeed = ProjectileSpeed; ProjectileMovement->MaxSpeed = ProjectileSpeed; + RemainingDamagableEnemies = projectileDataAsset->DamagableEnemies; } void AProjectile::ResetData_Implementation() { ProjectileSpeed = NULL; StaticMeshComponent->SetStaticMesh(nullptr); + RemainingDamagableEnemies = 1; } void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, @@ -96,13 +98,18 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon AProjectileWeapon* ownerWeapon = Cast(GetOwner()); EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->Damage, nullptr, ownerController, this); - AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld()); + RemainingDamagableEnemies--; - if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass())) + if (RemainingDamagableEnemies == 0) { - if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode)) + AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld()); + + if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass())) { - objectPoolManager->ReturnObject(this); + if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode)) + { + objectPoolManager->ReturnObject(this); + } } } } diff --git a/Source/vampires/Projectile.h b/Source/vampires/Projectile.h index 87be6eb..acd84b7 100644 --- a/Source/vampires/Projectile.h +++ b/Source/vampires/Projectile.h @@ -31,6 +31,9 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) UStaticMeshComponent* StaticMeshComponent = nullptr; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int RemainingDamagableEnemies = 1; + // Sets default values for this actor's properties AProjectile(); diff --git a/Source/vampires/ProjectileDataAsset.h b/Source/vampires/ProjectileDataAsset.h index 63fadc3..0c2e946 100644 --- a/Source/vampires/ProjectileDataAsset.h +++ b/Source/vampires/ProjectileDataAsset.h @@ -20,4 +20,7 @@ public: UPROPERTY(EditAnywhere) TObjectPtr StaticMesh; + + UPROPERTY(EditAnywhere) + int DamagableEnemies = 1; }; diff --git a/Source/vampires/Weapons/ProjectileWeapon.cpp b/Source/vampires/Weapons/ProjectileWeapon.cpp index bd03e68..1bf91d2 100644 --- a/Source/vampires/Weapons/ProjectileWeapon.cpp +++ b/Source/vampires/Weapons/ProjectileWeapon.cpp @@ -63,3 +63,20 @@ void AProjectileWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, OverlappedEnemies.Remove(Enemy); } } + +void AProjectileWeapon::FireWeaponAction_Implementation() +{ + Super::FireWeaponAction_Implementation(); + + remainingProjectilesToSpawn = ProjectilesPerActivation; + GetWorldTimerManager().SetTimer(FireProjectileTimerHandler, this, &AProjectileWeapon::FireProjectile, ProjectileSpawningDelay, true, 0.0f); +} + +void AProjectileWeapon::FireProjectile() +{ + remainingProjectilesToSpawn--; + if (remainingProjectilesToSpawn == 0) + { + GetWorldTimerManager().ClearTimer(FireProjectileTimerHandler); + } +} diff --git a/Source/vampires/Weapons/ProjectileWeapon.h b/Source/vampires/Weapons/ProjectileWeapon.h index 5766d61..e2b7127 100644 --- a/Source/vampires/Weapons/ProjectileWeapon.h +++ b/Source/vampires/Weapons/ProjectileWeapon.h @@ -25,9 +25,20 @@ public: UPROPERTY(EditAnywhere, Category = "Weapon Properties") TObjectPtr ProjectileTemplate = nullptr; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + int ProjectilesPerActivation = 1; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + float ProjectileSpawningDelay = 0.25f; + protected: TArray OverlappedEnemies = TArray(); + FTimerHandle FireProjectileTimerHandler; + +private: + int remainingProjectilesToSpawn = 0; + public: AProjectileWeapon(); @@ -43,4 +54,10 @@ public: UFUNCTION() void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); + + virtual void FireWeaponAction_Implementation() override; + +protected: + UFUNCTION() + virtual void FireProjectile(); };