// © 2025 Naked People Team. All Rights Reserved.


#include "CoverageObjectiveBase.h"

#include "NakedDesire/Clothing/ClothingManager.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"

void UCoverageObjectiveBase::OnActivate()
{
	Super::OnActivate(); // observer subscription

	if (Player && Player->ClothingManager)
	{
		Player->ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &UCoverageObjectiveBase::HandleClothingChanged);
		Player->ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &UCoverageObjectiveBase::HandleClothingChanged);
	}
}

void UCoverageObjectiveBase::OnDeactivate()
{
	if (Player && Player->ClothingManager)
	{
		Player->ClothingManager->OnClothingEquip.RemoveDynamic(this, &UCoverageObjectiveBase::HandleClothingChanged);
		Player->ClothingManager->OnClothingUnequip.RemoveDynamic(this, &UCoverageObjectiveBase::HandleClothingChanged);
	}

	Super::OnDeactivate(); // observer unsubscription
}

bool UCoverageObjectiveBase::IsFullyNaked() const
{
	if (!Player || !Player->ClothingManager)
		return false;

	UClothingManager* CM = Player->ClothingManager;
	return CM->GetEffectiveCoverage(EBodyPart::Boobs) <= 0.0f
		&& CM->GetEffectiveCoverage(EBodyPart::Ass) <= 0.0f
		&& CM->GetEffectiveCoverage(EBodyPart::Genitals) <= 0.0f;
}

bool UCoverageObjectiveBase::IsPartRevealing(EBodyPart Part) const
{
	if (!Player || !Player->ClothingManager)
		return false;

	return Player->ClothingManager->GetEffectiveCoverage(Part) < Player->ObservationRevealThreshold;
}

float UCoverageObjectiveBase::GetEffectiveCoverage(EBodyPart Part) const
{
	if (!Player || !Player->ClothingManager)
		return 0.0f;

	return Player->ClothingManager->GetEffectiveCoverage(Part);
}

bool UCoverageObjectiveBase::IsAnyPartRevealing() const
{
	return IsPartRevealing(EBodyPart::Boobs)
		|| IsPartRevealing(EBodyPart::Ass)
		|| IsPartRevealing(EBodyPart::Genitals);
}

void UCoverageObjectiveBase::HandleClothingChanged(UClothingItemInstance* ClothingItemInstance)
{
	NotifyConditionChanged();
}