local set_animation = defense_mob_api.library.set_animation

local do_observers = defense_mob_api.library.set_up_observers("register_on_attack")
local make_sound = defense_mob_api.library.make_sound

local function do_attack(self, obj, dir)
	local dir = vector.aim(self.object:get_pos(), obj:get_pos())
		
	do_observers(self, obj, dir)

	make_sound(self, "attack")
	obj:punch(self.object, self.timer - self.last_attack_time,  {
		full_punch_interval=self.attack_interval,
		damage_groups = {fleshy=self.attack_damage}
	}, dir)
	
	
	
	self.last_attack_time = self.timer

	if self.current_animation == "move" then
		set_animation(self, "move_attack")
	else
		set_animation(self, "attack")
	end
end

function defense_mob_api.library.try_attack(self, obj)
	if self.last_attack_time + self.attack_interval < self.timer
	then
		do_attack(self, obj, dir)
	end
	self.timers.remove_when_far.manipulate_time(self, -60, 300)
end
