86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#include "LMWaveManager.h"
|
|
#include "Enemy/LMEnemy.h"
|
|
|
|
// Sets default values
|
|
ALMWaveManager::ALMWaveManager()
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
}
|
|
|
|
// Called when the game starts or when spawned
|
|
void ALMWaveManager::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
StartWave();
|
|
}
|
|
|
|
void ALMWaveManager::SpawnEnemy(ALMSpawnPosition* spawnPosition, TSubclassOf<ALMEnemy> enemyToSpawn)
|
|
{
|
|
//Spawn sur une position
|
|
ALMEnemy* tempEnemy = GetWorld()->SpawnActor<ALMEnemy>(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()
|
|
{
|
|
|
|
}
|