diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8e3d9..8bf0569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +## v1.0.1.0307 +#### Fixes (bugs & defects): +* 双开探索时,队长退出后等待1s再邀请队员。 +* 重写了日志系统,使之更规范合理。 +* 修复了双开御魂乘客、司机争相标记。 +* 优化了最后截图保存,现在最后运行截图将会以时间作为文件名,而不是统一的full.png。 +* 调整了UI菜单栏,增加了向说明页面的导向,添加donate按钮。 +* 修复了探索打完BOSS后,没有宝箱使得无法有效退出的问题。 + ## v1.0.1.0304 #### New features: * 探索双开 diff --git a/explore/explore.py b/explore/explore.py index 8dc048e..d074ebf 100644 --- a/explore/explore.py +++ b/explore/explore.py @@ -189,7 +189,7 @@ def fight_moster(self, mood1, mood2): mood1.moodsleep() # 查看是否进入探索界面 self.yys.wait_game_img('img\\YING-BING.png') - self.log.writeinfo('进入探索页面') + self.log.info('进入探索页面') # 寻找经验怪,未找到则寻找boss,再未找到则退出 fight_pos = self.find_exp_moster() @@ -199,19 +199,19 @@ def fight_moster(self, mood1, mood2): fight_pos = self.find_boss() boss = True if fight_pos == -1: - self.log.writeinfo('未找到经验怪和boss') + self.log.info('未找到经验怪和boss') return -2 else: - self.log.writeinfo('未找到经验怪') + self.log.info('未找到经验怪') return -1 # 攻击怪 self.click_until('怪', 'img/YING-BING.png', fight_pos, step_time=0.3, appear=False) - self.log.writeinfo('已进入战斗') + self.log.info('已进入战斗') # 等待式神准备 self.yys.wait_game_img_knn('img\\ZHUN-BEI.png', thread=30) - logging.info('式神准备完成') + self.log.info('式神准备完成') # 检查狗粮经验 self.check_exp_full() @@ -250,16 +250,15 @@ def start(self): if result == 1: continue elif result == 2: - time.sleep(1) break else: - self.log.writeinfo('移动至下一个场景') + self.log.info('移动至下一个场景') self.next_scene() i += 1 # 退出探索 self.switch_to_scene(3) - self.log.writeinfo('结束本轮探索') + self.log.info('结束本轮探索') time.sleep(0.5) # 检查游戏次数 diff --git a/explore/explore_dual.py b/explore/explore_dual.py index 5907a17..8e9a28e 100644 --- a/explore/explore_dual.py +++ b/explore/explore_dual.py @@ -39,7 +39,7 @@ def __init__(self): for hwnd in hwndlist: yys = GameControl(hwnd) if yys.find_game_img('img/DUI.png', 1, (68, 242), (135, 306), thread=0.8): - self.driver = ExploreLeader(hwnd=hwnd) + self.driver = ExploreLeader(hwnd=hwnd, delay=True) hwndlist.remove(hwnd) logging.info('发现队长') break diff --git a/explore/explore_leader.py b/explore/explore_leader.py index 90a03ea..b03c764 100644 --- a/explore/explore_leader.py +++ b/explore/explore_leader.py @@ -1,8 +1,8 @@ from explore.explore import ExploreFight from tools.game_pos import TansuoPos import tools.utilities as ut +from tools.logsystem import MyLog -import logging import random import time @@ -12,12 +12,16 @@ class ExploreLeader(ExploreFight): 组队探索队长 ''' - def __init__(self, hwnd=0): + def __init__(self, hwnd=0, delay=False): ''' 初始化 + :param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 + :param mode=0: 狗粮模式:0-正常模式,1-组队后排狗粮 + :param delay=False: 完成一轮探索后,是否等待1s再邀请下一轮 ''' ExploreFight.__init__(self, hwnd=hwnd, mode=1) - self.name = 'Leader: ' + self.delay = delay + self.log = MyLog.dlogger def prev_scene(self): ''' @@ -38,9 +42,9 @@ def start(self): mood3 = ut.Mood() scene = self.get_scene() if scene == 4: - logging.info('Leader: 已进入探索,就绪') + self.log.info('已进入探索,就绪') else: - logging.warning('Leader: 请检查是否进入探索内,退出') + self.log.warning('请检查是否进入探索内,退出') return while self.run: @@ -49,7 +53,7 @@ def start(self): 'img/DUI.png', 'img/YING-BING.png') if maxVal_list[0] < 0.8 and maxVal_list[1] > 0.8: # 队长退出,结束 - logging.warning('Leader: 队员已退出,脚本结束') + self.log.warning('队员已退出,脚本结束') self.yys.quit_game() # 开始打怪 @@ -65,7 +69,7 @@ def start(self): elif result == 2: break else: - self.log.writeinfo('Leader: 移动至下一个场景') + self.log.info('移动至下一个场景') self.next_scene() i += 1 @@ -77,11 +81,11 @@ def start(self): fight_pos = self.yys.find_game_img('img/FIGHT.png') # 攻击怪 self.yys.mouse_click_bg(fight_pos) - self.log.writeinfo('Leader: 已进入战斗') + self.log.info('已进入战斗') # 等待式神准备 self.yys.wait_game_img_knn('img/ZHUN-BEI.png', thread=30) - logging.info('Leader: 式神准备完成') + self.log.info('式神准备完成') # 检查狗粮经验 self.check_exp_full() @@ -98,7 +102,7 @@ def start(self): self.get_reward(mood2, state) # 退出探索 - self.log.writeinfo('Leader: 结束本轮探索') + self.log.info('结束本轮探索') # 点击退出探索 self.click_until('退出按钮', 'img/QUE-REN.png', *TansuoPos.quit_btn, 2) @@ -106,6 +110,10 @@ def start(self): self.click_until('确认按钮', 'img/QUE-REN.png', *TansuoPos.confirm_btn, 2, False) + # 等待司机退出1s + if self.delay: + time.sleep(1) + # 下一轮自动邀请 self.yys.wait_game_img('img/QUE-DING.png', self.max_win_time) time.sleep(0.5) diff --git a/explore/explore_passenger.py b/explore/explore_passenger.py index 92fae07..fff42fe 100644 --- a/explore/explore_passenger.py +++ b/explore/explore_passenger.py @@ -1,8 +1,8 @@ from explore.explore import ExploreFight from tools.game_pos import TansuoPos +from tools.logsystem import MyLog import tools.utilities as ut -import logging import time @@ -16,7 +16,7 @@ def __init__(self, hwnd=0): 初始化 ''' ExploreFight.__init__(self, hwnd=hwnd) - self.name = 'Passenger: ' + self.log = MyLog.plogger def start(self): ''' @@ -25,19 +25,19 @@ def start(self): mood = ut.Mood(3) scene = self.get_scene() if scene == 4: - logging.info('Passenger: 已进入探索,就绪') + self.log.info('已进入探索,就绪') else: - logging.warning('Passenger: 请检查是否进入探索内,退出') + self.log.warning('请检查是否进入探索内,退出') return while self.run: # 检测当前场景 - maxVal_list, maxLoc_list = self.yys.find_multi_img( + maxVal_list, _ = self.yys.find_multi_img( 'img/DUI.png', 'img/YING-BING.png') # print(maxVal_list) if maxVal_list[0] < 0.8 and maxVal_list[1] > 0.8: # 队长退出,则跟着退出 - logging.info('Passenger: 队长已退出,跟随退出') + self.log.info('队长已退出,跟随退出') self.switch_to_scene(3) # 等待邀请 @@ -47,7 +47,7 @@ def start(self): # 点击接受邀请 if self.yys.find_game_img('img/JIE-SHOU.png'): self.yys.mouse_click_bg((js_loc[0]+33, js_loc[1]+34)) - self.log.writeinfo('Passenger: 接受邀请') + self.log.info('接受邀请') # 检查游戏次数 self.check_times() @@ -55,7 +55,7 @@ def start(self): elif maxVal_list[0] > 0.8 and maxVal_list[1] < 0.8: # 进入战斗,等待式神准备 self.yys.wait_game_img_knn('img/ZHUN-BEI.png', thread=30) - logging.info('Passenger: 式神准备完成') + self.log.info('式神准备完成') # 检查狗粮经验 self.check_exp_full() diff --git a/gameLib/fighter.py b/gameLib/fighter.py index acdde4f..5b71863 100644 --- a/gameLib/fighter.py +++ b/gameLib/fighter.py @@ -1,11 +1,10 @@ from gameLib.game_ctl import GameControl from gameLib.game_scene import GameScene -from tools.logsystem import WriteLog +from tools.logsystem import MyLog from tools.game_pos import TansuoPos, YuhunPos import tools.utilities as ut import configparser -import logging import os import random import threading @@ -15,16 +14,14 @@ class Fighter(GameScene): - def __init__(self, name='', emyc=0, hwnd=0): + def __init__(self, emyc=0, hwnd=0): ''' 初始化 - :param name='': 打手名称 : param emyc=0: 点怪设置:0-不点怪 : param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 ''' # 初始参数 self.emyc = emyc - self.name = name self.run = True # 读取配置文件 @@ -40,7 +37,7 @@ def __init__(self, name='', emyc=0, hwnd=0): self.run_times = 0 # 启动日志 - self.log = WriteLog() + self.log = MyLog.mlogger # 绑定窗口 if hwnd == 0: @@ -51,12 +48,12 @@ def __init__(self, name='', emyc=0, hwnd=0): # TansuoPos.InitPosWithClient__() # YuhunPos.InitPosWithClient__() self.yys = GameControl(hwnd, quit_game_enable) - self.log.writeinfo(self.name + '绑定窗口成功') - self.log.writeinfo(self.name + str(hwnd)) + self.log.info('绑定窗口成功') + self.log.info(str(hwnd)) # 激活窗口 self.yys.activate_window() - self.log.writeinfo(self.name + '激活窗口成功') + self.log.info('激活窗口成功') time.sleep(0.5) # 绑定场景 @@ -69,16 +66,16 @@ def __init__(self, name='', emyc=0, hwnd=0): def check_battle(self): # 检测是否进入战斗 - self.log.writeinfo(self.name + '检测是否进入战斗') + self.log.info('检测是否进入战斗') self.yys.wait_game_img('img\\ZI-DONG.png', self.max_win_time) - self.log.writeinfo(self.name + '已进入战斗') + self.log.info('已进入战斗') def check_end(self): ''' 检测是否打完 :return: 胜利页面返回0;奖励页面返回1 ''' - self.log.writeinfo(self.name + '检测是战斗是否结束') + self.log.info('检测是战斗是否结束') start_time = time.time() myend = -1 while time.time()-start_time <= self.max_win_time and self.run: @@ -93,10 +90,10 @@ def check_end(self): break time.sleep(0.5) if myend in [0, 3]: - logging.info(self.name + '战斗成功') + self.log.info('战斗成功') return 0 elif myend in [1, 2]: - logging.info(self.name + '本轮战斗结束') + self.log.info('本轮战斗结束') return 1 def check_times(self): @@ -104,16 +101,16 @@ def check_times(self): 监测游戏次数是否达到最大次数 ''' self.run_times = self.run_times + 1 - logging.info(self.name + '游戏已运行'+str(self.run_times)+'次') + self.log.info('游戏已运行'+str(self.run_times)+'次') if(self.run_times == self.max_times): if(self.end_operation == 0): - logging.warning(self.name + '关闭脚本(次数已满)...') + self.log.warning('关闭脚本(次数已满)...') self.run = False os._exit(0) elif(self.end_operation == 1): - logging.warning(self.name + '关闭游戏(次数已满)...') + self.log.warning('关闭游戏(次数已满)...') self.yys.quit_game() - logging.warning(self.name + '关闭脚本(次数已满)...') + self.log.warning('关闭脚本(次数已满)...') self.run = False os._exit(0) @@ -127,7 +124,7 @@ def get_reward(self, mood, state): mypos = ut.secondposition() if state == 0: self.yys.mouse_click_bg(mypos) - logging.info(self.name + '点击结算') + self.log.info('点击结算') mood.moodsleep() start_time = time.time() while time.time()-start_time <= self.max_op_time and self.run: @@ -143,7 +140,7 @@ def get_reward(self, mood, state): # 点击一次结算 self.yys.mouse_click_bg(mypos) - logging.info(self.name + '点击结算') + self.log.info('点击结算') mood.moodsleep() # 错误纠正 @@ -151,7 +148,7 @@ def get_reward(self, mood, state): 'img/FA-SONG-XIAO-XI.png', 'img/ZHI-LIAO-LIANG.png') if max(maxVal) > 0.9: self.yys.mouse_click_bg((35, 295), (140, 475)) - logging.info(self.name + '错误纠正') + self.log.info('错误纠正') mood.moodsleep() continue @@ -159,10 +156,10 @@ def get_reward(self, mood, state): maxVal, maxLoc = self.yys.find_multi_img( 'img/SHENG-LI.png', 'img/TIAO-DAN.png', 'img/JIN-BI.png', 'img/JIE-SU.png') if max(maxVal) < 0.9: - logging.info(self.name + '结算成功') + self.log.info('结算成功') return - self.log.writewarning(self.name + '点击结算失败!') + self.log.warning('点击结算失败!') # 提醒玩家点击失败,并在5s后退出 self.yys.activate_window() time.sleep(5) @@ -191,15 +188,15 @@ def mitama_team_click(self): ((x1, y1), (x2, y2)), (134, 227, 96), 5) # print('颜色位置', exp_pos) if exp_pos != -1: - self.log.writeinfo(self.name + '标记式神成功') + self.log.info('标记式神成功') return True else: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(*pos) - self.log.writeinfo(self.name + '标记式神') + self.log.info('标记式神') ut.mysleep(500) - self.log.writewarning(self.name + '标记式神失败') + self.log.warning('标记式神失败') def click_monster(self): # 点击怪物 @@ -221,21 +218,44 @@ def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.8, appear=Tr while time.time()-start_time <= self.max_op_time and self.run: # 点击指定位置 self.yys.mouse_click_bg(pos, pos_end) - self.log.writeinfo(self.name + '点击 ' + tag) + self.log.info('点击 ' + tag) ut.mysleep(step_time*1000) result = self.yys.find_game_img(img_path) if not appear: result = not result if result: - self.log.writeinfo(self.name + '点击 ' + tag + ' 成功') + self.log.info('点击 ' + tag + ' 成功') return True # 提醒玩家点击失败,并在5s后退出 - self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') - self.yys.activate_window() - time.sleep(5) - self.yys.quit_game() + self.click_failed() + + def click_until_multi(self, tag, *img_path, pos, pos_end=None, step_time=0.8): + ''' + 在某一时间段内,后台点击鼠标,直到出现列表中任一图片 + :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: + # 点击指定位置 + self.yys.mouse_click_bg(pos, pos_end) + self.log.info('点击 ' + tag) + ut.mysleep(step_time*1000) + + maxval, _ = self.yys.find_multi_img(*img_path) + if max(maxval) > 0.9: + self.log.info('点击 ' + tag + ' 成功') + return True + + # 提醒玩家点击失败,并在5s后退出 + self.click_failed() def click_until_knn(self, tag, img_path, pos, pos_end=None, step_time=0.8, appear=True, thread=0): ''' @@ -254,29 +274,33 @@ def click_until_knn(self, tag, img_path, pos, pos_end=None, step_time=0.8, appea while time.time()-start_time <= self.max_op_time and self.run: # 点击指定位置并等待下一轮 self.yys.mouse_click_bg(pos, pos_end) - self.log.writeinfo(self.name + '点击 ' + tag) + self.log.info('点击 ' + tag) ut.mysleep(step_time*1000) 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 + ' 成功') + self.log.info('点击 ' + tag + ' 成功') return True # 提醒玩家点击失败,并在5s后退出 - self.log.writewarning(self.name + '点击 ' + tag + ' 失败!') + self.click_failed() + + def click_failed(self): + # 提醒玩家点击失败,并在5s后退出 + self.log.warning('点击 ' + tag + ' 失败!') self.yys.activate_window() time.sleep(5) self.yys.quit_game() def activate(self): - self.log.writewarning(self.name + '启动脚本') + self.log.warning('启动脚本') self.run = True self.yys.run = True def deactivate(self): - self.log.writewarning(self.name + '手动停止脚本') + self.log.warning('手动停止脚本') self.run = False self.yys.run = False @@ -290,4 +314,4 @@ def slide_x_scene(self, distance): y0 = random.randint(436, 486) y1 = random.randint(436, 486) self.yys.mouse_drag_bg((x0, y0), (x1, y1)) - logging.info(self.name + '水平滑动界面') + self.log.info('水平滑动界面') diff --git a/gameLib/game_ctl.py b/gameLib/game_ctl.py index 77196a9..d399bf1 100644 --- a/gameLib/game_ctl.py +++ b/gameLib/game_ctl.py @@ -81,6 +81,7 @@ def window_full_shot(self, file_name=None, gray=0): else: return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY) except Exception: + self.clean_mem() self.init_mem() logging.warning('window_full_shot执行失败') a = traceback.format_exc() @@ -475,15 +476,17 @@ def quit_game(self): else: os.system( 'adb shell am force-stop com.netease.onmyoji.netease_simulator') - logging.info('退出,最后显示已保存至/img/full.png') + logging.info('退出,最后显示已保存至/img/screenshots文件夹') sys.exit(0) def takescreenshot(self): ''' 截图 ''' - img_src_path = 'img\\full.png' + name = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()) + img_src_path = 'img/screenshots/%s.png' %(name) self.window_full_shot(img_src_path) + logging.info('截图已保存至img/screenshots/%s.png' %(name)) def rejectbounty(self): ''' diff --git a/gameLib/game_scene.py b/gameLib/game_scene.py index 9870511..a417205 100644 --- a/gameLib/game_scene.py +++ b/gameLib/game_scene.py @@ -1,6 +1,5 @@ from tools.game_pos import TansuoPos, YuhunPos -import logging import time @@ -42,7 +41,7 @@ def switch_to_scene(self, scene): :return: 切换成功返回True;切换失败直接退出 ''' scene_now = self.get_scene() - logging.info(self.name + '目前场景:' + str(scene_now)) + self.log.info('目前场景:' + str(scene_now)) if scene_now == scene: return True if scene_now == 1: @@ -92,8 +91,8 @@ def switch_to_scene(self, scene): # 探索内 if scene == 3: # 点击退出探索 - self.click_until('退出按钮', 'img\\QUE-REN.png', - *TansuoPos.quit_btn, 2) + self.click_until_multi('退出按钮', 'img/QUE-REN.png', 'img/TAN-SUO.png', + pos=TansuoPos.quit_btn[0], pos_end=TansuoPos.quit_btn[1], step_time=2) # 点击确认 self.click_until('确认按钮', 'img\\QUE-REN.png', @@ -106,18 +105,18 @@ def switch_to_scene(self, scene): if scene == 6: # 点击御魂 self.click_until_knn('御魂选项', 'img/TIAO-ZHAN.png', - *YuhunPos.yuhun_btn, 2, thread=20) + *YuhunPos.yuhun_btn, 2, thread=20) # 递归 self.switch_to_scene(scene) elif scene == 7: # 点击业原火 self.click_until_knn('业原火选项', 'img/TIAO-ZHAN.png', - *YuhunPos.yeyuanhuo_btn, 2, thread=20) + *YuhunPos.yeyuanhuo_btn, 2, thread=20) # 递归 self.switch_to_scene(scene) elif scene == 8: # 点击卑弥呼 self.click_until_knn('卑弥呼选项', 'img/TIAO-ZHAN.png', - *YuhunPos.beimihu_btn, 2, thread=20) + *YuhunPos.beimihu_btn, 2, thread=20) # 递归 self.switch_to_scene(scene) diff --git a/goryou/single_fight.py b/goryou/single_fight.py index 7ada613..60353a5 100644 --- a/goryou/single_fight.py +++ b/goryou/single_fight.py @@ -10,7 +10,7 @@ class GoryouFight(Fighter): def __init__(self, done=1, emyc=0): # 初始化 - Fighter.__init__(self, '', emyc) + Fighter.__init__(self) def start(self): '''单人战斗主循环''' diff --git a/gui/tkui.py b/gui/tkui.py index 43330d7..e6b2079 100644 --- a/gui/tkui.py +++ b/gui/tkui.py @@ -1,12 +1,15 @@ import json import tkinter as tk import tkinter.messagebox +import webbrowser from tkinter import ttk class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) + self.url = 'http://www.onmyojibot.com' + self.source_url = 'https://github.com/AcademicDog/onmyoji_bot' self.master = master self.master.iconbitmap('img/icon/OnmyojiBot.ico') self.master.wm_title('OnmyojiBot') @@ -85,7 +88,8 @@ def create_menubar(self): # 创建菜单项 menu1 = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label="文件", menu=menu1) - menu1.add_command(label='关于', command=self.say_hi) + menu1.add_command(label='启动', command=self.start_onmyoji) + menu1.add_command(label='退出', command=self.stop_onmyoji) # 高级选项 menu2 = tk.Menu(menubar, tearoff=0) @@ -95,7 +99,10 @@ def create_menubar(self): # 帮助 menu3 = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label='帮助', menu=menu3) + menu3.add_command(label='关于', command=self.say_hi) menu3.add_command(label='使用说明', command=self.help) + menu3.add_separator() + menu3.add_command(label='捐赠', command=self.donate) # 设置 self.master.config(menu=menubar) @@ -105,7 +112,7 @@ def create_title(self): tk.Label(self.master, text='OnmyojiBot', font='Helvetica 20 bold').pack(anchor=tk.W) tk.Label( - self.master, text='https://github.com/AcademicDog/onmyoji_bot').pack(anchor=tk.W) + self.master, text=self.url).pack(anchor=tk.W) # 主页面 self.main_frame1 = tk.Frame(self.master) @@ -257,9 +264,13 @@ def create_frame3(self): text = tk.Text(self.frame3, height=5, width=25) text.pack(expand=True, fill=tk.BOTH) text.insert( - tk.END, '网址:https://github.com/AcademicDog/onmyoji_bot\n\n交流Q群:592055060') + tk.END, '网站:%s\n\n' % (self.url)) text.insert( - tk.END, '\n\n如果觉得脚本动作太慢,请到高级菜单自定义延迟。') + tk.END, '源码:%s\n\n' % (self.source_url)) + text.insert( + tk.END, '交流Q群:592055060\n\n') + text.insert( + tk.END, '如果觉得脚本动作太慢,请到高级菜单自定义延迟。') text.config(state=tk.DISABLED) def create_times(self): @@ -362,7 +373,7 @@ def say_hi(self): 测试 ''' tk.messagebox.showinfo( - "OnmyojiBot", '网址:https://github.com/AcademicDog/onmyoji_bot\n\n交流Q群:592055060') + "OnmyojiBot", '网站:%s\n\n源码:%s\n\n交流Q群:592055060' % (self.url, self.source_url)) def delay_dialog(self): pw = DelayDialog(self) @@ -372,8 +383,19 @@ def help(self): ''' 使用说明 ''' - tk.messagebox.showinfo( - "使用说明", '详细使用说明请参考https://academicdog.github.io/onmyoji_bot/') + Q = tk.messagebox.askyesno( + "使用说明", '详细使用说明请参考%s\n\n是否访问?' % (self.url)) + if Q: + webbrowser.open(self.url) + + def donate(self): + ''' + 捐赠 + ''' + Q = tk.messagebox.askyesno( + "捐赠", '量力而行,1分就够。\n\n前往捐赠?') + if Q: + webbrowser.open(self.url) def gouliang_state(self, state): ''' @@ -416,7 +438,7 @@ def get_gouliang(self): self.gouliang.append(2) if self.gouliang_3.get(): self.gouliang.append(3) - + # 后狗粮 self.gouliang_b = [] if self.gouliang_4.get(): @@ -455,7 +477,7 @@ def __init__(self, parent): 同时在1-3级延迟中选择一级作为副延迟。在此基础上乘以随机系数。\n\n') text.insert(tk.END, '2-每5分钟刷新选择,计算单位毫秒。\n\n') text.insert(tk.END, '3-主延迟用于截图、识图等一般操作的延迟,副延迟主要用于结算。\n\n') - text.insert(tk.END, '4-不要纠结为什么每次重开这个表格都不变,参数存在delay.json。\n\n') + text.insert(tk.END, '4-不要纠结为什么每次重开这个表格都不变,参数存在delay.json,重启有效。\n\n') text.config(state=tk.DISABLED) # 参数设置 diff --git a/img/screenshots/.gitkeep b/img/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/mitama/dual.py b/mitama/dual.py index 0594368..4391cba 100644 --- a/mitama/dual.py +++ b/mitama/dual.py @@ -1,7 +1,6 @@ from gameLib.game_ctl import GameControl from mitama.fighter_driver import DriverFighter from mitama.fighter_passenger import FighterPassenger -from tools.logsystem import WriteLog import logging import threading @@ -43,7 +42,7 @@ def __init__(self): self.driver = DriverFighter(hwnd=hwnd) hwndlist.remove(hwnd) logging.info('发现司机') - self.passenger = FighterPassenger(hwnd=hwndlist[0]) + self.passenger = FighterPassenger(hwnd=hwndlist[0], mark=False) logging.info('发现乘客') def start(self): diff --git a/mitama/fighter_driver.py b/mitama/fighter_driver.py index 0db9fbe..44e60b9 100644 --- a/mitama/fighter_driver.py +++ b/mitama/fighter_driver.py @@ -1,8 +1,8 @@ from gameLib.fighter import Fighter from tools.game_pos import CommonPos, YuhunPos +from tools.logsystem import MyLog import tools.utilities as ut -import logging import time @@ -11,7 +11,8 @@ class DriverFighter(Fighter): def __init__(self, emyc=0, hwnd=0): # 初始化 - Fighter.__init__(self, 'Driver: ', emyc, hwnd) + Fighter.__init__(self, emyc, hwnd) + self.log = MyLog.dlogger def start(self): '''单人御魂司机''' @@ -26,7 +27,7 @@ def start(self): while self.run: # 司机点击开始战斗,需要锁定御魂阵容 mood1.moodsleep() - self.log.writeinfo('Driver: 点击开始战斗按钮') + self.log.info('Driver: 点击开始战斗按钮') self.click_until('开始战斗按钮', 'img\\KAI-SHI-ZHAN-DOU.png', * YuhunPos.kaishizhandou_btn, mood2.get1mood()/1000, False) @@ -47,11 +48,11 @@ def start(self): self.get_reward(mood3, state) # 等待下一轮 - logging.info('Driver: 等待下一轮') + self.log.info('Driver: 等待下一轮') start_time = time.time() while time.time() - start_time <= 20 and self.run: if(self.yys.wait_game_img('img\\KAI-SHI-ZHAN-DOU.png', 1, False)): - self.log.writeinfo('Driver: 进入队伍') + self.log.info('Driver: 进入队伍') break # 点击默认邀请 @@ -59,7 +60,7 @@ def start(self): self.yys.mouse_click_bg((497, 319)) time.sleep(0.2) self.yys.mouse_click_bg((674, 384)) - self.log.writeinfo('Driver: 自动邀请') + self.log.info('Driver: 自动邀请') # 检查游戏次数 self.check_times() diff --git a/mitama/fighter_passenger.py b/mitama/fighter_passenger.py index bb8bee9..f403679 100644 --- a/mitama/fighter_passenger.py +++ b/mitama/fighter_passenger.py @@ -1,17 +1,24 @@ from gameLib.fighter import Fighter from tools.game_pos import TansuoPos +from tools.logsystem import MyLog import tools.utilities as ut -import logging import time class FighterPassenger(Fighter): '''御魂战斗乘客程序,参数mode, emyc''' - def __init__(self, emyc=0, hwnd=0): - # 初始化 - Fighter.__init__(self, 'Passenger: ', emyc, hwnd) + def __init__(self, emyc=0, hwnd=0, mark=True): + ''' + 初始化 + :param emyc=0: 点怪设置:0-不点怪 + :param hwnd=0: 指定窗口句柄:0-否;其他-窗口句柄 + :param mark=True: 是否全局启用标记功能 + ''' + Fighter.__init__(self, emyc, hwnd) + self.log = MyLog.plogger + self.mark = mark def start(self): '''单人御魂乘客''' @@ -25,7 +32,8 @@ def start(self): self.check_battle() # 在战斗中,标记己方式神 - self.mitama_team_click() + if self.mark: + self.mitama_team_click() # 已经进入战斗,乘客自动点怪 self.click_monster() @@ -38,12 +46,12 @@ def start(self): self.get_reward(mood3, state) # 等待下一轮 - logging.info('Passenger: 等待下一轮') + self.log.info('Passenger: 等待下一轮') start_time = time.time() while time.time() - start_time <= 5 and self.run: # 检测是否回到队伍中 if(self.yys.wait_game_img('img\\XIE-ZHAN-DUI-WU.png', 1, False)): - self.log.writeinfo('Passenger: 进入队伍') + self.log.info('Passenger: 进入队伍') break # 检测是否有御魂邀请 @@ -53,12 +61,12 @@ def start(self): # 点击自动接受邀请 if self.yys.find_game_img('img\\ZI-DONG-JIE-SHOU.png'): self.yys.mouse_click_bg((210, yuhun_loc[1])) - self.log.writeinfo('Passenger: 自动接受邀请') + self.log.info('Passenger: 自动接受邀请') # 点击普通接受邀请 elif self.yys.find_game_img('img\\JIE-SHOU.png'): self.yys.mouse_click_bg((125, yuhun_loc[1])) - self.log.writeinfo('Passenger: 接受邀请') + self.log.info('Passenger: 接受邀请') # 检查游戏次数 self.check_times() diff --git a/mitama/single_fight.py b/mitama/single_fight.py index 51fede4..56a1458 100644 --- a/mitama/single_fight.py +++ b/mitama/single_fight.py @@ -3,7 +3,6 @@ import tools.utilities as ut import configparser -import logging class SingleFight(Fighter): @@ -11,7 +10,7 @@ class SingleFight(Fighter): def __init__(self, done=1, emyc=0): # 初始化 - Fighter.__init__(self, '', emyc) + Fighter.__init__(self, emyc) # 读取配置文件 conf = configparser.ConfigParser() @@ -53,7 +52,7 @@ def start(self): # 在战斗结算页面 self.get_reward(mood3, state) - self.log.writeinfo("回到选择界面") + self.log.info("回到选择界面") # 检查游戏次数 self.check_times() diff --git a/onmyoji.py b/onmyoji.py index 4b28ef7..b7c36d1 100644 --- a/onmyoji.py +++ b/onmyoji.py @@ -7,13 +7,13 @@ from mitama.fighter_driver import DriverFighter from mitama.fighter_passenger import FighterPassenger from mitama.single_fight import SingleFight +from tools.logsystem import MyLog import configparser import ctypes import logging import os import sys -import tools.logsystem def init(): @@ -103,12 +103,13 @@ def my_excepthook(exc_type, exc_value, tb): if __name__ == "__main__": - logging.info('python version: %s', sys.version) - try: # 检测管理员权限 if is_admin(): - # 注册插件,获取权限 + # 初始化日志 + MyLog.init() + + # 错误消息进日志 sys.excepthook = my_excepthook logging.info('UAC pass') diff --git a/tools/logsystem.py b/tools/logsystem.py index 183a5e4..3b3d004 100644 --- a/tools/logsystem.py +++ b/tools/logsystem.py @@ -1,28 +1,25 @@ import logging -logging.basicConfig(level=logging.DEBUG, - format='%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s', - datefmt='%a, %d %b %Y %H:%M:%S', - filename='log.log', - filemode='w') -################################################################################################# -#定义一个StreamHandler,将INFO级别或更高的日志信息打印到标准错误,并将其添加到当前的日志处理对象# -console = logging.StreamHandler() -console.setLevel(logging.INFO) -formatter = logging.Formatter( - '%(asctime)s %(name)-12s: %(levelname)-8s %(message)s') -console.setFormatter(formatter) -logging.getLogger('').addHandler(console) -################################################################################################# +class MyLog(): + plogger = logging.getLogger('Passenger') + dlogger = logging.getLogger('Driver') + mlogger = logging.getLogger() + @staticmethod + def init(): + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s %(filename)-17s [line:%(lineno)-3s] %(levelname)-7s %(name)-9s %(message)s', + datefmt='%Y %b %d %H:%M:%S', + filename='log.log', + filemode='w') -class WriteLog: - def writeinfo(self, *args, **kwargs): - logging.info(*args, **kwargs) - - def writewarning(self, *args, **kwargs): - logging.warning(*args, **kwargs) - - def writedebug(self, *args, **kwargs): - logging.debug(*args, **kwargs) + ################################################################################################# + #定义一个StreamHandler,将INFO级别或更高的日志信息打印到标准错误,并将其添加到当前的日志处理对象# + console = logging.StreamHandler() + console.setLevel(logging.INFO) + formatter = logging.Formatter( + '%(asctime)s %(filename)-17s: %(levelname)-7s %(name)-9s %(message)s') + console.setFormatter(formatter) + MyLog.mlogger.addHandler(console) + ################################################################################################# diff --git a/ui.py b/ui.py index 5b505b3..133b816 100644 --- a/ui.py +++ b/ui.py @@ -1,4 +1,5 @@ from gui.tkui import Application +from tools.logsystem import MyLog import configparser import ctypes @@ -7,7 +8,6 @@ import subprocess import sys import tkinter as tk -import tools.logsystem def is_admin(): @@ -114,7 +114,12 @@ def my_excepthook(exc_type, exc_value, tb): try: # 检测管理员权限 if is_admin(): + # 初始化日志 + MyLog.init() + + # 错误消息进日志 sys.excepthook = my_excepthook + logging.info('获取管理员权限') # Query DPI Awareness (Windows 10 and 8) awareness = ctypes.c_int()