I think you should make a function that will return the biggest and closet priority target. The basic design is that first you make an array list of all the class you want to target, ordered by its priority. Then from the top of that list (the class of targets with biggest priority), search for all object of that calss. If there is none or they are too far away, then you continue to work with another class down the list. Else, you return the closet object to your character.