def commission_logic_wrapper(self): if (Utils.find_and_touch('notification_commission_complete')): Logger.log_msg('Completed commissions found.' + 'Opening commission panel.') while Utils.find_and_touch('commission_complete'): Logger.log_msg('Completed commission found.' + 'Redeeming reward.') Utils.touch_randomly() Utils.script_sleep(1) Utils.touch_randomly() Utils.script_sleep(1) if Utils.find_and_touch('commission_go'): # Ensure the list is scrolled up to the top before # checking in progress commissions Utils.swipe(190, 190, 75, 650) in_progress = len( Utils.find_all('commission_in_action', 0.87)[0]) while in_progress < 4: Utils.swipe(190, 190, 650, 75) if Utils.find_and_touch('commission_select'): Utils.find_and_touch('commission_advice') Utils.find_and_touch('commission_start') Utils.touch_randomly(Region(120, 60, 140, 650)) in_progress += 1 else: break Utils.find_and_touch('navigate_back_home') Utils.touch_randomly(Region(530, 60, 740, 590)) return False
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 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
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 retire_ships(self): """Clicks through the dialogs for retiring ships """ Utils.find_and_touch('retire_confirm', 0.8) Utils.wait_and_touch('retire_confirm', 0.8, 3) Utils.touch_randomly(Region(0, 0, 300, 300)) Utils.wait_and_touch('retire_confirm', 0.8, 3) Utils.wait_and_touch('retire_disassemble', 3) Utils.touch_randomly(Region(0, 0, 300, 300))
def mission_logic_wrapper(self): if (Utils.find_and_touch('mission_complete')): Logger.log_msg('Checking for completed missions.') self.stats.increment_missions_done() Utils.script_sleep(0.5) while Utils.find_and_touch('collect_mission'): Utils.touch_randomly() Utils.touch_randomly(Region(12, 8, 45, 30)) return True return False
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 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 collect_dorm_balloons(self): """" This method finds and collects all the dorm tokens and affinity points visible to the script. The various swipes may not work if there is a shipgirl at the starting point of the swipe. For this reason the wrapper to this methoed iterates its cycle for three times, refreshing the dorm. """ Utils.script_sleep(1) # tap dorm eye in order to hide UI Utils.touch_randomly(self.region["dorm_eye_button"]) Logger.log_debug("Collecting all visible dorm tokens/affinity points.") for i in range(0, 4): Utils.wait_update_screen(1) # since a rather low similarity is used, the variable j ensures a finite loop j = 0 while Utils.find_and_touch("headquarters/dorm_token", 0.75) and j < 5: Logger.log_msg("Collected dorm token.") Utils.wait_update_screen() j += 1 j = 0 while Utils.find_and_touch("headquarters/affinity_point", 0.75) and j < 5: Logger.log_msg("Collected affinity points.") Utils.wait_update_screen() j += 1 if i == 0: # swipe right and refresh Utils.swipe(960, 540, 560, 540, 300) continue if i == 1: # swipe left (also countering the previous swipe) and refresh Utils.swipe(960, 540, 1760, 540, 300) continue if i == 2: # undo previous swipe Utils.swipe(960, 540, 560, 540, 300) # swipe up and refresh Utils.swipe(960, 540, 960, 790, 300) continue if i == 3: # swipe bottom (also countering the previous swipe) and refresh Utils.swipe(960, 540, 960, 40, 300) continue # restore UI Utils.touch_randomly(self.region["dorm_eye_button"])
def clear_trash(self): """Finds trash mobs closest to the current fleet location and battles them until the boss spawns """ while self.kills_needed > 0: blacklist = [] tries = 0 if self.resume_previous_sortie: self.resume_previous_sortie = False Utils.find_and_touch('combat_attack') Utils.script_sleep(2) else: self.avoided_ambush = True while not Utils.exists('combat_battle_start'): if Utils.find_and_touch('combat_evade'): if Utils.wait_for_exist('combat_battle_start', 3): self.avoided_ambush = False else: Logger.log_msg('Successfully avoided ambush.') elif Utils.find_and_touch('combat_items_received'): pass else: enemy_coord = self.get_closest_enemy() if tries > 2: blacklist.append(enemy_coord) enemy_coord = self.get_closest_enemy(blacklist) Logger.log_msg( 'Navigating to enemy fleet at {}'.format(enemy_coord)) Utils.touch(enemy_coord) tries += 1 Utils.script_sleep(5) if self.conduct_prebattle_check(): if self.conduct_battle(): self.need_to_refocus = True else: self.resume_previous_sortie = True while not (Utils.exists('home_menu_build')): Utils.touch_randomly(self.region['nav_back']) # Add logic for retirement here? return False if self.avoided_ambush: self.kills_needed -= 1 Logger.log_msg('Kills left for boss to spawn: {}'.format( self.kills_needed)) Utils.script_sleep(1) return True
def reach_map(self): """ Method to move to the world where the specified map is located. Only works with worlds added to assets (from 1 to 8) and some event maps. Also checks if hard mode is enabled. """ _map = 0 if not self.chapter_map[0].isdigit(): letter = self.chapter_map[2:3] event_maps = ['A', 'B', 'C', 'D'] Utils.find_and_touch("menu/button_event") Utils.wait_update_screen(1) if event_maps.index(letter) < 2 and Utils.find("menu/button_normal_mode") or \ event_maps.index(letter) > 1 and not Utils.find("menu/button_normal_mode"): Utils.touch_randomly(Region(88, 990, 80, 40)) Utils.wait_update_screen(1) else: for x in range(1, 11): if Utils.find("maps/map_{}-1".format(x), 0.99): _map = x break if _map != 0: taps = int(self.chapter_map.split("-")[0]) - _map for x in range(0, abs(taps)): if taps >= 1: Utils.touch_randomly(self.region['map_nav_right']) Logger.log_debug("Swiping to the right") Utils.wait_update_screen() else: Utils.touch_randomly(self.region['map_nav_left']) Logger.log_debug("Swiping to the left") Utils.wait_update_screen() if Utils.find('maps/map_{}'.format(self.chapter_map), 0.99): Logger.log_msg( "Successfully reached the world where map is located.") else: Logger.log_error( "Cannot find the specified map, please move to the world where it's located." ) while not Utils.find('maps/map_{}'.format(self.chapter_map), 0.99): Utils.wait_update_screen(1)
def LogisticManager(): while True: Utils.update_screen() if Utils.find("ls_completed"): Utils.touch_randomly() Logger.log_msg("Logistic Mission finished") if Utils.find_and_touch("ls_ok_restart"): Logger.log_msg("Restarting Logistic Mission")
def CheckLogistic(): Utils.script_sleep(3) if Utils.find("ls_completed"): Utils.touch_randomly() Logger.log_msg("Logistic Mission finished") if Utils.find_and_touch("ls_ok_restart"): Logger.log_msg("Restarting Logistic Mission") CheckLogistic()
def completed_handler(self): Utils.touch_randomly(self.region["complete_commission"]) Utils.script_sleep(1) while True: Utils.update_screen() if Utils.find("commission/alert_perfect"): Utils.touch_randomly(self.region["tap_to_continue"]) self.stats.increment_commissions_received() continue if Utils.find("menu/item_found"): Utils.find_and_touch("menu/tap_to_continue") Utils.script_sleep(1) continue if Utils.find("commission/alert_available", 0.9): Logger.log_debug("Finished completing commissions.") Utils.script_sleep(0.5) return
def reach_map(self): """ Method to move to the world where the specified map is located. Only works with worlds added to assets (from 1 to 8). Also checks if hard mode is enabled. """ _map = 0 if Utils.find("menu/button_normal_mode"): Logger.log_debug("Disabling hard mode.") Utils.touch_randomly(Region(88, 990, 80, 40)) Utils.wait_update_screen(1) if not self.chapter_map[0].isdigit(): Utils.find_and_touch("menu/button_event") Utils.wait_update_screen(1) else: for x in range(1, 9): if Utils.find("maps/map_{}-1".format(x), 0.99): _map = x break if _map != 0: taps = int(self.chapter_map.split("-")[0]) - _map for x in range(0, abs(taps)): if taps >= 1: Utils.touch_randomly(Region(1831, 547, 26, 26)) Logger.log_debug("Swiping to the right") Utils.wait_update_screen() else: Utils.touch_randomly(Region(65, 547, 26, 26)) Logger.log_debug("Swiping to the left") Utils.wait_update_screen() if Utils.find('maps/map_{}'.format(self.chapter_map), 0.99): Logger.log_msg( "Successfully reached the world where map is located.") else: Logger.log_error( "Cannot find the specified map, please move to the world where it's located." ) while not Utils.find('maps/map_{}'.format(self.chapter_map), 0.99): Utils.wait_update_screen(1)
def combat_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of sortieing combat fleets and resolving combat. Returns: bool: True if the combat cycle was complete """ if self.check_need_to_sortie(): Logger.log_msg('Navigating to map.') Utils.touch_randomly(self.region['home_menu_attack']) Utils.script_sleep(1) if not self.resume_previous_sortie: self.kills_needed = self.config.combat['kills_needed'] if self.event_map: Utils.touch_randomly(self.region['event_map']) if self.hard_mode: Utils.find_and_touch('map_menu_hard') Utils.wait_and_touch('map_{}'.format(self.sortie_map), 5, 0.85) Utils.script_sleep() Utils.touch_randomly(self.region['map_go_1']) Utils.script_sleep() Utils.touch_randomly(self.region['map_go_2']) Utils.script_sleep(5) if self.config.combat['alt_clear_fleet']: Logger.log_msg('Alternate clearing fleet enabled, ' + 'switching to 2nd fleet to clear trash') self.switch_fleet() self.need_to_refocus = False # Trash if self.clear_trash(): # Boss if self.config.combat['boss_fleet']: Logger.log_msg('Switching to 2nd fleet to kill boss') self.switch_fleet() self.clear_boss() self.stats.increment_combat_done() self.next_combat_time = datetime.now() Logger.log_success('Sortie complete. Navigating back home.') while not (Utils.exists('home_menu_build')): Utils.touch_randomly(self.region['nav_back']) self.set_next_combat_time({'seconds': 10}) return True return False
def commission_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of starting and completing commissions. """ Logger.log_msg("Found commission completed alert.") Utils.touch_randomly(self.region["left_menu"]) Utils.script_sleep(1) Utils.touch_randomly(self.region["collect_oil"]) Utils.touch_randomly(self.region["collect_gold"]) self.attempts_count = 0 while True: Utils.update_screen() if Utils.find("commission/button_completed") and ( lambda x: x > 332 and x < 511)( Utils.find("commission/button_completed").y): Logger.log_debug("Found commission complete button.") self.completed_handler() if Utils.find("commission/alert_available", 0.9) and (lambda x: x > 332 and x < 511)(Utils.find( "commission/alert_available", 0.9).y): Logger.log_debug("Found commission available indicator.") if self.attempts_count > 2: Logger.log_msg( "Exceeded number of tries allowed. Resuming with other tasks." ) Utils.touch_randomly(self.region["dismiss_side_tab"]) break Utils.touch_randomly(self.region["button_go"]) self.attempts_count += 1 self.commission_start_attempts = 0 Utils.wait_update_screen(1) while not Utils.find("menu/commission"): Utils.touch_randomly(self.region["button_go"]) Utils.wait_update_screen(1) if Utils.find_and_touch("menu/alert_close"): Utils.script_sleep(1) if self.urgent_handler(): self.daily_handler() Utils.touch_randomly(self.region["button_back"]) continue if Utils.find("commission/button_go") and ( lambda x: x > 332 and x < 511)( Utils.find("commission/button_go").y): Logger.log_msg("All commissions are running.") Utils.touch_randomly(self.region["dismiss_side_tab"]) break Utils.wait_update_screen() return True
def conduct_battle(self): """Method to start the battle and click through the rewards once the battle is complete. """ Logger.log_msg('Starting battle') while (Utils.exists('combat_auto_enabled')): Utils.touch_randomly(self.region['battle_start']) if Utils.wait_for_exist('combat_notification_sort', 3): return False Utils.script_sleep(30) while not Utils.find_and_touch('combat_battle_confirm', 0.85): if Utils.find_and_touch('confirm'): Logger.log_msg('Locked new ship.') else: Utils.touch_randomly(Region(0, 100, 150, 150)) Utils.script_sleep() Logger.log_msg('Battle complete.') if Utils.wait_and_touch('confirm', 3): Logger.log_msg('Dismissing urgent notification.') return True
def set_filters(self): """Filters the ship list to only show rare and commmon ships """ Utils.touch_randomly(Region(1090, 15, 150, 40)) Utils.script_sleep(1) Utils.wait_for_exist('ship_filter_confirm', 3) Utils.touch_randomly(Region(300, 570, 100, 20)) Utils.find_and_touch('ship_filter_rarity_common') Utils.find_and_touch('ship_filter_rarity_rare') Utils.find_and_touch('ship_filter_confirm')
def urgent_handler(self): Utils.touch_randomly(self.region["urgent_tab"]) while True: Utils.update_screen() if Utils.find_and_touch("commission/commission_status"): Logger.log_msg("Found status indicator on urgent commission.") if not self.start_commission(): Logger.log_msg("No more commissions to start.") return False else: Utils.touch_randomly(self.region["daily_tab"]) Logger.log_msg("No urgent commissions left.") break Utils.script_sleep(1) return True
def retirement_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action filtering and retiring ships """ if self.need_to_retire: while not (Utils.find_and_touch('home_menu_build')): Utils.touch_randomly(Region(12, 8, 45, 30)) Utils.wait_and_touch('build_menu_retire', 5) Utils.script_sleep(1) self.set_filters() Utils.script_sleep(1) done = False while not done: self.select_ships() if (Utils.exists('retire_none_selected')): done = True # Click confirm button else: self.retire_ships()
def executeOrders(self): while True: n = self.nextOrder() if n[0] == 'end': break if n[0] == 'swipe': Utils.swipe(int(n[1]), int(n[2]), int(n[3]), int(n[4]), 1000) continue if n[0] == 'tap': Utils.touch_randomly(Region(int(n[1]), int(n[2]), 0, 0)) continue if n[0] == 'wait': Utils.script_sleep(int(n[1])) continue if n[0] == 'find_touch': if Utils.find_and_touch(n[1]): if n[1] == 'dock_full': Factory.enhance() return 1 continue if n[0] == 'wait_find': Utils.wait_till_find(n[1]) continue if n[0] == 'wait_find_touch': Utils.wait_till_find_touch(n[1]) continue if n[0] == 'swipe_topleft': Utils.swipe_top_left() continue if n[0] == 'log_info': Logger.log_info(n[1].replace('_', ' ')) continue if n[0] == 'deploy': if n[1] == 'start': self.deploy() else: self.deploy(False) continue print(n) return 0
def clear_boss(self): """Finds the boss and battles it """ while not Utils.exists('combat_battle_start'): boss = None similarity = 0.8 while boss is None: boss = Utils.scroll_find('combat_enemy_boss_alt', 250, 175, similarity) similarity -= 0.015 Logger.log_msg('Boss found at: {}'.format([boss.x, boss.y])) Logger.log_msg('Focusing on boss') Utils.swipe(boss.x, boss.y, 640, 360, 250) boss = None while boss is None: boss = Utils.find('combat_enemy_boss_alt', similarity) similarity -= 0.015 # Click slightly above boss to be able to click on it in case # the boss is obstructed by another fleet or enemy boss_coords = [boss.x + 50, boss.y - 15] Utils.touch(boss_coords) if Utils.wait_for_exist('combat_unable', 3): boss = Utils.scroll_find('combat_enemy_boss_alt', 250, 175, 0.75) enemies = Utils.find_all('combat_enemy_fleet', 0.89) enemies.remove(boss) closest_to_boss = enemies[Utils.find_closest(enemies, boss)[1]] Utils.find_and_touch(closest_to_boss) if Utils.wait_for_exist('combat_unable', 3): Utils.find_and_touch(self.get_closest_enemy()) if Utils.wait_for_exist('combat_battle_start', 3): self.conduct_battle() else: Utils.script_sleep(5) if Utils.find_and_touch('combat_evade'): if Utils.wait_for_exist('combat_battle_start', 3): self.conduct_battle() self.refocus_fleet() elif Utils.find_and_touch('combat_items_received'): pass if self.conduct_prebattle_check(): self.conduct_battle()
def combat_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of sortieing combat fleets and resolving combat. Returns: int: 1 if boss was defeated, 2 if morale is too low and 3 if dock is full. """ self.exit = 0 self.l.clear() self.blacklist.clear() while True: Utils.wait_update_screen() if Utils.find("menu/button_sort"): Utils.touch_randomly(Region(1326, 274, 35, 35)) self.exit = 3 if Utils.find("combat/alert_morale_low"): Utils.touch_randomly(Region(1326, 274, 35, 35)) self.exit = 2 break if Utils.find("commission/button_confirm"): Logger.log_msg("Found commission info message.") Utils.touch_randomly(self.region["combat_com_confirm"]) continue if Utils.find("menu/button_battle"): Logger.log_debug("Found menu battle button.") Utils.touch_randomly(self.region["menu_button_battle"]) Utils.wait_update_screen(1) continue if Utils.find("combat/menu_select_fleet"): Logger.log_debug("Found fleet select go button.") Utils.touch_randomly(self.region["fleet_menu_go"]) continue if Utils.find("combat/button_go"): Logger.log_debug("Found map summary go button.") Utils.touch_randomly(self.region["map_summary_go"]) continue if Utils.find("combat/button_retreat"): Logger.log_debug( "Found retreat button, starting clear function.") if not self.clear_map(): self.stats.increment_combat_attempted() break if self.exit == 1: self.stats.increment_combat_done() break if self.exit > 1: self.stats.increment_combat_attempted() break if Utils.find("menu/button_normal_mode"): Logger.log_debug("Disabling hard mode.") Utils.touch_randomly(Region(88, 990, 80, 40)) Utils.wait_update_screen(1) if Utils.find_and_touch('maps/map_{}'.format(self.chapter_map), 0.8): Logger.log_msg("Found specified map.") continue else: self.reach_map() continue Utils.script_sleep(1) Utils.menu_navigate("menu/button_battle") return self.exit
def combat_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of sortieing combat fleets and resolving combat. Returns: int: 1 if boss was defeated, 2 if morale is too low and 3 if dock is full. """ self.exit = 0 self.combats_done = 0 self.l.clear() self.blacklist.clear() while True: Utils.wait_update_screen() if Utils.find("menu/button_sort"): Utils.touch_randomly(self.region['close_info_dialog']) self.exit = 3 if Utils.find("combat/alert_morale_low"): Utils.touch_randomly(self.region['close_info_dialog']) self.exit = 2 break if Utils.find("menu/button_confirm"): Logger.log_msg("Found commission info message.") Utils.touch_randomly(self.region["combat_com_confirm"]) continue if Utils.find("menu/button_battle"): Logger.log_debug("Found menu battle button.") Utils.touch_randomly(self.region["menu_button_battle"]) Utils.wait_update_screen(1) continue if Utils.find("combat/menu_fleet") and ( lambda x: x > 414 and x < 584)( Utils.find("combat/menu_fleet").y ) and not self.config.combat['boss_fleet']: if not self.chapter_map[0].isdigit( ) and string.ascii_uppercase.index(self.chapter_map[ 2:3]) < 1 or self.chapter_map[0].isdigit(): Logger.log_msg( "Removing second fleet from fleet selection.") Utils.touch_randomly(self.region["clear_second_fleet"]) if Utils.find("combat/menu_select_fleet"): Logger.log_debug("Found fleet select go button.") Utils.touch_randomly(self.region["fleet_menu_go"]) Utils.script_sleep(1) continue if Utils.find("combat/button_go"): Logger.log_debug("Found map summary go button.") Utils.touch_randomly(self.region["map_summary_go"]) continue if Utils.find("combat/button_retreat"): Logger.log_debug( "Found retreat button, starting clear function.") if not self.clear_map(): self.stats.increment_combat_attempted() break if self.exit == 1 or self.exit == 5: self.stats.increment_combat_done() break if self.exit > 1: self.stats.increment_combat_attempted() break if Utils.find("menu/button_normal_mode" ) and self.chapter_map[0].isdigit(): Logger.log_debug("Disabling hard mode.") Utils.touch_randomly(self.region['normal_mode_button']) Utils.wait_update_screen(1) if Utils.find_and_touch('maps/map_{}'.format(self.chapter_map), 0.99): Logger.log_msg("Found specified map.") continue else: self.reach_map() continue Utils.script_sleep(1) Utils.menu_navigate("menu/button_battle") return self.exit
def event_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of completing an event """ event = self.config.events['name'] events = ['Crosswave', 'Royal_Maids'] if event in events and not self.finished: Logger.log_msg("Opening event menu.") while not Utils.find("menu/operation"): Utils.find_and_touch(f"event/{event}/menu_button") Utils.wait_update_screen(1) Logger.log_msg("Event levels: " + str(self.levels)) while ('EX' in self.levels): Utils.wait_update_screen(1) if Utils.find(f"event/{event}/ex_completed", 0.98): Logger.log_info("No more EX combats to do.") break Utils.touch_randomly(self.region[f'{event.lower()}_ex']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg(f"Finished EX {event.replace('_', ' ')} combat.") while ('H' in self.levels): Utils.wait_update_screen(1) if Utils.find(f"event/{event}/hard_completed"): Logger.log_info("No more Hard combats to do.") break Utils.touch_randomly(self.region[f'{event.lower()}_hard']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg(f"Finished Hard {event.replace('_', ' ')} combat.") while ('N' in self.levels): Utils.wait_update_screen(1) if Utils.find(f"event/{event}/normal_completed"): Logger.log_info("No more Normal combats to do.") break Utils.touch_randomly(self.region[f'{event.lower()}_normal']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg(f"Finished Normal {event.replace('_', ' ')} combat.") while ('E' in self.levels): Utils.wait_update_screen(1) if Utils.find(f"event/{event}/easy_completed"): Logger.log_info("No more Easy combats to do.") break Utils.touch_randomly(self.region[f'{event.lower()}_easy']) if self.pre_combat_handler(): self.combat_handler() Logger.log_msg(f"Finished Easy {event.replace('_', ' ')} combat.") Logger.log_msg("Finished all event combats, going back to menu.") Utils.menu_navigate("menu/button_battle") self.finished = True return
def battle_handler(self, boss=False): Logger.log_msg("Starting combat.") # enhancecement and retirement flags enhancement_failed = False retirement_failed = False while not (Utils.find("combat/menu_loading", 0.8)): Utils.update_screen() if Utils.find("menu/button_sort"): if self.config.enhancement[ 'enabled'] and not enhancement_failed: if not self.enhancement_module.enhancement_logic_wrapper( forced=True): enhancement_failed = True elif self.config.retirement[ 'enabled'] and not retirement_failed: if not self.retirement_module.retirement_logic_wrapper( forced=True): retirement_failed = True else: self.retreat_handler() return False elif Utils.find("combat/alert_morale_low"): self.retreat_handler() return False elif Utils.find("combat/combat_pause", 0.7): Logger.log_warning( "Loading screen was not found but combat pause is present, assuming combat is initiated normally." ) break else: Utils.touch_randomly(self.region["menu_combat_start"]) Utils.script_sleep(1) Utils.script_sleep(4) # flags in_battle = True items_received = False locked_ship = False confirmed_fight = False defeat = False confirmed_fleet_switch = False while True: Utils.update_screen() if in_battle and Utils.find("combat/combat_pause", 0.7): Logger.log_debug("In battle.") Utils.script_sleep(2.5) continue if not items_received: if Utils.find("combat/menu_touch2continue"): Logger.log_debug("Combat ended: tap to continue") Utils.touch_randomly(self.region['tap_to_continue']) in_battle = False continue if Utils.find("menu/item_found"): Logger.log_debug("Combat ended: items received screen") Utils.touch_randomly(self.region['tap_to_continue']) Utils.script_sleep(1) continue if (not locked_ship) and Utils.find("combat/alert_lock"): Logger.log_msg("Locking received ship.") Utils.touch_randomly(self.region['lock_ship_button']) locked_ship = True continue if Utils.find("menu/drop_elite"): Logger.log_msg("Received ELITE ship as drop.") Utils.touch_randomly(self.region['dismiss_ship_drop']) Utils.script_sleep(2) continue elif Utils.find("menu/drop_rare"): Logger.log_msg("Received new RARE ship as drop.") Utils.touch_randomly(self.region['dismiss_ship_drop']) Utils.script_sleep(2) continue elif Utils.find("menu/drop_ssr"): Logger.log_msg("Received SSR ship as drop.") Utils.touch_randomly(self.region['dismiss_ship_drop']) Utils.script_sleep(2) continue elif Utils.find("menu/drop_common"): Logger.log_msg("Received new COMMON ship as drop.") Utils.touch_randomly(self.region['dismiss_ship_drop']) Utils.script_sleep(2) continue if not in_battle: if (not confirmed_fight ) and Utils.find("combat/button_confirm"): Logger.log_msg("Combat ended.") items_received = True confirmed_fight = True Utils.touch_randomly(self.region["combat_end_confirm"]) if boss: return True Utils.wait_update_screen(3) if (not confirmed_fight) and Utils.find("combat/commander"): items_received = True # prevents fleet with submarines from getting stuck at combat end screen Utils.touch_randomly( self.region["combat_dismiss_surface_fleet_summary"]) continue if defeat and not confirmed_fleet_switch: if Utils.find("combat/alert_unable_battle"): Utils.touch_randomly(self.region['close_info_dialog']) Utils.script_sleep(3) self.exit = 5 return False if Utils.find("combat/alert_fleet_cannot_be_formed"): # fleet will be automatically switched Utils.touch_randomly(self.region['close_info_dialog']) confirmed_fleet_switch = True self.enemies_list.clear() self.mystery_nodes_list.clear() self.blacklist.clear() Utils.script_sleep(3) continue else: # flagship sunk, but part of backline still remains # proceed to retreat Utils.script_sleep(3) self.exit = 5 return False if confirmed_fight and Utils.find("menu/button_confirm"): Logger.log_msg("Found commission info message.") Utils.touch_randomly(self.region["combat_com_confirm"]) continue if confirmed_fight and Utils.find("combat/button_retreat"): #Utils.touch_randomly(self.region["hide_strat_menu"]) if confirmed_fleet_switch: # if fleet was defeated and it has now been switched return False else: # fleet won the fight self.combats_done += 1 self.kills_count += 1 if self.kills_count >= self.kills_before_boss[ self.chapter_map]: Utils.script_sleep(2.5) return True if confirmed_fight and Utils.find_and_touch( "combat/defeat_close_button"): Logger.log_debug("Fleet was defeated.") defeat = True Utils.script_sleep(3)
def combat_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of sortieing combat fleets and resolving combat. Returns: int: 1 if boss was defeated, 2 if successfully retreated after the specified number of fights, 3 if morale is too low, 4 if dock is full and unable to free it and 5 if fleet was defeated. """ self.exit = 0 self.start_time = datetime.now() # enhancecement and retirement flags enhancement_failed = False retirement_failed = False # get to map map_region = self.reach_map() Utils.touch_randomly(map_region) while True: Utils.wait_update_screen() if self.exit == 1 or self.exit == 2: self.stats.increment_combat_done() time_passed = datetime.now() - self.start_time if self.stats.combat_done % self.config.combat['retire_cycle'] == 0 or ((self.config.commissions['enabled'] or \ self.config.dorm['enabled'] or self.config.academy['enabled']) and time_passed.total_seconds() > 3600) or \ not Utils.check_oil(self.config.combat['oil_limit']): break else: self.exit = 0 Logger.log_msg("Repeating map {}.".format( self.chapter_map)) Utils.touch_randomly(map_region) continue if self.exit > 2: self.stats.increment_combat_attempted() break if Utils.find("combat/button_go", 0.9): Logger.log_debug("Found map summary go button.") Utils.touch_randomly(self.region["map_summary_go"]) Utils.wait_update_screen() if Utils.find("combat/menu_fleet") and ( lambda x: x > 414 and x < 584)( Utils.find("combat/menu_fleet").y ) and not self.config.combat['boss_fleet']: if not self.chapter_map[0].isdigit( ) and string.ascii_uppercase.index(self.chapter_map[ 2:3]) < 1 or self.chapter_map[0].isdigit(): Logger.log_msg( "Removing second fleet from fleet selection.") Utils.touch_randomly(self.region["clear_second_fleet"]) if Utils.find("combat/menu_select_fleet"): Logger.log_debug("Found fleet select go button.") Utils.touch_randomly(self.region["fleet_menu_go"]) Utils.wait_update_screen(2) if Utils.find("combat/button_retreat"): Logger.log_debug( "Found retreat button, starting clear function.") if not self.clear_map(): self.stats.increment_combat_attempted() break Utils.wait_update_screen() if Utils.find("menu/button_sort"): if self.config.enhancement[ 'enabled'] and not enhancement_failed: if not self.enhancement_module.enhancement_logic_wrapper( forced=True): enhancement_failed = True Utils.script_sleep(1) Utils.touch_randomly(map_region) continue elif self.config.retirement[ 'enabled'] and not retirement_failed: if not self.retirement_module.retirement_logic_wrapper( forced=True): retirement_failed = True else: # reset enhancement flag enhancement_failed = False Utils.script_sleep(1) Utils.touch_randomly(map_region) continue else: Utils.touch_randomly(self.region['close_info_dialog']) self.exit = 4 break if Utils.find("combat/alert_morale_low"): if self.config.combat['ignore_morale']: Utils.find_and_touch("menu/button_confirm") else: Utils.touch_randomly(self.region['close_info_dialog']) self.exit = 3 break if Utils.find("menu/button_confirm"): Logger.log_msg("Found commission info message.") Utils.touch_randomly(self.region["combat_com_confirm"]) Utils.script_sleep(1) Utils.menu_navigate("menu/button_battle") return self.exit
def start_logic(self): Logger.log_msg("开始练狗粮") self.enabled = True loc = RaiseDogState.NONE while True: if loc == RaiseDogState.NONE: Utils.update_screen() if Utils.find_and_touch("home/explore", 0.6, True): Logger.log_msg("首页,点击探索") Utils.script_sleep(3) loc = RaiseDogState.EXPLORE self.reset() elif Utils.find("explore/icon_yao"): Logger.log_msg("探索页面") loc = RaiseDogState.EXPLORE self.reset() if Utils.find_and_touch("explore/booty"): Logger.log_msg("!!发现宝箱 !!") Utils.script_sleep(2) Utils.touch_randomly() Utils.script_sleep(1) elif Utils.find("explore/explore_1"): Logger.log_msg("准备进本") Utils.touch_randomly(self.region["difficult_level"]) Utils.script_sleep() loc = RaiseDogState.EXPLORE_PRE self.first_time = True self.is_boss = False self.swipe_right = True self.swipe_count = 0 self.retry_count = 0 elif Utils.find("duplicate/back"): Logger.log_msg("在副本中") Utils.script_sleep() loc = RaiseDogState.SCENE elif Utils.find("combat/ready"): self.first_time = False Logger.log_msg("战斗") Utils.touch_randomly(globals_region["combat_ready"]) loc = RaiseDogState.FIGHT else: Logger.log_msg("未知场景。。") self.retry_count -= 1 if self.retry_count <= 0: sys.exit(-1) continue if loc == RaiseDogState.EXPLORE: sec = self.config.dog["section"] Logger.log_msg(f"查找章节:{sec}") # 查找对应章节 find_count = 0 down = True while not self.find_sec: # 尝试的次数 if find_count > 20: print("无法找到对应的章节") sys.exit(-1) if find_count == 10: find_count = 0 down = bool(1 - down) Utils.update_screen() r = Utils.find(f"explore/{sec}") if not r: if down: Utils.swipe(2148, 700, 2148, 500, randint(300, 500)) else: Utils.swipe(2148, 500, 2148, 700, randint(300, 500)) find_count += 1 Utils.script_sleep(1) else: self.find_sec = True Utils.touch_center(r) loc = RaiseDogState.EXPLORE_PRE continue if loc == RaiseDogState.EXPLORE_PRE: # reset self.reset() Logger.log_msg("选中困难") Utils.touch_randomly(self.region["difficult_level"]) Logger.log_msg("点击开始探索") Utils.touch_randomly(self.region["start_explore"]) loc = RaiseDogState.SCENE continue # 副本中 if loc == RaiseDogState.SCENE: Logger.log_msg("副本场景") if self.is_boss: Utils.script_sleep(3) Logger.log_msg("打完boss, 副本结束") Utils.update_screen() while Utils.find_and_touch("duplicate/booty"): Logger.log_msg("找到胜利品") Utils.script_sleep(1) Utils.touch_randomly(globals_region["combat_finish"]) Utils.script_sleep(1) Utils.update_screen() Logger.log_msg("查找胜利品结束") loc = RaiseDogState.NONE # 等一会跳到探索页面 Utils.script_sleep(2) continue Utils.update_screen() if Utils.find_and_touch("duplicate/boss"): Logger.log_msg("boss出现了..") loc = RaiseDogState.FIGHT Utils.script_sleep(2) self.is_boss = True elif Utils.find_and_touch("duplicate/fire"): loc = RaiseDogState.FIGHT Utils.script_sleep(2) self.is_boss = False else: if self.swipe_right: Logger.log_msg("划到右边看看") Utils.swipe(1437, 500, 960, 500, randint(300, 500)) else: Logger.log_msg("划到左边看看") Utils.swipe(960, 500, 1437, 500, randint(300, 500)) # Utils.script_sleep(1) self.swipe_count += 1 if self.swipe_count % 6 == 0: Logger.log_msg("换个方向") self.swipe_right = bool(1 - self.swipe_right) if self.swipe_count > 20: Logger.log_msg("超过最大次数重新判断当前页面。") loc = RaiseDogState.NONE continue if loc == RaiseDogState.FIGHT: # 由于怪物是跑动的,解决有时点击不中的bug Utils.update_screen() if Utils.find("duplicate/back"): Logger.log_msg("点不着,重试..") loc = RaiseDogState.SCENE self.is_boss = False continue if self.first_time: Logger.log_msg("开始检查是否满级") Utils.script_sleep() Utils.update_screen() thug_loc = int(self.config.dog["thug_loc"]) all_max = Utils.find_all("combat/level_max", 0.8) data = [False, False, False] if len(all_max) > 0: for (x, y) in all_max: if 500 < x < 764: data[0] = True elif 764 < x < 1115: data[1] = True elif 1115 < x < 1550: data[2] = True replace = False for i, v in enumerate(data): if i != thug_loc and v == True: Logger.log_msg("需要替换狗粮") replace = True break if replace: # 点击切换狗粮,要选2次 Logger.log_msg("点击切换狗粮,要选2次") Utils.touch_randomly(Region(495, 586, 192, 247)) Utils.script_sleep(0.1, 0.5) Utils.touch_randomly(Region(495, 586, 192, 247)) Utils.script_sleep() # 点击全部 Logger.log_msg("点击全部") Utils.touch_randomly(Region(51, 938, 103, 99)) Utils.script_sleep() # 选中N卡 Logger.log_msg("选中N卡") Utils.touch_randomly(Region(215, 470, 87, 87)) Utils.script_sleep() # 拉动滚动条 Logger.log_msg("拉动滚动条") Utils.swipe(385, 1037, 1671, 1037, randint(1500, 2000)) Utils.script_sleep(2) for i, v in enumerate(data): if i != thug_loc and v is True: if i == 0: Utils.wait_update_screen() r = Utils.find("combat/level_1", 0.8) Logger.log_msg("替换右边狗粮") Utils.swipe(r.x + 80, r.y + 80, 1800, 523, randint(300, 500)) elif i == 1: Utils.wait_update_screen() r = Utils.find("combat/level_1", 0.8) Logger.log_msg("替换中边狗粮") Utils.swipe(r.x + 80, r.y + 80, 1170, 523, randint(300, 500)) elif i == 2: Utils.wait_update_screen() r = Utils.find("combat/level_1", 0.8) Logger.log_msg("替换左边狗粮") Utils.swipe(r.x + 80, r.y + 80, 500, 523, randint(300, 500)) Utils.script_sleep() Logger.log_msg("战斗") Utils.touch_randomly(globals_region["combat_ready"]) self.first_time = False continue if Utils.find("combat/ready"): self.first_time = False Logger.log_msg("战斗") Utils.touch_randomly(globals_region["combat_ready"]) continue if Utils.find("combat/manual"): self.first_time = False Logger.log_msg("开启自动") Utils.touch_randomly(globals_region["combat_manual"]) continue if Utils.find("combat/victory"): Logger.log_msg("胜利") Utils.touch_randomly(globals_region["combat_finish"]) continue if Utils.find("combat/booty"): Logger.log_msg("获取胜利品。。") Utils.touch_randomly(globals_region["combat_finish"]) # 结束战斗后,留多点时间 Utils.script_sleep(3, 1) loc = RaiseDogState.SCENE continue if Utils.find("combat/fail"): Logger.log_msg("挑战失败。。") self.is_boss = False Utils.touch_randomly(globals_region["combat_finish"]) # 结束战斗后,留多点时间 Utils.script_sleep(3, 1) loc = RaiseDogState.SCENE continue Utils.script_sleep(2, 1)
def combat_logic_wrapper(self): """Method that fires off the necessary child methods that encapsulates the entire action of sortieing combat fleets and resolving combat. Returns: int: 1 if boss was defeated, 2 if morale is too low and 3 if dock is full. """ self.exit = 0 self.l.clear() self.blacklist.clear() while True: Utils.wait_update_screen() if Utils.find("menu/button_sort"): Utils.touch_randomly(Region(1312, 263, 64, 56)) self.exit = 3 if Utils.find("commission/button_confirm"): Logger.log_msg("Found commission info message.") Utils.touch_randomly(self.region["combat_com_confirm"]) continue if Utils.find("menu/button_battle"): Logger.log_debug("Found menu battle button.") Utils.touch_randomly(self.region["menu_button_battle"]) Utils.wait_update_screen(1) continue if Utils.find("combat/menu_select_fleet"): Logger.log_debug("Found fleet select go button.") Utils.touch_randomly(self.region["fleet_menu_go"]) continue if Utils.find("combat/button_go"): Logger.log_debug("Found map summary go button.") Utils.touch_randomly(self.region["map_summary_go"]) continue if Utils.find("combat/button_retreat"): Logger.log_debug( "Found retreat button, starting clear function.") if not self.clear_map(): self.stats.increment_combat_attempted() break if self.exit == 1: Logger.log_msg( "Boss successfully defeated, going back to menu.") self.stats.increment_combat_done() break if self.exit == 2: Logger.log_warning( "Ships morale is too low, entering standby mode for an hour." ) self.stats.increment_combat_attempted() break if self.exit == 3: Logger.log_warning("Dock is full, need to retire.") self.stats.increment_combat_attempted() break if Utils.find_and_touch('maps/map_{}'.format(self.chapter_map), 0.99): Logger.log_msg("Found specified map.") continue else: self.reach_map() continue Utils.script_sleep(1) while not Utils.find("menu/button_battle"): Utils.touch_randomly(Region(54, 57, 67, 67)) Utils.script_sleep(1) Utils.update_screen() return self.exit