// Gravity Stomp Copyright Kevin Poretti

#pragma once

// UE includes
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"

#include "GSPlayerController.generated.h"

/**
 *	Player controller for a team deathmatch/free for all game mode
 */
UCLASS()
class GRAVITYSTOMPGAME_API AGSPlayerController : public APlayerController
{
	GENERATED_BODY()

public:
	/**
	 *	Notify player that a game has started
	 */
	UFUNCTION(Reliable, Client)
	void Client_GameStarted();

	/**
	 *	Notify player when the warmup period has started
	 */
	UFUNCTION(Reliable, Client)
	void Client_WarmupStarted();

	UFUNCTION(BlueprintImplementableEvent, Category="Events")
	void OnWarmupStarted();

	/**
	 *	Notify a player that a game has started
	 */
	UFUNCTION(BlueprintImplementableEvent, Category="Events")
	void OnGameStarted();

	UFUNCTION(BlueprintImplementableEvent)
	void OnAcknowledgePossession();

	UFUNCTION(BlueprintImplementableEvent)
	void OnPawnInitialized();

    /**
     *	RPC when this player kills someone
     */
	UFUNCTION(Reliable, Client)
    void Client_OnKill(AGSPlayerState* KillerPlayerState, AGSPlayerState* VictimPlayerState);

    /**
     *	Blueprint event when the OnKill RPC is called
     */
    UFUNCTION(BlueprintImplementableEvent, Category="Events")
	void OnKill(AGSPlayerState* KillerPlayerState, AGSPlayerState* VictimPlayerState);

	/**
	 *	RPC when a death occurs so the player can update their UI
	 */
	UFUNCTION(Reliable, Client)
	void Client_OnDeath(AGSPlayerState* KillerPlayerState, AGSPlayerState* VictimPlayerState);

	/**
     *	Blueprint event when the OnDeath RPC is called
     */
    UFUNCTION(BlueprintImplementableEvent, Category="Events")
	void OnDeath(AGSPlayerState* KillerPlayerState, AGSPlayerState* VictimPlayerState);

	/** 
	 *	Blueprint event when the game ended RPC is called
	 */
	UFUNCTION(BlueprintImplementableEvent, Category="Events")
    void OnGameEnded(bool bIsWinner);

	UFUNCTION(Reliable, Client)
	void Client_GameRestarted();

	UFUNCTION(BlueprintImplementableEvent)
	void OnGameRestarted();

	// APlayerController interface
	/**
	 *	Override so no view target is set
	 */
	virtual void GameHasEnded(AActor* EndGameFocus, bool bIsWinner) override;

    /**
     *	Does character cleanup when the game ends
     */
    virtual void ClientGameEnded_Implementation(AActor* EndGameFocus, bool bIsWinner) override;

    /**
	 *	Request respawn from server when we are allowed
	 */
	virtual void UnFreeze() override;

    /**
     *	Calls OnAcknowledgePossession so the UI can bind itself to events like health updates
     */
	virtual void AcknowledgePossession(APawn* P) override;
	// End APlayerController interface
};
