Explorar el Código

Merge pull request #1767 from runhey/pr1761

Pr1761
huangrunheng hace 2 meses
padre
commit
01ed311bf1

+ 3 - 0
module/device/screenshot.py

@@ -232,6 +232,9 @@ class Screenshot(Adb, DroidCast, Scrcpy, Window, NemuIpc):
                 logger.critical('Please set emulator resolution to 1280x720')
                 logger.critical('Please set emulator resolution to 1280x720')
                 raise RequestHumanTakeover
                 raise RequestHumanTakeover
 
 
+    def check_screen_size_sample(self):
+        return self.image.shape  == (720, 1280, 3)
+
     def check_screen_black(self):
     def check_screen_black(self):
         if self._screen_black_checked:
         if self._screen_black_checked:
             return True
             return True

+ 4 - 4
tasks/Component/CostumeShikigami/assets.py

@@ -179,7 +179,7 @@ class CostumeShikigamiAssets:
 	# 点击御魂 
 	# 点击御魂 
 	I_ST_SOULS_2 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk2/sk2_st_souls_2.png")
 	I_ST_SOULS_2 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk2/sk2_st_souls_2.png")
 	# 更换 
 	# 更换 
-	I_ST_REPLACE_2 = RuleImage(roi_front=(861,150,100,100), roi_back=(872,169,78,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk2/sk2_st_replace_2.png")
+	I_ST_REPLACE_2 = RuleImage(roi_front=(861,150,100,100), roi_back=(861,150,100,100), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk2/sk2_st_replace_2.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
@@ -222,7 +222,7 @@ class CostumeShikigamiAssets:
 	# 点击御魂 
 	# 点击御魂 
 	I_ST_SOULS_3 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk3/sk3_st_souls_3.png")
 	I_ST_SOULS_3 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk3/sk3_st_souls_3.png")
 	# 更换 
 	# 更换 
-	I_ST_REPLACE_3 = RuleImage(roi_front=(860,168,100,100), roi_back=(872,186,78,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk3/sk3_st_replace_3.png")
+	I_ST_REPLACE_3 = RuleImage(roi_front=(860,168,100,100), roi_back=(860,168,100,100), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk3/sk3_st_replace_3.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
@@ -265,7 +265,7 @@ class CostumeShikigamiAssets:
 	# 点击御魂 
 	# 点击御魂 
 	I_ST_SOULS_4 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk4/sk4_st_souls_4.png")
 	I_ST_SOULS_4 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk4/sk4_st_souls_4.png")
 	# 更换 
 	# 更换 
-	I_ST_REPLACE_4 = RuleImage(roi_front=(860,168,100,100), roi_back=(872,186,78,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk4/sk4_st_replace_4.png")
+	I_ST_REPLACE_4 = RuleImage(roi_front=(860,168,100,100), roi_back=(860,168,100,100), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk4/sk4_st_replace_4.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
@@ -308,7 +308,7 @@ class CostumeShikigamiAssets:
 	# 点击御魂 
 	# 点击御魂 
 	I_ST_SOULS_5 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_st_souls_5.png")
 	I_ST_SOULS_5 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_st_souls_5.png")
 	# 更换 
 	# 更换 
-	I_ST_REPLACE_5 = RuleImage(roi_front=(860,168,100,100), roi_back=(872,186,78,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_st_replace_5.png")
+	I_ST_REPLACE_5 = RuleImage(roi_front=(860,168,100,100), roi_back=(860,168,100,100), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_st_replace_5.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets

+ 1 - 1
tasks/Component/CostumeShikigami/sk2/image.json

@@ -174,7 +174,7 @@
     "itemName": "st_replace_2",
     "itemName": "st_replace_2",
     "imageName": "sk2_st_replace_2.png",
     "imageName": "sk2_st_replace_2.png",
     "roiFront": "861,150,100,100",
     "roiFront": "861,150,100,100",
-    "roiBack": "872,169,78,63",
+    "roiBack": "861,150,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "更换"
     "description": "更换"

+ 1 - 1
tasks/Component/CostumeShikigami/sk3/image.json

@@ -174,7 +174,7 @@
     "itemName": "st_replace_3",
     "itemName": "st_replace_3",
     "imageName": "sk3_st_replace_3.png",
     "imageName": "sk3_st_replace_3.png",
     "roiFront": "860,168,100,100",
     "roiFront": "860,168,100,100",
-    "roiBack": "872,186,78,63",
+    "roiBack": "860,168,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "更换"
     "description": "更换"

+ 1 - 1
tasks/Component/CostumeShikigami/sk4/image.json

@@ -174,7 +174,7 @@
     "itemName": "st_replace_4",
     "itemName": "st_replace_4",
     "imageName": "sk4_st_replace_4.png",
     "imageName": "sk4_st_replace_4.png",
     "roiFront": "860,168,100,100",
     "roiFront": "860,168,100,100",
-    "roiBack": "872,186,78,63",
+    "roiBack": "860,168,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "更换"
     "description": "更换"

+ 1 - 1
tasks/Component/CostumeShikigami/sk5/image.json

@@ -174,7 +174,7 @@
     "itemName": "st_replace_5",
     "itemName": "st_replace_5",
     "imageName": "sk5_st_replace_5.png",
     "imageName": "sk5_st_replace_5.png",
     "roiFront": "860,168,100,100",
     "roiFront": "860,168,100,100",
-    "roiBack": "872,186,78,63",
+    "roiBack": "860,168,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "更换"
     "description": "更换"

+ 2 - 0
tasks/Component/GeneralInvite/assets.py

@@ -95,6 +95,8 @@ class GeneralInviteAssets:
 	I_BACK_YELLOW_SEA = RuleImage(roi_front=(31,16,42,42), roi_back=(31,16,42,42), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_back_yellow_sea.png")
 	I_BACK_YELLOW_SEA = RuleImage(roi_front=(31,16,42,42), roi_back=(31,16,42,42), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_back_yellow_sea.png")
 	# 识别到寄养邀请 
 	# 识别到寄养邀请 
 	I_I_ACCEPT_JY = RuleImage(roi_front=(248,258,46,25), roi_back=(231,205,75,326), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_i_accept_jy.png")
 	I_I_ACCEPT_JY = RuleImage(roi_front=(248,258,46,25), roi_back=(231,205,75,326), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_i_accept_jy.png")
+	# 房间左下角发言按钮(永生之海房间无表情按钮, 用此图识别) 
+	I_GI_SPEAK = RuleImage(roi_front=(23,503,82,85), roi_back=(23,503,82,85), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_speak.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets

+ 3 - 0
tasks/Component/GeneralInvite/general_invite.py

@@ -165,6 +165,9 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
             return True
             return True
         if self.appear(self.I_GI_EMOJI_2):
         if self.appear(self.I_GI_EMOJI_2):
             return True
             return True
+        # 永生之海房间没有表情按钮, 用左下角发言按钮识别
+        if self.appear(self.I_GI_SPEAK):
+            return True
         # if self.appear(self.I_MATCHING):
         # if self.appear(self.I_MATCHING):
         #     return False
         #     return False
         return False
         return False

BIN
tasks/Component/GeneralInvite/gi/gi_gi_speak.png


+ 9 - 0
tasks/Component/GeneralInvite/gi/image.json

@@ -376,5 +376,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "识别到寄养邀请"
     "description": "识别到寄养邀请"
+  },
+  {
+    "itemName": "gi_speak",
+    "imageName": "gi_gi_speak.png",
+    "roiFront": "23,503,82,85",
+    "roiBack": "23,503,82,85",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "房间左下角发言按钮(永生之海房间无表情按钮, 用此图识别)"
   }
   }
 ]
 ]

+ 41 - 0
tasks/EternitySea/script_task.py

@@ -4,6 +4,7 @@
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
 
 
 from module.exception import TaskEnd
 from module.exception import TaskEnd
+from module.base.timer import Timer
 from module.logger import logger
 from module.logger import logger
 
 
 from tasks.GameUi.game_ui import GameUi, Page
 from tasks.GameUi.game_ui import GameUi, Page
@@ -121,6 +122,8 @@ class ScriptTask(
                     is_first = False
                     is_first = False
                     self.run_general_battle(config=self._task_config.general_battle_config)
                     self.run_general_battle(config=self._task_config.general_battle_config)
 
 
+        # 战斗奖励动画可能还未结束, 先点掉残留奖励弹窗等界面稳定, 防止exit_room识别不到房间
+        self._wait_room_stable()
         # 当结束或者是失败退出循环的时候只有两个UI的可能,在房间或者是在组队界面
         # 当结束或者是失败退出循环的时候只有两个UI的可能,在房间或者是在组队界面
         # 如果在房间就退出
         # 如果在房间就退出
         if self.exit_room():
         if self.exit_room():
@@ -129,6 +132,9 @@ class ScriptTask(
         if self.exit_team():
         if self.exit_team():
             pass
             pass
 
 
+        # 永生之海选层界面无HOME按钮且页面系统识别不了, 点返回箭头回到御魂副本选择界面
+        self._back_to_soul_zones()
+
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_main)
         self.ui_goto(page_main)
 
 
@@ -136,6 +142,41 @@ class ScriptTask(
             return False
             return False
         return True
         return True
 
 
+    def _wait_room_stable(self) -> None:
+        """
+        打完最后一局领取奖励后, 奖励弹窗/金币动画可能遮挡左下角导致房间识别失败, 等待界面稳定
+        """
+        logger.info('Wait room stable')
+        timer = Timer(8).start()
+        while not timer.reached():
+            self.screenshot()
+            if self.appear_then_click(self.I_REWARD, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_REWARD_GOLD, interval=1.5):
+                continue
+            if not self.appear(self.I_REWARD) and not self.appear(self.I_REWARD_GOLD):
+                sleep(1)
+                return
+
+    def _back_to_soul_zones(self) -> None:
+        """
+        点返回箭头直到回到御魂副本选择界面(page_soul_zones可识别)
+        """
+        logger.info('Back to soul zones')
+        timer = Timer(15).start()
+        while not timer.reached():
+            self.screenshot()
+            if self.ui_page_appear(page_soul_zones):
+                return
+            if self.appear_then_click(self.I_GI_SURE, interval=1):
+                continue
+            if self.appear_then_click(self.I_BACK_YELLOW, interval=1):
+                continue
+            if self.appear_then_click(self.I_BACK_YELLOW_SEA, interval=1):
+                continue
+            if self.appear_then_click(self.I_BACK_BOTTOM, interval=1):
+                continue
+
 
 
     def run_member(self):
     def run_member(self):
         logger.info('Start run member')
         logger.info('Start run member')

+ 7 - 0
tasks/Restart/login.py

@@ -40,6 +40,10 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
                 orientation_timer.reset()
                 orientation_timer.reset()
 
 
             self.screenshot()
             self.screenshot()
+            # https://github.com/runhey/OnmyojiAutoScript/pull/1761
+            if not self.device.check_screen_size_sample():
+                continue
+
             # 取消继续战斗
             # 取消继续战斗
             if self.appear_then_click(self.I_CANCEL_BATTLE, interval=0.8):
             if self.appear_then_click(self.I_CANCEL_BATTLE, interval=0.8):
                 logger.info('Cancel continue battle')
                 logger.info('Cancel continue battle')
@@ -171,6 +175,9 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
         courtyard_affairs_done = False  # 庭院事务只执行一次
         courtyard_affairs_done = False  # 庭院事务只执行一次
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
+            # https://github.com/runhey/OnmyojiAutoScript/pull/1761
+            if not self.device.check_screen_size_sample():
+                continue
 
 
             # 点击'获得奖励'
             # 点击'获得奖励'
             if self.ui_reward_appear_click():
             if self.ui_reward_appear_click():

+ 2 - 3
tasks/RichMan/mall/honor.py

@@ -70,9 +70,8 @@ class Honor(Special):
         if not self.mall_check_money(4, 1500):
         if not self.mall_check_money(4, 1500):
             logger.warning('No enough money')
             logger.warning('No enough money')
             return
             return
-        # 使用动态位置点击购买
-        self.appear_then_click(self.I_HONOR_BLUE)
-        time.sleep(1)
+        # 购买: 点商品打开购买弹窗, 点加号拉满数量后确认购买
+        self.buy_more(self.I_HONOR_BLUE)
 
 
     def _honor_black_daruma_scrap(self, enable: bool=False):
     def _honor_black_daruma_scrap(self, enable: bool=False):
         logger.hr('Buy black daruma scrap', 3)
         logger.hr('Buy black daruma scrap', 3)

+ 3 - 9
tasks/RichMan/mall/special.py

@@ -163,15 +163,9 @@ class Special(Buy, MallNavbar):
                   .replace(':', ':').replace('火', '次')
                   .replace(':', ':').replace('火', '次')
                   .replace('教', '数').replace('刺', '剩')
                   .replace('教', '数').replace('刺', '剩')
                   .replace('头', '买'))
                   .replace('头', '买'))
-        try:
-            if ':' in result:
-                result = re.findall(r'(?:剩余)?购买次数:(\d+)', result)[0]
-                result = int(result)
-            else:
-                result = re.findall(r'本周剩余数量(\d+)', result)[0]
-                result = int(result)
-        except:
-            result = 0
+        # 冒号可能被漏识别, 如"剩余购买次数2", 所以冒号设为可选
+        matched = re.search(r'(?:剩余)?(?:购买次数|本周剩余数量):?(\d+)', result)
+        result = int(matched.group(1)) if matched else 0
         logger.info(f'Remain [{result}]')
         logger.info(f'Remain [{result}]')
         return result
         return result