extends Area2D

var hit_bodies = []

var base_damage = 2
var power = base_damage

var eq_comp: Equipment_Component

var weapon_item

onready var parent = get_parent()


	

func _ready() -> void:
	connect ("body_entered", self, "_on_body_entered")
	monitoring = false
	
	if parent.has_node("Equipment"):
		eq_comp = parent.get_node("Equipment")
	elif parent.has_node("EquipmentComponent"):
		eq_comp = parent.get_node("EquipmentComponent")
	
	


#fixme: replace with change_state...
func start_attack() -> void:
	if eq_comp.get_items_by_category("Weapon").size() > 0:
		weapon_item = eq_comp.get_items_by_category("Weapon")[0]

	if weapon_item == null:
		print ("weapon slot has  NO item")
		power = base_damage
	else:
		print ("weapon item found")
		print (weapon_item.i_damage)
		power = base_damage + weapon_item.i_damage
	
	
	
	monitoring = true
	hit_bodies = []
	
	
func stop_attack() -> void:
	monitoring = false


func on_parent_direction_changed(direction) -> void:
	rotation = direction.angle()


func _on_body_entered(body) -> void:
	var body_id = body.get_rid().get_id()
	if body_id in hit_bodies:
		return
	body.take_damage(self, power)
