Explorar el Código

fix(GeneralBattle): Add hook for handling special reward popups in settlement #1580

  - add _hook_special_reward() extension point in battle reward loop
  - implement hook in BaseExploration to dismiss skin fragment popups
  - adjust reward wait logic to not exit early when statistics icon is visible
  - update I_STATISTICS roiBack for broader detection coverage
ryland hace 5 meses
padre
commit
c084add72f

+ 3 - 3
dev_tools/assets_test.py

@@ -34,10 +34,10 @@ def detect_ocr(file: str, target: RuleOcr):
 
 
 # 图片文件路径 可以是相对路径
-IMAGE_FILE = r"C:\Users\Ryland\Desktop\ScreenShot_2026-01-04_222421_055.png"
+IMAGE_FILE = r"C:\Users\Ryland\Desktop\ScreenShot_2026-05-30_141821_235.png"
 if __name__ == '__main__':
-    from tasks.RichMan.script_task import ScriptTask
-    targe = ScriptTask.I_MALL_BONDLINGS_SURE
+    from tasks.Exploration.script_task import ScriptTask
+    targe = ScriptTask.I_TREASURE_BOX_CLICK
     print(detect_image(IMAGE_FILE, targe))
 
     # ocr demo

+ 1 - 1
tasks/Component/GeneralBattle/assets.py

@@ -98,7 +98,7 @@ class GeneralBattleAssets:
 	# 左下角的位置指针 
 	I_LOCAL = RuleImage(roi_front=(25,563,30,34), roi_back=(25,563,30,34), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_local.png")
 	# description 
-	I_STATISTICS = RuleImage(roi_front=(61,644,33,28), roi_back=(61,644,33,28), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_statistics.png")
+	I_STATISTICS = RuleImage(roi_front=(70,630,33,28), roi_back=(35,28,411,661), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_statistics.png")
 	# 左上角的退出 
 	I_EXIT = RuleImage(roi_front=(14,12,43,41), roi_back=(14,12,43,41), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_exit.png")
 	# 退出确认 

+ 2 - 2
tasks/Component/GeneralBattle/gb/image.json

@@ -137,8 +137,8 @@
   {
     "itemName": "statistics",
     "imageName": "gb_statistics.png",
-    "roiFront": "61,644,33,28",
-    "roiBack": "61,644,33,28",
+    "roiFront": "70,630,33,28",
+    "roiBack": "35,28,411,661",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

+ 14 - 5
tasks/Component/GeneralBattle/general_battle.py

@@ -73,7 +73,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
                     continue
                 continue
             # 未知界面, 既不是准备界面也不是战斗界面
-            logger.info('Wait for preparation page')
+            # logger.info('Wait for preparation page')  # 这玩意刷屏
             sleep(random.uniform(0.4, 0.8))
         return False
 
@@ -218,10 +218,11 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
                 if not self.appear(self.I_FALSE, threshold=0.6):
                     return False
         # 最后保证能点击 获得奖励
-        if not self.wait_until_appear(self.I_REWARD):
-            # 有些的战斗没有下面的奖励,所以直接返回
-            logger.info("There is no reward, Exit battle")
-            return win
+        if not self.wait_until_appear(self.I_REWARD, wait_time=10):
+            if not self.appear(self.I_STATISTICS):
+                # 有些的战斗没有下面的奖励,所以直接返回
+                logger.info("There is no reward, Exit battle")
+                return win
         logger.info("Get reward")
         while 1:
             self.screenshot()
@@ -237,6 +238,8 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
                 # self.appear_then_click(self.I_REWARD_SOUL_6, action=action_click, interval=1.5)
                 ):
                 continue
+            if self._hook_special_reward():
+                continue
             if (not self.appear(self.I_REWARD) and
                 not self.appear(self.I_REWARD_GOLD)  # and
                 # not self.appear(self.I_REWARD_STATISTICS) and
@@ -250,6 +253,12 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
 
         return win
 
+    def _hook_special_reward(self) -> bool:
+        """
+        For overwrite https://github.com/runhey/OnmyojiAutoScript/issues/1580
+        """
+        return False
+
     def green_mark(self, enable: bool = False, mark_mode: GreenMarkType = GreenMarkType.GREEN_MAIN):
         """
         绿标, 如果不使能就直接返回

+ 7 - 0
tasks/Exploration/base.py

@@ -409,6 +409,13 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
             if self.appear(self.I_EXPLORATION_TITLE) or self.appear(self.I_CHECK_EXPLORATION):
                 continue
 
+    def _hook_special_reward(self) -> bool:
+        if self.appear(self.I_STATISTICS) and not self.appear(self.I_REWARD) and not self.appear(self.I_WIN):
+            if self.appear_then_click(self.I_CONFIRM_CLOSE_DIFF_SOUL):
+                return True
+            self.click(self.C_RANDOM_CLICK, interval=1.5)
+        return False
+
     def fire(self, button) -> bool:
         self.ui_click_until_disappear(button, interval=3)
         self.screenshot()