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
class HouZi: def __init__(self): self.transform = TransForm() self.common = Common() self.keyboard = KeyBoard() self.screen = Screen() self.mouse = Mouse() def houzi_task(self, place): self.common.get_focus() # self.keyboard.press_shortcut_key('alt', '2', times=0.5) # self.mouse.click_element(320, 411, times=0.5) # self.mouse.click_element(540, 425, times=0.5) # self.keyboard.press_shortcut_key('alt', '2', times=0.5) # self.common.iswalking() num = 0 while num < 30: if num % 5: for j in range(5): if j is 0: self.mouse.click_element(697, 131, times=0.5) else: pyautogui.click() self.common.change_teamer() for i in place: # 打开地图 self.keyboard.press_shortcut_key('alt', '1', times=0.5) self.mouse.click_element(i[0], i[1], times=0.5) self.keyboard.press_shortcut_key('alt', '1', times=0.5) while True: walking = self.common.iswalking() if walking is False: break while True: result = self.task_start() if result is 'success': # self.keyboard.press_shortcut_key('alt', '2', times=0.5) # self.mouse.click_element(499, 419, times=0.5) # self.mouse.click_element(466, 211, times=0.5) num += 1 else: print("找不到") break def task_start(self): while True: self.screen.cut_screen_location(820, 650, 0, 0) time.sleep(0.5) result = Screen().find_color_ele(400, 400, 350, 250, r1=250, r2=260, g1=250, g2=260, b1=0, b2=10, cut_zone=True) if result is not None: self.mouse.click_element(result[0] - 10, result[1] - 25, times=0.5) self.screen.cut_screen() time.sleep(0.5) loc = self.screen.get_location_picture("D:\\dh2\\houzi\\2.png", num=0.7) if loc is not 0: self.mouse.click_element(178, 345, times=0.5) time.sleep(10) while True: self.screen.cut_screen() time.sleep(1.5) pos_zidong = self.screen.get_location_picture( "D:\\dh2\\game\\system\\zidong.png") if pos_zidong is None: break return 'success' else: return 'failed'
class JieFang: def __init__(self): self.transform = TransForm() self.common = Common() self.keyboard = KeyBoard() self.screen = Screen() self.mouse = Mouse() def find_flowers(self): # 拜访他人获得鲜花 for i in range(1): flower = 0 if i == 0: self.common.get_focus() # else: # self.common.change_teamer() # self.screen.find_ele_picture('game\\jiefang\\0', handle=True, k1='alt', k2='f') # # 打开好友列表查看组队信息 # 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]) # self.mouse.click_element_right(730, 315, 1) # self.mouse.click_element(303, 505) # self.mouse.click_element_right(388, 530, 1) # self.mouse.click_element(777, 549) # self.keyboard.press_shortcut_key('alt', 'f') # 点击领取街坊任务(花) self.mouse.click_element(757, 181) self.mouse.click_element(408, 354) self.mouse.click_element(182, 346) time.sleep(1) # for y_ in range(14): self.mouse.click_element(92, 227) for y in range(30): if y < 13: self.mouse.click_element(240, 235 + 20 * y) if y > 13: self.mouse.mouse_scroll(-10) time.sleep(0.5) self.mouse.click_element(240, 235 + 20 * 12) list = [[543, 307], [481, 334], [422, 366], [480, 396], [541, 427], [597, 395], [657, 362], [598, 332]] list_flower = [[556, 267], [483, 294], [426, 328], [488, 365], [545, 398], [602, 360], [672, 329], [617, 295]] time.sleep(1) self.screen.cut_screen() time.sleep(1) for index, j in enumerate(list_flower): index = index result = self.screen.find_color_ele(j[0], j[1], 30, 15, 190, 210, 10, 40, 0, 20) if result != None: self.mouse.click_element(list[index][0], list[index][1]) self.mouse.click_element(167, 327) for w in range(4): self.mouse.click_element_right(219, 250, 1) time.sleep(5) self.screen.cut_screen() # a = sceen.find_color_ele(426, 328, 10, 10) result = self.screen.template_image("D:\\dh2\\game\\jiefang\\1.PNG") result_ = self.screen.template_image("D:\\dh2\\game\\jiefang\\1_1.PNG") if len(result_)>0: list_ = [] lists = [] for c in result_: list_.append(c[0] + 1) for c in result: if c[0] in list_: str_ = c[0], c[1] lists.append(str_) for c in lists: self.mouse.click_element(c[0], c[1]) self.mouse.click_element(169, 359) time.sleep(3) self.mouse.click_element(760, 184) self.mouse.click_element(408, 350) self.mouse.click_element(182, 327) def jiefang_task(self): # 清除任务栏信息 # for i in range(10): # self.mouse.click_element(356,224) self.screen.cut_screen_location(width=200, height=300, x=150, y=190) result = self.screen.get_location_picture("D:\\dh2\\game\\system\\task\\0.png", 0.7, cut_zone=True) self.mouse.click_element(result[0]+150, result[1]+190)