// Gravity Stomp Copyright Kevin Poretti

#pragma once

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

#include "GSGameState.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTeamScoresUpdatedSignature, const TArray<int32>&, TeamScores);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRemainingTimeUpdatedDelegate, float, RemainingTime);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMatchStateUpdatedSignature, FName, MatchState);

/**
 *	Game state for a team deathmatch/free for all game mode
 */
UCLASS()
class GRAVITYSTOMPGAME_API AGSGameState : public AGameState
{
	GENERATED_BODY()

public:
	void SetNumTeams(int32 InNumTeams);

	FORCEINLINE int32 GetNumTeams() { return NumTeams; }

    /**
     *	Gives team of the supplied team index a point. Returns the new score for that team.
     */
    int32 GiveTeamPoint(int32 InTeamIdx);

	void ResetTeamScores();

	int32 GetWinningTeam();

	FORCEINLINE float GetRemainingTime() { return RemainingTime; } 

	void SetRemainingTime(float InRemainingTime);

	// Begin AGameState interface
	virtual void OnRep_MatchState() override;
	// End AGameState interface

protected:
	// number of teams currently in the game
	UPROPERTY(Replicated, BlueprintReadOnly)
	int32 NumTeams;

	// array of team scores, index by the team number
	UPROPERTY(ReplicatedUsing=OnRep_TeamScores, BlueprintReadOnly)
	TArray<int32> TeamScores;

	// time remaining for the current match state (i.e. warmup, the round itself, post round)
    UPROPERTY(ReplicatedUsing=OnRep_RemainingTime, BlueprintReadOnly)
	float RemainingTime;

	/** Triggered when this weapon is fired. */
	UPROPERTY(BlueprintAssignable, Category="Events")
	FTeamScoresUpdatedSignature OnTeamScoresUpdated;

	UPROPERTY(BlueprintAssignable, Category="Events")
	FRemainingTimeUpdatedDelegate OnRemainingTimeUpdated;

	UPROPERTY(BlueprintAssignable, Category="Events")
	FMatchStateUpdatedSignature OnMatchStateUpdated;

	UFUNCTION()
	void OnRep_TeamScores();

	UFUNCTION()
	void OnRep_RemainingTime();
};
