local DropItemSystem = inherited("DropItemSystem", SystemMap)

function DropItemSystem:new()
	local ms = instance(self)
	return ms
end

function DropItemSystem:dynamic_wants(ent)
	return ent.aspects.drop_item and ent.drop_slot
end

function DropItemSystem:ent_added(ent)
end

function DropItemSystem:ent_removed(ent)
end

function DropItemSystem:step(dt)
	for ent, _ in pairs(self.ents) do
		local drop_slot = ent.drop_slot
		if drop_slot then
			local item = drop_slot:pop_item()
			if item then
				local eject = Entity:new("pickup", ent.x, ent.y, ent.z + ent.drop_z)
				eject:set_item(item)
				eject:set_speed(math.randomGaussian()*10,math.randomGaussian()*10,125 + math.random()*100)
				self.world.universe:add_ent(eject)
			end
			ent:set_drop_slot_intent(nil)
			if ent.inventory_changed then
				ent:inventory_changed()
			end
		end
	end
end

return DropItemSystem