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 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 daily_handler(self): while True: Utils.update_screen() Utils.swipe(960, 680, 960, 400, 300) Utils.touch_randomly(self.region["last_commission"]) if not self.start_commission(): Logger.log_msg("No more commissions to start.") 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 get_enemies(self, blacklist=[], boss=False): sim = 0.99 filter_coordinates = True if len(self.enemies_list) == 0 else False if blacklist: Logger.log_info('Blacklist: ' + str(blacklist)) if len(blacklist) > 2: self.enemies_list.clear() while not self.enemies_list: if (boss and len(blacklist) > 4) or (not boss and len(blacklist) > 3) or sim < 0.97: if self.swipe_counter > 3: self.swipe_counter = 0 swipes = { 0: lambda: Utils.swipe(960, 240, 960, 940, 300), 1: lambda: Utils.swipe(1560, 540, 260, 540, 300), 2: lambda: Utils.swipe(960, 940, 960, 240, 300), 3: lambda: Utils.swipe(260, 540, 1560, 540, 300) } swipes.get(self.swipe_counter)() sim += 0.005 self.swipe_counter += 1 Utils.update_screen() l1 = filter(lambda x:(x[1] > 242 and x[1] < 1070 and x[0] > 180 and x[0] < 955) or (x[1] > 160 and x[1] < 938 and x[0] > 550 and x[0] < 1770), map(lambda x:[x[0] - 3, x[1] - 27], Utils.find_all('enemy/fleet_level', sim - 0.025, useMask=True))) l1 = [x for x in l1 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L1: " +str(l1)) l2 = filter(lambda x:(x[1] > 242 and x[1] < 1070 and x[0] > 180 and x[0] < 955) or (x[1] > 160 and x[1] < 938 and x[0] > 550 and x[0] < 1770), map(lambda x:[x[0] + 75, x[1] + 110], Utils.find_all('enemy/fleet_1_down', sim - 0.02))) l2 = [x for x in l2 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L2: " +str(l2)) l3 = filter(lambda x:(x[1] > 242 and x[1] < 1070 and x[0] > 180 and x[0] < 955) or (x[1] > 160 and x[1] < 938 and x[0] > 550 and x[0] < 1770), map(lambda x:[x[0] + 75, x[1] + 90], Utils.find_all('enemy/fleet_2_down', sim - 0.02))) l3 = [x for x in l3 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L3: " +str(l3)) l4 = filter(lambda x:(x[1] > 242 and x[1] < 1070 and x[0] > 180 and x[0] < 955) or (x[1] > 160 and x[1] < 938 and x[0] > 550 and x[0] < 1770), map(lambda x:[x[0] + 75, x[1] + 125], Utils.find_all('enemy/fleet_3_up', sim - 0.035))) l4 = [x for x in l4 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L4: " +str(l4)) l5 = filter(lambda x:(x[1] > 242 and x[1] < 1070 and x[0] > 180 and x[0] < 955) or (x[1] > 160 and x[1] < 938 and x[0] > 550 and x[0] < 1770), map(lambda x:[x[0] + 75, x[1] + 100], Utils.find_all('enemy/fleet_3_down', sim - 0.035))) l5 = [x for x in l5 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L5: " +str(l5)) l6 = filter(lambda x:(x[1] > 242 and x[1] < 1070 and x[0] > 180 and x[0] < 955) or (x[1] > 160 and x[1] < 938 and x[0] > 550 and x[0] < 1770), map(lambda x:[x[0] + 75, x[1] + 110], Utils.find_all('enemy/fleet_2_up', sim - 0.025))) l6 = [x for x in l6 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L6: " +str(l6)) if self.config.combat['siren_elites']: l7 = Utils.find_siren_elites() l7 = [x for x in l7 if (not self.filter_blacklist(x, blacklist))] Logger.log_debug("L7: " +str(l7)) self.enemies_list = l1 + l2 + l3 + l4 + l5 + l6 + l7 else: self.enemies_list = l1 + l2 + l3 + l4 + l5 + l6 sim -= 0.005 if filter_coordinates: self.enemies_list = Utils.filter_similar_coords(self.enemies_list) return self.enemies_list
def daily_handler(self): while True: Utils.update_screen() Utils.swipe(960, 680, 960, 400, 300) Utils.touch_randomly(self.region["last_commission"]) if not self.start_commission(): if self.commission_start_attempts > 10: Logger.log_warning("Going back to main menu and retrying.") else: Logger.log_msg("No more commissions to start.") return
def get_closest_enemy(self, blacklist=[]): """Method to get the enemy closest to the fleet's current location. Note this will not always be the enemy that is actually closest due to the asset used to find enemies and when enemies are obstructed by terrain or the second fleet Args: blacklist(array, optional): Defaults to []. An array of coordinates to exclude when searching for the closest enemy Returns: array: An array containing the x and y coordinates of the closest enemy to the fleet's current location """ x_dist = 125 y_dist = 175 swipes = [['n', 1.0], ['e', 1.0], ['s', 1.5], ['w', 1.5]] closest = None while closest is None: if self.need_to_refocus: self.refocus_fleet() current_location = self.get_fleet_location() for swipe in swipes: enemies = Utils.find_all('combat_enemy_fleet', 0.88) if enemies: for coord in blacklist: enemies.remove(coord) Logger.log_msg( 'Current location is: {}'.format(current_location)) Logger.log_msg('Enemies found at: {}'.format(enemies)) closest = enemies[Utils.find_closest( enemies, current_location)[1]] Logger.log_msg('Closest enemy is at {}'.format(closest)) return [closest[0], closest[1] - 10] else: direction, multiplier = swipe[0], swipe[1] if direction == 'n': current_location[1] = (current_location[1] + (2 * y_dist * multiplier)) Utils.swipe(640, 360 - y_dist * multiplier, 640, 360 + y_dist * multiplier, 250) elif direction == 's': current_location[1] = (current_location[1] - (2 * y_dist * multiplier)) Utils.swipe(640, 360 + y_dist * multiplier, 640, 360 - y_dist * multiplier, 250) elif direction == 'e': current_location[0] = (current_location[0] + (2 * x_dist * multiplier)) Utils.swipe(640 + x_dist * multiplier, 360, 640 - x_dist * multiplier, 360, 250) elif direction == 'w': current_location[0] = (current_location[0] - (2 * x_dist * multiplier)) Utils.swipe(640 - x_dist * multiplier, 360, 640 + x_dist * multiplier, 360, 250) self.need_to_refocus = True x_dist *= 1.5 y_dist *= 1.5 return None
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_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 get_enemies(self, blacklist=[], boss=False): sim = 0.99 i = 0 if blacklist: Logger.log_info('Blacklist: ' + str(blacklist)) self.l = [x for x in self.l if (x not in blacklist)] while not self.l: if (boss and len(blacklist) > 4) or (not boss and len(blacklist) > 1) or sim < 0.95: if i > 3: i = 0 swipes = { 0: lambda: Utils.swipe(960, 240, 960, 940, 300), 1: lambda: Utils.swipe(1560, 540, 260, 540, 300), 2: lambda: Utils.swipe(960, 940, 960, 240, 300), 3: lambda: Utils.swipe(260, 540, 1560, 540, 300) } swipes.get(i)() sim += 0.005 i += 1 Utils.update_screen() l1 = filter(lambda x:x[1] > 160 and x[1] < 977 and x[0] > 180, map(lambda x:[x[0] - 3, x[1] - 45], Utils.find_all('enemy/fleet_level', sim - 0.15, self.chapter_map))) l1 = [x for x in l1 if (not self.filter_blacklist(x, blacklist))] l2 = filter(lambda x:x[1] > 160 and x[1] < 977 and x[0] > 180, map(lambda x:[x[0] + 75, x[1] + 110], Utils.find_all('enemy/fleet_1_down', sim, self.chapter_map))) l2 = [x for x in l2 if (not self.filter_blacklist(x, blacklist))] l3 = filter(lambda x:x[1] > 160 and x[1] < 977 and x[0] > 180, map(lambda x:[x[0] + 75, x[1] + 110], Utils.find_all('enemy/fleet_2_down', sim - 0.02, self.chapter_map))) l3 = [x for x in l3 if (not self.filter_blacklist(x, blacklist))] l4 = filter(lambda x:x[1] > 160 and x[1] < 977 and x[0] > 180, map(lambda x:[x[0] + 75, x[1] + 130], Utils.find_all('enemy/fleet_3_up', sim - 0.06, self.chapter_map))) l4 = [x for x in l4 if (not self.filter_blacklist(x, blacklist))] l5 = filter(lambda x:x[1] > 160 and x[1] < 977 and x[0] > 180, map(lambda x:[x[0] + 75, x[1] + 110], Utils.find_all('enemy/fleet_3_down', sim - 0.06, self.chapter_map))) l5 = [x for x in l5 if (not self.filter_blacklist(x, blacklist))] l6 = filter(lambda x:x[1] > 160 and x[1] < 977 and x[0] > 180, map(lambda x:[x[0] + 75, x[1] + 110], Utils.find_all('enemy/fleet_2_up', sim - 0.06, self.chapter_map))) l6 = [x for x in l6 if (not self.filter_blacklist(x, blacklist))] self.l = l1 + l2 + l3 + l4 + l5 + l6 sim -= 0.005 self.l = Utils.filter_similar_coords(self.l) return self.l
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 start_logic(self): Logger.log_msg("开始妖气封印") self.enabled = True is_find_yqfy = False while True: # 更新屏幕 Utils.update_screen() if Utils.find("home/menu_close", 0.8): Logger.log_msg("卷轴被关闭,展开") Utils.touch_center(Region(2145, 872, 149, 168)) # 解决封印协同任务 if Utils.find("popup/close", 0.8): Logger.log_msg("封印任务弹窗") Utils.touch_center(Region(1461, 740, 228, 77)) if Utils.find("home/team_up", 0.96): hp = Utils.read_numbers(1727, 31, 86, 35) Logger.log_msg(f"首页,当前体力:{hp}") # hp_limit = self.config.seal["hp_limit"] # if hp <= int(hp_limit): # Logger.log_warning("体力过少,退出") # sys.exit() if Utils.find("home/seal_queuing", 0.9): Logger.log_msg("正在排队") Utils.script_sleep(13, 2) continue if Utils.find("home/team_up"): Utils.touch_center(self.region["home_team_up"]) continue if Utils.find("teamup/back"): Logger.log_msg("进入组队页面") name = self.config.seal["monster"] t = Utils.find("seal/" + name + "_normal") t1 = Utils.find("seal/" + name + "_select") if t and t1: Logger.log_msg(f"找到{name}") if t.vol > t1.vol: Logger.log_msg(f"点击{name}") Utils.touch_randomly(t) Utils.script_sleep() Logger.log_msg(f"点击自动匹配") Utils.touch_randomly(self.region["auto_team_up"]) continue if is_find_yqfy: Logger.log_msg(f"滑一滑,找找{name}") Utils.swipe(950, 800, 950, 400, randint(80, 120)) Utils.script_sleep(1, 2) continue seal = Utils.find("seal/yqfy_normal", 0.95, False) if seal: Logger.log_msg("找到妖气封印") is_find_yqfy = True Utils.touch_randomly(seal) continue else: Logger.log_msg("找不到妖气封印...滑一下") Utils.swipe(600, 800, 600, 400, randint(100, 150)) Utils.script_sleep(1, 2) continue if Utils.find("team/back"): Logger.log_msg("进入组队页面") r = Utils.find("team/challenge") if r: Logger.log_msg("成为队长了,挑战~") Utils.touch_randomly(self.region["assist_challenge"]) continue if Utils.find("combat/ready"): Logger.log_msg("战斗") Utils.touch_randomly(self.region["combat_ready"]) continue if Utils.find("combat/manual"): Logger.log_msg("开启自动") Utils.touch_randomly(self.region["combat_manual"]) continue if Utils.find("combat/victory"): Logger.log_msg("胜利") Utils.touch_randomly(self.region["combat_finish"]) Utils.script_sleep(1, 1) continue if Utils.find("combat/booty"): Logger.log_msg("获取胜利品。。") Utils.touch_randomly(self.region["combat_finish"]) continue if Utils.find("combat/fail"): Logger.log_msg("挑战失败。。") Utils.touch_randomly(self.region["combat_finish"]) continue if Utils.find("combat/auto_invite"): Logger.log_msg("取消自动邀请队友") Utils.touch_randomly(self.region["combat_cancel_invite"]) continue Utils.script_sleep(2, 1)
def clear_map(self): """ Clears map. """ Logger.log_msg("Started map clear.") Utils.script_sleep(2.5) while Utils.find("combat/fleet_lock", 0.99): Utils.touch_randomly(self.region["fleet_lock"]) Logger.log_warning("Fleet lock is not supported, disabling it.") Utils.wait_update_screen() #swipe map to fit everything on screen swipes = { 'E-C3': lambda: Utils.swipe(960, 800, 960, 400, 100), 'E-A3': lambda: Utils.swipe(960, 800, 960, 400, 100), 'E-SP5': lambda: Utils.swipe(350, 500, 960, 800, 100), '12-2': lambda: Utils.swipe(1000, 570, 1300, 540, 100), '12-3': lambda: Utils.swipe(1250, 530, 1300, 540, 100), '12-4': lambda: Utils.swipe(960, 300, 960, 540, 100), '13-1': lambda: Utils.swipe(1020, 500, 1300, 540, 100), '13-2': lambda: Utils.swipe(1125, 550, 1300, 540, 100), '13-3': lambda: Utils.swipe(1150, 510, 1300, 540, 100), '13-4': lambda: Utils.swipe(1200, 450, 1300, 540, 100) } swipes.get(self.chapter_map, lambda: 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"): Utils.touch_randomly(self.region['close_info_dialog']) self.exit = 4 if self.config.combat[ 'retreat_after'] != 0 and self.combats_done >= self.config.combat[ 'retreat_after']: Logger.log_msg("Retreating after defeating {} enemies".format( self.config.combat['retreat_after'])) self.exit = 5 if self.exit != 0: self.retreat_handler() return True if Utils.find_in_scaling_range("enemy/fleet_boss"): Logger.log_msg("Boss fleet was found.") if self.config.combat['boss_fleet']: s = 0 swipes = { 0: lambda: Utils.swipe(960, 240, 960, 940, 300), 1: lambda: Utils.swipe(1560, 540, 260, 540, 300), 2: lambda: Utils.swipe(960, 940, 960, 240, 300), 3: lambda: Utils.swipe(260, 540, 1560, 540, 300) } Utils.touch_randomly(self.region['button_switch_fleet']) Utils.wait_update_screen(2) boss_region = Utils.find_in_scaling_range( "enemy/fleet_boss") while not boss_region: if s > 3: s = 0 swipes.get(s)() Utils.wait_update_screen(0.5) boss_region = Utils.find_in_scaling_range( "enemy/fleet_boss") s += 1 Utils.swipe(boss_region.x, boss_region.y, 960, 540, 300) Utils.wait_update_screen() boss_region = Utils.find_in_scaling_range("enemy/fleet_boss") #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) 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 replace_dog(): Logger.log_msg("开始检查是否满级") Utils.script_sleep(2) Utils.update_screen() thug_loc = 1 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(486, 615, 440, 85)) Utils.script_sleep(0.1, 0.5) Utils.touch_randomly(Region(486, 615, 440, 85)) 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, 1500) 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, 1000) 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, 1000) 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, 1000) Utils.script_sleep() # # Logger.log_msg("点击返回") # Utils.touch_randomly(Region(13, 12, 82, 77)) # Utils.script_sleep(2) # Logger.log_msg("战斗") # Utils.touch_randomly(globals_region["combat_ready"]) pass
def commission_logic_wrapper(self): while True: Utils.update_screen() if Utils.find("commission/alert_completed"): Logger.log_msg("Found commission completed alert.") Utils.touch_randomly(self.region["left_menu"]) continue 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.") Utils.touch_randomly(self.region["collect_oil"]) Utils.touch_randomly(self.region["collect_gold"]) Utils.touch_randomly(self.region["complete_commission"]) Utils.script_sleep(1) continue if Utils.find("commission/alert_perfect"): Utils.touch_randomly(Region(661, 840, 598, 203)) self.stats.increment_commissions_received() continue if Utils.find("menu/item_found"): Utils.touch_randomly(Region(661, 840, 598, 203)) Utils.script_sleep(1) continue if Utils.find("commission/alert_available") and ( lambda x: x > 332 and x < 511)( Utils.find("commission/alert_available").y): Logger.log_debug("Found commission available indicator.") Utils.touch_randomly(self.region["button_go"]) continue if Utils.find("commission/button_go"): Logger.log_msg("All commissions are running.") Utils.touch_randomly(Region(970, 148, 370, 784)) return True while Utils.find("menu/commission"): Utils.update_screen() if Utils.find("commission/alert_begun"): Logger.log_msg("Successfully started commission.") Utils.touch_randomly(Region(688, 11, 538, 55)) Utils.script_sleep(1) self.stats.increment_commissions_started() continue if Utils.find("commission/button_confirm"): Logger.log_debug("Found commission oil warning message.") Utils.touch_randomly(self.region["oil_warning"]) continue if Utils.find("commission/commissions_full"): Logger.log_msg("No more commissions to start.") Utils.touch_randomly(self.region["button_back"]) Utils.script_sleep(1) break if Utils.find("commission/button_complete"): Logger.log_debug("Found commission start button.") Utils.touch_randomly(self.region["commission_start"]) continue if Utils.find("commission/button_recommend"): Logger.log_debug("Found commission recommend button.") Utils.touch_randomly(self.region["commission_recommend"]) continue if self.urgent_checked == False: Utils.touch_randomly(self.region["urgent_tab"]) Utils.update_screen() if Utils.find_and_touch("commission/commission_status"): Logger.log_msg( "Found status indicator on urgent commission.") else: Utils.script_sleep() Utils.touch_randomly(self.region["daily_tab"]) Logger.log_msg("No urgent commissions.") self.urgent_checked = True else: Utils.swipe(960, 680, 960, 400, 80) Utils.touch_randomly(self.region["last_commission"]) Logger.log_debug("Found status indicator on commission.")
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 clear_map(self): """ Clears map. """ self.combats_done = 0 self.kills_count = 0 self.enemies_list.clear() self.mystery_nodes_list.clear() self.blacklist.clear() self.swipe_counter = 0 Logger.log_msg("Started map clear.") Utils.script_sleep(2.5) while Utils.find("combat/fleet_lock", 0.99): Utils.touch_randomly(self.region["fleet_lock"]) Logger.log_warning("Fleet lock is not supported, disabling it.") Utils.wait_update_screen() #swipe map to fit everything on screen swipes = { 'E-SP1': lambda: Utils.swipe(960, 540, 1400, 640, 300), 'E-SP2': lambda: Utils.swipe(960, 540, 1500, 540, 300), 'E-SP3': lambda: Utils.swipe(960, 540, 1300, 740, 300), '7-2': lambda: Utils.swipe(960, 540, 1300, 600, 300), '12-2': lambda: Utils.swipe(1000, 570, 1300, 540, 300), '12-3': lambda: Utils.swipe(1250, 530, 1300, 540, 300), '12-4': lambda: Utils.swipe(960, 300, 960, 540, 300), '13-1': lambda: Utils.swipe(1020, 500, 1300, 540, 300), '13-2': lambda: Utils.swipe(1125, 550, 1300, 540, 300), '13-3': lambda: Utils.swipe(1150, 510, 1300, 540, 300), '13-4': lambda: Utils.swipe(1200, 450, 1300, 540, 300) } swipes.get(self.chapter_map, lambda: Utils.swipe(960, 540, 1300, 540, 300))() # disable subs' hunting range if self.config.combat["hide_subs_hunting_range"]: Utils.script_sleep(0.5) Utils.touch_randomly(self.region["open_strategy_menu"]) Utils.script_sleep() Utils.touch_randomly(self.region["disable_subs_hunting_radius"]) Utils.script_sleep() Utils.touch_randomly(self.region["close_strategy_menu"]) target_info = self.get_closest_target(self.blacklist) while True: Utils.update_screen() if Utils.find("combat/alert_unable_battle"): Utils.touch_randomly(self.region['close_info_dialog']) self.exit = 5 if self.config.combat[ 'retreat_after'] != 0 and self.combats_done >= self.config.combat[ 'retreat_after']: Logger.log_msg("Retreating after defeating {} enemies".format( self.config.combat['retreat_after'])) self.exit = 2 if self.exit != 0: self.retreat_handler() return True if self.kills_count >= self.kills_before_boss[ self.chapter_map] and Utils.find_in_scaling_range( "enemy/fleet_boss"): Logger.log_msg("Boss fleet was found.") if self.config.combat['boss_fleet']: s = 0 swipes = { 0: lambda: Utils.swipe(960, 240, 960, 940, 300), 1: lambda: Utils.swipe(1560, 540, 260, 540, 300), 2: lambda: Utils.swipe(960, 940, 960, 240, 300), 3: lambda: Utils.swipe(260, 540, 1560, 540, 300) } Utils.touch_randomly(self.region['button_switch_fleet']) Utils.wait_update_screen(2) boss_region = Utils.find_in_scaling_range( "enemy/fleet_boss") while not boss_region: if s > 3: s = 0 swipes.get(s)() Utils.wait_update_screen(0.5) boss_region = Utils.find_in_scaling_range( "enemy/fleet_boss") s += 1 # swipe to center the boss fleet on the screen # first calculate the translation vector coordinates horizontal_translation = 150 if boss_region.x < 960 else -150 angular_coefficient = -1 * ((540 - boss_region.y) / (960 - boss_region.x)) Utils.swipe( boss_region.x + horizontal_translation, boss_region.y + int(horizontal_translation * angular_coefficient), 960 + horizontal_translation, 540 + int(horizontal_translation * angular_coefficient), 300) Utils.wait_update_screen() boss_region = Utils.find_in_scaling_range("enemy/fleet_boss", similarity=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: target_info = self.get_closest_target( self.blacklist, mystery_node=( not self.config.combat["ignore_mystery_nodes"])) if target_info: #tap at target's coordinates Utils.touch(target_info[0:2]) Utils.update_screen() else: continue 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 get_enemies(self, blacklist=[], boss=False): sim = 0.99 filter_coordinates = True if len(self.enemies_list) == 0 else False if blacklist: Logger.log_info('Blacklist: ' + str(blacklist)) if len(blacklist) > 2: self.enemies_list.clear() while not self.enemies_list: if (boss and len(blacklist) > 4) or ( not boss and len(blacklist) > 3) or sim < 0.985: if self.swipe_counter > 3: self.swipe_counter = 0 swipes = { 0: lambda: Utils.swipe(960, 240, 960, 940, 300), 1: lambda: Utils.swipe(1560, 540, 260, 540, 300), 2: lambda: Utils.swipe(960, 940, 960, 240, 300), 3: lambda: Utils.swipe(260, 540, 1560, 540, 300) } swipes.get(self.swipe_counter)() sim += 0.005 self.swipe_counter += 1 Utils.update_screen() if self.use_intersection: base_region_type = Region(60, 60, 100, 100) base_region_level = Region(-60, -80, 100, 100) single_triangle = map( lambda coords: Region( coords[0].item() + base_region_type.x, coords[1].item( ) + base_region_type.y, base_region_type.w, base_region_type.h), Utils.find_all('enemy/enemyt1', sim - 0.04, useMask=True)) double_triangle = map( lambda coords: Region( coords[0].item() + base_region_type.x, coords[1].item( ) + base_region_type.y, base_region_type.w, base_region_type.h), Utils.find_all('enemy/enemyt2', sim - 0.075, useMask=True)) triple_triangle = map( lambda coords: Region( coords[0].item() + base_region_type.x, coords[1].item( ) + base_region_type.y, base_region_type.w, base_region_type.h), Utils.find_all('enemy/enemyt3', sim - 0.075, useMask=True)) lv_enemies = list( map( lambda coords: Region( coords[0].item() + base_region_level.x, coords[ 1].item() + base_region_level.y, base_region_level.w, base_region_level.h), Utils.find_all('enemy/enemylv', sim - 0.04, useMask=True))) t1_enemies = [] for st in single_triangle: t1_enemies.extend(map(st.intersection, lv_enemies)) t1_enemies = filter(None, t1_enemies) t2_enemies = [] for dt in double_triangle: t2_enemies.extend(map(dt.intersection, lv_enemies)) t2_enemies = filter(None, t2_enemies) t3_enemies = [] for tt in triple_triangle: t3_enemies.extend(map(tt.intersection, lv_enemies)) t3_enemies = filter(None, t3_enemies) intersections = [] intersections.extend(t1_enemies) intersections.extend(t2_enemies) intersections.extend(t3_enemies) # filter duplicate intersections by intersecting them filtered_intersections = [] while intersections: region = intersections.pop(0) new_intersections = [] for item in intersections: res = region.intersection(item) if res: region = res else: new_intersections.append(item) intersections = new_intersections filtered_intersections.append(region) enemies_coords = map(Region.get_center, filtered_intersections) # filter coordinates inside prohibited regions for p_region in self.prohibited_region.values(): enemies_coords = [ x for x in enemies_coords if (not p_region.contains(x)) ] self.enemies_list = [ x for x in enemies_coords if (not self.filter_blacklist(x, blacklist)) ] else: l1 = list( map( lambda x: [x[0] - 3, x[1] - 27], Utils.find_all_with_resize('enemy/fleet_level', sim - 0.025, useMask=True))) Logger.log_debug("L1: " + str(l1)) l2 = list( map( lambda x: [x[0] + 75, x[1] + 110], Utils.find_all_with_resize('enemy/fleet_1_down', sim - 0.02))) Logger.log_debug("L2: " + str(l2)) l3 = list( map( lambda x: [x[0] + 75, x[1] + 90], Utils.find_all_with_resize('enemy/fleet_2_down', sim - 0.02))) Logger.log_debug("L3: " + str(l3)) l4 = list( map( lambda x: [x[0] + 75, x[1] + 125], Utils.find_all_with_resize('enemy/fleet_3_up', sim - 0.035))) Logger.log_debug("L4: " + str(l4)) l5 = list( map( lambda x: [x[0] + 75, x[1] + 100], Utils.find_all_with_resize('enemy/fleet_3_down', sim - 0.035))) Logger.log_debug("L5: " + str(l5)) l6 = list( map( lambda x: [x[0] + 75, x[1] + 110], Utils.find_all_with_resize('enemy/fleet_2_up', sim - 0.025))) Logger.log_debug("L6: " + str(l6)) enemies_coords = l1 + l2 + l3 + l4 + l5 + l6 # filter coordinates inside prohibited regions for p_region in self.prohibited_region.values(): enemies_coords = [ x for x in enemies_coords if (not p_region.contains(x)) ] self.enemies_list = [ x for x in enemies_coords if (not self.filter_blacklist(x, blacklist)) ] if self.config.combat['siren_elites']: l7 = Utils.find_siren_elites() # filter coordinates inside prohibited regions for p_region in self.prohibited_region.values(): l7 = [x for x in l7 if (not p_region.contains(x))] l7 = [ x for x in l7 if (not self.filter_blacklist(x, blacklist)) ] Logger.log_debug("L7 " + str(l7)) self.enemies_list.extend(l7) sim -= 0.005 if filter_coordinates: self.enemies_list = Utils.filter_similar_coords(self.enemies_list, distance=67) return self.enemies_list
def swipeTest(): Utils.swipe(385, 1037, 1671, 1037, 1000) sleep(2) Utils.swipe(1689, 878, 1172, 483, 1000) sleep(2) Utils.swipe(1689, 878, 1828, 483, 1000)