def enhance(): Utils.wait_till_find("factory") Utils.touch_randomly(regions["enhance"]) Utils.wait_till_find_touch("select_character") Utils.script_sleep(1) gun = None gun = Utils.find("enhance_1_l") if not gun: gun = Utils.find("enhance_1") if not gun: gun = Utils.find("enhance_2_l") if not gun: gun = Utils.find("enhance_2") if not gun: gun = Region(150, 400, 0, 0) Utils.touch_randomly(gun) Utils.wait_till_find_touch("select_character_2") Utils.wait_till_find_touch("smart_select") Utils.script_sleep(2) if not Utils.find("smart_select"): Utils.touch_randomly(regions["ok"]) Utils.script_sleep(1) Utils.touch_randomly(regions["ok"]) Utils.script_sleep(2) Utils.find_and_touch("ls_ok_restart") Utils.touch_randomly(regions["ok"]) Utils.script_sleep(1) Factory.enhance() else: Utils.touch_randomly(regions["return"]) Utils.touch_randomly(regions["return"]) Utils.wait_till_find("test")
def get_fleet_location(self): """Method to get the fleet's current location. Note it uses the green fleet marker to find the location but returns around the area of the feet of the flagship Returns: array: An array containing the x and y coordinates of the fleet's current location. """ coords = [0, 0] count = 0 while coords == [0, 0]: Utils.update_screen() count += 1 if count > 4: Utils.swipe(960, 540, 960, 540 + 150 + count * 20, 100) Utils.update_screen() if Utils.find('combat/fleet_ammo', 0.8): coords = Utils.find('combat/fleet_ammo', 0.8) coords = [coords.x + 140, coords.y + 225 - count * 20] elif Utils.find('combat/fleet_arrow', 0.9): coords = Utils.find('combat/fleet_arrow', 0.9) coords = [coords.x + 25, coords.y + 320 - count * 20] if count > 4: Utils.swipe(960, 540 + 150 + count * 20, 960, 540, 100) elif (math.isclose(coords[0], 160, abs_tol=30) & math.isclose(coords[1], 142, abs_tol=30)): coords = [0, 0] Utils.update_screen() return coords
def feed_snacks(self): Utils.touch_randomly(self.region["supplies_bar"]) Utils.script_sleep(1) Utils.update_screen() alert_found = Utils.find("menu/alert_close") retry_counter = 0 while retry_counter < 40 and self.get_dorm_bar_empty( self.stop_feed_threshold) and not alert_found: retry_counter += 1 find_food = False for idx in self.supply_order: region = self.supply_region[idx] if Utils.get_region_color_average( region)[2] < self.supply_whiteout_threshold: Utils.touch_randomly(region) find_food = True break if not find_food: break else: Utils.wait_update_screen(0.5) alert_found = Utils.find("menu/alert_close") if alert_found: Utils.touch_randomly(alert_found) Utils.wait_update_screen(1) # tap out Utils.touch_randomly(self.region["exit_snacks_menu"])
def refill_dorm(self): """ This method refill the dorm supplies with 10 oxy cola (150 minutes) if the supplies bar is empty. """ Utils.script_sleep(5) Logger.log_debug("Refilling dorm supplies if empty.") while True: Utils.wait_update_screen(1) if Utils.find("headquarters/dorm_summary_confirm_button"): # dismiss dorm summary, if any Utils.touch_randomly(self.region["confirm_dorm_summary"]) continue if Utils.find("headquarters/give_food_button"): # dismiss notification by tapping ignore Utils.touch_randomly(self.region["ignore_give_food_button"]) continue if self.get_dorm_bar_empty(self.start_feed_threshold, True): # proceed to refill self.feed_snacks() break else: # exit loop Logger.log_debug("Ending refill loop.") break
def start_commission(self): Logger.log_debug("Starting commission.") tapped_recommend = False while True: Utils.update_screen() if self.commission_start_attempts > 10: Logger.log_warning("Failed to start commission.") Utils.touch_randomly(self.region["dismiss_message"]) break if Utils.find("commission/alert_begun"): Logger.log_msg("Successfully started commission.") Utils.touch_randomly(self.region["dismiss_message"]) self.stats.increment_commissions_started() break if Utils.find("menu/button_confirm"): Logger.log_debug("Found commission oil warning message.") Utils.touch_randomly(self.region["oil_warning"]) continue if tapped_recommend and Utils.find("commission/button_ready"): Logger.log_debug("Found commission start button.") Utils.touch_randomly(self.region["commission_start"]) tapped_recommend = False continue if Utils.find("commission/button_recommend"): Logger.log_debug("Found commission recommend button.") Utils.touch_randomly(self.region["commission_recommend"]) tapped_recommend = True self.commission_start_attempts += 1 continue Utils.wait_update_screen(1) return not (Utils.find("commission/commissions_full") or self.commission_start_attempts > 10)
def combat_handler(self): Logger.log_msg("Starting combat.") Utils.touch_randomly(self.region['menu_combat_start']) Utils.script_sleep(4) while True: Utils.update_screen() if Utils.find("combat/combat_pause", 0.7): Logger.log_debug("In battle.") Utils.script_sleep(5) continue if Utils.find("combat/menu_touch2continue"): Utils.touch_randomly(Region(661, 840, 598, 203)) continue if Utils.find("menu/item_found"): Utils.touch_randomly(Region(661, 840, 598, 203)) Utils.script_sleep(1) continue if Utils.find("combat/button_confirm"): Logger.log_msg("Combat ended.") Utils.touch_randomly(Region(1520, 963, 216, 58)) Utils.script_sleep(1) return if Utils.find("combat/menu_combat_finished"): Utils.touch_randomly(Region(725, 965, 647, 76)) Utils.script_sleep(1) continue
def refill_dorm(self): """ This method refill the dorm supplies with 10 oxy cola (150 minutes) if the supplies bar is empty. """ Utils.script_sleep(5) Logger.log_debug("Refilling dorm supplies if empty.") while True: Utils.wait_update_screen(1) if Utils.find("headquarters/dorm_summary_confirm_button"): # dismiss dorm summary, if any Utils.touch_randomly(self.region["confirm_dorm_summary"]) continue if Utils.find("headquarters/give_food_button"): # dismiss notification by tapping ignore Utils.touch_randomly(self.region["ignore_give_food_button"]) continue if Utils.find("headquarters/supplies_bar_empty"): # proceed to refill Utils.touch_randomly(self.region["supplies_bar"]) Utils.script_sleep(1) # tap oxy cola ten times for i in range(0, 10): Utils.touch_randomly(self.region["oxy_cola"]) Logger.log_msg("Refilled dorm supplies.") # tap out Utils.touch_randomly(self.region["exit_snacks_menu"]) else: # exit loop Logger.log_debug("Ending refill loop.") break
def combat_handler(self): Logger.log_msg("Starting combat.") Utils.touch_randomly(self.region['menu_combat_start']) Utils.script_sleep(4) while True: Utils.update_screen() if Utils.find("combat/combat_pause", 0.7): Logger.log_debug("In battle.") Utils.script_sleep(5) continue if Utils.find("combat/menu_touch2continue"): Utils.touch_randomly(self.region['tap_to_continue']) continue if Utils.find("menu/item_found"): Utils.touch_randomly(self.region['tap_to_continue']) Utils.script_sleep(1) continue if Utils.find("combat/button_confirm"): Logger.log_msg("Combat ended.") Utils.touch_randomly(self.region['combat_end_confirm']) self.stats.increment_combat_done() Utils.script_sleep(1) return if Utils.find("combat/menu_combat_finished"): Utils.touch_randomly(self.region['dismiss_combat_finished']) Utils.script_sleep(1) continue
def handle_retirement(self): Utils.touch_randomly(Region(1510, 978, 216, 54)) items_found = 0 while True: Utils.update_screen() if Utils.find("retirement/alert_bonus"): Utils.touch_randomly(Region(1412, 938, 218, 61)) Utils.script_sleep(1) continue if Utils.find("menu/item_found"): Utils.touch_randomly(Region(661, 840, 598, 203)) Utils.script_sleep(1) items_found += 1 if items_found > 1: return continue if Utils.find("menu/alert_info"): Utils.touch_randomly(Region(1320, 785, 232, 62)) Utils.script_sleep(1) continue if Utils.find("retirement/button_disassemble"): Utils.touch_randomly(Region(1099, 827, 225, 58)) Utils.script_sleep(1) continue
def handle_retirement(self): """ Method that handles the disassembling of the ship materials used in the enhancement process. """ #tap the "enhance" button Utils.touch_randomly(Region(1705, 916, 167, 40)) Utils.update_screen() if not Utils.find("enhancement/alert_enhanced", 0.85): Logger.log_debug("Didn't find enhanced alert.") return else: Logger.log_debug("Successfully enhanced ship.") while True: Utils.update_screen() if Utils.find("menu/alert_info"): Utils.touch_randomly(Region(1320, 785, 232, 62)) Utils.script_sleep(1) continue if Utils.find("retirement/button_disassemble"): Utils.touch_randomly(Region(1099, 827, 225, 58)) Utils.script_sleep(1) continue if Utils.find("menu/item_found"): Utils.touch_randomly(Region(661, 840, 598, 203)) Utils.script_sleep(1) return
def handle_retirement(self): Utils.touch_randomly(self.region['confirm_retire_button']) items_found = 0 while True: Utils.update_screen() if Utils.find("retirement/alert_bonus"): Utils.touch_randomly( self.region['confirm_selected_ships_button']) Utils.script_sleep(1) continue if Utils.find("menu/item_found"): Utils.touch_randomly(self.region['tap_to_continue']) Utils.script_sleep(1) items_found += 1 if items_found > 1: return continue if Utils.find("menu/alert_info"): Utils.touch_randomly( self.region['confirm_selected_equipment_button']) Utils.script_sleep(1) continue if Utils.find("retirement/button_disassemble"): Utils.touch_randomly(self.region['disassemble_button']) Utils.script_sleep(1) continue
def enhancement_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of enhancing a ship """ if self.need_to_enhance: self.last_enhance = self.stats.combat_done Logger.log_msg("Opening dock to enhance ship.") while True: Utils.update_screen() if Utils.find("menu/button_battle"): Utils.touch_randomly(self.region['dock_tab']) Utils.script_sleep(1) continue if Utils.find("enhancement/button_favorite", 0.99): self.enhance_ship() Utils.touch_randomly(self.region['button_favorite']) Utils.touch_randomly(self.region['button_go_back']) return if Utils.find("menu/dock"): Utils.touch_randomly(self.region['button_favorite']) continue else: Utils.touch_randomly(self.region['button_go_back']) Utils.script_sleep(2)
def handle_retirement(self): """ Method that handles the disassembling of the ship materials used in the enhancement process. """ #tap the "enhance" button Utils.touch_randomly(self.region['enhance_orange_button']) #the enhanced alert lasts about three seconds, so there's enough time to catch it #even if the scripts sleeps for a little bit. This pause ensures the script does not take #the screenshot before the alert is shown. Utils.script_sleep(0.5) Utils.update_screen() if not Utils.find("enhancement/alert_enhanced", 0.85): Logger.log_debug("Didn't find enhanced alert.") return else: Logger.log_debug("Successfully enhanced ship.") while True: Utils.update_screen() if Utils.find("menu/alert_info"): Utils.touch_randomly( self.region['confirm_selected_equipment_button']) Utils.script_sleep(1) continue if Utils.find("retirement/button_disassemble"): Utils.touch_randomly(self.region['disassemble_button']) Utils.script_sleep(1) continue if Utils.find("menu/item_found"): Utils.touch_randomly(self.region['tap_to_continue']) Utils.script_sleep(1) return
def unable_handler(self, coords): """ Method called when the path to the boss fleet is obstructed by mobs: it procedes to switch targets to the mobs which are blocking the path. Args: coords (list): coordinate_x, coordinate_y. These coordinates describe the boss location. """ Logger.log_debug("Unable to reach boss function started.") closest_to_boss = self.get_closest_target(self.blacklist, coords) Utils.touch(closest_to_boss) Utils.wait_update_screen(1) if Utils.find("combat/alert_unable_reach"): Logger.log_warning("Unable to reach next to boss.") self.blacklist.append(closest_to_boss) while True: closest_enemy = self.get_closest_target(self.blacklist) Utils.touch(closest_enemy) Utils.update_screen() if Utils.find("combat/alert_unable_reach"): self.blacklist.append(closest_to_boss) else: break self.movement_handler(closest_enemy) self.battle_handler() return else: self.movement_handler(closest_to_boss) self.battle_handler() return
def enhance_ship(self): """ Method that selects the first (leftmost of the first row) favorite ship and proceeds to enhance her. """ #selects ship Utils.touch_randomly(Region(209, 209, 80, 120)) Utils.script_sleep(1) while True: Utils.update_screen() if Utils.find("enhancement/menu_enhance"): Logger.log_debug("Filling with ships.") #taps the "fill" button Utils.touch_randomly(Region(1467, 917, 140, 38)) Utils.update_screen() if Utils.find("enhancement/alert_no_items", 0.85): Logger.log_warning("Not enough ships to enhance.") break if Utils.find("enhancement/menu_level", 0.8): self.handle_retirement() Logger.log_msg("Successfully finished enhancing.") break if Utils.find("enhancement/menu_details"): Logger.log_debug("Opening enhance menu.") if not Utils.find("enhancement/menu_retrofit", 0.9): Utils.touch_randomly(Region(31, 188, 91, 91)) else: Utils.touch_randomly(Region(31, 329, 91, 91)) continue Utils.touch_randomly(self.region['button_go_back']) Utils.script_sleep(1) return
def set_sort(self): while not self.sorted: Utils.update_screen() if Utils.find("retirement/selected_none"): Logger.log_debug("Retirement: Opening sorting menu.") Utils.touch_randomly(self.region['sort_filters_button']) Utils.script_sleep(0.5) # Touch the All button to clear any current filter Utils.touch_randomly(self.region['all_ship_filter']) continue if self.config.retirement['commons'] and not Utils.find( "retirement/button_sort_common", 0.99): Logger.log_debug("Retirement: Sorting commons") Utils.touch_randomly(self.region['common_ship_filter']) Utils.script_sleep(0.5) continue if self.config.retirement['rares'] and not Utils.find( 'retirement/button_sort_rare', 0.99): Logger.log_debug("Retirement: Sorting rares") Utils.touch_randomly(self.region['rare_ship_filter']) Utils.script_sleep(0.5) continue Logger.log_debug("Retirement: Confirming sort options") self.sorted = True Utils.touch_randomly(self.region['confirm_filter_button']) Utils.script_sleep(1)
def retreat_handler(self): """ Retreats if necessary. """ force_retreat = True if self.exit != 1 else False pressed_retreat_button = False while True: Utils.update_screen() if Utils.find("combat/menu_formation"): Utils.touch_randomly(self.region["menu_nav_back"]) Utils.script_sleep(1) continue if force_retreat and (not pressed_retreat_button ) and Utils.find("combat/button_retreat"): Logger.log_msg("Retreating...") Utils.touch_randomly(self.region['retreat_button']) pressed_retreat_button = True Utils.script_sleep(1) continue if Utils.find_and_touch("menu/button_confirm"): # confirm either the retreat or an urgent commission alert Utils.script_sleep(1) continue if Utils.find("menu/attack"): return
def retirement_logic_wrapper(self, forced=False): """Method that fires off the necessary child methods that encapsulates the entire action of filtering and retiring ships Args: forced: Forces retirement to start even if need_to_retire returns False. """ if self.need_to_retire or forced: self.last_retire = self.stats.combat_done Logger.log_msg("Opening build menu to retire ships.") while True: Utils.update_screen() if Utils.find("menu/button_sort"): # Tap menu retire button Utils.touch_randomly(Region(549, 735, 215, 64)) Utils.script_sleep(1) continue # In case function is called from menu if Utils.find("menu/button_battle"): Utils.touch_randomly(Region(1452, 1007, 198, 52)) Utils.script_sleep(1) continue if Utils.find("menu/build"): if Utils.find("event/build_limited"): Utils.touch_randomly(Region(30, 816, 94, 94)) else: Utils.touch_randomly(Region(20, 661, 115, 99)) Utils.script_sleep(1) continue if Utils.find("retirement/selected_none"): self.retire_ships() Utils.touch_randomly(Region(54, 57, 67, 67)) return
def select_daily(self): Utils.wait_update_screen(1) # while True: if not Utils.find("combat/daily_attempts"): Utils.touch_randomly(self.region["center_daily"]) Logger.log_info("Found daily challenge.") Utils.script_sleep(1) Utils.update_screen() # continue if Utils.find("combat/daily_attempts"): Utils.touch_randomly(self.region["select_daily"]) Logger.log_info("Select daily challenge.") Utils.script_sleep(1) Utils.update_screen() # continue if Utils.find("combat/daily_out"): Logger.log_info("You're out of daily stage challenges.") Utils.touch_randomly(self.region["menu_nav_back"]) # return True Utils.wait_update_screen(1) self.start_daily()
def enhancement_logic_wrapper(self, forced=False): """Method that fires off the necessary child methods that encapsulates the entire action of enhancing a ship. Args: forced (bool): Forces enhancement to start even if need_to_enhance returns False. Returns: enhancement_done (bool): whether at least one enhancement was completed. """ if self.need_to_enhance or forced: self.last_enhance = self.stats.combat_done self.fill_count = 0 self.called_from_menu = False self.enhancement_done = False Logger.log_msg("Opening dock to enhance ship.") while True: Utils.update_screen() if Utils.find("menu/button_sort"): # Tap enhace button from dock is full alert Utils.touch_randomly(self.region['combat_enhance_button']) Utils.script_sleep(3) continue if Utils.find("menu/button_battle"): Utils.touch_randomly(self.region['dock_tab']) self.called_from_menu = True Utils.script_sleep(2) continue if Utils.find("retirement/empty"): Logger.log_msg("No ships left to enhance.") Utils.touch_randomly(self.region['button_favorite']) Utils.script_sleep(0.5) if self.called_from_menu: Utils.menu_navigate("menu/button_battle") else: Utils.touch_randomly(self.region['button_go_back']) return self.enhancement_done if Utils.find("enhancement/button_favorite", 0.99): Utils.script_sleep(1.0) Utils.touch_randomly(self.region['button_favorite']) Utils.script_sleep(0.5) self.enhance_ship() Utils.script_sleep(1) if self.called_from_menu: self.previous_call_place = "menu" Utils.menu_navigate("menu/button_battle") else: self.previous_call_place = "combat" Utils.touch_randomly(self.region['button_go_back']) return self.enhancement_done if Utils.find("menu/dock"): Utils.touch_randomly(self.region['button_favorite']) Utils.script_sleep(1) self.set_sort() continue else: Utils.touch_randomly(self.region['button_go_back']) Utils.script_sleep(2)
def event_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of completing an event """ if self.config.events['name'] == 'Crosswave' and not self.finished: Logger.log_msg("Opening event menu.") while not Utils.find("menu/operation"): Utils.find_and_touch("event/crosswave/menu_button") Utils.wait_update_screen(1) Logger.log_msg("Event levels: " + str(self.levels)) while ('EX' in self.levels): Utils.update_screen() if Utils.find("event/crosswave/ex_completed", 0.98): Logger.log_info("No more EX combats to do.") break Utils.touch_randomly(self.region['crosswave_ex']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg("Finished EX crosswave combat.") while ('H' in self.levels): Utils.update_screen() if Utils.find("event/crosswave/hard_completed"): Logger.log_info("No more hard combats to do.") break Utils.touch_randomly(self.region['crosswave_hard']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg("Finished hard crosswave combat.") while ('N' in self.levels): Utils.update_screen() if Utils.find("event/crosswave/normal_completed"): Logger.log_info("No more normal combats to do.") break Utils.touch_randomly(self.region['crosswave_normal']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg("Finished normal crosswave combat.") while ('E' in self.levels): Utils.update_screen() if Utils.find("event/crosswave/easy_completed"): Logger.log_info("No more easy combats to do.") break Utils.touch_randomly(self.region['crosswave_easy']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg("Finished easy crosswave combat.") Logger.log_msg("Finished all event combats, going back to menu.") Utils.menu_navigate("menu/button_battle") self.finished = True return
def clear_map(self): Logger.log_msg("Started map clear.") Utils.script_sleep(2.5) #hide strat menu Utils.touch_randomly(self.region["hide_strat_menu"]) #swipe map to the left Utils.swipe(960, 540, 1300, 540, 100) target_info = self.get_closest_target(self.blacklist) while True: Utils.update_screen() if Utils.find("combat/alert_unable_battle"): Logger.log_warning("Failed to defeat enemy.") Utils.touch_randomly(Region(869, 741, 185, 48)) return False if self.exit is not 0: return True if Utils.find("enemy/fleet_boss", 0.9): Logger.log_msg("Boss fleet was found.") boss_region = Utils.find("enemy/fleet_boss", 0.9) #extrapolates boss_info(x,y,enemy_type) from the boss_region found boss_info = [boss_region.x + 50, boss_region.y + 25, "boss"] self.clear_boss(boss_info) continue if target_info == None: if Utils.find("combat/question_mark", 0.9): target_info = self.get_closest_target(self.blacklist, mystery_node=True) #if it is a mystery_node (question_mark), tap a bit lower if target_info[2] == "mystery_node": #coord_y += 140 target_info[1] += 140 else: target_info = self.get_closest_target(self.blacklist) continue if target_info: #tap at target's coordinates Utils.touch(target_info[0:2]) Utils.update_screen() if Utils.find("combat/alert_unable_reach", 0.8): Logger.log_warning("Unable to reach the target.") self.blacklist.append(target_info[0:2]) target_info = None continue else: movement_result = self.movement_handler(target_info) if movement_result == 1: self.battle_handler() target_info = None self.blacklist.clear() continue
def start_daily(self): while True: if Utils.find("combat/battle_button"): Utils.touch_randomly(self.region["menu_combat_start"]) Logger.log_debug( "Found battle button, starting clear function.") self.daily_handler() if Utils.find("combat/daily_out"): Logger.log_info("You're out of daily stage challenges.") Utils.touch_randomly(self.region["menu_nav_back"]) Utils.update_screen()
def pre_combat_handler(self): """Handles pre-combat stuff like fleet selection and starts combat_handler function. """ while True: Utils.update_screen() if Utils.find("combat/menu_select_fleet"): Logger.log_debug("Found event fleet go button.") Utils.touch_randomly(self.region['menu_fleet_go']) continue if Utils.find("combat/menu_formation"): Logger.log_debug("Found formation asset.") return True
def skill_levelling(self): """ This method ensures that the skills currently being levelled continue to do so. The skillbooks used are the ones indicated by the SkillBookTier setting in the config.ini file. """ Utils.script_sleep(5) Logger.log_msg("Levelling the skills of the previously chosen ships.") while True: Utils.wait_update_screen(1) if Utils.find_and_touch("menu/button_confirm"): Logger.log_msg("Starting/ending skill levelling session.") Utils.script_sleep(3.5) continue if Utils.find("headquarters/skill_exp_gain"): if Utils.find_and_touch( "headquarters/t{}_offense_skillbook".format( self.config.academy["skill_book_tier"]), 0.99): # levelling offesinve skill Logger.log_msg("Selected T{} offensive skill book.".format( self.config.academy["skill_book_tier"])) self.stats.increment_offensive_skillbook_used() elif Utils.find_and_touch( "headquarters/t{}_defense_skillbook".format( self.config.academy["skill_book_tier"]), 0.99): # levelling defesinve skill Logger.log_msg("Selected T{} defensive skill book.".format( self.config.academy["skill_book_tier"])) self.stats.increment_defensive_skillbook_used() elif Utils.find_and_touch( "headquarters/t{}_support_skillbook".format( self.config.academy["skill_book_tier"]), 0.99): # levelling support skill Logger.log_msg("Selected T{} support skill book.".format( self.config.academy["skill_book_tier"])) self.stats.increment_support_skillbook_used() else: Logger.log_warning( "Skillbook specified not found. Cancelling lesson.") Utils.touch_randomly(self.region["cancel_lesson_button"]) continue Utils.script_sleep(1) Utils.touch_randomly(self.region["start_lesson_button"]) continue if Utils.find("headquarters/tactical_class"): # exit tactical class Utils.touch_randomly(self.region["button_back"]) Logger.log_msg("All classes have started.") Utils.script_sleep(1) break
def retire_ships(self): while True: Utils.update_screen() if Utils.find("retirement/empty"): Logger.log_msg("No ships left to retire.") Utils.touch_randomly(self.region['menu_nav_back']) return if Utils.find("retirement/selected_none"): self.select_ships() continue if Utils.find("retirement/bonus"): self.handle_retirement() continue
def retirement_logic_wrapper(self, forced=False): """Method that fires off the necessary child methods that encapsulates the entire action of filtering and retiring ships Args: forced (bool): Forces retirement to start even if need_to_retire returns False. Returns: retirement_done (bool): whether at least one retirement was completed. """ if self.need_to_retire or forced: self.last_retire = self.stats.combat_done self.called_from_menu = False self.retirement_done = False Logger.log_msg("Opening build menu to retire ships.") while True: Utils.update_screen() if Utils.find("menu/button_sort"): # Tap menu retire button Utils.touch_randomly(self.region['combat_sort_button']) Utils.script_sleep(1) continue # In case function is called from menu if Utils.find("menu/button_battle"): self.called_from_menu = True Utils.touch_randomly(self.region['build_menu']) Utils.script_sleep(1) continue if Utils.find("menu/build"): if Utils.find("event/build_limited"): Utils.touch_randomly(self.region['retire_tab_2']) else: Utils.touch_randomly(self.region['retire_tab_1']) Utils.script_sleep(1) continue if Utils.find("retirement/selected_none"): self.set_sort() self.retire_ships() if self.called_from_menu: self.previous_call_place = "menu" Utils.menu_navigate("menu/button_battle") else: self.previous_call_place = "combat" Utils.touch_randomly(self.region['menu_nav_back']) return self.retirement_done Utils.update_screen()
def start_project(self): Utils.touch_randomly(self.region['commence_tab']) Utils.wait_update_screen(1) #solution for projects that don't require confirmation. if Utils.find("research/terminate", 0.99): return True if Utils.find("research/confirm", 0.99): Utils.touch_randomly(self.region['confirm_tab']) Utils.wait_update_screen(1) if Utils.find("research/terminate", 0.99): return True else: return False
def clear_boss(self, boss_info): Logger.log_debug("Started boss function.") self.enemies_list.clear() self.mystery_nodes_list.clear() self.blacklist.clear() while True: #tap at boss' coordinates Utils.touch(boss_info[0:2]) Utils.update_screen() if Utils.find("combat/alert_unable_reach", 0.8): Logger.log_msg("Unable to reach boss.") #handle boss' coordinates if not self.unable_handler(boss_info[0:2]): return continue else: self.movement_handler(boss_info) if self.battle_handler(boss=True): self.exit = 1 Logger.log_msg("Boss successfully defeated.") Utils.script_sleep(3) return
def movement_handler(self, target_info): """ Method that handles the fleet movement until it reach its target (mystery node or enemy node). If the coordinates are wrong, they will be blacklisted and another set of coordinates to work on is obtained. If the target is a mystery node and what is found is ammo, then the method will fall in the blacklist case and search for another enemy: this is inefficient and should be improved, but it works. Args: target_info (list): coordinate_x, coordinate_y, type. Describes the selected target. Returns: (int): 1 if a fight is needed, otherwise 0. """ Logger.log_msg("Moving towards objective.") count = 0 location = [target_info[0], target_info[1]] Utils.script_sleep(1) while True: Utils.update_screen() event = self.check_movement_threads() if event["combat/button_evade"]: Logger.log_msg("Ambush was found, trying to evade.") Utils.touch_randomly(self.region["combat_ambush_evade"]) Utils.script_sleep(0.5) continue if event["combat/alert_failed_evade"]: Logger.log_warning("Failed to evade ambush.") Utils.touch_randomly(self.region["menu_combat_start"]) self.battle_handler() continue if event["menu/item_found"]: Logger.log_msg("Item found on node.") Utils.touch_randomly(Region(661, 840, 598, 203)) if Utils.find("combat/menu_emergency"): Utils.script_sleep(1) Utils.touch_randomly(self.region["hide_strat_menu"]) if target_info[2] == "mystery_node": Logger.log_msg("Target reached.") return 0 continue if event["menu/alert_info"]: Logger.log_debug("Found alert.") Utils.find_and_touch("menu/alert_close") continue if event["combat/menu_formation"] or event["combat/menu_loading"]: return 1 else: if count != 0 and count % 3 == 0: Utils.touch(location) if count > 21: Logger.log_msg( "Blacklisting location and searching for another enemy." ) self.blacklist.append(location) self.l.clear() location = self.get_closest_target(self.blacklist) count = 0 count += 1