def on_execute(self, capture): super().on_execute(capture) global_status.is_in_battle = False logger.log_with_echo("battle {} finish".format( global_status.loop_number)) logger.save_battle_info(global_status.turn_num, global_status.apple_eat_count)
def on_execute(self, capture): ui_util.match_and_click(resources.item_sliver_apple) wait_for(resources.apple_eat_dialog_confirm_button, step=1) ui_util.match_and_click(resources.apple_eat_dialog_confirm_button) global_status.apple_eat_count = global_status.apple_eat_count + 1 logger.log_with_echo("eat apple, total is {}".format( global_status.apple_eat_count)) time.sleep(random.randrange(1, 3))
def on_execute(self, capture): skill_used = global_status.skill_history.get(self.template, {}) logger.log("skill history for {} is {}".format( logger.resource_path_to_name(self.template), skill_used)) can_use_skill = False for skill in self.skill_index: if not skill_used.get(skill, False): can_use_skill = True break if not can_use_skill: return wait_for(resources.battle_attack_button) skill_position = global_status.skill_position_cache.get( self.template, ()) if len(skill_position) == 0: logger.log( "not find cached skill position, start match in capture") local_count = 0 while local_count < 5: local_count = local_count + 1 capture = ui_util.get_new_capture() max_val, tl_loc, br_loc = cv_util.match_template( self.template, capture) if max_val > 0.6: left, top, right, bottom = tl_loc[0], tl_loc[1], br_loc[ 0], br_loc[1] skill_position = (left, top, right, bottom) global_status.skill_position_cache[ self.template] = skill_position logger.log("find skill template ,position is {}".format( skill_position)) break else: wait_for(self.template) if len(skill_position) == 0: logger.log("not find skill position, return") return left, top, right, bottom = skill_position[0], skill_position[ 1], skill_position[2], skill_position[3] width = right - left item_width = width / 3 center_y = (top + bottom) / 2 for skill in self.skill_index: if not skill_used.get(skill, False): wait_for(resources.battle_attack_button) x = left + item_width * (skill - 1) + item_width / 2 random_x = random.Random().randrange(start=-10, stop=10) random_y = random.Random().randrange(start=-10, stop=10) logger.log_with_echo( "click skill {}, original position is ({} ,{}), random_delta = ({}, {})" .format(logger.resource_path_to_name(self.template), x, center_y, random_x, random_y)) ui_util.click(x + random_x, center_y + random_y) skill_used = global_status.skill_history.get(self.template, {}) skill_used[skill] = True global_status.skill_history[self.template] = skill_used time.sleep(random.randrange(2, 3))
def on_execute(self, capture): img = cv_util.read_img(capture) has_ready = False for i in range(3): has_ready = has_ready or self.check(img, i) # 如果第一次检测不成功那么再重新截图检测一次 if not has_ready: img = cv_util.read_img(ui_util.get_new_capture()) for i in range(3): self.check(img, i) logger.log_with_echo("check hougo result is {}".format( global_status.hougu_status))
def execute(self, capture): super().execute(capture) logger.log( "click start battle task ,before reset status ,skill history is {}" .format(global_status.skill_history)) global_status.is_in_battle = True global_status.turn_num = 1 global_status.skill_history = {} global_status.skill_history.clear() # global_status.skill_position_cache = {} global_status.hougu_status = [False, False, False] global_status.loop_number = global_status.loop_number + 1 logger.log( "click start battle task ,after reset status ,skill history is {}". format(global_status.skill_history)) logger.log_with_echo("start new battle {}".format( global_status.loop_number))
def on_execute(self, capture): global_status.is_in_battle = True turns = [ ([ resources.battle_turn_1_of_3, resources.battle_turn_1_of_2, resources.battle_turn_1_of_1 ], 1), ([resources.battle_turn_2_of_3, resources.battle_turn_2_of_2], 2), ([resources.battle_turn_3_of_3], 3), ] for templates in turns: for t in templates[0]: if cv_util.has_match(t, capture): original = global_status.turn_num if original != templates[1]: global_status.turn_num = templates[1] logger.log_with_echo( "update turn num from {} to {}".format( original, templates[1])) return
def on_execute(self, capture): if len(self.special_templates) > 0: target_card = self.special_templates.get(global_status.turn_num, []) if len(target_card) == 0: target_card = self.special_templates.get(-1, []) if len(target_card) > 0: for card in target_card: local_count = 0 while local_count < 2: local_count = local_count + 1 if ui_util.match_and_click(card, delete_after_match=True): time.sleep(random.randrange(1, 3)) logger.log_with_echo("selected card {}".format( logger.resource_path_to_name(card))) break else: for index in range(3): if global_status.hougu_status[index]: # 此处坐标获取方法同NP检测,均为手动比划得来 top, bottom = 170, 300 item_width = 100 left = 96 * (index + 1) + 100 * index right = left + item_width x = random.randrange(left, right) y = random.randrange(top, bottom) ui_util.click(x, y) global_status.hougu_status[index] = False time.sleep(random.randrange(0, 2)) logger.log_with_echo( "select hougo card at {}".format(index)) break card_queue = [ resources.action_buster, resources.action_arts, resources.action_quick ] for card in card_queue: if ui_util.match_and_click(card, delete_after_match=True): logger.log_with_echo("selected card {}".format( logger.resource_path_to_name(card))) time.sleep(random.randrange(1, 3)) break
def on_execute(self, capture): logger.log_with_echo( "need clear space, auto battle count is {}".format( global_status.loop_number)) raise StopBattleException()