#include "WTap.h"

#include "Utils/TimeUtils.h"
#include "Utils/MoveUtils.h"

auto WTap::onAttack(Actor& actor) -> void {
	unsprint = true;
}

auto WTap::onWorldTick(Player* _this) -> void {
	if (mode != 0) return;

	long long now = Utils::Time::getMs();
	static long long start = now;
	if (unsprint) {
		Utils::Move::setSprinting(_this, false);
		sprint = true;
		unsprint = false;
		start = now;
	}
	if (sprint) {
		if (now - start >= 100.f) {
			Utils::Move::setSprinting(_this, true);
			sprint = false;
		}
	}
}

auto WTap::onPacketSendBefore(Packet* packet) -> void {
	if (mode != 1) return;

	if (packet->getID() == PacketID::PlayerAuthInput) {
		auto playerauthinput = reinterpret_cast<PlayerAuthInputPacket*>(packet);
		long long now = Utils::Time::getMs();
		static long long start = now;
		if (unsprint) {
			playerauthinput->setInputData(PlayerAuthInputPacket::InputData::Sprinting, false);
			playerauthinput->setInputData(PlayerAuthInputPacket::InputData::StartSprinting, false);
			sprint = true;
			unsprint = false;
			start = now;
		}
		if (sprint) {
			if (now - start >= 100.f) {
				playerauthinput->setInputData(PlayerAuthInputPacket::InputData::Sprinting, true);
				playerauthinput->setInputData(PlayerAuthInputPacket::InputData::StartSprinting, true);
				sprint = false;
			}
		}
	}
}
