void ATankAIController::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
	auto aiTank = GetPawn();
	auto playerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
	if (ensure(playerTank)) {

		// TODO Move towards the player
		MoveToActor(playerTank, acceptanceRadius); // TODO check radius is in cm

		// Aim towards the player
		auto aimComponent = aiTank->FindComponentByClass<UTankAimingComponent>();
		aimComponent->AimAt(playerTank->GetActorLocation());
		

		//GetPawn().reloadTimeInSeconds = 10;
		// Fire if ready
		if (aimComponent->GetFiringState() == EFiringStatus::Ready) {
			aimComponent->Fire();
			//UE_LOG(LogTemp,Warning,TEXT("AI Tank Ready and Firing!"))
		}


		
	}

}
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
	auto AITank = GetPawn();

	if (!ensure(PlayerTank && AITank)) { return; }

	auto AIAimComp = AITank->FindComponentByClass<UTankAimingComponent>();
	// Move towards Actor
	MoveToActor(PlayerTank, AcceptanceRadius);
	// Aim towards the player
	AIAimComp->AimAt(PlayerTank->GetActorLocation());

	if (AIAimComp->GetFiringState() == EFiringState::Locked)
	{
		AIAimComp->Fire();
	}
}
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
	auto ControlledTank =GetPawn();
	if (!ensure(PlayerTank && ControlledTank)) { return; }
	//Move Towards the player
	MoveToActor(PlayerTank, AcceptanceRadius);

	//aim towards the player
	auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>();
	AimingComponent->AimAt(PlayerTank->GetActorLocation());
		
	//if aiming or locked
	if (AimingComponent->GetFiringState() == EFiringState::Locked)
	{
		AimingComponent->Fire(); //TODO dont fire every frame , limit fire rate
	}
	
}