def iswalking(self): screen = Screen() screen.cut_screen_by_PIL(30, 65, 140, 85, "D:\\dh2\\system\\2.png") time.sleep(3) screen.cut_screen_by_PIL(30, 65, 140, 85, "D:\\dh2\\system\\2_.png") img1 = cv2.imread('D:\\dh2\\system\\2.png') img2 = cv2.imread('D:\\dh2\\system\\2_.png') hash1 = self.dHash(img1) hash2 = self.dHash(img2) n = self.cmpHash(hash1, hash2) return n
class GuiWang(): def __init__(self): self.transform = TransForm() self.common = Common() self.keyboard = KeyBoard() self.screen = Screen() self.mouse = Mouse() def task_start(self): print("任务开始") self.common.get_focus() for j in range(3): self.mouse.click_element(675, 366, 1, True) time.sleep(2.5) self.keyboard.press_shortcut_key('alt', '5') time.sleep(10) # 领取任务 while True: print("领取任务") self.mouse.click_element(392, 350) time.sleep(1) self.screen.cut_screen() result = self.screen.get_locations_picture( "D:\\dh2\\game\\guiwang\\0.png", 0.9) if result is not 0: self.mouse.click_element(225, 383) time.sleep(0.5) self.mouse.click_element(180, 353) time.sleep(0.5) self.mouse.click_element(180, 353) result_king = self.is_ghostKing() if result_king is True: self.mouse.click_element(392, 350) time.sleep(1) self.screen.cut_screen() result = self.screen.get_locations_picture( "D:\\dh2\\game\\guiwang\\0.png", 0.9) if result is not 0: self.mouse.click_element(268, 330) time.sleep(1) self.mouse.click_element(268, 330) else: break # 返回长安 开始寻路 print("返回长安") while True: self.mouse.click_element(392, 350) time.sleep(1) self.screen.cut_screen() result = self.screen.get_locations_picture( "D:\\dh2\\game\\guiwang\\0.png", 0.75) if result is not 0: self.mouse.click_element(268, 365) time.sleep(2) self.mouse.click_element(29, 255) break self.common.capation_eat_xiang() # 找到NPC,开始战斗 print("找NPC") time.sleep(10) self.screen.find_ele_picture('game\\guiwang\\1', 'mouse', 210, 340) for index in range(5): time.sleep(2) self.keyboard.press_shortcut_key('alt', '8') self.common.change_teamer() self.mouse.click_element(412, 429) time.sleep(10) self.screen.find_ele_picture('game\\guiwang\\2_', 'mouse', 172, 340) time.sleep(1) self.screen.cut_screen() time.sleep(1) ress = self.screen.get_locations_picture( "D:\\dh2\\game\\guiwang\\2_.png", 0.7) self.mouse.click_element(ress[0]['result'][0], ress[0]['result'][1]) time.sleep(1) self.mouse.click_element(784, 539) time.sleep(1) print("回家 判断") self.return_home() time.sleep(1) Screen().cut_screen() box_result = Screen().get_location_picture( 'D:\\dh2\\game\\xiaogui\\3.png', 0.8) if box_result is not 0: Mouse().click_element(327, 535) def is_ghostKing(self): self.screen.cut_screen_by_PIL(20, 265, 50, 300, "D:\\dh2\\system\\1.PNG") result = self.screen.find_color_ele(10, 10, 8, 8, 255, 255, 0, 0, 0, 0, True) if result is not None: return True else: return False def return_home(self): time.sleep(1) self.screen.cut_screen() result = self.screen.get_locations_picture( "D:\\dh2\\game\\guiwang\\3.png", 0.7) print(result) if len(result) is not 0: self.mouse.click_element(757, 455, 1, True) time.sleep(1.5) self.mouse.click_element(757, 455, 1, True) self.mouse.click_element(569, 450) self.mouse.click_element(178, 347)
class Common: def __init__(self): self.personList = [75, 250, 400, 545, 700] self.mouse = Mouse() self.keyboard = KeyBoard() self.screen = Screen() self.transform = TransForm() def get_focus(self, index=True): if index is True: self.mouse.click_direct_element( self.transform.trans_location(75, 0), self.transform.trans_location(45, 1)) else: self.mouse.click_direct_element( self.transform.trans_location(700, 0), self.transform.trans_location(45, 1)) def create_team(self): # 创建队伍 self.keyboard.press_shortcut_key('alt', 't', 1) self.mouse.click_element(403, 318) # 打开好友列表查看组队信息 self.keyboard.press_shortcut_key('alt', 'f', 1) time.sleep(0.5) self.screen.cut_screen() result = self.screen.find_color_ele(679, 291) if result != None: self.mouse.click_element(result[0], result[1]) list = [315, 345, 375, 405] for i in list: self.mouse.click_element_right(730, i, 1) self.mouse.click_element(388, 505) self.mouse.click_element_right(388, 530, 1) self.keyboard.press_shortcut_key('alt', 'f', 1) for i in range(4): self.keyboard.press_shortcut_key('ctrl', 'tab', 1) self.mouse.click_element(347, 410) self.keyboard.press_shortcut_key('ctrl', 'tab', 1) def change_teamer(self, times=1): self.keyboard.press_shortcut_key('ctrl', 'tab', times) def change_dog(self, num): self.keyboard.press_shortcut_key('alt', 'o') if num == 1: self.mouse.click_element(90, 186) elif num == 2: self.mouse.click_element(90, 208) elif num == 3: self.mouse.click_element(90, 230) elif num == 4: self.mouse.click_element(90, 252) elif num == 5: self.mouse.click_element(90, 274) elif num == 6: self.mouse.click_element(90, 296) time.sleep(1.5) self.screen.cut_screen_location(width=200, height=50, x=200, y=350) time.sleep(1) result = self.screen.get_location_picture( "D:\\dh2\\game\\system\\0.png", 0.9, cut_zone=True) if result == 0: self.mouse.click_element(320, 380) self.keyboard.press_shortcut_key('alt', 'o') def clear_task(self): # 清除任务列表 # self.keyboard.press_shortcut_key('alt', 'q') # for i in range(5): # self.mouse.click_element(359, 223) # list = [27, 46, 65, 85, 103, 122, 141] # for i in list: # time.sleep(1) # self.screen.cut_screen_location(width=200, height=300, x=150, y=190) # result = self.screen.find_color_ele(11, i, 2, 1, 190, 220, 60, 75, 50, 60, True) # print(result) # if result == None: # self.mouse.click_element(11 + 200, i + 190) self.keyboard.press_shortcut_key('alt', '2') time.sleep(1) self.mouse.click_element(507, 419) time.sleep(1) self.mouse.click_element(310, 381) self.screen.find_ele_picture('game\\bangpai\\0_', 'mouse', 220, 328) time.sleep(2) self.keyboard.press_shortcut_key('alt', '1') time.sleep(1) self.mouse.click_element(500, 313) def iswalking(self): self.screen.cut_screen_by_PIL(30, 65, 140, 85, "D:\\dh2\\system\\2.PNG") time.sleep(2) self.screen.cut_screen_by_PIL(30, 65, 140, 85, "D:\\dh2\\system\\2_.PNG") result = Walking().iswalking() if result < 10: return False else: return True def click_until_find(self, file_name, x, y): Mouse().click_element(x, y) Screen().cut_screen() result = Screen().get_location_picture(file_name) if result is not 0: return True return False def capation_eat_xiang(self): KeyBoard().press_shortcut_key('alt', 'e') Mouse().click_element(344, 397) Mouse().click_element(44, 454, right=True) KeyBoard().press_shortcut_key('alt', 'e') def score_for_shifu(self): Screen().cut_screen() result = Screen().get_location_picture("D:\\dh2\\game\\system\\3.PNG") if result is not 0: Mouse().click_element(222, 264) Mouse().click_element(409, 506) def task_box(self): pass # 寻找共计目标 def find_attack(self, type, str='zidong'): list = [[198, 280], [198, 320], [198, 360]] endtime = time.time() + int(1000) while time.time() < endtime: time.sleep(1.5) self.screen.cut_screen() pos_zidong = self.screen.get_location_picture( "D:\\dh2\\game\\system\\" + str + ".png") if pos_zidong is not 0: if type is 'f5' or type is 'f6' or type is 'f7': self.keyboard.press_key(type) for i in list: self.mouse.click_element(i[0], i[1], times=0.5) time.sleep(1) self.screen.cut_screen() pos_zidong = self.screen.get_location_picture( "D:\\dh2\\game\\system\\" + str + ".png") if pos_zidong is not 0: return i elif type is None: for i in list: self.mouse.click_element(i[0], i[1], times=0.5) time.sleep(1) self.screen.cut_screen() pos_zidong = self.screen.get_location_picture( "D:\\dh2\\game\\system\\" + str + ".png") if pos_zidong is not 0: return i return 'failed' def game_over(self): endtime = time.time() + int(300) while time.time() < endtime: time.sleep(1) self.screen.cut_screen() time.sleep(1) result = self.screen.get_location_picture( "D:\\dh2\\game\\system\\zidong.png", num=0.8) if result is 0: return True return False