From fbe2340f0598770e5635563a620aae187e3c3ea2 Mon Sep 17 00:00:00 2001 From: sSebster Date: Mon, 10 Mar 2025 15:03:39 +0100 Subject: [PATCH] Added : WaveManagement + Fix : RangeEnemy (un peu) --- .../DistantEnemy/AIC_DistantEnnemy.uasset | 2 +- .../DistantEnemy/BP_DistantEnemy.uasset | 4 +- .../Ennemy/MeleeEnemy/BP_MeleeEnemy.uasset | 4 +- .../Ennemy/Range/BT_RangeEnnemy.uasset | 4 +- .../Ennemy/Range/EQC_DistantEnemy.uasset | 4 +- .../Ennemy/Range/EQS_RangeEnnemy.uasset | 4 +- .../Legumix/Spawner/BP_SpawnPosition.uasset | 3 + Content/Legumix/Spawner/BP_WaveManager.uasset | 3 + Content/Legumix/Spawner/LVL_TestSpawn.umap | 3 + Source/LegumeMix/Private/LMSpawnPosition.cpp | 43 ++++++++++++- Source/LegumeMix/Private/LMWaveManager.cpp | 64 ++++++++++++++++++- Source/LegumeMix/Public/Enemy/LMEnemy.h | 5 ++ Source/LegumeMix/Public/LMSpawnPosition.h | 5 ++ Source/LegumeMix/Public/LMWaveManager.h | 32 ++++++++++ 14 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 Content/Legumix/Spawner/BP_SpawnPosition.uasset create mode 100644 Content/Legumix/Spawner/BP_WaveManager.uasset create mode 100644 Content/Legumix/Spawner/LVL_TestSpawn.umap diff --git a/Content/Legumix/Ennemy/DistantEnemy/AIC_DistantEnnemy.uasset b/Content/Legumix/Ennemy/DistantEnemy/AIC_DistantEnnemy.uasset index 59e4b75..605c305 100644 --- a/Content/Legumix/Ennemy/DistantEnemy/AIC_DistantEnnemy.uasset +++ b/Content/Legumix/Ennemy/DistantEnemy/AIC_DistantEnnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d97eacadb31bb9062ca3918e5b2fde965a8a75a4002d97f6c113960d725acab8 +oid sha256:a43a1d5bdf9c177b7dff0a3e4483d922c933f947fb6c7ed881407456aea0c29c size 25060 diff --git a/Content/Legumix/Ennemy/DistantEnemy/BP_DistantEnemy.uasset b/Content/Legumix/Ennemy/DistantEnemy/BP_DistantEnemy.uasset index dce9aca..437bc56 100644 --- a/Content/Legumix/Ennemy/DistantEnemy/BP_DistantEnemy.uasset +++ b/Content/Legumix/Ennemy/DistantEnemy/BP_DistantEnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ba2b4f7892a06fef6bc4a1bb6c2523b28b0e97bdc61ee71c582885fb9f967251 -size 98029 +oid sha256:e06cea4316bcc227241820a09a8402afbf9d4c1f47c39369c8e1019c57422445 +size 101403 diff --git a/Content/Legumix/Ennemy/MeleeEnemy/BP_MeleeEnemy.uasset b/Content/Legumix/Ennemy/MeleeEnemy/BP_MeleeEnemy.uasset index 15490a4..8dedffc 100644 --- a/Content/Legumix/Ennemy/MeleeEnemy/BP_MeleeEnemy.uasset +++ b/Content/Legumix/Ennemy/MeleeEnemy/BP_MeleeEnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:79ce1eaf8c92f3dcbe0b59ca6c976be1a161d8acf14d36cea7a8f3e6e3b43349 -size 141512 +oid sha256:29534465dba433326ec7756d3d27802b425de34e5affe6d5a82e0c4457dc9513 +size 276 diff --git a/Content/Legumix/Ennemy/Range/BT_RangeEnnemy.uasset b/Content/Legumix/Ennemy/Range/BT_RangeEnnemy.uasset index 635eedb..da22e3b 100644 --- a/Content/Legumix/Ennemy/Range/BT_RangeEnnemy.uasset +++ b/Content/Legumix/Ennemy/Range/BT_RangeEnnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:27f9ba95cfca71840ebbbc94e90b01c5e27b58683eb469abf0b4bb4c88bcec3b -size 9834 +oid sha256:6089fbd58c4b3a3147d697436b6b658fa104340c8da5444193b7cd5966b91023 +size 10654 diff --git a/Content/Legumix/Ennemy/Range/EQC_DistantEnemy.uasset b/Content/Legumix/Ennemy/Range/EQC_DistantEnemy.uasset index f0a8015..781ccbc 100644 --- a/Content/Legumix/Ennemy/Range/EQC_DistantEnemy.uasset +++ b/Content/Legumix/Ennemy/Range/EQC_DistantEnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:27627c3e68d8f037eab74f88d7a323ebffec892585bfea545314895e1579edb7 -size 50496 +oid sha256:e97cdced00ff8423916cb950e7b1036fe9e6d0b1b8d9a6c54fa3db2aa42e1ce1 +size 49086 diff --git a/Content/Legumix/Ennemy/Range/EQS_RangeEnnemy.uasset b/Content/Legumix/Ennemy/Range/EQS_RangeEnnemy.uasset index 05c648e..0e8435a 100644 --- a/Content/Legumix/Ennemy/Range/EQS_RangeEnnemy.uasset +++ b/Content/Legumix/Ennemy/Range/EQS_RangeEnnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6b8e531aea4ed9bb40efdd6c0c8307d192a0aae0a750f7eb3310b3ec87e89bf3 -size 25492 +oid sha256:e2ed31b3c45e5eae7fcd0b9a792ccc38df0806cd82b5bcf1e3a7b8059a24ef29 +size 38311 diff --git a/Content/Legumix/Spawner/BP_SpawnPosition.uasset b/Content/Legumix/Spawner/BP_SpawnPosition.uasset new file mode 100644 index 0000000..e167370 --- /dev/null +++ b/Content/Legumix/Spawner/BP_SpawnPosition.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2f452f3199434194497de99f44e5297eec71fd708cd7ec8c6770a8a5ef2a65b +size 22491 diff --git a/Content/Legumix/Spawner/BP_WaveManager.uasset b/Content/Legumix/Spawner/BP_WaveManager.uasset new file mode 100644 index 0000000..8578348 --- /dev/null +++ b/Content/Legumix/Spawner/BP_WaveManager.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a89a42534cfb20692937e8053e058e5fb4d428610221f1f419e274c64a8d9f6e +size 22304 diff --git a/Content/Legumix/Spawner/LVL_TestSpawn.umap b/Content/Legumix/Spawner/LVL_TestSpawn.umap new file mode 100644 index 0000000..9fd5345 --- /dev/null +++ b/Content/Legumix/Spawner/LVL_TestSpawn.umap @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c66f6a8227ba03137a1a9a32451b8be1b400d73f51ce06f8c532dc0aee38fd0 +size 79804 diff --git a/Source/LegumeMix/Private/LMSpawnPosition.cpp b/Source/LegumeMix/Private/LMSpawnPosition.cpp index 68f899f..0715e59 100644 --- a/Source/LegumeMix/Private/LMSpawnPosition.cpp +++ b/Source/LegumeMix/Private/LMSpawnPosition.cpp @@ -2,6 +2,9 @@ #include "LMSpawnPosition.h" +#include "Kismet/GameplayStatics.h" +#include "Engine/World.h" +#include "DrawDebugHelpers.h" // Sets default values ALMSpawnPosition::ALMSpawnPosition() @@ -11,6 +14,11 @@ ALMSpawnPosition::ALMSpawnPosition() } +bool ALMSpawnPosition::CanSpawn() const +{ + return !IsPlayerVisible(); +} + // Called when the game starts or when spawned void ALMSpawnPosition::BeginPlay() { @@ -22,6 +30,39 @@ void ALMSpawnPosition::BeginPlay() void ALMSpawnPosition::Tick(float DeltaTime) { Super::Tick(DeltaTime); - + UE_LOG(LogTemp, Warning, TEXT("CanSpawn: %s"), CanSpawn() ? TEXT("true") : TEXT("false")); +} + +bool ALMSpawnPosition::IsPlayerVisible() const +{ + AActor* Player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); + if (!Player) return false; + + FVector Start = GetActorLocation(); + FVector End = Player->GetActorLocation(); + + FHitResult HitResult; + FCollisionQueryParams Params; + Params.AddIgnoredActor(this); + + bool bHit = GetWorld()->LineTraceSingleByChannel( + HitResult, + Start, + End, + ECC_Visibility, + Params + ); + + // Debug trace + DrawDebugLine(GetWorld(), Start, End, bHit ? FColor::Red : FColor::Green, false, 2.0f); + + if (bHit) + { + UE_LOG(LogTemp, Warning, TEXT("LineTrace Hit: %s"), *HitResult.GetActor()->GetName()); + return HitResult.GetActor() == Player; // Retourne true uniquement si l'acteur touché est le joueur + } + + UE_LOG(LogTemp, Warning, TEXT("LineTrace: No Hit")); + return false; // Aucun obstacle, le joueur est visible } diff --git a/Source/LegumeMix/Private/LMWaveManager.cpp b/Source/LegumeMix/Private/LMWaveManager.cpp index 88d198e..85e8155 100644 --- a/Source/LegumeMix/Private/LMWaveManager.cpp +++ b/Source/LegumeMix/Private/LMWaveManager.cpp @@ -1,7 +1,7 @@ // Fill out your copyright notice in the Description page of Project Settings. - #include "LMWaveManager.h" +#include "Enemy/LMEnemy.h" // Sets default values ALMWaveManager::ALMWaveManager() @@ -15,13 +15,71 @@ ALMWaveManager::ALMWaveManager() void ALMWaveManager::BeginPlay() { Super::BeginPlay(); - + StartWave(); +} + +void ALMWaveManager::SpawnEnemy(ALMSpawnPosition* spawnPosition, TSubclassOf enemyToSpawn) +{ + //Spawn sur une position + ALMEnemy* tempEnemy = GetWorld()->SpawnActor(enemyToSpawn, spawnPosition->GetActorLocation(), FRotator::ZeroRotator); + + //ajoute l'ennemis à la liste des ennemis vivants + EnemyAliveList.Add(tempEnemy); + + //bind la method ennemydead à la death de l'ennemis + tempEnemy->OnEnemyDeath.AddUniqueDynamic(this, &ALMWaveManager::EnemyDead); +} + +void ALMWaveManager::EnemyDead(ALMEnemy* enemyToRemoveFromLife) +{ + //remove l'ennemis de la liste des ennemis vivants + enemyToRemoveFromLife->OnEnemyDeath.RemoveDynamic(this,&ALMWaveManager::EnemyDead); + EnemyAliveList.Remove(enemyToRemoveFromLife); +} + +bool ALMWaveManager::RemainsEnemyToSpawn() +{ + bool no = EnemyAliveList.Num() < MaxEnemyInstantiate; + return EnemyNumberInWave != EnemySpawned && no; +} + +void ALMWaveManager::CheckForSpawnerOK() +{ + SpawnPositionsOK.Empty(); + for (ALMSpawnPosition* spawnPosition : SpawnPositionsList) + { + if(spawnPosition->CanSpawn()) + { + SpawnPositionsOK.Add(spawnPosition); + } + } } // Called every frame void ALMWaveManager::Tick(float DeltaTime) { Super::Tick(DeltaTime); - + if(RemainsEnemyToSpawn()) + { + CheckForSpawnerOK(); + if(SpawnPositionsOK.Num() > 0) + { + //Choose spawnpoint to spawn + int32 RandomIndex = FMath::RandRange(0, SpawnPositionsOK.Num() - 1); + SpawnEnemy(SpawnPositionsOK[RandomIndex],TypeOfEnemy); + EnemySpawned++; + } + } + else + { + //lauch break time + // Lance un timer de 3 secondes avant d'appeler StartWave() + GetWorld()->GetTimerManager().SetTimer(BreakTimer, this, &ALMWaveManager::StartWave, BreakTime, false); + } } + +void ALMWaveManager::StartWave() +{ + +} diff --git a/Source/LegumeMix/Public/Enemy/LMEnemy.h b/Source/LegumeMix/Public/Enemy/LMEnemy.h index b129aa2..001b14d 100644 --- a/Source/LegumeMix/Public/Enemy/LMEnemy.h +++ b/Source/LegumeMix/Public/Enemy/LMEnemy.h @@ -18,11 +18,16 @@ class LEGUMEMIX_API ALMEnemy : public ACharacter { GENERATED_BODY() + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEnnemyDeathSignature, ALMEnemy*, pleasefonctionne); + public: ALMEnemy(); virtual void Tick(float DeltaTime) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + UPROPERTY(BlueprintCallable, BlueprintAssignable, Category = "Legumix") + FOnEnnemyDeathSignature OnEnemyDeath; + protected: virtual void BeginPlay() override; diff --git a/Source/LegumeMix/Public/LMSpawnPosition.h b/Source/LegumeMix/Public/LMSpawnPosition.h index 3720305..b3dd41e 100644 --- a/Source/LegumeMix/Public/LMSpawnPosition.h +++ b/Source/LegumeMix/Public/LMSpawnPosition.h @@ -15,6 +15,9 @@ public: // Sets default values for this actor's properties ALMSpawnPosition(); + // Méthode pour vérifier si le spawn est possible + bool CanSpawn() const; + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; @@ -23,4 +26,6 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; +private: + bool IsPlayerVisible() const; }; diff --git a/Source/LegumeMix/Public/LMWaveManager.h b/Source/LegumeMix/Public/LMWaveManager.h index 89712fe..48fb0c9 100644 --- a/Source/LegumeMix/Public/LMWaveManager.h +++ b/Source/LegumeMix/Public/LMWaveManager.h @@ -4,8 +4,11 @@ #include "CoreMinimal.h" #include "GameFramework/Actor.h" +#include "LMSpawnPosition.h" #include "LMWaveManager.generated.h" +class ALMEnemy; + UCLASS() class LEGUMEMIX_API ALMWaveManager : public AActor { @@ -14,13 +17,42 @@ class LEGUMEMIX_API ALMWaveManager : public AActor public: // Sets default values for this actor's properties ALMWaveManager(); + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix") + TArray EnemyAliveList; // Liste des ennemis + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix") + TArray SpawnPositionsList; // Liste des ennemis + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix") + int EnemyNumberInWave; // Nombre d'ennemis dans la wave + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix") + int MaxEnemyInstantiate; // Nombre d'ennemis max spawnés + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix") + TSubclassOf TypeOfEnemy; // Type d'ennemis to spawn + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix") + float BreakTime; // Nombre d'ennemis dans la wave protected: // Called when the game starts or when spawned virtual void BeginPlay() override; + virtual void StartWave(); + virtual void SpawnEnemy(ALMSpawnPosition* spawnPosition, TSubclassOf enemyToSpawn); + UFUNCTION() + virtual void EnemyDead(ALMEnemy* enemyToRemoveFromLife); + virtual bool RemainsEnemyToSpawn(); + virtual void CheckForSpawnerOK(); + public: // Called every frame virtual void Tick(float DeltaTime) override; +private: + TArray SpawnPositionsOK; + int EnemySpawned; + + FTimerHandle BreakTimer; };