Skip to content

Commit

Permalink
1.0.1.0229
Browse files Browse the repository at this point in the history
  • Loading branch information
AcademicDog committed Feb 29, 2020
1 parent 66cedd0 commit 79f39c1
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## v1.0.1.0229
#### New features:
* 增加了更详细的调试信息显示。
#### Fixes (bugs & defects):
* 进一步提高了结算可靠性。
* 进一步提高了结算速度。

## v1.0.1.0227
#### New features:
* 新增对MuMu模拟器的支持。
Expand Down
16 changes: 10 additions & 6 deletions gameLib/fighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '本轮战斗结束')
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 22 additions & 7 deletions gameLib/game_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import time
import traceback
import random
import cv2
import numpy as np
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
# 返回列表
Expand Down Expand Up @@ -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):
Expand Down
67 changes: 63 additions & 4 deletions gui/tkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
'''
创建主选项卡
Expand Down Expand Up @@ -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')))
Expand Down Expand Up @@ -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()
Expand Down
Binary file modified img/JIE-SUAN-JIA-CHENG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mitama/single_fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 6 additions & 8 deletions tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 79f39c1

Please sign in to comment.