Off-duty police officer opens fire during attempted robbery