Skip to content

Commit

Permalink
rewrite the stop botton as pause
Browse files Browse the repository at this point in the history
  • Loading branch information
AcademicDog committed Sep 26, 2019
1 parent e03490b commit 52fd247
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## v1.0.0.0924
#### Fixes (bugs & defects):
* 改进了脚本的结束按钮,现在点击“结束”不再退出脚本UI。
* 将部分英文日志记录更改为中文

## v1.0.0.0922
#### New features:
* 优化了更换满级狗粮,现在更换狗粮时会拖动至10% N卡进度条。
Expand Down
10 changes: 5 additions & 5 deletions explore/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 14 additions & 3 deletions gameLib/fighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, name='', emyc=0):
# 初始参数
self.emyc = emyc
self.name = name
self.run = True

# 读取配置文件
conf = configparser.ConfigParser()
Expand All @@ -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):
Expand Down Expand Up @@ -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 + ' 成功')
Expand All @@ -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
7 changes: 5 additions & 2 deletions gameLib/game_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mitama/fighter_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: 点击开始战斗按钮')
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mitama/fighter_passenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def start(self):
mood3 = ut.Mood(3)

# 战斗主循环
while True:
while self.run:
# 检测是否进入战斗
self.check_battle()

Expand All @@ -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: 进入队伍')
Expand Down
6 changes: 3 additions & 3 deletions mitama/single_fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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("回到御魂选择界面")
18 changes: 10 additions & 8 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__":

Expand Down

0 comments on commit 52fd247

Please sign in to comment.