// Copyright Pacificao. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "AgrarianMapBoundaryVolume.generated.h"

class AAgrarianGameCharacter;
class UBoxComponent;

UCLASS(Blueprintable)
class AGRARIANGAME_API AAgrarianMapBoundaryVolume : public AActor
{
	GENERATED_BODY()

public:
	AAgrarianMapBoundaryVolume();

	virtual void Tick(float DeltaSeconds) override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Map Boundary")
	TObjectPtr<UBoxComponent> BoundaryVolume;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Map Boundary")
	FName BoundaryId = TEXT("ground_zero_mvp_tile");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Map Boundary")
	bool bClampPlayersAtBoundary = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Map Boundary", meta = (ClampMin = "0"))
	float BoundaryPaddingCm = 250.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Map Boundary", meta = (ClampMin = "0"))
	float WarningDistanceCm = 3000.0f;

	UFUNCTION(BlueprintCallable, Category = "Agrarian|Map Boundary")
	bool IsLocationOutsideBoundary(const FVector& WorldLocation) const;

	UFUNCTION(BlueprintCallable, Category = "Agrarian|Map Boundary")
	bool IsLocationInsideWarningZone(const FVector& WorldLocation) const;

	UFUNCTION(BlueprintCallable, Category = "Agrarian|Map Boundary")
	FVector ClampLocationToBoundary(const FVector& WorldLocation) const;

protected:
	void EnforceBoundaryForCharacter(AAgrarianGameCharacter* Character) const;
};
