diff --git a/README.md b/README.md index 9a90d66..bf80738 100644 --- a/README.md +++ b/README.md @@ -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) 开源协议。 diff --git a/fighter_driver.py b/fighter_driver.py index db7ca9f..9693d37 100644 --- a/fighter_driver.py +++ b/fighter_driver.py @@ -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() \ No newline at end of file diff --git a/fighter_passenger.py b/fighter_passenger.py index 374a498..54960f0 100644 --- a/fighter_passenger.py +++ b/fighter_passenger.py @@ -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() \ No newline at end of file diff --git a/game_ctl.py b/game_ctl.py index edc9df0..0eb6c4c 100644 --- a/game_ctl.py +++ b/game_ctl.py @@ -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 @@ -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): """ @@ -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) @@ -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: diff --git a/img/YU-HUN.png b/img/YU-HUN.png new file mode 100644 index 0000000..3263404 Binary files /dev/null and b/img/YU-HUN.png differ diff --git a/single_fight.py b/single_fight.py index 65c712f..de076c5 100644 --- a/single_fight.py +++ b/single_fight.py @@ -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") diff --git a/utilities.py b/utilities.py index 6c099b6..28c5405 100644 --- a/utilities.py +++ b/utilities.py @@ -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: