// Project Lab - NHTV Igad

#pragma once

#include "GameFramework/GameMode.h"
#include "DefaultGameMode.generated.h"

UCLASS(minimalapi)
class ADefaultGameMode : public AGameMode
{
	GENERATED_BODY()

public:
	ADefaultGameMode();

	virtual void PreInitializeComponents() override;
	virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;
	virtual void BeginPlay() override;
	virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;

	virtual void PostSeamlessTravel() override;
	virtual void HandleSeamlessTravelPlayer(AController*& C) override;
	virtual void PreLogin(const FString& Options, const FString& Address, const TSharedPtr<const FUniqueNetId>& UniqueId, FString& ErrorMessage) override;
	virtual APlayerController* Login(class UPlayer* NewPlayer, ENetRole InRemoteRole, const FString& Portal, const FString& Options, const TSharedPtr<const FUniqueNetId>& UniqueId, FString& ErrorMessage) override;
	virtual void PostLogin(APlayerController* NewPlayer) override;
	virtual void Logout(AController* Exiting);

	virtual void Tick(float DeltaTime) override;

	virtual void HandleMatchHasStarted() override;
	virtual void HandleMatchHasEnded() override;

	void RegisterPlayerSpawn(class APlayerSpawn& spawn);

	void RegisterPlayer(class ANetworkPlayer& player);
	void UnregisterPlayer(class ANetworkPlayer& player);

	void StartGame();

	APlayerSpawn* GetOptimalSpawn(int32 team);

	TArray<class ANetworkPlayer*> GetPlayers();

	void BossHasBeenKilled(int32 team);
	float GetGameTime();
protected:
	void m_StartGameStartTimer();
	void m_GameStart();
	float m_gameTimer;
	float m_gameRestartTimer;
	FTimerHandle m_gameStartTimer;

	UPROPERTY()
	class ALobbyState* m_lobbyState;

	int32 m_numTravelledPlayers;
	int32 m_totalPlayerCount;

	TArray<FString> m_connectedPlayersNetID;

	UPROPERTY()
	TArray<class APlayerSpawn*> m_playerSpawns;
	UPROPERTY()
	TArray<class ANetworkPlayer*> m_players;
};