def drag_to(self, name, loader=_imageLoader, offset=(0, 0)): if GameStatus().game_stage == GameStage.Stopped: return self.log('try drag' + name) p = loader.get(name) max_val = 0 x, y = 0, 0 while max_val < 0.8: if GameStatus().game_stage == GameStage.Stopped: return self.capture() res = cv2.matchTemplate(self.screen, p, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) self.log(name + ' ' + str(max_val)) x, y = max_loc time.sleep(self._delay) m, n, q = p.shape x += n / 2 y += m / 2 pyautogui.moveTo(x, y, 0) pyautogui.dragTo(0, 200)
def test_handlerWithGameOver(self): # Pre-condition - HangmanGame table must be created and empty input = self.loadEvent( "./test/resources/test-StatusGame-input-01.json") event = GameStatus.handler(input["input"], {}) print(event) self.assertEqual(event["data"]["game"]["gameState"], "running")
def __init__(self): super().__init__() self._stop = threading.Event() self.cnt = 0 GameStatus().window.status_changed() self.screen = Screen() self.do_loop = True
def __init__(self): t = ImageGrab.grab().convert("RGB") self.screen = cv2.cvtColor(numpy.array(t), cv2.COLOR_RGB2BGR) self.ultLoader = ImageLoader('image/ult/') if self.have('topleft'): tl = self._imageLoader.get('topleft') res = cv2.matchTemplate(self.screen, tl, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) x1, y1 = max_loc rd = self._imageLoader.get('rightdown') res = cv2.matchTemplate(self.screen, rd, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) x2, y2 = max_loc # default 989 GameStatus().y = y2 - y1 GameStatus().use_Droid4X = True
def fight(self): GameStatus().current_level = Screen().get_current_level() if GameStatus().current_level == 3: for key in Screen()._skills.get_all(): while Screen().have(key, loader=Screen()._skills): if GameStatus().game_stage == GameStage.Stopped: return Screen().click_on(key, loader=Screen()._skills) time.sleep(2) Screen().log('use ' + key) GameStatus().cards = [] while len(GameStatus().cards) < 3: if self.stopped(): return if Screen().have('atk_btn'): Screen().click_on('atk_btn') time.sleep(1) Screen().get_cards() for i in range(0, 3): x, y = GameStatus().cards[i] Screen()._click(x, y) time.sleep(Screen()._delay)
def click_on(self, name, repeat=False, loader=_imageLoader): if GameStatus().game_stage == GameStage.Stopped: return self.log('try click ' + name) p = loader.get(name) max_val = 0 x, y = 0, 0 while max_val < 0.8: if GameStatus().game_stage == GameStage.Stopped: return self.capture() res = cv2.matchTemplate(self.screen, p, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) self.log(name + ' ' + str(max_val)) x, y = max_loc time.sleep(self._delay) m, n, q = p.shape x += n / 2 y += m / 2 self._click(x, y) max_val = 1 if repeat else 0 while max_val > 0.8: if GameStatus().game_stage == GameStage.Stopped: return time.sleep(1) self.capture() res = cv2.matchTemplate(self.screen, p, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) if max_val > 0.8: self._click(x, y)
def run(self): GameStatus().window.status_changed() screen = self.screen while self.do_loop: start_time = time.time() if GameStatus().game_stage == GameStage.BeforeFight: # 点击黑森林 target = 'target' screen.click_on(target, repeat=True, loader=screen.target) if screen.have('huangjinguoshi'): screen.click_on('huangjinguoshi') screen.click_on('jueding') screen.click_on(target, loader=screen.target) # 助战选择 第一个? screen.click_on('zhuzhan') # 开始任务 screen.click_on('kaishirenwu') GameStatus().game_stage = GameStage.Fighting elif GameStatus().game_stage == GameStage.Fighting: # attack # 选3张卡 循环 while not screen.have('jiban'): if self.stopped(): return if screen.have('atk_btn'): self.fight() elif screen.have('network_error'): screen.click_on('retry') else: time.sleep(0.5) GameStatus().game_stage = GameStage.AfterFight elif GameStatus().game_stage == GameStage.AfterFight: # 点击 羁绊 screen.click_on('jiban', repeat=True) if screen.have('lvup'): screen.click_on('lvup', repeat=True) if screen.have('jibanup'): screen.click_on('jibanup', repeat=True) # 点击exp screen.click_on('exp', repeat=True) if screen.have('lvup'): screen.click_on('lvup', repeat=True) screen.click_on('xiayibu') self.cnt += 1 GameStatus().window.status_changed() GameStatus().window.add_text( "---战斗 %s 完成 历时 %s 秒 ---" % (self.cnt, time.time() - start_time)) GameStatus().game_stage = GameStage.BeforeFight elif GameStatus().game_stage == GameStage.Stopped: break else: raise RuntimeError('Unknown Status')
def stop(self): GameStatus().game_stage = GameStage.Stopped self._stop.set()
def get_cards(self): self.capture() GameStatus().cards = [] GameStatus().cards += self.find_list('buster') GameStatus().cards += self.find_list('art') GameStatus().cards += self.find_list('quick')
def log(text): GameStatus().window.add_text(text)
def run(self): GameStatus().window.status_changed() screen = self.screen yaoguaifaxain_loader = ImageLoader(self.imagesPath + "yaoguaifaxian/") while self.do_loop: while GameStatus().game_stage == GameStage.Yaoguaifaxian: time.sleep(3) left_counter = 0 right_counter = 0 direction = "right" if left_counter == 10: left_counter = 0 direction = "right" if right_counter == 10: right_counter = 0 direction = "left" if screen.have('yaoguaifaxian_16', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_16', loader=yaoguaifaxain_loader) if screen.have('yaoguaifaxian_hard_unactive', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_hard_unactive', loader=yaoguaifaxain_loader) time.sleep(1) if screen.have('yaoguaifaxian_16', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_16', loader=yaoguaifaxain_loader) if screen.have('yaoguaifaxian_hard_actived', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_explore', repeat=True, loader=yaoguaifaxain_loader) time.sleep(3) while True: if screen.have('yaoguaifaxian_unlock', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_unlock', loader=yaoguaifaxain_loader) if screen.have('yaoguaifaxian_boss_fight', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_boss_fight', loader=yaoguaifaxain_loader) time.sleep(2) if screen.have('yaoguaifaxian_xiaoguai_fight', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_xiaoguai_fight', loader=yaoguaifaxain_loader) time.sleep(2) if screen.have( 'shoudong', loader=yaoguaifaxain_loader) or screen.have( 'zidong', loader=yaoguaifaxain_loader ) or screen.have('zhunbei', loader=yaoguaifaxain_loader): while True: if screen.have('zhunbei', loader=yaoguaifaxain_loader): screen.click_on( 'zhunbei', repeat=True, loader=yaoguaifaxain_loader) if screen.have('shoudong', loader=yaoguaifaxain_loader): screen.click_on( 'shoudong', repeat=True, loader=yaoguaifaxain_loader) if screen.have('yaoguaifaxian_win', loader=yaoguaifaxain_loader): screen.click_on( 'yaoguaifaxian_win', repeat=True, loader=yaoguaifaxain_loader) screen.click_on( 'yaoguaifaxian_damo', repeat=True, loader=yaoguaifaxain_loader) screen.click_on( 'yaoguaifaxian_damo1', repeat=True, loader=yaoguaifaxain_loader) break elif screen.have('yaoguaifaxian_lose', loader=yaoguaifaxain_loader): screen.click_on( 'yaoguaifaxian_lose', repeat=True, loader=yaoguaifaxain_loader) break if screen.have('yaoguaifaxian_xiangzi', loader=yaoguaifaxain_loader): screen.click_on('yaoguaifaxian_xiangzi', repeat=True, loader=yaoguaifaxain_loader) screen.click_on('yaoguaifaxian_huodejiangli', repeat=False, loader=yaoguaifaxain_loader, offset=(-350, 350)) if screen.have('yaoguaifaxian_right', loader=yaoguaifaxain_loader): if direction == "right": screen.click_on("yaoguaifaxian_right", loader=yaoguaifaxain_loader) time.sleep(1.5) right_counter += 1 elif direction == "left": screen.click_on("yaoguaifaxian_left", loader=yaoguaifaxain_loader) time.sleep(1.5) left_counter += 1 if screen.have('yaoguaifaxian_over', loader=yaoguaifaxain_loader): break
def drag_to(self, name, loader=_imageLoader, offset=(0, 0)): if GameStatus().game_stage == GameStage.Stopped: return self.log('try drag from ' + name) p = loader.get(name) pass