def longClick(self, x, y, duration=2.0): if duration <= 0: raise ValueError( "Operation duration cannot be less equal 0. Please provide a positive number." ) pos = self.get_target_pos(x, y) touch(pos, duration=duration)
def input_keyboard_code(code, record_pos=None, resolution=(1920, 1080)): if code == 0: record_pos = (0.268, 0.25) elif code == 1: record_pos = (0.231, 0.21) elif code == 2: record_pos = (0.304, 0.209) elif code == 3: record_pos = (0.379, 0.21) elif code == 4: record_pos = (0.23, 0.17) elif code == 5: record_pos = (0.305, 0.169) elif code == 6: record_pos = (0.379, 0.17) elif code == 7: record_pos = (0.229, 0.131) elif code == 8: record_pos = (0.304, 0.131) elif code == 9: record_pos = (0.379, 0.131) elif code == "dot": record_pos = (0.379, 0.251) elif code == "yesforpay": record_pos = (0.379, 0.249) elif code == "yes": record_pos = (0.453, 0.229) touch( Template(r"images/" + str(code) + r".png", threshold=0.5, record_pos=record_pos, resolution=resolution))
def SelectExplore(e: Explore): """ 选择战斗类别 example-> SelectExplore(Explore.A) """ touch(P[PM.explore][e]) sleep(0.5)
def SelectChapter(chapter: Chapter): ''' 选择第x节 example:SelectChapter(Chapter.C1) ''' touch(P[PM.chapter][chapter]) sleep(0.5)
def SelectEvent(event: Event): ''' 切换章节 example:SelectEvent(Event.Story1) ''' touch(P[PM.event][event]) sleep(0.5)
def click_img(self, img_file, is_rgb): logging.info('click_element') touch( Template(filename=img_file, threshold=self.threshold, resolution=self.resolution, rgb=is_rgb))
def GoFarSeek(): """进入远征页面""" if exists(T[TM.farseek]) or exists(T[TM.farseek_temp]): touch(T[PM.farseek]) sleep(0.5) return True return False
def click(self, times=1, **kwargs): print(self.template) if isinstance(self.template, Template): touch(self.template, times, **kwargs) else: self.template.click() time.sleep(kwargs.get("timeout", 0))
def focus_shoot(): """尝试使用集中普通攻击""" try: touch(wait(T[TM.focus_shoot], 3)) return True except TargetNotFoundError: logger.error("focus_shoot fail") return False
def longClick(self, x, y, duration=2.0): if duration <= 0: raise ValueError( "Operation duration cannot be less equal 0. Please provide a positive number." ) pw, ph = self._get_touch_resolution() pos = [x * pw, y * ph] touch(pos, duration=duration)
def spread_shoot(): """尝试使用扩散普通攻击""" try: touch(wait(T[TM.spread_shoot], 3)) return True except TargetNotFoundError: logger.error("spread_shoot fail") return False
def ChangeGroup(last=False): ''' 切换打本队伍 last=True 选择向左切换 False向右切换 ''' if last: touch(P[PM.group][0]) else: touch(P[PM.group][1])
def click_subscribe(): """ 点击点阅按钮,成功返回True,失败返回False """ ret = exists(Template(CLICK_SUBSCRIBE, threshold=0.80)) if ret: touch(Template(CLICK_SUBSCRIBE, threshold=0.80)) return True return False
def select_level(level: Level): """ 选择关卡 example->select_level(Level.M1) """ try: touch(P[PM.level][level]) return True except: return False
def _click(self,ui:Union[PocoUi,PootUi,Picture,Coordinate],focus:tuple=None,times=None,onlyOne=True,assertExist=True,**kw): ''' 点击 :param ui: poco\poot\picture\coordinate :param focus:点击焦点,仅支持【poco和poot】 :param times:点击时长,单位秒,仅支持图像识别】【poco链式字符串】【poot链式字符串】 :param onlyOne:多个控件是否都点击,仅支持【poco】 :param kw:其他查询参数 :return: ''' #尝试先等待控件出现 if assertExist: if(type(ui) in [PocoUi,PootUi,Picture]): self._wait_ui_appear(ui) #检查入参 self.__para_check(ui,[PocoUi,PootUi,Picture,Coordinate]) #图像 if type(ui)==Picture: if times==None: touch(ui.getTemplate(), 1, **kw) else: touch(ui.getTemplate(),times,**kw) #坐标 elif type(ui)==Coordinate: if g().isThePootUsed(): g().activePoot.tap_x_y(ui.x,ui.y) else: g().activePoco.click((ui.x,ui.y)) #poot和poco链式 elif type(ui)==PootUi: u = self.__poot(ui.info) if not onlyOne: for i in u: i.tap(focus, times) else: u.tap(focus, times) elif type(ui)==PocoUi: u=self.__poco(ui.info) #设置焦点 if not onlyOne: for i in u: i=self.__set_focus(i,focus) if times!=None: i.long_click(times) else: i.click() else: u=self.__set_focus(u,focus) if times!=None: u.long_click(times) else: u.click() else: raise BaseException("不支持对类型为{}的操作".format(type(ui)))
def poke_wife(drone=None, **kwargs): # 现在可以批量收信赖+制造站,就放在一起了。 print("少女祈祷中...") Navigator.goto_screen(Navigator.GAY) # TODO count passed errors. # TODO auto change exhausted. errors = [] # Wait for notifications to fade sleep(3) if utils.try_touch("notification", rgb=True): sleep(2) # 制造站 utils.try_touch("manufacturer") # 信赖 utils.try_touch("trust") # 贸易站 utils.try_touch("orders") # auto drone manufacturing if drone: # manufacturing if drone.endswith("+"): pos = utils.touch("manufacturing_station") while not utils.try_touch("open_up_manufacturing"): # 防止刚好生产出来一个新的,导致没点进去。 touch(pos) # 假设最多只有5个制造站 for i in range(1, 6): utils.try_touch(f"0{i}", threshold=0.9) if utils.exists(drone): utils.touch("drone_manufacturing", POSITION_CACHE) utils.touch("max_drone", POSITION_CACHE) utils.touch("ok", POSITION_CACHE) utils.touch("gather", POSITION_CACHE) break Navigator.go_back(2) # trade elif drone.endswith("-"): pos = utils.touch("trade") while not utils.try_touch("open_up_trade"): # 防止刚好有新订单,导致没点进去。 touch(pos) for i in range(1, 6): utils.try_touch(f"0{i}", threshold=0.9) if utils.exists(drone): while not utils.exists("0drone", threshold=0.9): utils.touch("drone_trade", False) utils.touch("max_drone", POSITION_CACHE) utils.touch("ok", POSITION_CACHE) utils.try_touch("deliver") break
def SelectDifficulty(d: Difficulty): ''' 切换副本难度 example:SelectDifficulty(Difficulty.normal) ''' if d in [Difficulty.normal, Difficulty.hard, Difficulty.lunatic]: #pos = PointSet([427, 652], src_resolution) for i in range(3): if not exists(T[d]): touch(P[PM.difficultychange]) sleep(1) else: break
def use_spell(s: Spell): """ 使用符卡 example-> use_spell(Spell.A) """ try: #wait(Template(r"tpl1588523129888.png", record_pos=(-0.448, 0.089), resolution=(1280, 720))) #touch(Template(r"tpl1588523129888.png", record_pos=(-0.448, 0.089), resolution=(1280, 720))) touch(P[PM.spell_open]) #wait(Template(r"tpl1588559730239.png", record_pos=(-0.448, 0.088), resolution=(1280, 720)), 5) sleep(1.5) touch(P[PM.spell][s]) except TargetNotFoundError: logger.error("use_spell fail, spell: " + str(s))
def switchFliters(self): self.poco(text="Filters").click() sleep(1) while exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))): touch( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))) sleep(1) self.poco("My").click() sleep(1) assert_exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(0.095, -0.21), resolution=(1440, 2560)), "去除mine勾选成功") self.poco("My").click() sleep(1) self.poco("other").click() sleep(1) assert_exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(0.095, -0.21), resolution=(1440, 2560)), "other可以除去勾选框") self.poco("other").click() sleep(1) self.poco("Played").click() sleep(1) assert_exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(0.095, -0.21), resolution=(1440, 2560)), "not hide played today可以除去勾选框")
def do_click_by_template(img_file, record_pos, resolution): """ 根据截图来确定按钮的点击 oppo的设备执行到点击安装的步骤时,会将后台运行中的PocoService进程中断,无法通过poco获取对象,只能截图 :param img_file: 手机屏幕的分辨率 :param record_pos: 截图时对于手机屏幕的相对位置 :param resolution: 手机屏幕的分辨率 :return: """ try: tmp = Template(img_file, record_pos=tuple(record_pos), resolution=tuple(resolution)) touch(tmp) except Exception as e: print("error: %s" % (str(e)))
def recoveryFilters(self): self.poco(text="Filters").click() while exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))): touch( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))) sleep(1) self.poco.click([360.0 / 720, 700.0 / 1280]) sleep(2)
def goto_screen(screen): # do nothing if at home, else show menu home_icon_pos = utils.exists_now("home_icon") if home_icon_pos: touch(home_icon_pos) if screen == Navigator.HOME: utils.touch("menu_home") elif screen == Navigator.GAY_FRIENDS: if home_icon_pos: utils.touch("menu_friends") else: utils.touch("friends") utils.touch("friend_list") utils.touch("gay_friends") elif screen == Navigator.RECRUIT: if home_icon_pos: utils.touch("menu_recruit") else: utils.touch("recruit") elif screen == Navigator.TASK: if home_icon_pos: utils.touch("menu_tasks") else: utils.touch("task") elif screen == Navigator.GAY: if home_icon_pos: utils.touch("menu_gay") else: utils.touch("gay") sleep(5) elif screen == Navigator.MAPS: if home_icon_pos: utils.touch("menu_maps") else: utils.touch("maps") sleep(0.5) if utils.try_touch("confirm"): # in gay. sleep(5)
def cancelAll(self): #去除所有勾选 while exists( Template(r"tpl1524898630127.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.096, -0.211), resolution=(720, 1280))): touch( Template(r"tpl1524898630127.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.096, -0.211), resolution=(720, 1280))) sleep(0.5) self.poco.click([360.0 / 720, 700.0 / 1280]) sleep(1) assert ("去掉所有人的关卡") if not self.poco("Tree").child().exists(): assert ("去掉所有人的关卡成功")
def onlyMine(self, player): self.poco(text="Filters").click() sleep(1) while exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))): touch( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))) sleep(0.5) self.poco("other").click() sleep(1) self.poco("Played").click() sleep(1) self.poco.click([360.0 / 720, 700.0 / 1280]) sleep(1) self.poco(text="Popularity").click() sleep(1) myLevels = self.poco("Tree").child() marklist = [] # player = self.poco("ToUserInfo").child("Text").get_text() for i in myLevels: if str(player) in i.child("LvMaker").get_text(): marklist.append(1) else: marklist.append(0) assert (marklist) if max(marklist) == min(marklist) and max(marklist) == 1: assert ("只保留自己的关卡成功")
def exit(): """中途退出战斗""" if exists(T[TM.battle_menu]): touch(T[TM.battle_menu]) if exists(T[TM.quit_battle]): touch(T[TM.quit_battle]) if exists(T[TM.quit_confirm]): touch(T[TM.quit_confirm]) return True return False
def use_skill(*args: Skill): """ 使用技能,可以多个 example-> use_skill(Skill.A,Skill.B) """ try: touch(P[PM.skill_open]) sleep(1) for i in args: touch(P[PM.skill][i]) sleep(0.75) touch(P[PM.confirm]) sleep(0.75) except TargetNotFoundError: logger.error("use_skill fail, skill: " + str(args)) finally: touch(P[PM.skill_expanded]) sleep(0.5)
def auto_retry(): """ 战斗结算重试+符卡|技能页面收回 最终异常处理 """ if exists(T[TM.battle_fail]): touch(T[TM.battle_fail]) return if exists(T[TM.battle_success]): touch(T[TM.battle_success]) return #删除了旧版的结算决定按键 if exists(T[TM.spell_expanded]): touch(T[TM.spell_expanded]) return if exists(T[TM.skill_expanded]): touch(T[TM.skill_expanded]) return exit()
def GoHome(): """返回主界面""" auto_timeout() if AtHome(): return True #有回家按钮直接点 if exists(T[TM.home]): touch(T[TM.home]) sleep(3) #结算页面的情况 elif exists(T[TM.next]): touch(P[PM.next]) sleep(3) touch(T[TM.home]) sleep(3) #如果在战斗中退出战斗之后回主页 elif exists(T[TM.battle_menu]): if exit(): sleep(3) touch(T[TM.home]) sleep(3) return AtHome()
def done_tab(main_line=False): last_pos = None for i in range(12): # Limit max loop time. if main_line: pos = utils.exists_now("receive_main_line") else: pos = utils.exists_now("receive") if pos: last_pos = pos touch(pos) sleep(1) if main_line: touch(pos) elif last_pos: # receive bonus perhaps touch(last_pos) last_pos = None sleep(1) else: break
def click(self, x, y): pos = self.get_target_pos(x, y) touch(pos, duration=self.default_touch_down_duration)