Skip to content

Commit

Permalink
hotfix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
AcademicDog committed Jun 23, 2019
1 parent c150cb3 commit 6611f6b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ v1.0.0.0621--修改了完成战斗后,等待时间重复计算的bug,同时

v1.0.0.06211--根据[#2](https://github.com/AcademicDog/onmyoji_bot/issues/2),增加了对已编译文件使用的说明,同时将/img文件夹一起打包发布。

v1.0.0.0622--根据[#3](https://github.com/AcademicDog/onmyoji_bot/issues/3),优化了乘客结算代码;将原先的灰度图像识别更改为彩色图像识别;在结算失败时,通过激活窗口来提醒玩家。

# 协议 (License)

该源代码使用了 [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) 开源协议。
Expand Down
12 changes: 8 additions & 4 deletions fighter_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ def start(self):

# 在战斗结算页面
self.yys.mouse_click_bg(utilities.firstposition())
mood3.moodsleep()
start_time = time.time()
while time.time() - start_time <= 10:
# 点击结算
self.yys.mouse_click_bg(utilities.secondposition())
while time.time() - start_time <= 10:
if(self.yys.wait_game_img('img\\KAI-SHI-ZHAN-DOU.png', mood3.get1mood()/1000, False)):
self.log.writeinfo('Driver: in team')
break

# 点击结算
self.yys.mouse_click_bg(utilities.secondposition())

# 点击默认邀请
if(self.yys.wait_game_img('img\\ZI-DONG-YAO-QING.png', 0.2, False)):
self.yys.mouse_click_bg((497, 319))
time.sleep(0.2)
self.yys.mouse_click_bg((674, 384))
self.log.writeinfo('Driver: auto invited')

# 如果没有成功开车,切到主界面提醒玩家
if time.time() - start_time > 10:
self.yys.activate_window()
30 changes: 19 additions & 11 deletions fighter_passenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,29 @@ def start(self):

# 在战斗结算页面
self.yys.mouse_click_bg(utilities.firstposition())
mood3.moodsleep()
start_time = time.time()
while time.time() - start_time <= 10:
# 点击结算
self.yys.mouse_click_bg(utilities.secondposition())
# 检测是否回到队伍中
if(self.yys.wait_game_img('img\\LI-KAI-DUI-WU.png', mood3.get1mood()/1000, False)):
self.log.writeinfo('Passenger: in team')
break

# 点击自动接受邀请
if(self.yys.wait_game_img('img\\ZI-DONG-JIE-SHOU.png', 0.1, False)):
self.yys.mouse_click_bg((210, 227))
self.log.writeinfo('Passenger: auto accepted')
# 点击结算
self.yys.mouse_click_bg(utilities.secondposition())

# 点击普通接受邀请
elif(self.yys.wait_game_img('img\\JIE-SHOU.png', 0.1, False)):
self.yys.mouse_click_bg((125, 230))
self.log.writeinfo('Passenger: accepted')
# 检测是否有御魂邀请
yuhun_loc = self.yys.wait_game_img('img\\YU-HUN.png', 0.1, False)
if yuhun_loc:
# 点击自动接受邀请
if(self.yys.wait_game_img('img\\ZI-DONG-JIE-SHOU.png', 0.1, False)):
self.yys.mouse_click_bg((210, yuhun_loc[1]))
self.log.writeinfo('Passenger: auto accepted')

# 点击普通接受邀请
elif(self.yys.wait_game_img('img\\JIE-SHOU.png', 0.1, False)):
self.yys.mouse_click_bg((125, yuhun_loc[1]))
self.log.writeinfo('Passenger: accepted')

# 如果没有成功上车,切到主界面提醒玩家
if time.time() - start_time > 10:
self.yys.activate_window()
8 changes: 4 additions & 4 deletions game_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def window_full_shot(self,file_name=None):
win32gui.DeleteObject(bmp.GetHandle())
#cv2.imshow("image", cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
#cv2.waitKey(0)
return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
except:
pass

Expand Down Expand Up @@ -85,7 +85,7 @@ def window_part_shot(self,pos1,pos2,file_name=None):
memdc.DeleteDC()
win32gui.ReleaseDC(self.hwnd, hwindc)
win32gui.DeleteObject(bmp.GetHandle())
return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)
return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)

def find_color(self,region,color,tolerance=0):
"""
Expand Down Expand Up @@ -132,7 +132,7 @@ def find_img(self,img_template_path):
:return: (maxVal,maxLoc) maxVal为相关性,越接近1越好,maxLoc为得到的坐标
"""
img_src = self.window_full_shot()
img_template=cv2.imread(img_template_path,0)
img_template=cv2.imread(img_template_path, cv2.IMREAD_COLOR)
res = cv2.matchTemplate(img_src, img_template, cv2.TM_CCOEFF_NORMED)
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(res)
#print(maxLoc)
Expand Down Expand Up @@ -236,7 +236,7 @@ def wait_game_img(self, img_path, max_time = 100, quit=True):
while time.time()-start_time<=max_time:
maxVal,maxLoc=self.find_img(img_path)
if maxVal>0.97:
return True
return maxLoc
if max_time > 5:
time.sleep(1)
else:
Expand Down
Binary file added img/YU-HUN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions single_fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ def start(self):

# 在战斗结算页面
self.yys.mouse_click_bg(utilities.firstposition())
mood3.moodsleep()
start_time = time.time()
while time.time() - start_time <= 10:
self.yys.mouse_click_bg(utilities.secondposition())
while time.time() - start_time <= 10:
if(self.yys.wait_game_img('img\\TIAO-ZHAN.png', mood3.get1mood()/1000, False)):
break

# 点击结算
self.yys.mouse_click_bg(utilities.secondposition())

# 如果没有成功上车,切到主界面提醒玩家
if time.time() - start_time > 10:
self.yys.activate_window()

self.log.writeinfo("Back to YUHUN level selection")
2 changes: 1 addition & 1 deletion utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def secondposition():
w = 1136
h = 640
while True:
position = (random.randint(0, w), random.randint(50, h-40))
position = (random.randint(0, w), random.randint(50, h - 90))
if position[0] < 210 or position[0] > 952:
return position
elif position[1] < 112 or position[1] > 490:
Expand Down

0 comments on commit 6611f6b

Please sign in to comment.