// Project Lab - NHTV Igad

#pragma once

#include "PlayerStateBase.h"
#include "DefaultPlayerState.generated.h"

/*
	In-game state of a player.
*/
UCLASS()
class UNREALPROJECT_API ADefaultPlayerState : public APlayerStateBase
{
	GENERATED_BODY()
public:
	ADefaultPlayerState();
	virtual void BeginPlay() override;

	// Get Functions
	// Integer level value from 1-max
	UFUNCTION(BlueprintCallable, Category = "Level Functions")
	int32 GetLevel() const;
	UFUNCTION(BlueprintCallable, Category = "Level Functions")
	int32 GetMaxLevel() const;
	// Current experience in-level
	UFUNCTION(BlueprintCallable, Category = "Level Functions")
	int32 GetExperience() const;
	// Totale experience needed for the next level
	UFUNCTION(BlueprintCallable, Category = "Level Functions")
	int32 GetExperienceToLevel() const;

	// DEBUG functionality for setting a player level
	void SetLevel(int32 level);

	// Call the function to grant a player with experience, this function will also handle leveling up.
	UFUNCTION(BlueprintCallable, Category = "Level Functions")
	void GainExperience(int32 gainedExperience);

	// The character the player currently controls, or null when dead
	UPROPERTY(BlueprintReadOnly, Replicated, Category = "Character")
	class ANetworkPlayer* character;

	// The person that is in the same team as this player, or null when dead or there is none
	UPROPERTY(BlueprintReadOnly, Replicated, Category = "Character")
	class ADefaultPlayerState* teamMate;

	UPROPERTY(BlueprintReadonly, Replicated, Category = "Score")
	int32 kills;
	UPROPERTY(BlueprintReadonly, Replicated, Category = "Score")
	int32 deaths;

private:
	// Calculates the experience needed to level up to a given level
	int32 m_CalculateExperienceToLevel(int32 level);

	// Variables to keep track of what level/experience the player has.
	UPROPERTY(Replicated)
	int8 m_level;
	UPROPERTY(Replicated)
	int32 m_experience;
	// Variable to check if a player has leveled up.
	UPROPERTY(Replicated)
	int32 m_experienceToLevel;
	// Variables for calculating the experience to level up.
	int32 m_baseExperience;
	int32 m_variableExperience;
	float m_exponentExperience;
};
