#include "Spider.h"

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

auto Spider::onWorldTick(Player* _this) -> void {
	glm::vec3 vel = Utils::Move::getVelocity(_this);

	bool isHorizontal_ = Utils::Move::isHorizontal(_this);
	bool isHorizontal = false;

	long long now = Utils::Time::getMs();
	static long long start = now;
	if (isHorizontal_) {
		if (now - start >= delay * 100.f) {
			isHorizontal = isHorizontal_;
			start = now;
		}
	}
	else {
		start = now;
	}

	switch (mode) {
	case 0:
		if (isHorizontal)
			Utils::Move::setVelocity(_this, glm::vec3(vel.x, speed, vel.z));
		break;
	case 1: {
		static bool off = false;
		if (isHorizontal) {
			Utils::Move::setJumping(_this, true);
			off = true;
		}
		else if (off) {
			Utils::Move::setJumping(_this, false);
			off = false;
		}
		break;
	}
	}
}

auto Spider::onClient() -> void {
	for (Setting* setting : Client::findSetting(this, _("Climb Speed"))) {
		setting->visible = mode == 0;
	}
}

auto Spider::getMode() -> std::string {
	switch (mode) {
	case 0:
		return _("Normal");
	case 1:
		return _("Jump");
	}

	return _("Unknown");
}
