diff --git a/CHANGELOG.md b/CHANGELOG.md index 64ada10..5f0c03d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## v1.0.1.0229 +#### New features: +* 增加了更详细的调试信息显示。 +#### Fixes (bugs & defects): +* 进一步提高了结算可靠性。 +* 进一步提高了结算速度。 + ## v1.0.1.0227 #### New features: * 新增对MuMu模拟器的支持。 diff --git a/gameLib/fighter.py b/gameLib/fighter.py index 1d23fa4..7ca3fd9 100644 --- a/gameLib/fighter.py +++ b/gameLib/fighter.py @@ -78,18 +78,20 @@ def check_end(self): 检测是否打完 :return: 胜利页面返回0;奖励页面返回1 ''' + self.yys.rejectbounty() self.log.writeinfo(self.name + '检测是战斗是否结束') start_time = time.time() while time.time()-start_time <= self.max_win_time and self.run: maxVal, maxLoc = self.yys.find_multi_img( - 'img/SHENG-LI.png', 'img/TIAO-DAN.png', 'img/JIN-BI.png') + 'img/SHENG-LI.png', 'img/TIAO-DAN.png', 'img/JIN-BI.png', 'img/JIE-SU.png') end_cof = max(maxVal) if end_cof > 0.9: myend = maxVal.index(end_cof) break - ut.mysleep(800) - if myend in [0]: + time.sleep(0.5) + if myend in [0, 3]: logging.info(self.name + '战斗成功') + self.yys.mouse_click_bg(*ut.firstposition()) return 0 elif myend in [1, 2]: logging.info(self.name + '本轮战斗结束') @@ -120,12 +122,14 @@ def get_reward(self, mood, state): :param state: 上一步的状态。0-战斗成功页面; 1-领取奖励页面 ''' if state == 0: - self.click_until('奖励', 'img/TIAO-DAN.png', - ut.firstposition(), None, mood.get1mood()/1000) + self.click_until('奖励', 'img/TIAO-DAN.png', * + ut.firstposition(), mood.get1mood()/1000) + mood.moodsleep() + self.yys.mouse_click_bg(ut.secondposition()) start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: maxVal, maxLoc = self.yys.find_multi_img( - 'img/FA-SONG-XIAO-XI.png', 'img/ZHI-LIAO-LIANG.png', 'JIE-SUAN-JIA-CHENG.png') + 'img/FA-SONG-XIAO-XI.png', 'img/ZHI-LIAO-LIANG.png', 'img/JIE-SUAN-JIA-CHENG.png') if max(maxVal) > 0.9: self.yys.mouse_click_bg((35, 295), (140, 475)) result = self.yys.find_game_img_knn('img/TIAO-DAN.png', thread=2) diff --git a/gameLib/game_ctl.py b/gameLib/game_ctl.py index d125c00..09ca273 100644 --- a/gameLib/game_ctl.py +++ b/gameLib/game_ctl.py @@ -5,6 +5,7 @@ import os import sys import time +import traceback import random import cv2 import numpy as np @@ -76,8 +77,10 @@ def window_full_shot(self, file_name=None, gray=0): return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR) else: return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY) - except: - pass + except Exception: + logging.warning('window_full_shot执行失败') + a = traceback.format_exc() + logging.warning(a) def window_part_shot(self, pos1, pos2, file_name=None, gray=0): """ @@ -143,7 +146,10 @@ def find_color(self, region, color, tolerance=0): r2, g2, b2 = pixel[:3] if abs(r1-r2) <= tolerance and abs(g1-g2) <= tolerance and abs(b1-b2) <= tolerance: return x+region[0][0], y+region[0][1] - except: + except Exception: + logging.warning('find_color执行失败') + a = traceback.format_exc() + logging.warning(a) return -1 return -1 @@ -193,7 +199,10 @@ def find_img(self, img_template_path, part=0, pos1=None, pos2=None, gray=0): minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res) # print(maxLoc) return maxVal, maxLoc - except: + except Exception: + logging.warning('find_img执行失败') + a = traceback.format_exc() + logging.warning(a) return 0, 0 def find_img_knn(self, img_template_path, part=0, pos1=None, pos2=None, gray=0, thread=0): @@ -224,7 +233,10 @@ def find_img_knn(self, img_template_path, part=0, pos1=None, pos2=None, gray=0, maxLoc = match_img_knn(img_template, img_src, thread) # print(maxLoc) return maxLoc - except: + except Exception: + logging.warning('find_img_knn执行失败') + a = traceback.format_exc() + logging.warning(a) return -1 def find_multi_img(self, *img_template_path, part=0, pos1=None, pos2=None, gray=0): @@ -260,7 +272,10 @@ def find_multi_img(self, *img_template_path, part=0, pos1=None, pos2=None, gray= minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res) maxVal_list.append(maxVal) maxLoc_list.append(maxLoc) - except: + except Exception: + logging.warning('find_multi_img执行失败') + a = traceback.format_exc() + logging.warning(a) maxVal_list.append(0) maxLoc_list.append(0) # 返回列表 @@ -450,13 +465,13 @@ def quit_game(self): if not self.run: return False if self.quit_game_enable: - logging.info('退出游戏,最后显示已保存至/img/full.png') if self.client == 0: win32gui.SendMessage( self.hwnd, win32con.WM_DESTROY, 0, 0) # 退出游戏 else: os.system( 'adb shell am force-stop com.netease.onmyoji.netease_simulator') + logging.info('退出,最后显示已保存至/img/full.png') sys.exit(0) def takescreenshot(self): diff --git a/gui/tkui.py b/gui/tkui.py index a2af4c8..0b2cc19 100644 --- a/gui/tkui.py +++ b/gui/tkui.py @@ -77,10 +77,15 @@ def create_menubar(self): # 创建菜单项 menu1 = tk.Menu(menubar, tearoff=0) - menu1.add_command(label='About', command=self.say_hi) + menu1.add_command(label='关于', command=self.say_hi) # 链接 - menubar.add_cascade(label="File", menu=menu1) + menubar.add_cascade(label="文件", menu=menu1) + + # 高级选项 + menu2 = tk.Menu(menubar, tearoff=0) + menubar.add_cascade(label="高级", menu=menu2) + menu2.add_command(label='自定义延迟', command=self.delay_dialog) # 设置 self.master.config(menu=menubar) @@ -107,7 +112,7 @@ def create_client(self): self.client.pack(fill=tk.X, padx=2, pady=2) self.client.current(0) self.client.config(state='readonly') - + def create_section(self): ''' 创建主选项卡 @@ -280,7 +285,7 @@ def create_command(self): def show_params(self): self.params.config(state=tk.NORMAL) - self.params.insert(tk.END, '########1.0.1.0228########\n') + self.params.insert(tk.END, '########1.0.1.0229########\n') self.params.insert(tk.END, 'client: ' + str(self.client.current())) self.params.insert(tk.END, '\nrun_section: ' + str(self.section.index('current'))) @@ -319,12 +324,66 @@ def say_hi(self): tk.messagebox.showinfo( "OnmyojiBot", '网址:https://github.com/AcademicDog/onmyoji_bot\n\n交流Q群:592055060') + def delay_dialog(self): + pw = DelayDialog(self) + self.wait_window(pw) + def start_onmyoji(self): self.show_params() def stop_onmyoji(self): pass +class DelayDialog(tk.Toplevel): + def __init__(self, parent): + super().__init__() + self.title('延迟设置') + self.parent = parent + + # 延迟机制 + row1 = tk.Frame(self) + row1.pack(fill=tk.X) + tk.Label(row1, text='延迟机制:').pack(anchor=tk.W) + text = tk.Text(row1, height=8, width=40) + text.pack(expand=True, fill=tk.BOTH) + text.insert(tk.INSERT, '1-总共5级延迟,脚本随机从1-5级延迟中选择一级作为主延迟,\ +同时在1-3级延迟中选择一级作为副延迟。\n\n') + text.insert(tk.INSERT, '2-每5分钟刷新选择,计算单位毫秒。\n\n') + text.insert(tk.END, '3-主延迟用于截图、识图等一般操作的延迟,副延迟主要用于结算。\n\n') + text.config(state=tk.DISABLED) + + # 参数设置 + row2 = tk.Frame(self) + row2.pack(fill=tk.X) + tk.Label(row2, text='一级: ').grid(row=0, column=0) + tk.Label(row2, text='最低').grid(row=0, column=1) + tk.Entry(row2, width=7).grid(row=0, column=3) + tk.Label(row2, text='最高').grid(row=0, column=4) + tk.Entry(row2, width=7).grid(row=0, column=5) + + tk.Label(row2, text='二级: ').grid(row=2, column=0) + tk.Label(row2, text='最低').grid(row=2, column=1) + tk.Entry(row2, width=7).grid(row=2, column=3) + tk.Label(row2, text='最高').grid(row=2, column=4) + tk.Entry(row2, width=7).grid(row=2, column=5) + + tk.Label(row2, text='三级: ').grid(row=3, column=0) + tk.Label(row2, text='最低').grid(row=3, column=1) + tk.Entry(row2, width=7).grid(row=3, column=3) + tk.Label(row2, text='最高').grid(row=3, column=4) + tk.Entry(row2, width=7).grid(row=3, column=5) + + tk.Label(row2, text='四级: ').grid(row=4, column=0) + tk.Label(row2, text='最低').grid(row=4, column=1) + tk.Entry(row2, width=7).grid(row=4, column=3) + tk.Label(row2, text='最高').grid(row=4, column=4) + tk.Entry(row2, width=7).grid(row=4, column=5) + + tk.Label(row2, text='五级: ').grid(row=5, column=0) + tk.Label(row2, text='最低').grid(row=5, column=1) + tk.Entry(row2, width=7).grid(row=5, column=3) + tk.Label(row2, text='最高').grid(row=5, column=4) + tk.Entry(row2, width=7).grid(row=5, column=5) if __name__ == "__main__": root = tk.Tk() diff --git a/img/JIE-SUAN-JIA-CHENG.png b/img/JIE-SUAN-JIA-CHENG.png index 3598ff9..155bfc3 100644 Binary files a/img/JIE-SUAN-JIA-CHENG.png and b/img/JIE-SUAN-JIA-CHENG.png differ diff --git a/mitama/single_fight.py b/mitama/single_fight.py index 9d42b94..51fede4 100644 --- a/mitama/single_fight.py +++ b/mitama/single_fight.py @@ -34,6 +34,7 @@ def start(self): self.yys.wait_game_img_knn( 'img\\TIAO-ZHAN.png', max_time=self.max_win_time, thread=20) mood1.moodsleep() + self.yys.mouse_click_bg(*YuhunPos.tiaozhan_btn) self.click_until_knn('挑战按钮', 'img\\TIAO-ZHAN.png', *YuhunPos.tiaozhan_btn, appear=False, thread=20) diff --git a/requirements.txt b/requirements.txt index e926cf3..4603c20 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ numpy==1.17.1 pywin32==224 opencv_python==4.1.0.25 Pillow==6.1.0 +opencv_contrib_python==3.4.2.16 \ No newline at end of file diff --git a/tools/utilities.py b/tools/utilities.py index 0d275db..31764c2 100644 --- a/tools/utilities.py +++ b/tools/utilities.py @@ -49,14 +49,12 @@ def firstposition(): 获得点击位置,扣除御魂部分 :return: 返回随机位置坐标 ''' - w = 1136 - h = 640 - while True: - position = (random.randint(0, w), random.randint(50, h)) - if position[0] < 332 or position[0] > 931: - return position - elif position[1] < 350 or position[1] > 462: - return position + safe_area = { + 1: ((20, 106), (211, 552)), + 2: ((931, 60), (1120, 620))} + + index = random.randint(1, 2) + return safe_area[index] def secondposition(): diff --git a/ui.py b/ui.py index 1a24212..b6c8ede 100644 --- a/ui.py +++ b/ui.py @@ -85,7 +85,7 @@ def start_onmyoji(self): # 显示参数 self.show_params() - subprocess.Popen("cmd.exe /c start onmyoji.exe") + subprocess.Popen("cmd.exe /c start Core.exe") # os.system("onmyoji.exe") def stop_onmyoji(self):