def set_saodang_cishu(self, target: int, one_tili=None, left_tili=None, right_tili=None, sc=None, max_retry=6, delay=1): # 设定扫荡次数 if sc is None: sc = self.getscreen() if left_tili is None: left_tili = self.get_tili_left(sc) if right_tili is None: right_tili = self.get_tili_right(sc) if one_tili is None: one_tili = left_tili - right_tili now_cishu = (left_tili - right_tili) // one_tili # 使用X张 的识别效果很不好 if now_cishu < 1: now_cishu = 1 retry = 0 while now_cishu != target: if retry >= max_retry: raise LockMaxRetryError("设定扫荡次数尝试过多!") if now_cishu < target: for _ in range(target - now_cishu): self.click(MAOXIAN_BTN["saodang_plus"]) elif now_cishu > target: for _ in range(now_cishu - target): self.click(MAOXIAN_BTN["saodang_minus"]) time.sleep(delay) right_tili = self.get_tili_right() now_cishu = (left_tili - right_tili) // one_tili if abs(now_cishu - target) > 5: self.log.write_log("warning", "可能是OCR出现问题,体力识别失败了!") if save_debug_img: self._a.save_last_screen(f"debug_imgs/tili_rec_{time.time()}.bmp") return retry += 1
def check(self): """ 检查场景上是否存在满足要求的scene。 若存在指定scene,则返回该scene。 若无scene,则返回None """ last_check_time = None no_scene = False start_time = time.time() retry = 0 while retry < self.max_retry: if self.timeout is not None and time.time( ) - start_time > self.timeout: raise LockTimeoutError("SceneList判断超时!") for scene in self.scene_list: screen = self.getscreen() if scene.feature(screen): return scene if self.no_scene_feature is not None: no_scene = self.no_scene_feature(screen) else: no_scene = True if no_scene: start_time = time.time() if last_check_time is None: last_check_time = time.time() else: if time.time() - last_check_time > self.double_check: return None # No Msg else: time.sleep(-time.time() + last_check_time + self.double_check) # Double Check else: last_check_time = None retry += 1 raise LockMaxRetryError("SceneList判断超出尝试上限!")
def check(self, double_check=None, check_double_scene=None, timeout=None, max_retry=None, no_scene_feature=None): """ 检查场景上是否存在满足要求的scene。 若存在指定scene,则返回该scene。 若无scene,则返回None """ if double_check is None: double_check = self.double_check if check_double_scene is None: check_double_scene = self.check_double_scene if timeout is None: timeout = self.timeout if no_scene_feature is None: no_scene_feature = self.no_scene_feature if max_retry is None: max_retry = self.max_retry last_check_time = None last_scene = type(None) no_scene = False start_time = time.time() retry = 0 while retry < max_retry: if timeout is not None and time.time() - start_time > timeout: raise LockTimeoutError("SceneList判断超时!") screen = self.getscreen() if not self.not_loading(screen): start_time = time.time() for scene in self.scene_list: if scene.feature(screen): if isinstance(scene, PCRMsgBoxBase): return scene else: # 场景双判 if check_double_scene: if isinstance(scene, last_scene): return scene else: last_scene = type(scene) time.sleep(double_check) continue else: return scene if no_scene_feature is not None: if no_scene_feature is False: no_scene = False else: no_scene = no_scene_feature(screen) else: no_scene = True if no_scene: start_time = time.time() if last_check_time is None: last_check_time = time.time() else: if time.time() - last_check_time > double_check: return None # No Msg else: time.sleep(-time.time() + last_check_time + double_check) # Double Check else: last_check_time = None retry += 1 raise LockMaxRetryError("SceneList判断超出尝试上限!")