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()

onready var player_data  = get_tree().get_root().find_node("PlayerData", true, false)


	

func _ready() -> void:
	connect ("body_entered", self, "_on_body_entered")
	monitoring = false
	
	eq_comp = player_data.find_node("Equipment")
	
	


#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)
