#include "PlayerUtils.h"

#include "Mod/AntiBot.h"
#include "Mod/HitBoxes.h"

auto Utils::Players::isRealPlayer(class Player* _this) -> bool {
	auto antibotmod = Client::findMod<AntiBot>(_("Anti Bot"));
	if (!antibotmod->enabled) return true;

	auto hitboxesmod = Client::findMod<HitBoxes>(_("Hit Boxes"));

	if (!_this) return false;

	if (antibotmod->checkInvisible) {
		if (_this->isInvisible())
			return false;
	}

	if (antibotmod->checkSize) {
		auto aabbshapecomponent = _this->getAABBShapeComponent();
		if (aabbshapecomponent) {
			if (
				_this->getAABBShapeComponent()->mBBDim.x != (hitboxesmod->enabled ? 0.6f * hitboxesmod->width : 0.6f) ||
				_this->getAABBShapeComponent()->mBBDim.y != (hitboxesmod->enabled ? 1.8f * hitboxesmod->height : 1.8f)
				) {
				return false;
			}
		}
	}

	if (antibotmod->checkType) {
		auto actortypecomponent = _this->getActorTypeComponent();
		if (actortypecomponent) {
			if (actortypecomponent->mType != ActorType::Player)
				return false;
		}
	}

	if (antibotmod->checkName) {
		std::string name = Utils::String::removeSymbols(_this->getLocalNameTag());
		if (name.find(_("{")) != std::string::npos)
			return false;

		if (name.empty())
			return false;

		if (name.size() < 3)
			return false;
	}

	return true;
}

auto Utils::Players::getHealth(class Player* _this) -> float {
	return 20.f;

	auto attributecomponent = _this->getAttributeComponent();
	if (!attributecomponent) return 0.f;

	auto instance = attributecomponent->baseattributes.getInstance(1);
	if (!instance) return 0.f;

	return instance->getValue();
}

auto Utils::Players::getAbsorption(class Player* _this) -> float {
	return 0.f;

	auto attributecomponent = _this->getAttributeComponent();
	if (!attributecomponent) return 0.f;

	auto instance = attributecomponent->baseattributes.getInstance(8);
	if (!instance) return 0.f;

	return instance->getValue();
}
