def duanyazuobiao(self): self.tag = 0 time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/duanyazuobiao.jpg'): pcr_log(self.account).write_log(level='info', message='>>>成功识别标记,开始刷图.<<<\r\n') break if self.tag > 11: # 超过11次点击则不刷图 pcr_log(self.account).write_log(level='warning', message='>>>点击超过11次,已错过标记点!刷图任务异常,开启高延迟!<<<\r\n' '提示:请增加duanyazuobiao的延迟时间<<<\r\n') if UIMatcher.img_where(screen_shot_, 'img/duanyazuobiao.jpg'): break if self.tag > 22: # 超过11次点击则不刷图 pcr_log(self.account).write_log(level='warning', message='>>>已错过标记点,高延迟模式失败,放弃刷图.<<<\r\n' '>>>提示:请增加duanyazuobiao的延迟时间<<<\r\n') break else: for _ in range(1): self.click(925, 275) self.tag += 1 time.sleep(4) # 这是高延迟识别时间,模拟器卡顿请加时. else: for _ in range(1): self.click(27, 272) self.tag += 1 time.sleep(2) # 这是延迟识别时间,模拟器卡顿请加时.
def mianfeishilian(self): # 免费十连 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 self.lockimg('img/liwu.bmp', ifclick=[(750, 510)], ifdelay=1, at=(891, 413, 930, 452)) # 点进扭蛋界面 time.sleep(1) screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/mianfeishilian.jpg'): # 仅当有免费十连时抽取免费十连 self.d.click(872, 355) # 点击十连 time.sleep(1) self.d.click(592, 369) # 确认 while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/liwu.bmp', at=(891, 413, 930, 452)): break self.d.click(900, 40) time.sleep(0.5) self.d.click(100, 505) time.sleep(0.5) self.d.click(100, 505) time.sleep(1) # 首页锁定,保证回到首页
def doActivityHard(self): # 进入冒险 time.sleep(2) self.click(480, 505) time.sleep(2) while True: screen_shot_ = self.getscreen() if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break # 点击进入活动 self.click(415, 430) time.sleep(3) while True: screen_shot_ = self.getscreen() self.click(480, 380) time.sleep(0.5) self.click(480, 380) if UIMatcher.img_where(screen_shot_, 'img/zhuxian.jpg'): self.click(880, 80) if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): break self.shuatuzuobiao(689, 263, self.times) # 1-5 self.continueDo9(570, 354) # 1-4 self.continueDo9(440, 255) # 1-3 self.continueDo9(300, 339) # 1-2 self.continueDo9(142, 267) # 1-1 self.lock_home()
def doActivityHard(self): # 进入冒险 time.sleep(2) self.d.click(480, 505) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break # 点击进入活动 self.d.click(415, 430) time.sleep(3) while True: screen_shot_ = self.d.screenshot(format="opencv") self.d.click(480, 380) time.sleep(0.5) self.d.click(480, 380) if UIMatcher.img_where(screen_shot_, 'img/normal.jpg'): self.d.click(880, 80) if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): break self.shuatuzuobiao(689, 263, self.times) # 1-5 self.continueDo9(570, 354) # 1-4 self.continueDo9(440, 255) # 1-3 self.continueDo9(300, 339) # 1-2 self.continueDo9(142, 267) # 1-1 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def ocr_local(self, x1, y1, x2, y2, screen_shot=None, size=1.0): if screen_shot is None: screen_shot = self.getscreen() try: if screen_shot.shape[0] > screen_shot.shape[1]: if anticlockwise_rotation_times >= 1: for _ in range(anticlockwise_rotation_times): screen_shot = UIMatcher.AutoRotateClockWise90( screen_shot) screen_shot = UIMatcher.AutoRotateClockWise90(screen_shot) part = screen_shot[y1:y2, x1:x2] # 对角线点坐标 part = cv2.resize(part, None, fx=size, fy=size, interpolation=cv2.INTER_LINEAR) # 利用resize调整图片大小 img_binary = cv2.imencode('.png', part)[1].tobytes() files = {'file': ('tmp.png', img_binary, 'image/png')} local_ocr_text = requests.post( url="http://127.0.0.1:5000/ocr/local_ocr/", files=files) pcr_log(self.account).write_log(level='info', message='本地OCR识别结果:%s' % local_ocr_text.text) return local_ocr_text.text except Exception as ocr_error: pcr_log(self.account).write_log(level='error', message='本地OCR识别失败,原因:%s' % ocr_error) return -1
def mianfeishilian(self): # 免费十连 self.lock_home() self.lock_img('img/liwu.bmp', ifclick=[(750, 510)], ifdelay=1, at=(891, 413, 930, 452)) # 点进扭蛋界面 time.sleep(1) screen_shot_ = self.getscreen() if UIMatcher.img_where(screen_shot_, 'img/mianfeishilian.jpg'): # 仅当有免费十连时抽取免费十连 self.click(872, 355) # 点击十连 time.sleep(1) self.click(592, 369) # 确认 while True: screen_shot_ = self.getscreen() if UIMatcher.img_where(screen_shot_, 'img/liwu.bmp', at=(891, 413, 930, 452)): break self.click(900, 40) time.sleep(0.5) self.click(100, 505) time.sleep(0.5) self.click(100, 505) time.sleep(1) # 首页锁定,保证回到首页
def shuajingyan(self, map): """ 刷图刷1-1 map为主图 """ # 进入冒险 time.sleep(2) self.d.click(480, 505) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.d.click(562, 253) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg', at=(660, 72, 743, 94)): break for i in range(map): time.sleep(3) self.d.click(27, 272) self.shuatuzuobiao(106, 279, 160) # 1-1 刷7次体力为佳 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def shuatu12(self): # 进入冒险 self.click(480, 505, pre_delay=2, post_delay=2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.click( 562, 253, ) self.click(701, 83, pre_delay=4, post_delay=2) self.duanyazuobiao() if self.tag < 22: # 暂时先按各11次来判定 for _ in range(5): # 以7图为基向右移动5图 self.click(925, 275, post_delay=3) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg', at=(660, 72, 743, 94)): break if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): self.click(701, 83, pre_delay=0, post_delay=2) break self.switch = 0 self.d.drag(600, 270, 200, 270, 0.1) # 拖拽到最右 time.sleep(2) self.shuatuzuobiao(760, 255, self.times) # 12-17 self.shuatuzuobiao(610, 245, self.times) # 12-16 self.shuatuzuobiao(450, 270, self.times) # 12-15 self.shuatuzuobiao(565, 415, self.times) # 12-14 self.shuatuzuobiao(400, 425, self.times) # 12-13 self.shuatuzuobiao(280, 365, self.times) # 12-12 self.shuatuzuobiao(265, 245, self.times) # 12-11 self.shuatuzuobiao(130, 265, self.times) # 12-10 self.d.drag(200, 270, 600, 270, 0.1) # 拖拽到最左 time.sleep(2) self.shuatuzuobiao(675, 380, self.times) # 12-9 self.shuatuzuobiao(550, 440, self.times) # 12-8 self.shuatuzuobiao(445, 365, self.times) # 12-7 self.shuatuzuobiao(575, 245, self.times) # 12-6 self.shuatuzuobiao(435, 250, self.times) # 12-5 self.shuatuzuobiao(310, 285, self.times) # 12-4 self.shuatuzuobiao(265, 395, self.times) # 12-3 self.shuatuzuobiao(155, 315, self.times) # 12-2 self.shuatuzuobiao(185, 210, self.times) # 12-1 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 else: pcr_log(self.account).write_log(level='error', message='>>>高延迟模式刷图失败,放弃刷图<<<\r\n') self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def shuatu11(self): # 进入冒险 self.click(480, 505, pre_delay=2, post_delay=2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.click( 562, 253, ) self.click(701, 83, pre_delay=4, post_delay=2) self.duanyazuobiao() if self.tag < 22: # 暂时先按各11次来判定 for _ in range(4): # 以7图为基向右移动4图 self.click(925, 275, post_delay=3) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg', at=(660, 72, 743, 94)): break if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): self.click(701, 83, pre_delay=0, post_delay=2) break self.switch = 0 self.d.drag(600, 270, 200, 270, 0.1) # 拖拽到最右 time.sleep(2) self.shuatuzuobiao(663, 408, self.times) # 11-17 self.shuatuzuobiao(542, 338, self.times) # 11-16 self.shuatuzuobiao(468, 429, self.times) # 11-15 self.shuatuzuobiao(398, 312, self.times) # 11-14 self.shuatuzuobiao(302, 428, self.times) # 11-13 self.shuatuzuobiao(182, 362, self.times) # 11-12 self.shuatuzuobiao(253, 237, self.times) # 11-11 self.shuatuzuobiao(107, 247, self.times) # 11-10 self.d.drag(200, 270, 600, 270, 0.1) # 拖拽到最左 time.sleep(2) self.shuatuzuobiao(648, 316, self.times) # 11-9 self.shuatuzuobiao(594, 420, self.times) # 11-8 self.shuatuzuobiao(400, 432, self.times) # 11-7 self.shuatuzuobiao(497, 337, self.times) # 11-6 self.shuatuzuobiao(558, 240, self.times) # 11-5 self.shuatuzuobiao(424, 242, self.times) # 11-4 self.shuatuzuobiao(290, 285, self.times) # 11-3 self.shuatuzuobiao(244, 412, self.times) # 11-2 self.shuatuzuobiao(161, 325, self.times) # 11-1 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 else: pcr_log(self.account).write_log(level='error', message='>>>高延迟模式刷图失败,放弃刷图<<<\r\n') self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def shuatu10(self): # 进入冒险 self.click(480, 505, pre_delay=2, post_delay=2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.click( 562, 253, ) self.click(701, 83, pre_delay=4, post_delay=2) self.duanyazuobiao() if self.tag < 22: # 暂时先按各11次来判定 for _ in range(3): # 以7图为基向右移动3图 self.click(925, 275, post_delay=3) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg', at=(660, 72, 743, 94)): break if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): self.click(701, 83, pre_delay=0, post_delay=2) break self.switch = 0 self.d.drag(600, 270, 200, 270, 0.1) time.sleep(2) self.shuatuzuobiao(821, 299, self.times) # 10-17 self.shuatuzuobiao(703, 328, self.times) # 10-16 self.shuatuzuobiao(608, 391, self.times) # 10-15 self.shuatuzuobiao(485, 373, self.times) # 10-14 self.shuatuzuobiao(372, 281, self.times) # 10-13 self.shuatuzuobiao(320, 421, self.times) # 10-12 self.shuatuzuobiao(172, 378, self.times) # 10-11 self.shuatuzuobiao(251, 235, self.times) # 10-10 self.shuatuzuobiao(111, 274, self.times) # 10-9 self.d.drag(200, 270, 600, 270, 0.1) # 拖拽到最左 time.sleep(2) self.shuatuzuobiao(690, 362, self.times) # 10-8 self.shuatuzuobiao(594, 429, self.times) # 10-7 self.shuatuzuobiao(411, 408, self.times) # 10-6 self.shuatuzuobiao(518, 332, self.times) # 10-5 self.shuatuzuobiao(603, 238, self.times) # 10-4 self.shuatuzuobiao(430, 239, self.times) # 10-3 self.shuatuzuobiao(287, 206, self.times) # 10-2 self.shuatuzuobiao(146, 197, self.times) # 10-1 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 else: pcr_log(self.account).write_log(level='error', message='>>>高延迟模式刷图失败,放弃刷图<<<\r\n') self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def shuatu8(self): # 进入冒险 self.click(480, 505, pre_delay=2, post_delay=2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.click( 562, 253, ) self.click(701, 83, pre_delay=4, post_delay=2) self.duanyazuobiao() if self.tag < 22: # 暂时先按各11次来判定 for _ in range(1): # 以7图为基向右移动3图 self.click(925, 275, post_delay=3) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg', at=(660, 72, 743, 94)): break if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): self.click(701, 83, pre_delay=0, post_delay=2) break self.switch = 0 self.d.drag(600, 270, 200, 270, 0.1) time.sleep(2) self.shuatuzuobiao(584, 260, self.times) # 8-14 self.shuatuzuobiao(715, 319, self.times) # 8-13 self.shuatuzuobiao(605, 398, self.times) # 8-12 self.shuatuzuobiao(478, 374, self.times) # 8-11 self.shuatuzuobiao(357, 405, self.times) # 8-10 self.shuatuzuobiao(263, 324, self.times) # 8-9 self.shuatuzuobiao(130, 352, self.times) # 8-8 self.d.drag(200, 270, 600, 270, 0.1) # 拖拽到最左 time.sleep(2) self.shuatuzuobiao(580, 401, self.times) # 8-7 self.shuatuzuobiao(546, 263, self.times) # 8-6 self.shuatuzuobiao(457, 334, self.times) # 8-5 self.shuatuzuobiao(388, 240, self.times) # 8-4 self.shuatuzuobiao(336, 314, self.times) # 8-3 self.shuatuzuobiao(230, 371, self.times) # 8-2 self.shuatuzuobiao(193, 255, self.times) # 8-1 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 else: pcr_log(self.account).write_log(level='error', message='>>>高延迟模式刷图失败,放弃刷图<<<\r\n') self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def do_activity_normal(self, buy_tili=0, activity_name="", mode=0): self.lock_home() if activity_name == "": raise Exception("请指定活动名") def enter_activity(): # 进入冒险 time.sleep(2) self.click(480, 505) time.sleep(2) while True: screen_shot_ = self.getscreen() if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break # 点击进入活动 self.click(415, 430) time.sleep(3) def GetXYTD_activity(activity_name, mode, num): if mode == 0: D = ACTIVITY_COORD[activity_name] DR = D["right"] DL = D["left"] if num in DR: return DR[num].x, DR[num].y, 1, "right" else: return DL[num].x, DL[num].y, 1, "left" elif mode == 1: D = HARD_COORD[activity_name] return D[num].x, D[num].y, 1, None enter_activity() while True: screen_shot_ = self.getscreen() self.click(480, 380) time.sleep(0.5) self.click(480, 380) if UIMatcher.img_where(screen_shot_, 'img/home/zhuxian.bmp'): self.click(880, 80) if UIMatcher.img_where(screen_shot_, 'img/juqing/caidanyuan.bmp'): self.chulijiaocheng(turnback=None) enter_activity() if UIMatcher.img_where(screen_shot_, 'img/normal.jpg'): break for i in range(1,5): result = self.zhandouzuobiao(*GetXYTD_activity(activity_name=activity_name, mode=mode, num=i), buy_tili=buy_tili, duiwu=-2, bianzu=-2, juqing_in_fight=1, end_mode=1) if result < 3: raise Exception("你的练度不适合刷活动图,请提升练度后重试") result = self.zhandouzuobiao(*GetXYTD_activity(activity_name=activity_name, mode=mode, num=5), buy_tili=buy_tili, use_saodang=True, times="all", juqing_in_fight=1, end_mode=1) self.lock_home()
def Click_Zhuangbei(screen=None): at = (549, 155, 858, 352) if screen is None: screen = self.getscreen() old = UIMatcher.img_cut(screen, at) while True: self.click(525, 71, post_delay=0.5) screen = self.getscreen() new = UIMatcher.img_cut(screen, at) if self.img_equal(old, new) > 0.98: continue break
def shuatu7(self): # 进入冒险 self.click(480, 505, pre_delay=2, post_delay=2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.d.click(562, 253) time.sleep(3) self.d.click(701, 83) time.sleep(2) self.duanyazuobiao() if self.tag < 22: # 暂时先按各11次来判定 while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg', at=(660, 72, 743, 94)): break if UIMatcher.img_where(screen_shot_, 'img/hard.jpg'): self.d.click(701, 83) break self.switch = 0 self.d.drag(600, 270, 200, 270, 0.1) # 拖拽到最右 time.sleep(2) self.shuatuzuobiao(760, 240, self.times) # 7-14 self.shuatuzuobiao(630, 257, self.times) # 7-13 self.shuatuzuobiao(755, 350, self.times) # 7-12 self.shuatuzuobiao(664, 410, self.times) # 7-11 self.shuatuzuobiao(544, 400, self.times) # 7-10 self.shuatuzuobiao(505, 300, self.times) # 7-9 self.shuatuzuobiao(410, 240, self.times) # 7-8 self.d.drag(200, 270, 600, 270, 0.1) # 拖拽到最左 time.sleep(2) self.shuatuzuobiao(625, 230, self.times) # 7-7 self.shuatuzuobiao(680, 365, self.times) # 7-6 self.shuatuzuobiao(585, 425, self.times) # 7-5 self.shuatuzuobiao(500, 330, self.times) # 7-4 self.shuatuzuobiao(450, 240, self.times) # 7-3 self.shuatuzuobiao(353, 285, self.times) # 7-2 self.shuatuzuobiao(275, 200, self.times) # 7-1 self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 else: pcr_log(self.account).write_log(level='error', message='>>>高延迟模式刷图失败,放弃刷图<<<\r\n') self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def change_acc(self): # 切换账号 self.d.click(871, 513) # 主菜单 while True: # 锁定帮助 screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/bangzhu.bmp'): break self.d.click(165, 411) # 退出账号 while True: # 锁定帮助 screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/ok.bmp'): break self.d.click(591, 369) # ok time.sleep(1)
async def juqingtiaoguo(self): # 异步跳过教程 By:CyiceK # 测试 global th_sw global screenshot while th_sw == 0: cpu_occupy = psutil.cpu_percent(interval=5, percpu=False) if cpu_occupy >= 80: # print('ka') time.sleep(0.8) try: # await asyncio.sleep(10) # time.sleep(10) # 过快可能会卡 if UIMatcher.img_where(screenshot, 'img/caidan_yuan.jpg', at=(860, 0, 960, 100)): self.d.click(917, 39) # 菜单 time.sleep(1) self.d.click(807, 44) # 跳过 time.sleep(1) self.d.click(589, 367) # 跳过ok time.sleep(5) if UIMatcher.img_where(screenshot, 'img/kekeluo.bmp', at=(181, 388, 384, 451)): # 防妈骑脸 self.d.click(1, 1) time.sleep(3) self.d.click(1, 1) if UIMatcher.img_where(screenshot, 'img/dxc_tb_1.bmp', at=(0, 390, 147, 537)): self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1) # 回首页 if UIMatcher.img_where(screenshot, 'img/dxc_tb_2.bmp', at=(580, 320, 649, 468)): time.sleep(4) self.d.click(610, 431) self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1) # 回首页 except Exception as e: pcr_log(self.account).write_log( level='error', message='异步线程终止并检测出异常{}'.format(e)) th_sw = 1 # sys.exit() break
def enterJJC(self, x, y): self.d.click(480, 505) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.d.click(x, y) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") self.d.click(36, 77) if UIMatcher.img_where(screen_shot_, 'img/list.jpg'): break
def init_home(self): while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/liwu.bmp', at=(891, 413, 930, 452)): break if UIMatcher.img_where(screen_shot_, 'img/niudan_jiasu.jpg', at=(700, 0, 960, 100)): self.d.click(893, 39) # 跳过 time.sleep(0.5) continue if UIMatcher.img_where(screen_shot_, 'img/jingsaikaishi.bmp', at=(755, 471, 922, 512)): self.d.click(786, 308) # 选角色 time.sleep(0.2) self.d.click(842, 491) # 开始 time.sleep(0.5) continue self.d.click(1, 1) self.d.click(330, 270) # 跳过特别庆典 self.lockimg('img/liwu.bmp', elseclick=[(1, 1)], elsedelay=0.2, at=(891, 413, 930, 452)) # 首页锁定 time.sleep(0.5) # 这里防一波第二天可可萝跳脸教程 screen_shot_ = self.d.screenshot(format="opencv") num_of_white, _, _ = UIMatcher.find_gaoliang(screen_shot_) if num_of_white < 50000: self.lockimg('img/renwu_1.bmp', elseclick=[(837, 433)], elsedelay=1) self.lockimg('img/liwu.bmp', elseclick=[(90, 514)], elsedelay=0.2, at=(891, 413, 930, 452)) return if UIMatcher.img_where(screen_shot_, 'img/kekeluo.bmp'): self.lockimg('img/renwu_1.bmp', elseclick=[(837, 433)], elsedelay=1) self.lockimg('img/liwu.bmp', elseclick=[(90, 514)], elsedelay=0.2, at=(891, 413, 930, 452))
def hanghui(self): """ 行会自动捐赠装备 """ self.find_img('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页 time.sleep(1) # self.d.click(693, 436) self.find_img('img/hanghui.bmp', elseclick=[(693, 436)], elsedelay=1) # 锁定进入行会 time.sleep(1) while True: # 6-17修改:减少opencv使用量提高稳定性 screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/zhiyuansheding.bmp'): time.sleep(3) # 加载行会聊天界面会有延迟 for _ in range(2): time.sleep(2) screen_shot = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot, 'img/juanzengqingqiu.jpg'): self.click(367, 39, post_delay=2) # 点击定位捐赠按钮 screen_shot = self.d.screenshot(format="opencv") self.guochang(screen_shot, ['img/juanzeng.jpg'], suiji=0) self.click(644, 385, pre_delay=1, post_delay=3) # 点击max screen_shot = self.d.screenshot(format="opencv") self.guochang(screen_shot, ['img/ok.bmp'], suiji=0) self.click(560, 369, pre_delay=2, post_delay=1) while True: self.click(1, 1, post_delay=1) screen_shot = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot, 'img/zhiyuansheding.bmp'): break break time.sleep(2) # 处理多开捐赠失败的情况 screen_shot = self.d.screenshot(format="opencv") self.guochang(screen_shot, ['img/ok.bmp'], suiji=0) self.click(1, 1, post_delay=1) # 处理被点赞的情况 self.click(100, 505, post_delay=1) # 回到首页 self.find_img('img/liwu.bmp', elseclick=[(131, 533), (1, 1)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def PartIN(self: Automator): # 进入冒险 time.sleep(2) self.d.click(480, 505) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/dixiacheng.jpg'): break self.d.click(562, 253) time.sleep(2) while True: screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/normal.jpg'): break
def init_home(self): # 2020-07-31 TheAutumnOfRice: 检查完毕 while True: screen_shot_ = self.getscreen() if self.is_exists(MAIN_BTN["liwu"], screen=screen_shot_): break if self.is_exists(MAIN_BTN["xiazai"], screen=screen_shot_): self.click(MAIN_BTN["xiazai"]) if self.is_exists(MAIN_BTN["tiaoguo"], screen=screen_shot_): self.click(893, 39, post_delay=0.5) # 跳过 continue if self.is_exists(MAIN_BTN["xzcw"], screen=screen_shot_): raise Exception("下载错误") if self.is_exists(MAIN_BTN["jingsaikaishi"], screen=screen_shot_): self.click(786, 308, post_delay=0.2) # 选角色 self.click(842, 491) # 开始 continue # num_of_white, _, x, y = UIMatcher.find_gaoliang(screen_shot_) # print(num_of_white) # if num_of_white < 77000: # break # 跳过特别庆典 self.click(1, 1, post_delay=0.5) self.click(330, 270, post_delay=1) # 跳过抽签(备用) self.d.touch.down(470, 30).sleep(0.1).move(470, 500).sleep(0.2).up(470, 500) self.lock_home() time.sleep(0.5) # 这里防一波第二天可可萝跳脸教程 screen_shot_ = self.getscreen() num_of_white, _, _, _ = UIMatcher.find_gaoliang(screen_shot_) if num_of_white < 50000: self.lock_img('img/renwu_1.bmp', elseclick=[(837, 433)], elsedelay=1) self.lock_home() return if UIMatcher.img_where(screen_shot_, 'img/kekeluo.bmp'): self.lock_img('img/renwu_1.bmp', elseclick=[(837, 433)], elsedelay=1) self.lock_home() time.sleep(1) self.lock_home() # 追加检测
def guochang(self, screen_shot, template_paths, suiji=1): # suji标号置1, 表示未找到时将点击左上角, 置0则不点击 # 输入截图, 模板list, 得到下一次操作 self.dWidth, self.dHeight = self.d.window_size() screen_shot = screen_shot template_paths = template_paths active_path = UIMatcher.imgs_where(screen_shot, template_paths) if active_path: # print(active_path) if 'img/caidan_tiaoguo.jpg' in active_path: x, y = active_path['img/caidan_tiaoguo.jpg'] self.d.click(x, y) else: for name, (x, y) in active_path.items(): # print(name) self.d.click(x, y) time.sleep(0.5) else: if suiji: # print('未找到所需的按钮,将点击左上角') self.d.click(0.1 * self.dWidth, 0.1 * self.dHeight) else: # print('未找到所需的按钮,无动作') pass
def get_six_clothes(screen=None): if screen is None: screen = self.getscreen() Six_Points = [ (101, 111), (336, 112), (65, 198), (371, 199), (101, 284), (336, 286), ] sc = cv2.cvtColor(screen, cv2.COLOR_RGB2HSV) value = sc[:, :, 1] out = [] # 从左到右,从上到下 for p in Six_Points: w, h = 60, 30 pic = UIMatcher.img_cut(value, (p[0], p[1], p[0] + w, p[1] + h)) if debug: print(pic.max()) if pic.max() > 150: out += [True] else: out += [False] if debug: print(out) return out
def _check_img_in_list_or_dir(self, target_txt, target_pic_at, target_dir, target_list_name, screen): data = self._load_data_cache() if data is None: return target_txt # No Dataset, Do Nothing. target_list = getattr(data, target_list_name) if target_txt in target_list: return target_txt # Good if not os.path.isdir(target_dir): os.makedirs(target_dir) P = pathlib.Path(target_dir) if target_pic_at is not None: screen = UIMatcher.img_cut(screen, target_pic_at) for p in P.iterdir(): if p.suffix == ".bmp": bmp2 = cv2.imdecode(np.fromfile(str(p), dtype=np.uint8), -1) if self.img_equal(screen, bmp2, similarity=0.5) > 0.98: if debug: print("找到相似图片:", p) if p.stem in target_list: return p.stem # 失败 target_name = checkNameValid(target_txt) save_target = os.path.join(target_dir, target_name + ".bmp") save_target = str(pathlib.Path(save_target)) cv2.imencode('.bmp', screen)[1].tofile(save_target) self.log.write_log("warning", f"文字{target_txt}可能识别有误!请修改{save_target}的文件名为正确的值!") return target_txt
def get_bar(self, bar: PCRelement, screen=None): """ 进度条类百分比获取 :param bar: 含有at,fc,bc元素的PCRelement 其中,at为截取进度条,fc为进度条【横向中线】前景色,bc为进度条【横向中线】背景色 :param screen: 设置为None,重新截屏 :return: 百分比0~1 """ if screen is None: screen = self.getscreen() at, fc, bc = bar.at, bar.fc, bar.bc x1, y1, x2, y2 = at ym = int((y1 + y2) / 2) # 只取中之条 mid_line = UIMatcher.img_cut(screen, (x1, ym, x2, ym)) # R,G,B -> B G R fc = np.array([fc[2], fc[1], fc[0]]) bc = np.array([bc[2], bc[1], bc[0]]) tf = np.sqrt(((mid_line - fc)**2).sum(axis=2)).ravel() tb = np.sqrt(((mid_line - bc)**2).sum(axis=2)).ravel() t = tf < tb left = 0 right = len(t) - 1 for ind in range(len(t)): if t[ind]: left = ind break for ind in range(len(t) - 1, -1, -1): if not t[ind]: right = ind break t = t[left:right + 1] return t.sum() / len(t)
def lock_home(self): """ 锁定首页 要求场景:存在“我的主页”按钮 逻辑:不断点击我的主页,直到右下角出现“礼物” """ self.clear_all_initFC() last = time.time() while True: sc = self.getscreen() if self.is_exists(MAIN_BTN["xiazai"], screen=sc): self.click(MAIN_BTN["xiazai"]) num_of_white, _, x, y = UIMatcher.find_gaoliang(sc) if num_of_white < 77000: self.chulijiaocheng(None) # 增加对教程的处理功能 last = time.time() if self.is_exists(MAIN_BTN["liwu"], screen=sc): return # if self.is_exists(MAIN_BTN["guanbi"], screen=sc): # self.click(MAIN_BTN["guanbi"]) try: r_list = self.img_where_all(img=MAIN_BTN["guanbi"], screen=sc) if self.lock_no_img(img=MAIN_BTN["guanbi"], elseclick=(int(r_list[0]), int(r_list[1])), side_check=self.juqing_kkr): time.sleep(5) continue except: pass self.click(MAIN_BTN["zhuye"]) # 防卡公告 self.click(1, 1) time.sleep(1.5) if time.time() - last > lockimg_timeout: raise Exception("lock_home时出错:超时!")
def buyExp(self): # 进入商店 count = 0 self.d.click(616, 434) while True: self.d.click(82, 84) screen_shot_ = self.d.screenshot(format="opencv") if UIMatcher.img_where(screen_shot_, 'img/exp.jpg'): break count += 1 time.sleep(1) if count > 4: break if count <= 4: self.d.click(386, 148) self.d.click(556, 148) self.d.click(729, 148) self.d.click(897, 148) self.d.click(795, 437) time.sleep(1) self.d.click(596, 478) time.sleep(1) self.lockimg('img/liwu.bmp', elseclick=[(131, 533)], elsedelay=1, at=(891, 413, 930, 452)) # 回首页
def guochang(self, screen_shot, template_paths, suiji=1): # suji标号置1, 表示未找到时将点击左上角, 置0则不点击 # 输入截图, 模板list, 得到下一次操作 # 2020-08-08 建议弃用该函数。 screen_shot = screen_shot template_paths = template_paths active_path = UIMatcher.imgs_where(screen_shot, template_paths) if active_path: # print(active_path) if 'img/juqing/tiaoguo_1.bmp' in active_path: x, y = active_path['img/juqing/tiaoguo_1.bmp'] self.click(x, y) else: for name, (x, y) in active_path.items(): # print(name) self.click(x, y) time.sleep(0.5) else: if suiji: # print('未找到所需的按钮,将点击左上角') self.click(0.1 * self.dWidth, 0.1 * self.dHeight) else: # print('未找到所需的按钮,无动作') pass
def wait_for_loading(self, screen=None, delay=0.5, timeout=30): """ 等待黑屏loading结束 :param screen: 设置为None时,截图,否则使用screen :param delay: 检测间隔 :param timeout: 超过timeout,报错 Add 2020-08-15: 增加对Connect的检测。 """ time.sleep(delay) sc = self.getscreen() if screen is None else screen last_time = time.time() while True: self._move_check() if self.is_exists(img='img/connecting.bmp', at=(748, 20, 931, 53), screen=sc): time.sleep(delay) sc = self.getscreen() continue sc_cut = UIMatcher.img_cut(sc, MAIN_BTN["loading_left"].at) if not (sc_cut == 1).all(): break if time.time() - last_time > timeout: raise Exception("Loading 超时!") time.sleep(delay) sc = self.getscreen()
def is_exists(self, img, threshold=0.84, at=None, screen=None, is_black=False, black_threshold=1500, method=cv2.TM_CCOEFF_NORMED): """ 判断一个图片是否存在。 :param black_threshold: 判断暗点的阈值 :param is_black: 是否判断为暗色图片(多用于检测点击按钮后颜色变暗)灰色返回Ture,默认需要配合at,否则自行调整阈值 :param method: :param img: 一个字符串,表示图片的地址;或者为PCRelement类型。 当img为PCRelement时,如果at参数为None,则会使用img.at。 :param threshold: 判定阈值 :param at: 搜素范围 :param screen: 若设置为None,则重新截图;否则使用screen为截图 :return: 是否存在 """ if screen is None: screen = self.getscreen() img, at = self._get_img_at(img, at) return UIMatcher.img_where(screen, img, threshold, at, method, is_black, black_threshold) is not False