#include "TargetStrafe.h"
#include "Client.h"

#include "Utils/MoveUtils.h"

#include "Interface.h"
#include "KillAura.h"
#include "Speed.h"

auto TargetStrafe::onWorldTick(Player* _this) -> void {
	auto killauraMod = Client::findMod<KillAura>(
		Client::findMod<Interface>(_("Interface"))->renameaura ? _("Aura") : _("Kill Aura")
	);
	
	auto actorrotationcomponent = _this->getActorRotationComponent();
	if (!actorrotationcomponent) return;

	if (Utils::Move::isOnGround(_this) && onjump) return;
	if (!Client::findMod<Speed>(_("Speed"))->enabled && speedonly) return;


	if (killauraMod && killauraMod->enabled && !killauraMod->list.empty()) {
		if (killauraMod->rotations == 1 && killauraMod->flicking) return;

		glm::vec2 angle = Utils::Math::getAngle(Utils::Move::getPosition(_this), Utils::Move::getPosition(killauraMod->list[killauraMod->targetindex]));
		actorrotationcomponent->mRotationDegree.x = angle.x;
		actorrotationcomponent->mRotationDegree.y = angle.y;

		actorrotationcomponent->mRotationDegreePrevious.x = angle.x;
		actorrotationcomponent->mRotationDegreePrevious.y = angle.y;
	}
}
