<s> """<STR_LIT>""" <EOL> from pyherc . ai . pathfinding import a_star <EOL> from pyherc . aspects import log_debug <EOL> from pyherc . data . geometry import find_direction <EOL> from pyherc . data import find_free_space <EOL> from pyherc . events import new_lose_focus_event , new_notice_event <EOL> from pyherc . ports import is_move_legal , move , attack , equip <EOL> class SkeletonWarriorAI ( ) : <EOL> """<STR_LIT>""" <EOL> @ log_debug <EOL> def __init__ ( self , character ) : <EOL> """<STR_LIT>""" <EOL> self . character = character <EOL> self . mode = '<STR_LIT>' <EOL> self . destination = None <EOL> def __call__ ( self , model , action_factory , rng ) : <EOL> self . act ( model , action_factory , rng ) <EOL> @ log_debug <EOL> def act ( self , model , action_factory , rng ) : <EOL> """<STR_LIT>""" <EOL> del self . character . short_term_memory [ : ] <EOL> if self . character . inventory . weapon is None : <EOL> self . _wield_weapon ( action_factory ) <EOL> c_location = self . character . location <EOL> p_location = model . player . location <EOL> distance = ( ( c_location [ <NUM_LIT:0> ] - p_location [ <NUM_LIT:0> ] ) ** <NUM_LIT:2> + <EOL> ( c_location [ <NUM_LIT:1> ] - p_location [ <NUM_LIT:1> ] ) ** <NUM_LIT:2> ) ** <NUM_LIT:0.5> <EOL> if distance < <NUM_LIT:4> : <EOL> if self . mode != '<STR_LIT>' : <EOL> self . character . raise_event ( <EOL> new_notice_event ( character = self . character , <EOL> target = model . player ) ) <EOL> self . mode = '<STR_LIT>' <EOL> else : <EOL> if self . mode != '<STR_LIT>' : <EOL> self . character . raise_event ( <EOL> new_lose_focus_event ( character = self . character ) ) <EOL> self . mode = '<STR_LIT>' <EOL> if self . mode == '<STR_LIT>' : <EOL> self . _patrol ( model , action_factory , rng ) <EOL> else : <EOL> self . _combat ( model , action_factory , rng ) <EOL> @ log_debug <EOL> def _wield_weapon ( self , action_factory ) : <EOL> """<STR_LIT>""" <EOL> weapons = [ item for item in <EOL> self . character . inventory <EOL> if item . weapon_data is not None ] <EOL> if weapons : <EOL> equip ( self . character , <EOL> weapons [ <NUM_LIT:0> ] ) <EOL> @ log_debug <EOL> def _patrol ( self , model , action_factory , rng ) : <EOL> """<STR_LIT>""" <EOL> character = self . character <EOL> level = self . character . level <EOL> while ( self . destination is None <EOL> or character . location == self . destination ) : <EOL> self . destination = find_free_space ( level ) <EOL> path , connections , updated = a_star ( character . location , <EOL> self . destination , <EOL> level ) <EOL> next_tile = path [ <NUM_LIT:1> ] <EOL> direction = find_direction ( character . location , <EOL> next_tile ) <EOL> if is_move_legal ( character , <EOL> direction , <EOL> '<STR_LIT>' , <EOL> action_factory ) : <EOL> move ( character , direction , action_factory ) <EOL> else : <EOL> character . tick = character . tick + <NUM_LIT:10> <EOL> @ log_debug <EOL> def _combat ( self , model , action_factory , rng ) : <EOL> """<STR_LIT>""" <EOL> character = self . character <EOL> player = model . player <EOL> c_location = character . location <EOL> p_location = player . location <EOL> distance = ( ( c_location [ <NUM_LIT:0> ] - p_location [ <NUM_LIT:0> ] ) ** <NUM_LIT:2> + <EOL> ( c_location [ <NUM_LIT:1> ] - p_location [ <NUM_LIT:1> ] ) ** <NUM_LIT:2> ) ** <NUM_LIT:0.5> <EOL> if distance == <NUM_LIT:1> : <EOL> direction = find_direction ( c_location , <EOL> p_location ) <EOL> attack ( character , <EOL> direction , <EOL> rng ) <EOL> else : <EOL> path , connections , updated = a_star ( c_location , <EOL> p_location , <EOL> character . level ) <EOL> next_tile = path [ <NUM_LIT:1> ] <EOL> direction = find_direction ( character . location , <EOL> next_tile ) <EOL> if is_move_legal ( character , <EOL> direction , <EOL> '<STR_LIT>' , <EOL> action_factory ) : <EOL> move ( character , direction , action_factory ) <EOL> else : <EOL> character . tick = character . tick + <NUM_LIT:10> </s>
