added cast range check before applying enemy AI attacks