def quit_battle(mouse_instance): time.sleep(5) battle_finish, still_in_battle = False, False while not battle_finish: time.sleep(1) battle_finish, position_1 = CVModule.match_template( 'Battle_finish_sign3') still_in_battle, position_2 = CVModule.match_template('Attack_button') if still_in_battle: print("Can not finish battle as scripted, use random cards now." ) # 翻车检测 act_and_use_random_cards(mouse_instance) time.sleep(10) if battle_finish: print("Battle finished.") time.sleep(1) retry = 20 is_battle_exited = False while (not is_battle_exited) and retry > 0: is_battle_exited, location = CVModule.match_template( "LastOrder_sign", show_switch=False) mouse_instance.touch(1000, 1100, 2) time.sleep(1) retry = retry - 1 print('Quit success') return True
def is_ready_to_make_experience_card(): """ check if is ready to make an experience_card :return: True if ready, False if not. """ retry = 60 found, location = CVModule.match_template('Attack_button') while retry > 0 and not found: time.sleep(1) found, location = CVModule.match_template('Attack_button') retry = retry - 1 if not found: print("ERROR: can not check if in ready to act status.") return found
def is_ready_to_act(): """ check if in battle state :return: True if in battle, False if not. """ retry = 60 found, location = CVModule.match_template('Attack_button') while retry > 0 and not found: time.sleep(1) found, location = CVModule.match_template('Attack_button') retry = retry - 1 if not found: print("ERROR: can not check if in ready to act status.") return found
def select_assist_servant(self, servant, retry_times): """ select given servant. if not found, drag down the scroll bar for "drag_times",and search servant again. :param self: :param servant: :param retry_times: the current retry time. decrease when servant still not found when drag all down. :return: touch and select given servant """ time.sleep(0.3) found, location = CVModule.match_template(servant) drag_times = 3 while (not found) and (drag_times > 0): found, location, drag_times = self.drag_and_find_servant(servant, drag_times) if found: # select the servant time.sleep(0.1) self.mouse_instance.touch(location[0] + self.servant_location_error[0], location[1] + self.servant_location_error[1]) return True, retry_times else: # refresh the assist servant self.refresh_servant() retry_times = retry_times + 1 return False, retry_times
def start_battle(self): time.sleep(1) found, location = CVModule.match_template("Start_button") if found: print("enter battle now.") self.mouse_instance.set_zero() self.mouse_instance.touch(location[0] - 50, location[1] + 450) else: print("cannot find Start_button, please check template!") print("exit battle.")
def refresh_servant(self): # find the drag bar found, location = CVModule.match_template("Refresh_friend") if found: # click refresh button self.mouse_instance.touch(location[0] - 55, location[1] + 80) time.sleep(0.5) # click confirm button self.mouse_instance.touch(location[0] - 55, location[1] + 820) time.sleep(1) else: print("cannot refresh the assist servant!")
def select_assist_servant_class(self, servant_class: str): """ select and touch the given class of servant. :param servant_class: the class of given servant. :return: touch the servant_class button """ print("Start select servant_class [{}]".format(servant_class)) found, location = CVModule.match_template(servant_class) if not found: # try to match the selected version template found, location = CVModule.match_template(servant_class + "_selected") if found: self.mouse_instance.set_zero() time.sleep(0.1) self.mouse_instance.touch(location[0] + self.servant_class_location_error[0], location[1] + self.servant_class_location_error[1], 2) print("Complete select servant_class [{}]".format(servant_class)) return True else: print("Can not select servant_class [{}]".format(servant_class)) return False
def drag_and_find_servant(self, servant, drag_times): """ try to find the drag bar and drag down, to search more servant :param self: :param servant: :param drag_times: :return: """ # find the drag bar self.mouse_instance.set_zero() time.sleep(0.3) found, location = CVModule.match_template("drag_bar") if found: # touch the drag bar self.mouse_instance.touch(location[0] - 60, location[1] + 100) # drag for 1 screen long self.mouse_instance.drag(location[0] - 60, location[1] + 300) drag_times = drag_times - 1 found, location = CVModule.match_template(servant) return found, location, drag_times else: return False, (0, 0), 0
def is_return_to_menu(): found, location = CVModule.match_template('Return_button') return found
def is_in_friend_menu(): found, location = CVModule.match_template('friend_sign') return found