diff --git a/CHANGELOG.md b/CHANGELOG.md index 034f475..49c6898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## v1.0.0.0924 +#### Fixes (bugs & defects): +* 改进了脚本的结束按钮,现在点击“结束”不再退出脚本UI。 +* 将部分英文日志记录更改为中文 + ## v1.0.0.0922 #### New features: * 优化了更换满级狗粮,现在更换狗粮时会拖动至10% N卡进度条。 diff --git a/explore/explore.py b/explore/explore.py index b8a31ea..d93417d 100644 --- a/explore/explore.py +++ b/explore/explore.py @@ -45,7 +45,7 @@ def check_exp_full(self): return # 开始换狗粮 - while True: + while self.run: # 点击狗粮位置 self.yys.mouse_click_bg(*TansuoPos.change_monster) if self.yys.wait_game_img('img\\QUAN-BU.png', 3, False): @@ -112,7 +112,7 @@ def fight_moster(self, mood1, mood2): 打经验怪 :return: 打完返回True;未找到经验怪返回False ''' - while True: + while self.run: mood1.moodsleep() # 查看是否进入探索界面 self.yys.wait_game_img('img\\YING-BING.png') @@ -157,7 +157,7 @@ def start(self): '''单人探索主循环''' mood1 = ut.Mood(2) mood2 = ut.Mood(3) - while True: + while self.run: # 点击挑战按钮 if self.yys.find_game_img('img\\TAN-SUO.png'): self.click_until('探索按钮', 'img\\YING-BING.png', @@ -170,7 +170,7 @@ def start(self): # 开始打怪 i = 0 - while i < 4: + while i < 4 and self.run: result = self.fight_moster(mood1, mood2) if result: continue @@ -181,7 +181,7 @@ def start(self): # 退出探索 if self.yys.find_game_img('img\\YING-BING.png'): - while True: + while self.run: self.yys.mouse_click_bg(*TansuoPos.quit_btn) if self.yys.wait_game_img('img\\QUE-REN.png', 3, False): break diff --git a/gameLib/fighter.py b/gameLib/fighter.py index 35dc280..d47ca91 100644 --- a/gameLib/fighter.py +++ b/gameLib/fighter.py @@ -11,6 +11,7 @@ def __init__(self, name='', emyc=0): # 初始参数 self.emyc = emyc self.name = name + self.run = True # 读取配置文件 conf = configparser.ConfigParser() @@ -24,11 +25,11 @@ def __init__(self, name='', emyc=0): # 绑定窗口 self.yys = GameControl(u'阴阳师-网易游戏', quit_game_enable) - self.log.writeinfo(self.name + 'Registration successful') + self.log.writeinfo(self.name + '绑定窗口成功') # 激活窗口 self.yys.activate_window() - self.log.writeinfo(self.name + 'Activation successful') + self.log.writeinfo(self.name + '激活窗口成功') time.sleep(0.5) def check_battle(self): @@ -59,7 +60,7 @@ def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.5): ''' # 在指定时间内反复监测画面并点击 start_time = time.time() - while time.time()-start_time <= self.max_op_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('点击 ' + tag + ' 成功') @@ -75,3 +76,13 @@ def click_until(self, tag, img_path, pos, pos_end=None, step_time=0.5): 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 diff --git a/gameLib/game_ctl.py b/gameLib/game_ctl.py index 03d6a12..aebf6a4 100644 --- a/gameLib/game_ctl.py +++ b/gameLib/game_ctl.py @@ -18,6 +18,7 @@ def __init__(self, window_name, quit_game_enable=1): :param window_name: 需要绑定的窗口名称 :param quit_game_enable: 程序死掉时是否退出游戏。True为是,False为否 ''' + self.run = True self.hwnd = win32gui.FindWindow(0, window_name) self.quit_game_enable = quit_game_enable #user32 = ctypes.windll.user32 @@ -282,7 +283,7 @@ def wait_game_img(self, img_path, max_time=100, quit=True): """ self.rejectbounty() start_time = time.time() - while time.time()-start_time <= max_time: + while time.time()-start_time <= max_time and self.run: maxVal, maxLoc = self.find_img(img_path) if maxVal > 0.97: return maxLoc @@ -308,7 +309,7 @@ def wait_game_color(self, region, color, tolerance=0, max_time=60, quit=True): """ self.rejectbounty() start_time = time.time() - while time.time()-start_time <= max_time: + while time.time()-start_time <= max_time and self.run: pos = self.find_color(region, color) if pos != -1: return True @@ -324,6 +325,8 @@ def quit_game(self): 退出游戏 """ self.takescreenshot() # 保存一下现场 + if not self.run: + return False if self.quit_game_enable: win32gui.SendMessage(self.hwnd, win32con.WM_DESTROY, 0, 0) # 退出游戏 sys.exit(0) diff --git a/mitama/fighter_driver.py b/mitama/fighter_driver.py index 9b4667c..4fad3b4 100644 --- a/mitama/fighter_driver.py +++ b/mitama/fighter_driver.py @@ -22,7 +22,7 @@ def start(self): # 战斗主循环 self.yys.wait_game_img('img\\KAI-SHI-ZHAN-DOU.png', self.max_win_time) - while True: + while self.run: # 司机点击开始战斗,需要锁定御魂阵容 mood1.moodsleep() self.log.writeinfo('Driver: 点击开始战斗按钮') @@ -40,7 +40,7 @@ def start(self): # 在战斗结算页面 self.yys.mouse_click_bg(ut.firstposition()) start_time = time.time() - while time.time() - start_time <= 10: + while time.time() - start_time <= 10 and self.run: if(self.yys.wait_game_img('img\\KAI-SHI-ZHAN-DOU.png', mood3.get1mood()/1000, False)): self.log.writeinfo('Driver: 进入队伍') break diff --git a/mitama/fighter_passenger.py b/mitama/fighter_passenger.py index 0f15f15..f416991 100644 --- a/mitama/fighter_passenger.py +++ b/mitama/fighter_passenger.py @@ -19,7 +19,7 @@ def start(self): mood3 = ut.Mood(3) # 战斗主循环 - while True: + while self.run: # 检测是否进入战斗 self.check_battle() @@ -33,7 +33,7 @@ def start(self): # 在战斗结算页面 self.yys.mouse_click_bg(ut.firstposition()) start_time = time.time() - while time.time() - start_time <= 10: + while time.time() - start_time <= 10 and self.run: # 检测是否回到队伍中 if(self.yys.wait_game_img('img\\XIE-ZHAN-DUI-WU.png', mood3.get1mood()/1000, False)): self.log.writeinfo('Passenger: 进入队伍') diff --git a/mitama/single_fight.py b/mitama/single_fight.py index 94b77ac..de45f51 100644 --- a/mitama/single_fight.py +++ b/mitama/single_fight.py @@ -15,13 +15,13 @@ def start(self): mood1 = ut.Mood() mood2 = ut.Mood() mood3 = ut.Mood(3) - while True: + while self.run: # 在御魂主选单,点击“挑战”按钮, 需要使用“阵容锁定”! self.yys.wait_game_img('img\\TIAO-ZHAN.png', self.max_win_time) mood1.moodsleep() self.yys.mouse_click_bg(*YuhunPos.tiaozhan_btn) - self.log.writeinfo('Already clicked TIAO-ZHAN') + self.log.writeinfo('点击 挑战按钮') # 检测是否进入战斗 self.check_battle() @@ -37,4 +37,4 @@ def start(self): self.yys.mouse_click_bg(ut.firstposition()) self.click_until('结算', 'img\\TIAO-ZHAN.png', *CommonPos.second_position, mood3.get1mood()/1000) - self.log.writeinfo("Back to YUHUN level selection") + self.log.writeinfo("回到御魂选择界面") diff --git a/ui.py b/ui.py index 8061fde..0b59334 100644 --- a/ui.py +++ b/ui.py @@ -78,22 +78,22 @@ def start_onmyoji(self): # 御魂 if mode == 0: # 单刷 - fight = SingleFight() + self.fight = SingleFight() if mode == 2: # 司机 - fight = DriverFighter() + self.fight = DriverFighter() if mode == 3: # 乘客 - fight = FighterPassenger() + self.fight = FighterPassenger() elif section == 1: # 探索 - fight = ExploreFight() + self.fight = ExploreFight() - self.task = threading.Thread(target = fight.start) - self.task.start() + task = threading.Thread(target = self.fight.start) + task.start() def set_mood1(self): global mode @@ -108,8 +108,10 @@ def set_mood3(self): mode = 3 def stop_onmyoji(self): - logging.info('Quitting!') - os._exit(0) + try: + self.fight.deactivate() + except: + pass if __name__=="__main__":