## # Retrieve next pathfinding move # def pathfind_next_move # Find possible moves possible_moves = [] possible_moves << 4 if @goto_x < @x && passable?(@x, @y, 4) possible_moves << 6 if @goto_x > @x && passable?(@x, @y, 6) possible_moves << 8 if @goto_y < @y && passable?(@x, @y, 8) possible_moves << 2 if @goto_y > @y && passable?(@x, @y, 2) if possible_moves.empty? # No possible moves => pathfinding finished @pathfinding = false if (@goto_x - @x).abs + (@goto_y - @y).abs <= 0 # At destination check_event_trigger_here([0]) else # The destination may be right next to us so try to face and trigger it # if possible. possible_moves << 4 if @goto_x < @x possible_moves << 6 if @goto_x > @x possible_moves << 8 if @goto_y < @y possible_moves << 2 if @goto_y > @y unless possible_moves.include?(direction) # Try to turn towards the goal turn = possible_moves[rand(possible_moves.size)] change_direction(turn) end # Calculate next tile new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) # Actions are prolonged one tile when facing counters dist = $game_map.counter?(new_x, new_y) ? 2 : 1 if (@goto_x - @x).abs + (@goto_y - @y).abs <= dist # Check action and contact triggers. # Note the case where this could case a faulty trigger cannot occur # due to the map design. check_event_trigger_there([0,1,2]) else # Only check contact trigger (event + player) check_event_trigger_there([1,2]) end end else # Choose a possible move at random move = possible_moves[rand(possible_moves.size)] pathfinding_move(move) end end