Module: TravianBot::Application::Hero
- Includes:
- Navigation, Time
- Included in:
- TravianBot::Application, Shell
- Defined in:
- lib/travian_bot/application/hero.rb
Instance Method Summary collapse
Methods included from Time
Methods included from Navigation
#to_hero_quest_page, #to_map_page, #to_reports_page, #to_resources_page, #to_stats_page, #to_village_page
Instance Method Details
#start_closest_adventure(selenium) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/travian_bot/application/hero.rb', line 9 def start_closest_adventure(selenium) to_hero_quest_page(selenium) elements = selenium.find_elements(:xpath, '//div[@class="hero_adventure"]/table/tbody/tr') quests = Hash.new elements.each_with_index do |item, index| quests[index] = to_seconds(item.find_element(:class, 'moveTime').text) end shortest_quest = quests.sort{|a,b| a[1] <=> b[1]}.first.first elements[shortest_quest].find_element(:class, 'gotoAdventure').click begin link = selenium.find_element(:link_text, 'Abenteuer starten') link.click rescue return ['Currently the hero is busy for a quest.', [0, 0]] end mission_name = selenium.find_element(:xpath, '//span[@class="coordinates coordinatesWithText"]/span[@class="coordText"]') coordinate_x = selenium.find_element(:xpath, 'span[@class="coordinates coordinatesWithText"]/span[@class="coordinateX"]') coordinate_y = selenium.find_element(:xpath, 'span[@class="coordinates coordinatesWithText"]/span[@class="coordinateY"]') confirm_link = selenium.find_element(:id, 'btn_ok') confirm_link.click [mission_name, [coordinate_x.sub('(', ''), coordinate_y.sub(')', '')]] end |