#include "BoneCollisionShape.h"

#include <godot_cpp/classes/engine.hpp>

using namespace godot;

namespace blitz {

void BoneCollisionShape::_bind_methods() {
	ClassDB::bind_method(D_METHOD("get_head_damage"), &BoneCollisionShape::get_head_damage);
	ClassDB::bind_method(D_METHOD("set_head_damage", "m_HeadDamage"), &BoneCollisionShape::set_head_damage);
	ADD_PROPERTY(PropertyInfo(Variant::INT, "m_HeadDamage"), "set_head_damage", "get_head_damage");

	ClassDB::bind_method(D_METHOD("get_body_damage"), &BoneCollisionShape::get_body_damage);
	ClassDB::bind_method(D_METHOD("set_body_damage", "m_BodyDamage"), &BoneCollisionShape::set_body_damage);
	ADD_PROPERTY(PropertyInfo(Variant::INT, "m_BodyDamage"), "set_head_damage", "get_body_damage");

	ADD_SIGNAL(MethodInfo("a_ZombieHeadShotHit", PropertyInfo(Variant::INT, "dam")));
	ADD_SIGNAL(MethodInfo("a_ZombieBodyShotHit", PropertyInfo(Variant::INT, "dam")));

	ClassDB::bind_method(D_METHOD("headshot_hit"), &BoneCollisionShape::headshot_hit);
	ClassDB::bind_method(D_METHOD("bodyshot_hit"), &BoneCollisionShape::bodyshot_hit);
}

BoneCollisionShape::BoneCollisionShape() {}

BoneCollisionShape::~BoneCollisionShape() {}

void BoneCollisionShape::_ready() {
#if DEBUG_ENABLED
	if (Engine::get_singleton()->is_editor_hint()) {
		return;
	}
#endif
	m_Crosshair = Object::cast_to<Crosshair>(
		get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair"));
	DEV_ASSERT(m_Crosshair);
}

void BoneCollisionShape::set_head_damage(int a_D) {
	m_HeadDamage = a_D;
}

int BoneCollisionShape::get_head_damage() const {
	return m_HeadDamage;
}

void BoneCollisionShape::set_body_damage(int a_D) {
	m_BodyDamage = a_D;
}

int BoneCollisionShape::get_body_damage() const {
	return m_BodyDamage;
}

void BoneCollisionShape::headshot_hit() {
	ERR_PRINT("zombie headshot hit");
	m_Crosshair->set_dot_color(Color(1, 0, 0, 1));
	emit_signal("a_ZombieHeadShotHit", m_HeadDamage);
}

void BoneCollisionShape::bodyshot_hit() {
	ERR_PRINT("zombie body hit");
	m_Crosshair->set_dot_color(Color(0, 0, 1, 1));
	emit_signal("a_ZombieBodyShotHit", m_BodyDamage);
}

}  // namespace blitz