
local do_observers = defense_mob_api.library.set_up_observers("register_on_step")

local set_animation = defense_mob_api.library.set_animation

function defense_mob_api.library.on_step(self, dtime)
	local ceas = os.clock()
	
	do_observers(self, dtime)
	
	for _, timer in ipairs(self.timers)
	do
		timer.manipulate_time(self, dtime)
	end
	
	self:is_standing()
	self.target = self:find_target()
	
	
	
	
	
	if not self.paused
	then
		if self.destination
		then
			self:move(dtime, self.destination)
			if vector.distance(self.object:get_pos(), self.destination) < 0.5
			then
				self.destination = nil
			end
		else
			self:move(dtime, self.object:get_pos())
		end
	end
	
	if self.movement ~= "air" and not self.standing
	then
		set_animation(self, "fall", {"jump", "attack", "move_attack"})
	end
	
	local target = self.target

	-- Disable collision when far enough
	if self.collide_with_objects
	then
		if target.distance > 6
		then
			self.collide_with_objects = false
			self.object:set_properties({collide_with_objects = self.collide_with_objects})
		end
	else
		if target.distance < 1.5
		then
			self.collide_with_objects = true
			self.object:set_properties({collide_with_objects = self.collide_with_objects})
		end
	end
	
	self.timer = self.timer + dtime
	defense_mob_api:track_time("prototype on_step", os.clock() - ceas)
end

