class Fighter: def __init__(self, name='', emyc=0): # 初始参数 self.emyc = emyc self.name = name # 启动日志 self.log = WriteLog() # 绑定窗口 self.yys = GameControl(u'阴阳师-网易游戏') self.log.writeinfo(self.name + 'Registration successful') # 激活窗口 self.yys.activate_window() self.log.writeinfo(self.name + 'Activation successful') ut.mysleep(500) def check_battle(self): # 检测是否进入战斗 self.yys.wait_game_img('img\\ZI-DONG.png') self.log.writeinfo(self.name + 'Already in battle') def check_end(self): # 检测是否打完 self.yys.wait_game_img('img\\JIE-SU.png') self.log.writeinfo(self.name + "Battle finished") def click_monster(self): # 点击怪物 pass
class Fighter: def __init__(self, name='', emyc=0, hwnd=0): ''' 初始化 :param name='': 打手名称 : param emyc=0: 点怪设置:0-不点怪 : param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 ''' # 初始参数 self.emyc = emyc self.name = name self.run = True # 读取配置文件 conf = configparser.ConfigParser() conf.read('conf.ini') quit_game_enable = conf.getboolean('watchdog', 'watchdog_enable') self.max_op_time = conf.getint('watchdog', 'max_op_time') self.max_win_time = conf.getint('watchdog', 'max_win_time') # 启动日志 self.log = WriteLog() # 绑定窗口 if hwnd == 0: hwnd = win32gui.FindWindow(0, u'阴阳师-网易游戏') self.yys = GameControl(hwnd, quit_game_enable) self.log.writeinfo(self.name + '绑定窗口成功') self.log.writeinfo(self.name + str(hwnd)) # 激活窗口 self.yys.activate_window() self.log.writeinfo(self.name + '激活窗口成功') time.sleep(0.5) def check_battle(self): # 检测是否进入战斗 self.log.writeinfo(self.name + '检测是否进入战斗') self.yys.wait_game_img('img\\ZI-DONG.png', self.max_win_time) self.log.writeinfo(self.name + '已进入战斗') def check_end(self): # 检测是否打完 self.log.writeinfo(self.name + '检测是战斗是否结束') self.yys.wait_game_img('img\\JIE-SU.png', self.max_win_time) self.log.writeinfo(self.name + "战斗结束") def click_monster(self): # 点击怪物 pass def click_until(self, tag, img_path, pos, pos_end=None, step_time=None, appear=True, point=0.97): ''' 在某一时间段内,后台点击鼠标,直到出现某一图片出现或消失 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :appear: 图片出现或消失:Ture-出现;False-消失 :point: 判定图片的的识别概率 :return: 成功返回True, 失败退出游戏 ''' # 在指定时间内反复监测画面并点击 start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: result = self.yys.find_game_img(img_path, point=point) if not appear: result = not result if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) self.log.writeinfo(self.name + '点击 ' + tag) if step_time == None: time.sleep(random.randint(1, 3)) else: time.sleep(step_time) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) # self.yys.quit_game() self.log.writewarning("强制退出脚本") sys.exit(0) def activate(self): self.log.writewarning(self.name + '启动脚本') self.run = True self.yys.run = True def deactivate(self): self.log.writewarning(self.name + '手动停止脚本') self.run = False self.yys.run = False def slide_x_scene(self, distance): ''' 水平滑动场景 :return: 成功返回True; 失败返回False ''' x0 = random.randint(distance + 10, 1126) x1 = x0 - distance y0 = random.randint(436, 486) y1 = random.randint(436, 486) self.yys.mouse_drag_bg((x0, y0), (x1, y1)) logging.info(self.name + '水平滑动界面') def get_scene(self): ''' 识别当前场景 :return: 返回场景名称:1-庭院; 2-探索界面; 3-章节界面; 4-探索内 ''' # 拒绝悬赏 self.yys.rejectbounty() # 分别识别庭院、探索、章节页、探索内 maxVal, maxLoc = self.yys.find_multi_img( 'img\\JIA-CHENG.png', 'img\\JUE-XING.png', 'img\\TAN-SUO.png', 'img\\YING-BING.png') scene_cof = max(maxVal) if scene_cof > 0.97: scene = maxVal.index(scene_cof) return scene + 1 else: return 0 def get_scene_baigui(self): ''' 识别百鬼结束的画面 :return: 返回场景名称:1-百鬼首页,2-结算页面 ''' # 拒绝悬赏 self.yys.rejectbounty() # 分别识别百鬼首页、结算页面 maxVal, maxLoc = self.yys.find_multi_img( 'img\\BAI-GUI-YE-XING.png', 'img\\BAI-GUI-QI-YUE-SHU.png') scene_cof = max(maxVal) if scene_cof > 0.97: scene = maxVal.index(scene_cof) return scene + 1 else: return 0 def get_scene_breakthrough(self): ''' 识别结界突破结果 :return: 返回场景名称:1-成功,2-失败 ''' # 拒绝悬赏 self.yys.rejectbounty() # 分别识别百鬼首页、结算页面 maxVal, maxLoc = self.yys.find_multi_img( 'img\\SHENG-LI.png', 'img\\SHI-BAI.png') scene_cof = max(maxVal) if scene_cof > 0.97: scene = maxVal.index(scene_cof) return scene + 1 else: return 0 def switch_to_scene(self, scene): ''' 切换场景 :param scene: 需要切换到的场景:1-庭院; 2-探索界面; 3-章节界面; 4-探索内 :return: 切换成功返回True;切换失败直接退出 ''' scene_now = self.get_scene() logging.info(self.name + '目前场景:' + str(scene_now)) if scene_now == scene: return True if scene_now == 1: # 庭院中 if scene == 2 or scene == 3 or scene == 4: # 先将界面划到最右边 self.slide_x_scene(800) time.sleep(2) self.slide_x_scene(800) # 点击探索灯笼进入探索界面 self.click_until('探索灯笼', 'img\\JUE-XING.png', * TansuoPos.tansuo_denglong) # 递归 self.switch_to_scene(scene) if scene_now == 2: # 探索界面 if scene == 3 or scene == 4: # 点击最后章节 self.click_until('最后章节', 'img\\TAN-SUO.png', *TansuoPos.last_chapter) # 递归 self.switch_to_scene(scene) if scene_now == 3: # 章节界面 if scene == 4: # 点击探索按钮 self.click_until('探索按钮', 'img\\YING-BING.png', *TansuoPos.tansuo_btn) # 递归 self.switch_to_scene(scene) if scene_now == 4: # 探索内 if scene == 3: # 点击退出探索 self.click_until('退出按钮', 'img\\QUE-REN.png', *TansuoPos.quit_btn) # 点击确认 self.click_until('确认按钮', 'img\\QUE-REN.png', *TansuoPos.confirm_btn, 2, False) # 递归 self.switch_to_scene(scene)
class Fighter: def __init__(self, name='', emyc=0, hwnd=0): ''' 初始化 :param name='': 打手名称 : param emyc=0: 点怪设置:0-不点怪 : param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 ''' # 初始参数 self.emyc = emyc self.name = name self.run = True # 读取配置文件 conf = configparser.ConfigParser() conf.read('conf.ini') quit_game_enable = conf.getboolean('watchdog', 'watchdog_enable') self.max_op_time = conf.getint('watchdog', 'max_op_time') self.max_win_time = conf.getint('watchdog', 'max_win_time') self.mitama_team_mark = conf.getint('mitama', 'mitama_team_mark') # 启动日志 self.log = WriteLog() # 绑定窗口 if hwnd == 0: hwnd = win32gui.FindWindow(0, u'阴阳师-网易游戏') self.yys = GameControl(hwnd, quit_game_enable) self.log.writeinfo(self.name + '绑定窗口成功') self.log.writeinfo(self.name + str(hwnd)) # 激活窗口 self.yys.activate_window() self.log.writeinfo(self.name + '激活窗口成功') time.sleep(0.5) # 自检 debug_enable = conf.getboolean('others', 'debug_enable') if debug_enable: task = threading.Thread(target=self.yys.debug) task.start() def check_battle(self): # 检测是否进入战斗 self.log.writeinfo(self.name + '检测是否进入战斗') self.yys.wait_game_img('img\\ZI-DONG.png', self.max_win_time) self.log.writeinfo(self.name + '已进入战斗') def check_end(self): # 检测是否打完 self.log.writeinfo(self.name + '检测是战斗是否结束') self.yys.wait_game_img('img\\JIE-SU.png', self.max_win_time) self.log.writeinfo(self.name + "战斗结束") def mitama_team_click(self): ''' 御魂标记己方式神 ''' num = self.mitama_team_mark if num > 0: # 100 1040 # 125 50 # 御魂场景获取标记位置 min = (num - 1) * 105 + (num - 1) * 100 + 95 max = min + 50 pos = (min, 355), (max, 425) start_time = time.time() while time.time() - start_time <= 3: x1 = pos[0][0] - 100 y1 = pos[0][1] - 250 x2 = pos[1][0] + 100 y2 = pos[1][1] exp_pos = self.yys.find_color( ((x1, y1), (x2, y2)), (134, 227, 96), 5) # print('颜色位置', exp_pos) if exp_pos != -1: self.log.writeinfo(self.name + '标记式神成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(*pos) self.log.writeinfo(self.name + '标记式神') time.sleep(0.4) self.log.writewarning(self.name + '标记式神失败') def click_monster(self): # 点击怪物 pass def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.5, appear=True): ''' 在某一时间段内,后台点击鼠标,直到出现某一图片出现或消失 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :appear: 图片出现或消失:Ture-出现;False-消失 :return: 成功返回True, 失败退出游戏 ''' # 在指定时间内反复监测画面并点击 start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: result = self.yys.find_game_img(img_path) if not appear: result = not result if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) self.log.writeinfo(self.name + '点击 ' + tag) time.sleep(step_time) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) self.yys.quit_game() def activate(self): self.log.writewarning(self.name + '启动脚本') self.run = True self.yys.run = True def deactivate(self): self.log.writewarning(self.name + '手动停止脚本') self.run = False self.yys.run = False def slide_x_scene(self, distance): ''' 水平滑动场景 :return: 成功返回True; 失败返回False ''' x0 = random.randint(distance + 10, 1126) x1 = x0 - distance y0 = random.randint(436, 486) y1 = random.randint(436, 486) self.yys.mouse_drag_bg((x0, y0), (x1, y1)) logging.info(self.name + '水平滑动界面') def get_scene(self): ''' 识别当前场景 :return: 返回场景名称:1-庭院; 2-探索界面; 3-章节界面; 4-探索内 ''' # 拒绝悬赏 self.yys.rejectbounty() # 分别识别庭院、探索、章节页、探索内 maxVal, maxLoc = self.yys.find_multi_img( 'img/JIA-CHENG.png', 'img/JUE-XING.png', 'img/TAN-SUO.png', 'img/YING-BING.png') scene_cof = max(maxVal) if scene_cof > 0.97: scene = maxVal.index(scene_cof) return scene + 1 else: return 0 def switch_to_scene(self, scene): ''' 切换场景 :param scene: 需要切换到的场景:1-庭院; 2-探索界面; 3-章节界面; 4-探索内 :return: 切换成功返回True;切换失败直接退出 ''' scene_now = self.get_scene() logging.info(self.name + '目前场景:' + str(scene_now)) if scene_now == scene: return True if scene_now == 1: # 庭院中 if scene == 2 or scene == 3 or scene == 4: # 先将界面划到最右边 self.slide_x_scene(800) time.sleep(2) self.slide_x_scene(800) # 点击探索灯笼进入探索界面 self.click_until('探索灯笼', 'img/JUE-XING.png', * TansuoPos.tansuo_denglong, 2) # 递归 self.switch_to_scene(scene) if scene_now == 2: # 探索界面 if scene == 3 or scene == 4: # 点击最后章节 self.click_until('最后章节', 'img/TAN-SUO.png', *TansuoPos.last_chapter, 2) # 递归 self.switch_to_scene(scene) if scene_now == 3: # 章节界面 if scene == 4: # 点击探索按钮 self.click_until('探索按钮', 'img/YING-BING.png', *TansuoPos.tansuo_btn, 2) # 递归 self.switch_to_scene(scene) if scene_now == 4: # 探索内 if scene == 3: # 点击退出探索 self.click_until('退出按钮', 'img\\QUE-REN.png', *TansuoPos.quit_btn, 2) # 点击确认 self.click_until('确认按钮', 'img\\QUE-REN.png', *TansuoPos.confirm_btn, 2, False) # 递归 self.switch_to_scene(scene)
class Fighter: def __init__(self, name='', emyc=0, hwnd=0): ''' 初始化 :param name='': 打手名称 : param emyc=0: 点怪设置:0-不点怪 : param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 ''' # 初始参数 self.emyc = emyc self.name = name self.run = True self.run_time = time.time() # 读取配置文件 conf = configparser.ConfigParser() conf.read('conf.ini') quit_game_enable = conf.getboolean('watchdog', 'watchdog_enable') self.max_op_time = conf.getint('watchdog', 'max_op_time') self.max_win_time = conf.getint('watchdog', 'max_win_time') self.quit_time = conf.getint('watchdog', 'quit_time') self.team = conf.getboolean('others', 'team') self.team_id = conf.getint('others', 'team_id') self.monster = conf.getboolean('others', 'monster') # 启动日志 self.log = WriteLog() # 绑定窗口 if hwnd == 0: hwnd = win32gui.FindWindow(0, u'阴阳师-网易游戏') self.yys = GameControl(hwnd, quit_game_enable) self.log.writeinfo(self.name + '绑定窗口成功') self.log.writeinfo(self.name + str(hwnd)) # 激活窗口 self.yys.activate_window() self.log.writeinfo(self.name + '激活窗口成功') time.sleep(0.5) # 自检 debug_enable = conf.getboolean('others', 'debug_enable') if debug_enable: task = threading.Thread(target=self.yys.debug) task.start() def check_battle(self): # 检测是否进入战斗 self.log.writeinfo(self.name + '检测是否进入战斗') self.yys.wait_game_img('img\\ZI-DONG.png', self.max_win_time) self.log.writeinfo(self.name + '已进入战斗') def check_end(self): # 检测是否打完 self.log.writeinfo(self.name + '检测是战斗是否结束') self.yys.wait_game_img('img\\JIE-SU.png', self.max_win_time, 0.8) self.log.writeinfo(self.name + "战斗结束") def click_monster(self): # 点击怪物 pass def click_team(self, mode=1, number=0): """ 标记式神 :param mode 标记场景类型 1:御魂 2: 突破 """ # 标记式神 num = 0 if number > 0: num = number if self.team and self.team_id > 0: num = self.team_id if num > 0: # 100 1040 # 125 50 if mode == 1: # 御魂场景获取标记位置 min = (num - 1) * 105 + (num - 1) * 100 + 95 max = min + 50 pos = (min, 355), (max, 425) elif mode == 2: # 突破场景获取标记位置 pos = { 1: ((79, 385), (142, 418)), 2: ((315, 335), (360, 358)), 3: ((523, 270), (570, 325)), 4: ((715, 340), (750, 380)), 5: ((955, 400), (1055, 430)), }.get(num) start_time = time.time() while time.time() - start_time <= 3 and self.run: x1 = pos[0][0] - 100 y1 = pos[0][1] - 250 x2 = pos[1][0] + 100 y2 = pos[1][1] exp_pos = self.yys.find_color(((x1, y1), (x2, y2)), (134, 227, 96), 5) # print('颜色位置', exp_pos) if exp_pos != -1: self.log.writeinfo(self.name + ' 标记式神成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(*pos) self.log.writeinfo(self.name + '标记式神') time.sleep(0.4) self.log.writewarning(self.name + '标记式神失败') def click_until_multi(self, tag, *img_path, pos, pos_end=None, sleep_time=0.5): ''' 在某一时间段内,后台点击鼠标,直到出现某些图片出现 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :return: 成功返回True, 失败退出游戏 ''' start_time = time.time() while time.time() - start_time <= self.max_op_time and self.run: result = self.yys.find_multi_game_img(*img_path) if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) self.log.writeinfo(self.name + '点击 ' + tag) time.sleep(sleep_time) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) self.yys.quit_game() def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.5, appear=True): ''' 在某一时间段内,后台点击鼠标,直到出现某一图片出现或消失 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :appear: 图片出现或消失:Ture-出现;False-消失 :return: 成功返回True, 失败退出游戏 ''' # 在指定时间内反复监测画面并点击 start_time = time.time() self.log.writeinfo(self.name + '点击 ' + tag) while time.time() - start_time <= self.max_op_time and self.run: result = self.yys.find_game_img(img_path) if not appear: result = not result if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 # print("点击") self.yys.mouse_click_bg(pos, pos_end) # self.log.writeinfo(self.name + '点击 ' + tag) time.sleep(step_time) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') return False # 提醒玩家点击失败,并在5s后退出 # self.yys.activate_window() # time.sleep(5) # self.yys.quit_game() def activate(self): self.log.writewarning(self.name + '启动脚本') self.run = True self.yys.run = True def deactivate(self): self.log.writewarning(self.name + '手动停止脚本') self.run = False self.yys.run = False def slide_x_scene(self, distance): ''' 水平滑动场景 :return: 成功返回True; 失败返回False ''' x0 = random.randint(distance + 10, 1126) x1 = x0 - distance y0 = random.randint(436, 486) y1 = random.randint(436, 486) self.yys.mouse_drag_bg((x0, y0), (x1, y1)) logging.info(self.name + '水平滑动界面') def get_scene(self): ''' 识别当前场景 :return: 返回场景名称:1-庭院; 2-探索界面; 3-章节界面; 4-探索内 ''' # 拒绝悬赏 self.yys.rejectbounty() # 分别识别庭院、探索、章节页、探索内 maxVal, maxLoc = self.yys.find_multi_img('img/JIA-CHENG.png', 'img/JUE-XING.png', 'img/TAN-SUO.png', 'img/YING-BING.png') scene_cof = max(maxVal) if scene_cof > 0.97: scene = maxVal.index(scene_cof) return scene + 1 else: return 0 def switch_to_scene(self, scene): ''' 切换场景 :param scene: 需要切换到的场景:1-庭院; 2-探索界面; 3-章节界面; 4-探索内 :return: 切换成功返回True;切换失败直接退出 ''' scene_now = self.get_scene() logging.info(self.name + '目前场景:' + str(scene_now)) if scene_now == scene: return True if scene_now == 1: # 庭院中 if scene == 2 or scene == 3 or scene == 4: # 先将界面划到最右边 self.slide_x_scene(800) time.sleep(2) self.slide_x_scene(800) # 点击探索灯笼进入探索界面 self.click_until('探索灯笼', 'img/JUE-XING.png', *TansuoPos.tansuo_denglong, 2) # 递归 self.switch_to_scene(scene) if scene_now == 2: # 探索界面 if scene == 3 or scene == 4: # 点击最后章节 self.click_until('最后章节', 'img/TAN-SUO.png', *TansuoPos.last_chapter, 2) # 递归 self.switch_to_scene(scene) if scene_now == 3: # 章节界面 if scene == 4: # 点击探索按钮 self.click_until('探索按钮', 'img/YING-BING.png', *TansuoPos.tansuo_btn, 2) # 递归 self.switch_to_scene(scene) if scene_now == 4: # 探索内 if scene == 3: # 点击退出探索 self.click_until('退出按钮', 'img\\QUE-REN.png', *TansuoPos.quit_btn, 2) # 点击确认 self.click_until('确认按钮', 'img\\QUE-REN.png', *TansuoPos.confirm_btn, 2, False) # 递归 self.switch_to_scene(scene) def check_quit_game(self): if self.quit_time > 0: if time.time() - self.run_time > self.quit_time: # 切换到庭院 is_home = False while not is_home: maxVal, maxLoc = self.yys.find_img('img/JIA-CHENG.png') print("加成", maxVal) if maxVal > 0.9: is_home = True continue # 检查关闭 if self.yys.mouse_click_img('img/close.png'): time.sleep(0.3) # 检查返回 if self.yys.mouse_click_img('img/back.png'): time.sleep(0.5) # 检查确认 if self.yys.mouse_click_img('img/que-ding.png'): time.sleep(0.3) # 关闭加成 is_jiacheng = True self.click_until('加成', 'img/yu-hun-jia-cheng.png', *CommonPos.jia_cheng_btn, 0.3) while is_jiacheng: pos = self.yys.find_many_game_img('img/on-jia-cheng.png') print(pos) if len(pos) <= 0: is_jiacheng = False else: for item in pos: pos1 = (item[0] + 8, item[1] + 3) pos2 = (item[0] + 60, item[1] + 15) print(pos1, pos2) self.yys.mouse_click_bg(pos1, pos2) mood1 = ut.Mood(1) mood1.moodsleep() self.yys.quit_true_game()
class Fighter(GameScene): def __init__(self, name='', emyc=0, hwnd=0): ''' 初始化 :param name='': 打手名称 : param emyc=0: 点怪设置:0-不点怪 : param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 ''' # 初始参数 self.emyc = emyc self.name = name self.run = True # 读取配置文件 conf = configparser.ConfigParser() conf.read('conf.ini') quit_game_enable = conf.getboolean('watchdog', 'watchdog_enable') self.max_op_time = conf.getint('watchdog', 'max_op_time') self.max_win_time = conf.getint('watchdog', 'max_win_time') self.mitama_team_mark = conf.getint('mitama', 'mitama_team_mark') self.max_times = conf.getint('DEFAULT', 'max_times') self.end_operation = conf.getint('DEFAULT', 'end_operation') self.run_times = 0 # 启动日志 self.log = WriteLog() # 绑定窗口 if hwnd == 0: hwnd = win32gui.FindWindow(0, u'阴阳师-网易游戏') self.yys = GameControl(hwnd, quit_game_enable) self.log.writeinfo(self.name + '绑定窗口成功') self.log.writeinfo(self.name + str(hwnd)) # 激活窗口 self.yys.activate_window() self.log.writeinfo(self.name + '激活窗口成功') time.sleep(0.5) # 绑定场景 # 自检 debug_enable = conf.getboolean('others', 'debug_enable') if debug_enable: task = threading.Thread(target=self.yys.debug) task.start() def check_battle(self): # 检测是否进入战斗 self.log.writeinfo(self.name + '检测是否进入战斗') self.yys.wait_game_img('img\\ZI-DONG.png', self.max_win_time) self.log.writeinfo(self.name + '已进入战斗') def check_end(self): ''' 检测是否打完 :return: 胜利页面返回0;奖励页面返回1 ''' self.log.writeinfo(self.name + '检测是战斗是否结束') if self.yys.wait_game_img_knn('img/SHENG-LI.png', self.max_win_time, False, 8): logging.info('战斗成功') return 0 elif self.yys.wait_game_img_knn('img/TIAO-DAN.png', 2, thread=20): logging.info('本轮战斗结束') return 1 def check_times(self): ''' 监测游戏次数是否达到最大次数 ''' self.run_times = self.run_times + 1 logging.info('游戏已运行'+str(self.run_times)+'次') if(self.run_times == self.max_times): if(self.end_operation == 0): logging.warning('关闭脚本(次数已满)...') self.run = False os._exit(0) elif(self.end_operation == 1): logging.warning('关闭游戏(次数已满)...') self.yys.quit_game() logging.warning('关闭脚本(次数已满)...') self.run = False os._exit(0) def get_reward(self, mood, state): ''' 结算处理 :param mood: 状态函数 :param state: 上一步的状态。0-战斗成功页面; 1-领取奖励页面 ''' if state == 0: self.click_until_knn('奖励', 'img/TIAO-DAN.png', ut.firstposition(), None, mood.get1mood()/1000, thread=20) start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: result = self.yys.find_game_img_knn('img/TIAO-DAN.png', thread=2) if not result: logging.info(self.name + '结算成功') return else: self.yys.mouse_click_bg(ut.secondposition()) self.log.writeinfo(self.name + '点击结算') mood.moodsleep() self.log.writewarning(self.name + '点击结算失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) self.yys.quit_game() def mitama_team_click(self): ''' 御魂标记己方式神 ''' num = self.mitama_team_mark if num > 0: # 100 1040 # 125 50 # 御魂场景获取标记位置 min = (num - 1) * 105 + (num - 1) * 100 + 95 max = min + 50 pos = (min, 355), (max, 425) start_time = time.time() while time.time() - start_time <= 3: x1 = pos[0][0] - 100 y1 = pos[0][1] - 250 x2 = pos[1][0] + 100 y2 = pos[1][1] exp_pos = self.yys.find_color( ((x1, y1), (x2, y2)), (134, 227, 96), 5) # print('颜色位置', exp_pos) if exp_pos != -1: self.log.writeinfo(self.name + '标记式神成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(*pos) self.log.writeinfo(self.name + '标记式神') time.sleep(0.4) self.log.writewarning(self.name + '标记式神失败') def click_monster(self): # 点击怪物 pass def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.5, appear=True): ''' 在某一时间段内,后台点击鼠标,直到出现某一图片出现或消失 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :appear: 图片出现或消失:Ture-出现;False-消失 :return: 成功返回True, 失败退出游戏 ''' # 在指定时间内反复监测画面并点击 start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: result = self.yys.find_game_img(img_path) if not appear: result = not result if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) self.log.writeinfo(self.name + '点击 ' + tag) ut.mysleep(step_time*1000) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) self.yys.quit_game() def click_until_knn(self, tag, img_path, pos, pos_end=None, step_time=0.5, appear=True, thread=0): ''' 在某一时间段内,后台点击鼠标,直到出现某一图片出现或消失 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :appear: 图片出现或消失:Ture-出现;False-消失 :thread: 检测阈值 :return: 成功返回True, 失败退出游戏 ''' # 在指定时间内反复监测画面并点击 start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: result = self.yys.find_game_img_knn(img_path, thread=thread) if not appear: result = not result if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) self.log.writeinfo(self.name + '点击 ' + tag) ut.mysleep(step_time*1000) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) self.yys.quit_game() def activate(self): self.log.writewarning(self.name + '启动脚本') self.run = True self.yys.run = True def deactivate(self): self.log.writewarning(self.name + '手动停止脚本') self.run = False self.yys.run = False def slide_x_scene(self, distance): ''' 水平滑动场景 :return: 成功返回True; 失败返回False ''' x0 = random.randint(distance + 10, 1126) x1 = x0 - distance y0 = random.randint(436, 486) y1 = random.randint(436, 486) self.yys.mouse_drag_bg((x0, y0), (x1, y1)) logging.info(self.name + '水平滑动界面')
class Fighter: def __init__(self, name='', emyc=0, hwnd=0): ''' 初始化 :param name='': 打手名称 : param emyc=0: 点怪设置:0-不点怪 : param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 ''' # 初始参数 self.emyc = emyc self.name = name self.run = True # 读取配置文件 conf = configparser.ConfigParser() conf.read('conf.ini') quit_game_enable = conf.getboolean('watchdog', 'watchdog_enable') self.max_op_time = conf.getint('watchdog', 'max_op_time') self.max_win_time = conf.getint('watchdog', 'max_win_time') # 启动日志 self.log = WriteLog() # 绑定窗口 if hwnd == 0: hwnd = win32gui.FindWindow(0, u'阴阳师-网易游戏') self.yys = GameControl(hwnd, quit_game_enable) self.log.writeinfo(self.name + '绑定窗口成功') self.log.writeinfo(self.name + str(hwnd)) # 激活窗口 self.yys.activate_window() self.log.writeinfo(self.name + '激活窗口成功') time.sleep(0.5) def check_battle(self): # 检测是否进入战斗 self.log.writeinfo(self.name + '检测是否进入战斗') self.yys.wait_game_img('img\\ZI-DONG.png', self.max_win_time) self.log.writeinfo(self.name + '已进入战斗') def check_end(self): # 检测是否打完 self.log.writeinfo(self.name + '检测是战斗是否结束') self.yys.wait_game_img('img\\JIE-SU.png', self.max_win_time) self.log.writeinfo(self.name + "战斗结束") def click_monster(self): # 点击怪物 pass def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.5): ''' 在某一时间段内,后台点击鼠标,直到出现某一图片出现 :param tag: 按键名 :param img_path: 图片路径 :param pos: (x,y) 鼠标单击的坐标 :param pos_end=None: (x,y) 若pos_end不为空,则鼠标单击以pos为左上角坐标pos_end为右下角坐标的区域内的随机位置 :step_time=0.5: 查询间隔 :return: 成功返回True, 失败退出游戏 ''' # 在指定时间内反复监测画面并点击 start_time = time.time() while time.time() - start_time <= self.max_op_time and self.run: result = self.yys.find_game_img(img_path) if result: self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) self.log.writeinfo(self.name + '点击 ' + tag) time.sleep(step_time) self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) self.yys.quit_game() def activate(self): self.log.writewarning(self.name + '启动脚本') self.run = True self.yys.run = True def deactivate(self): self.log.writewarning(self.name + '手动停止脚本') self.run = False self.yys.run = False
# 司机 fight = DriverFighter() fight.start() if mode == 3: # 乘客 fight = FighterPassenger() fight.start() def tansuo(): '''探索战斗''' fight = ExploreFight() fight.start() if __name__ == "__main__": log.writeinfo('python version: %s', sys.version) try: # 检测管理员权限 if is_admin(): # 注册插件,获取权限 log.writeinfo('UAC pass') # 设置战斗参数 init() # 开始战斗 if section == 0: yuhun() elif section == 1: tansuo()