#pragma once

#include "td/game/BaseGame.h"
#include "td/misc/Time.h"
#include "ServerWorld.h"

namespace td {
namespace server {

class Server;

class ServerGame : public game::Game, public game::GameListener {
private:
	Server* m_Server;
	ServerWorld m_ServerWorld;
	utils::AutoTimer m_GoldMineTimer;
	utils::AutoTimer m_MobStatesTimer;
	utils::CooldownTimer m_EndGameCooldown;
public:
	ServerGame(Server* server);
	~ServerGame() {}

	ServerWorld* GetServerWorld() { return &m_ServerWorld; }

	virtual void Tick(std::uint64_t delta);
	virtual void Reset() override;

	void StartGame();

	// GameListener

	virtual void OnGameStateUpdate(game::GameState newState) override;
	virtual void OnGameBegin() override;
	virtual void OnGameEnd() override;
	virtual void OnGameClose() override;

	virtual void OnPlayerJoin(game::PlayerID id) override;
	virtual void OnPlayerLeave(game::PlayerID id) override;
private:
	void BalanceTeams();
	void InitPlayerStats();
	void UpdateMobStates();
	void UpdateGoldMines();
	void UpdatePlayerStats();
};

} // namespace game
} // namespace td
