// Copyright Pacificao. All Rights Reserved.

#include "AgrarianWaterSource.h"

#include "AgrarianGameCharacter.h"
#include "AgrarianSurvivalComponent.h"
#include "Components/StaticMeshComponent.h"

AAgrarianWaterSource::AAgrarianWaterSource()
{
	bReplicates = true;
	NetCullDistanceSquared = FMath::Square(6500.0f);

	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
	RootComponent = Mesh;
	Mesh->SetCollisionProfileName(TEXT("BlockAll"));

	DisplayName = FText::FromString(TEXT("Fresh Water"));
}

FText AAgrarianWaterSource::GetInteractionText_Implementation(const AAgrarianGameCharacter* Interactor) const
{
	return FText::Format(NSLOCTEXT("AgrarianWaterSource", "DrinkFromWaterSource", "Drink from {0}"), DisplayName);
}

bool AAgrarianWaterSource::CanInteract_Implementation(const AAgrarianGameCharacter* Interactor) const
{
	return Interactor != nullptr && Interactor->GetSurvivalComponent() != nullptr;
}

void AAgrarianWaterSource::Interact_Implementation(AAgrarianGameCharacter* Interactor)
{
	if (!HasAuthority() || !Interactor)
	{
		return;
	}

	if (UAgrarianSurvivalComponent* SurvivalComponent = Interactor->GetSurvivalComponent())
	{
		SurvivalComponent->AddWater(WaterRestoreAmount);
	}
}
