فهرست منبع

Merge nearaura dev through 09571eb4 for MetaDemon and navigation

Runhey returned Repository not found. Merge the authorized fallback range
55c3b151..09571eb4 (22 commits). Adopt the public/shared demon controls,
team unlock and preset handling, battle result hooks, UI templates,
exploration marker range, mall sign navigation, minitouch pressure range,
and updated project documentation.

Use the upstream PNGs directly. All 30 changed PNG paths match nearaura,
including 16 removals. Align right_enter dimensions in the rule and JSON
with the supplied 46x34 PNG. Bound the store sign wait even when both
controls are absent, and stop before launching a battle on unlock timeout.

Keep the emulator's exact ROI and desktop two-pixel tolerance using the
shared clipped expansion helper. Preserve fixed explicit animation crops
and the local battle strategy contexts. Limit the upstream mirror workflow
to its source repositories so fork pushes do not mirror to third parties.

Validation: 556 tests passed (tests and both FrogBoss suites), three
deprecation warnings. Checked 14 Python files, 11 production imports,
six JSON files, workflow YAML, removed asset references, 15 rules and
60 synthetic matches. git diff --check passed. No emulator run.
unknown 5 روز پیش
والد
کامیت
fc57fbd630
54فایلهای تغییر یافته به همراه325 افزوده شده و 251 حذف شده
  1. 3 2
      .github/workflows/github-mirror.yml
  2. 19 6
      README.md
  3. 3 1
      assets/i18n/zh-CN.json
  4. 1 1
      dev_tools/README.md
  5. 4 2
      module/atom/animate.py
  6. 3 9
      module/atom/image.py
  7. 11 0
      module/base/utils/utils.py
  8. 2 2
      module/device/method/minitouch.py
  9. 1 1
      tasks/Component/Costume/README.md
  10. 7 0
      tasks/Component/GeneralBattle/assets.py
  11. 9 0
      tasks/Component/GeneralBattle/battle_wait.py
  12. 20 0
      tasks/Component/GeneralBattle/lock/image.json
  13. BIN
      tasks/Component/GeneralBattle/lock/lock_team_lock.png
  14. BIN
      tasks/Component/GeneralBattle/lock/lock_team_unlock.png
  15. 11 3
      tasks/DailyTrifles/script_task.py
  16. 2 2
      tasks/GameUi/assets.py
  17. 1 1
      tasks/GameUi/page/image_exploration.json
  18. 2 2
      tasks/GameUi/page/image_main.json
  19. BIN
      tasks/GameUi/page/page_check_mall.png
  20. 9 37
      tasks/MetaDemon/assets.py
  21. 1 0
      tasks/MetaDemon/config.py
  22. BIN
      tasks/MetaDemon/md/Screenshots_a2.png
  23. BIN
      tasks/MetaDemon/md/Screenshots_a3.png
  24. BIN
      tasks/MetaDemon/md/Screenshots_a4.png
  25. BIN
      tasks/MetaDemon/md/Screenshots_a5.png
  26. BIN
      tasks/MetaDemon/md/Screenshots_a6.png
  27. 6 141
      tasks/MetaDemon/md/image.json
  28. 17 8
      tasks/MetaDemon/md/image_2025.json
  29. BIN
      tasks/MetaDemon/md/md_back_check.png
  30. BIN
      tasks/MetaDemon/md/md_battle_demon.png
  31. BIN
      tasks/MetaDemon/md/md_boos_public.png
  32. BIN
      tasks/MetaDemon/md/md_boss_convene.png
  33. BIN
      tasks/MetaDemon/md/md_boss_empty.png
  34. BIN
      tasks/MetaDemon/md/md_boss_empty_1.png
  35. BIN
      tasks/MetaDemon/md/md_crafting_1.png
  36. BIN
      tasks/MetaDemon/md/md_crafting_card_star_1.png
  37. BIN
      tasks/MetaDemon/md/md_crafting_start.png
  38. BIN
      tasks/MetaDemon/md/md_enter2.png
  39. BIN
      tasks/MetaDemon/md/md_md_enter.png
  40. BIN
      tasks/MetaDemon/md/md_md_extreme.png
  41. BIN
      tasks/MetaDemon/md/md_md_find.png
  42. BIN
      tasks/MetaDemon/md/md_md_fire.png
  43. BIN
      tasks/MetaDemon/md/md_md_fire_common.png
  44. BIN
      tasks/MetaDemon/md/md_md_fire_power.png
  45. BIN
      tasks/MetaDemon/md/md_md_gift_box.png
  46. BIN
      tasks/MetaDemon/md/md_md_hard.png
  47. BIN
      tasks/MetaDemon/md/md_md_main.png
  48. BIN
      tasks/MetaDemon/md/md_md_win.png
  49. BIN
      tasks/MetaDemon/md/md_red_back.png
  50. BIN
      tasks/MetaDemon/md/md_right_enter.png
  51. 74 33
      tasks/MetaDemon/script_task.py
  52. 15 0
      tests/module/atom/test_roi_padding.py
  53. 57 0
      tests/tasks/GameUi/test_exploration_marker.py
  54. 47 0
      tests/tasks/MetaDemon/test_battle_flow.py

+ 3 - 2
.github/workflows/github-mirror.yml

@@ -13,6 +13,7 @@ name: GitHub-Mirrors
 jobs:
   run:
     name: Run
+    if: github.repository == 'runhey/OnmyojiAutoScript' || github.repository == 'nearaura/OnmyojiAutoScript'
     runs-on: ubuntu-latest
     steps:
       - name: Get repo and time
@@ -36,7 +37,7 @@ jobs:
       - name: Mirror the GitHub repos to Gitee with cache
         uses: Yikun/hub-mirror-action@master
         with:
-          src: github/runhey
+          src: github/${{ github.repository_owner }}
           dst: gitee/runheng
           dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 复用公钥
           dst_token: ${{ secrets.GITEE_TOKEN }}
@@ -50,7 +51,7 @@ jobs:
       - name: Mirror the GitHub repos to GitCode with cache
         uses: Yikun/hub-mirror-action@master
         with:
-          src: github/runhey
+          src: github/${{ github.repository_owner }}
           dst: gitcode/OnmyojiAutoScript
           dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 复用公钥
           dst_token: ${{ secrets.GITCODE_TOKEN }}

+ 19 - 6
README.md

@@ -23,7 +23,7 @@
 一键托管
 
 
-### [文档](https://runhey.github.io/OnmyojiAutoScript-website/)
+### [文档](https://www.onmyojiautoscript.cn/)
 
 #### 主仓库: [https://github.com/runhey/OnmyojiAutoScript](https://github.com/runhey/OnmyojiAutoScript)
 
@@ -31,6 +31,19 @@
 
 阴阳师,作为一个手游,已经进入了生命周期的晚期。从现在到关服的这段时间里,请减少花费在阴阳师上的时间,把一切都交给 OAS。
 
+
+## 临时仓库
+
+2026.11.08 runhey 账号被 github 禁掉了。不知名原因、没有邮件通知,在申诉成功之前暂时使用当前备份仓库:
+
+https://github.com/nearaura/OnmyojiAutoScript
+
+国内镜像仓库,一直都挺稳定的:
+
+https://gitcode.com/OnmyojiAutoScript/OnmyojiAutoScript
+
+https://gitee.com/runheng/OnmyojiAutoScript
+
 ## 功能 Features
 
 - **日常任务**: 悬赏封印、小猫咪、小杂签到、金币妖怪、年兽、花合战、地鬼、封魔、御魂整理
@@ -44,7 +57,7 @@
 - **全部任务**: 你能想到的没有想到的都有,一条龙给你解放双手(该画饼画饼,该挖坑挖坑)
 - **无缝衔接**: 时间管理大师,优异的任务调度系统,无缝寄养,无缝执行任务
 - **装饰可选**: 全部初始皮肤是什么鬼,这里支持你喜欢的庭院、主题等等,[详细说明](https://github.com/runhey/OnmyojiAutoScript/issues/180)
-- **百鬼夜行**: 利用AI来智能撒豆子,模型包含所有式神,[效果展示](https://runhey.github.io/OnmyojiAutoScript-website/docs/user-manual/hyakkiyakou)
+- **百鬼夜行**: 利用AI来智能撒豆子,模型包含所有式神,[效果展示](https://www.onmyojiautoscript.cn/docs/user-manual/hyakkiyakou)
 
 ## 许可证 LICENSE
 
@@ -97,10 +110,10 @@ OAS 在其基础上进行了如下优化:
 
 ## 安装 Installation 
 
-- [学会提问](https://runhey.github.io/OnmyojiAutoScript-website/docs/user-manual/scientific-question): 最基本的要求,**必看必学必会**
-- [用户手册](https://runhey.github.io/OnmyojiAutoScript-website/docs/user-manual/getting-started): 在线手册,不定期更新,包含所有使用说明
-- [安装教程](https://runhey.github.io/OnmyojiAutoScript-website/docs/user-manual/installation): 保姆式安装手册,多翻翻有惊喜
-- [开发文档](https://runhey.github.io/OnmyojiAutoScript-website/docs/development/preamble): 虽然迭代很多、年久失修,但入门开发必读,具体以源码为准
+- [学会提问](https://www.onmyojiautoscript.cn/docs/user-manual/scientific-question): 最基本的要求,**必看必学必会**
+- [用户手册](https://www.onmyojiautoscript.cn/docs/user-manual/getting-started): 在线手册,不定期更新,包含所有使用说明
+- [安装教程](https://www.onmyojiautoscript.cn/docs/user-manual/installation): 保姆式安装手册,多翻翻有惊喜
+- [开发文档](https://www.onmyojiautoscript.cn/docs/development/preamble): 虽然迭代很多、年久失修,但入门开发必读,具体以源码为准
 
 ## 鸣谢 Acknowledgements
 

+ 3 - 1
assets/i18n/zh-CN.json

@@ -70,6 +70,8 @@
   "limit_daily_training_help": "",
   "limit_cultivation_drills": "修行合训挑战鬼王数量",
   "limit_cultivation_drills_help": "搜寻到一只后会一直打,直到打完算一次",
+  "auto_shared_boss": "自动挑战共享鬼王",
+  "auto_shared_boss_help": "是否自动挑战其他玩家共享的鬼王",
   "enable_switch_daily_training": "日常训练开启切换御魂",
   "enable_switch_cultivation_drills": "修行合训开启切换御魂",
   "demon_battle_config": "逢魔战斗内切换阵容",
@@ -167,4 +169,4 @@
   "green_mark_type_help": "按坐标点击指定绿标,或按式神名OCR 匹配后点击",
   "green_mark_name": "绿标式神名称",
   "green_mark_name_help": "仅当绿标按式神名匹配时生效,填写目标式神名"
-}
+}

+ 1 - 1
dev_tools/README.md

@@ -1,6 +1,6 @@
 ### 这三个都是窗口的管理工具
 
-塞进仓库并不是一个很好的选择,现已移出,已链接形式提供,请查阅文档[**模拟器支持**](https://runhey.github.io/OnmyojiAutoScript-website/docs/user-manual/emulator-support)
+塞进仓库并不是一个很好的选择,现已移出,已链接形式提供,请查阅文档[**模拟器支持**](https://www.onmyojiautoscript.cn/docs/user-manual/emulator-support)
 
 - Spyxx (微软自家的)
 - ViewWizard2(简易版本)

+ 4 - 2
module/atom/animate.py

@@ -41,6 +41,8 @@ class RuleAnimate(RuleImage):
 
         if name is not None:
             self._name = name
+        # match() 会更新 roi_front;动画帧比较始终使用初始裁剪区域,避免搜索范围扩大后发生漂移。
+        self._crop_roi = tuple(roi_front)
         self._last_image = None
 
     @property
@@ -55,12 +57,12 @@ class RuleAnimate(RuleImage):
         @return:
         """
         if self._last_image is None:
-            self._last_image = self.corp(image, self.roi_front)
+            self._last_image = self.corp(image, self._crop_roi)
             return False
 
         self._image = self._last_image
         matched = self.match(image)
-        self._last_image = self.corp(image, self.roi_front)
+        self._last_image = self.corp(image, self._crop_roi)
 
         if matched:
             if refresh_after_stable:

+ 3 - 9
module/atom/image.py

@@ -10,7 +10,7 @@ from pathlib import Path
 from module.atom.RuleImageMallResourceMixin import RuleImageMallResourceMixin
 from module.base.decorator import cached_property, del_cached_property
 from module.logger import logger
-from module.base.utils import is_approx_rectangle
+from module.base.utils import expand_roi, is_approx_rectangle
 from module.base.utils.utils import random_normal_distribution_int
 
 # 模板匹配容差:把搜索区域(roi_back)四边各外扩该像素数,用于吸收非原生渲染
@@ -163,13 +163,7 @@ class RuleImage(RuleImageMallResourceMixin):
         并连带把回算出的 roi_front 算偏;右/下侧越界由切片自然截断。
         返回的 x0/y0 是外扩后的原点,命中回算必须以它做基准。
         """
-        x, y, w, h = [int(v) for v in roi]
-        pad = ROI_MATCH_PAD
-        if pad <= 0:
-            return x, y, w, h
-        x0 = max(0, x - pad)
-        y0 = max(0, y - pad)
-        return x0, y0, x + w + pad - x0, y + h + pad - y0
+        return expand_roi(roi, ROI_MATCH_PAD)
 
     @property
     def mask(self):
@@ -254,7 +248,7 @@ class RuleImage(RuleImageMallResourceMixin):
         :param roi
         :return:
         """
-        x, y, w, h = self._pad_roi(self.roi_back if roi is None else roi)
+        x, y, w, h = self._pad_roi(self.roi_back) if roi is None else roi
         return image[y:y + h, x:x + w]
 
     def match(self, image: np.array, threshold: float = None) -> bool:

+ 11 - 0
module/base/utils/utils.py

@@ -225,6 +225,17 @@ def area_pad(area, pad=10):
     return upper_left_x + pad, upper_left_y + pad, bottom_right_x - pad, bottom_right_y - pad
 
 
+def expand_roi(roi, padding=2, screen_size=(1280, 720)):
+    """Expand an (x, y, width, height) ROI and clip it to the screen bounds."""
+    x, y, width, height = [int(value) for value in roi]
+    screen_width, screen_height = screen_size
+    x0 = min(max(0, x - padding), screen_width)
+    y0 = min(max(0, y - padding), screen_height)
+    x1 = min(max(0, x + width + padding), screen_width)
+    y1 = min(max(0, y + height + padding), screen_height)
+    return x0, y0, max(0, x1 - x0), max(0, y1 - y0)
+
+
 def limit_in(x, lower, upper):
     """
     Limit x within range (lower, upper)

+ 2 - 2
module/device/method/minitouch.py

@@ -411,7 +411,7 @@ class Minitouch(Connection):
 
     def _humanized_pressure(self) -> int:
         top = getattr(self, 'max_pressure', 100) or 100
-        return random.randint(max(20, top // 2), top)
+        return random.randint(max(1, top // 2), top)
 
     def _humanized_dwell(self) -> int:
         return int(random.triangular(45, 130, 65))
@@ -634,4 +634,4 @@ class Minitouch(Connection):
 
 if __name__ == '__main__':
     mm = Minitouch(config='oas1')
-    mm.click_minitouch(200, 150)
+    mm.click_minitouch(200, 150)

+ 1 - 1
tasks/Component/Costume/README.md

@@ -42,4 +42,4 @@
 
    **在测试之前你需要打开一次 OASX 修改你对应的庭院皮肤的选项**
 
-8. 完事啦???哪有那么简单,你没有发现打开 OASX 的时候发现你的选项还是 `costume_main_xxx` 这种吗。你还需要添加一个翻译,[点击这儿](https://runhey.github.io/OnmyojiAutoScript-website/docs/development/user-option#7翻译)
+8. 完事啦???哪有那么简单,你没有发现打开 OASX 的时候发现你的选项还是 `costume_main_xxx` 这种吗。你还需要添加一个翻译,[点击这儿](https://www.onmyojiautoscript.cn/docs/development/user-option#7翻译)

+ 7 - 0
tasks/Component/GeneralBattle/assets.py

@@ -267,3 +267,10 @@ class GeneralBattleAssets:
 	I_END_FIX_2 = RuleImage(roi_front=(800,251,100,33), roi_back=(32,90,1137,547), threshold=0.85, method="Template matching", file="./tasks/Component/GeneralBattle/gw/gw_end_fix_2.png")
 	#  
 	I_END_FIX_3 = RuleImage(roi_front=(871,278,150,49), roi_back=(119,66,1136,620), threshold=0.85, method="Template matching", file="./tasks/Component/GeneralBattle/gw/gw_end_fix_3.png")
+
+
+	# Image Rule Assets
+	# 显示是锁队伍的图标
+	I_TEAM_LOCK = RuleImage(roi_front=(1135,379,26,31), roi_back=(728,354,470,341), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/lock/lock_team_lock.png")
+	# 显示是没有锁队伍的图标
+	I_TEAM_UNLOCK = RuleImage(roi_front=(1136,379,25,27), roi_back=(724,346,472,342), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/lock/lock_team_unlock.png")

+ 9 - 0
tasks/Component/GeneralBattle/battle_wait.py

@@ -341,6 +341,15 @@ class PerTaskPreset:
     # 一次任务类型触发一次,想要再次触发把done设置False
     done: bool = False
 
+    @classmethod
+    def reset_preset_state(cls, owner: 'BattleWait') -> None:
+        if runtime.task_owner is not owner:
+            # runtime 还没绑定到本任务,per_task 会在首个钩子调用时整体重建,这里无需处理
+            return
+        for hook_name, ctx in runtime.pri_ctx.items():
+            if runtime.hook2event(hook_name) == 'preset':
+                ctx.per_task = cls()
+
 
 @dataclass
 class PerTaskGreen:

+ 20 - 0
tasks/Component/GeneralBattle/lock/image.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "team_lock",
+    "imageName": "lock_team_lock.png",
+    "roiFront": "1135,379,26,31",
+    "roiBack": "728,354,470,341",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "显示是锁队伍的图标"
+  },
+  {
+    "itemName": "team_unlock",
+    "imageName": "lock_team_unlock.png",
+    "roiFront": "1136,379,25,27",
+    "roiBack": "724,346,472,342",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "显示是没有锁队伍的图标"
+  }
+]

BIN
tasks/Component/GeneralBattle/lock/lock_team_lock.png


BIN
tasks/Component/GeneralBattle/lock/lock_team_unlock.png


+ 11 - 3
tasks/DailyTrifles/script_task.py

@@ -222,8 +222,16 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
     def run_store_sign(self):
 
         self.goto_page(page_store_gift_room)
-        self.screenshot()
-        self.appear_then_click(self.I_GIFT_RECOMMEND, interval=1)
+
+        cnt = 0
+        timeout = Timer(6).start()
+        while True:
+            self.screenshot()
+            if self.appear(self.I_GIFT_SIGN) or cnt >= 4 or timeout.reached():
+                break
+            if self.appear_then_click(self.I_GIFT_RECOMMEND, interval=1):
+                cnt += 1
+                continue
         logger.info('Enter store sign')
         sleep(1)  # 等个动画
         self.screenshot()
@@ -302,4 +310,4 @@ if __name__ == '__main__':
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.run_friend_love()
+    t.run()

+ 2 - 2
tasks/GameUi/assets.py

@@ -31,7 +31,7 @@ class GameUiAssets:
 
 	# Image Rule Assets
 	# 探索界面标识
-	I_CHECK_EXPLORATION = RuleImage(roi_front=(1152,148,21,22), roi_back=(1152,148,21,22), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_exploration.png")
+	I_CHECK_EXPLORATION = RuleImage(roi_front=(1152,148,21,22), roi_back=(1138,134,56,50), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_exploration.png")
 	# 探索前往觉醒 
 	I_EXPLORATION_GOTO_AWAKE_ZONE = RuleImage(roi_front=(161,633,47,44), roi_back=(33,619,1150,99), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_exploration_goto_awake_zone.png")
 	# 探索前往御魂 
@@ -144,7 +144,7 @@ class GameUiAssets:
 	# 花合战页面标志
 	I_CHECK_DAILY = RuleImage(roi_front=(28,515,58,62), roi_back=(1,487,154,145), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_daily.png")
 	# 商店页面标志
-	I_CHECK_MALL = RuleImage(roi_front=(231,455,131,78), roi_back=(201,432,185,121), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_mall.png")
+	I_CHECK_MALL = RuleImage(roi_front=(1087,413,47,114), roi_back=(1043,397,116,155), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_mall.png")
 	# 商店页面标志(紫色招牌)
 	I_CHECK_MALL_PURPLE = RuleImage(roi_front=(231,455,131,78), roi_back=(201,432,185,121), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_mall_purple.png")
 	# 商店推荐页面标志

+ 1 - 1
tasks/GameUi/page/image_exploration.json

@@ -3,7 +3,7 @@
     "itemName": "check_exploration",
     "imageName": "page_check_exploration.png",
     "roiFront": "1152,148,21,22",
-    "roiBack": "1152,148,21,22",
+    "roiBack": "1138,134,56,50",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "探索界面标识"

+ 2 - 2
tasks/GameUi/page/image_main.json

@@ -164,8 +164,8 @@
   {
     "itemName": "check_mall",
     "imageName": "page_check_mall.png",
-    "roiFront": "231,455,131,78",
-    "roiBack": "201,432,185,121",
+    "roiFront": "1087,413,47,114",
+    "roiBack": "1043,397,116,155",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "商店页面标志"

BIN
tasks/GameUi/page/page_check_mall.png


+ 9 - 37
tasks/MetaDemon/assets.py

@@ -11,55 +11,25 @@ class MetaDemonAssets:
 
 
 	# Image Rule Assets
-	# description 
-	I_MD_ENTER = RuleImage(roi_front=(426,463,60,80), roi_back=(239,369,547,215), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_enter.png")
-	# description 
-	I_MD_MAIN = RuleImage(roi_front=(658,156,41,139), roi_back=(636,133,100,245), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_main.png")
-	# description 
-	I_MD_FIND = RuleImage(roi_front=(1112,581,100,100), roi_back=(1112,581,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_find.png")
-	# 高 
-	I_MD_HARD = RuleImage(roi_front=(513,515,26,27), roi_back=(513,515,26,27), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_hard.png")
-	# description 
-	I_MD_FIRE = RuleImage(roi_front=(1107,563,109,113), roi_back=(1107,563,109,113), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_md_fire.png")
-	# description 
-	I_MD_GIFT_BOX = RuleImage(roi_front=(1184,182,42,50), roi_back=(1184,182,42,50), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_gift_box.png")
-	# 难度 
-	I_MD_EXTREME = RuleImage(roi_front=(512,516,30,25), roi_back=(512,516,30,25), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_extreme.png")
-	# description 
-	I_MD_FIRE_COMMON = RuleImage(roi_front=(1065,499,100,36), roi_back=(1065,499,100,36), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_fire_common.png")
-	# description 
-	I_MD_FIRE_POWER = RuleImage(roi_front=(1159,498,100,37), roi_back=(1159,498,100,37), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_fire_power.png")
 	# 失败 
 	I_MD_BATTLE_FAILURE = RuleImage(roi_front=(412,105,100,100), roi_back=(412,105,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_battle_failure.png")
-	# 进入鬼王界面 
-	I_A2 = RuleImage(roi_front=(751,137,41,149), roi_back=(751,137,41,149), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/Screenshots_a2.png")
-	# 召唤鬼王 
-	I_A3 = RuleImage(roi_front=(1137,581,100,100), roi_back=(1137,581,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/Screenshots_a3.png")
-	# 挑战 
-	I_A4 = RuleImage(roi_front=(1137,581,100,100), roi_back=(1137,581,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/Screenshots_a4.png")
-	# 准备 
-	I_A5 = RuleImage(roi_front=(1129,536,100,100), roi_back=(1129,536,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/Screenshots_a5.png")
-	# description 
-	I_A6 = RuleImage(roi_front=(435,147,100,100), roi_back=(435,147,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/Screenshots_a6.png")
-	# 超鬼王打完了 
-	I_BACK_CHECK = RuleImage(roi_front=(378,257,68,32), roi_back=(378,257,68,32), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_back_check.png")
-	# 红色的叉叉 
-	I_RED_BACK = RuleImage(roi_front=(925,181,47,48), roi_back=(925,181,47,48), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_red_back.png")
+	#
+	I_MD_WIN = RuleImage(roi_front=(691,55,236,170), roi_back=(668,32,282,216), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_win.png")
 
 
 	# Image Rule Assets
 	# 右侧进去 
-	I_RIGHT_ENTER = RuleImage(roi_front=(1183,314,46,34), roi_back=(1150,131,100,360), threshold=0.75, method="Template matching", file="./tasks/MetaDemon/md/md_right_enter.png")
+	I_RIGHT_ENTER = RuleImage(roi_front=(1188,220,46,34), roi_back=(1150,131,100,360), threshold=0.75, method="Template matching", file="./tasks/MetaDemon/md/md_right_enter.png")
 	# description 
-	I_ENTER2 = RuleImage(roi_front=(461,265,44,156), roi_back=(428,220,100,258), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_enter2.png")
+	I_ENTER2 = RuleImage(roi_front=(933,150,73,125), roi_back=(893,47,116,244), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_enter2.png")
 	# 寻找鬼王 
 	I_FIND_DEMON = RuleImage(roi_front=(1140,582,86,81), roi_back=(1102,546,132,133), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_find_demon.png")
 	# 点击战斗 
-	I_BATTLE_DEMON = RuleImage(roi_front=(1131,573,100,100), roi_back=(1085,536,165,161), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_battle_demon.png")
+	I_BATTLE_DEMON = RuleImage(roi_front=(1133,595,98,54), roi_back=(1085,536,165,161), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_battle_demon.png")
 	# description 
 	I_BOSS_EMPTY = RuleImage(roi_front=(44,134,88,85), roi_back=(44,134,88,85), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty.png")
 	# 集结 
-	I_BOSS_CONVENE = RuleImage(roi_front=(247,146,47,52), roi_back=(228,127,88,85), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_boss_convene.png")
+	I_BOSS_CONVENE = RuleImage(roi_front=(251,155,47,52), roi_back=(228,127,88,90), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_boss_convene.png")
 	# description 
 	I_BOSS_EMPTY_1 = RuleImage(roi_front=(46,372,87,90), roi_back=(46,372,87,90), threshold=0.5, method="Template matching", file="./tasks/MetaDemon/md/md_boss_empty_1.png")
 	# description 
@@ -69,7 +39,7 @@ class MetaDemonAssets:
 	# 空 
 	I_CRAFTING_EMPTY = RuleImage(roi_front=(939,460,75,81), roi_back=(922,447,108,111), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_empty.png")
 	# 一星卡片 
-	I_CRAFTING_CARD_STAR_1 = RuleImage(roi_front=(217,156,87,92), roi_back=(191,127,140,137), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_card_star_1.png")
+	I_CRAFTING_CARD_STAR_1 = RuleImage(roi_front=(214,152,87,92), roi_back=(191,127,140,137), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_card_star_1.png")
 	# 开始合成 
 	I_CRAFTING_START = RuleImage(roi_front=(889,561,140,39), roi_back=(840,521,231,100), threshold=0.75, method="Template matching", file="./tasks/MetaDemon/md/md_crafting_start.png")
 	# description 
@@ -82,6 +52,8 @@ class MetaDemonAssets:
 	I_STAR56_HP_THRESHOLD_F = RuleImage(roi_front=(659,517,26,19), roi_back=(659,517,26,19), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_star56_hp_threshold_f.png")
 	# description 
 	I_ENTER_ENSURE = RuleImage(roi_front=(541,578,186,48), roi_back=(443,555,370,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_enter_ensure.png")
+	# 已公开
+	I_BOOS_PUBLIC = RuleImage(roi_front=(251,155,47,52), roi_back=(228,127,88,90), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_boos_public.png")
 
 
 	# Ocr Rule Assets

+ 1 - 0
tasks/MetaDemon/config.py

@@ -76,6 +76,7 @@ class Strategy(ConfigBase):
 class MetaDemonConfig(ConfigBase):
     meta_crafting_card: bool = Field(default=True, description='craft_essence_help')
     auto_tea: bool = Field(default=False, description='auto_tea_help')
+    auto_shared_boss: bool = Field(default=True, description='auto_shared_boss_help')
     # extreme_notify: bool = Field(default=False, description='extreme_notify_help')
     md_strategy_count: int = Field(default=0, ge=0, description='md_strategy_count_help')
     md_use_strategy: bool = Field(default=False, description='md_use_strategy_help')

BIN
tasks/MetaDemon/md/Screenshots_a2.png


BIN
tasks/MetaDemon/md/Screenshots_a3.png


BIN
tasks/MetaDemon/md/Screenshots_a4.png


BIN
tasks/MetaDemon/md/Screenshots_a5.png


BIN
tasks/MetaDemon/md/Screenshots_a6.png


+ 6 - 141
tasks/MetaDemon/md/image.json

@@ -1,85 +1,4 @@
 [
-  {
-    "itemName": "md_enter",
-    "imageName": "md_md_enter.png",
-    "roiFront": "426,463,60,80",
-    "roiBack": "239,369,547,215",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "md_main",
-    "imageName": "md_md_main.png",
-    "roiFront": "658,156,41,139",
-    "roiBack": "636,133,100,245",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "md_find",
-    "imageName": "md_md_find.png",
-    "roiFront": "1112,581,100,100",
-    "roiBack": "1112,581,100,100",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "md_hard",
-    "imageName": "md_md_hard.png",
-    "roiFront": "513,515,26,27",
-    "roiBack": "513,515,26,27",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "高"
-  },
-  {
-    "itemName": "md_fire",
-    "imageName": "md_md_fire.png",
-    "roiFront": "1107,563,109,113",
-    "roiBack": "1107,563,109,113",
-    "method": "Template matching",
-    "threshold": 0.7,
-    "description": "description"
-  },
-  {
-    "itemName": "md_gift_box",
-    "imageName": "md_md_gift_box.png",
-    "roiFront": "1184,182,42,50",
-    "roiBack": "1184,182,42,50",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "md_extreme",
-    "imageName": "md_md_extreme.png",
-    "roiFront": "512,516,30,25",
-    "roiBack": "512,516,30,25",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "难度"
-  },
-  {
-    "itemName": "md_fire_common",
-    "imageName": "md_md_fire_common.png",
-    "roiFront": "1065,499,100,36",
-    "roiBack": "1065,499,100,36",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "md_fire_power",
-    "imageName": "md_md_fire_power.png",
-    "roiFront": "1159,498,100,37",
-    "roiBack": "1159,498,100,37",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
   {
     "itemName": "md_battle_failure",
     "imageName": "md_md_battle_failure.png",
@@ -90,66 +9,12 @@
     "description": "失败"
   },
   {
-    "itemName": "a2",
-    "imageName": "Screenshots_a2.png",
-    "roiFront": "751,137,41,149",
-    "roiBack": "751,137,41,149",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "进入鬼王界面"
-  },
-  {
-    "itemName": "a3",
-    "imageName": "Screenshots_a3.png",
-    "roiFront": "1137,581,100,100",
-    "roiBack": "1137,581,100,100",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "召唤鬼王"
-  },
-  {
-    "itemName": "a4",
-    "imageName": "Screenshots_a4.png",
-    "roiFront": "1137,581,100,100",
-    "roiBack": "1137,581,100,100",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "挑战"
-  },
-  {
-    "itemName": "a5",
-    "imageName": "Screenshots_a5.png",
-    "roiFront": "1129,536,100,100",
-    "roiBack": "1129,536,100,100",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "准备"
-  },
-  {
-    "itemName": "a6",
-    "imageName": "Screenshots_a6.png",
-    "roiFront": "435,147,100,100",
-    "roiBack": "435,147,100,100",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
-  {
-    "itemName": "back_check",
-    "imageName": "md_back_check.png",
-    "roiFront": "378,257,68,32",
-    "roiBack": "378,257,68,32",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "超鬼王打完了"
-  },
-  {
-    "itemName": "red_back",
-    "imageName": "md_red_back.png",
-    "roiFront": "925,181,47,48",
-    "roiBack": "925,181,47,48",
+    "itemName": "md_win",
+    "imageName": "md_md_win.png",
+    "roiFront": "691,55,236,170",
+    "roiBack": "668,32,282,216",
     "method": "Template matching",
     "threshold": 0.8,
-    "description": "红色的叉叉"
+    "description": ""
   }
-]
+]

+ 17 - 8
tasks/MetaDemon/md/image_2025.json

@@ -2,7 +2,7 @@
   {
     "itemName": "right_enter",
     "imageName": "md_right_enter.png",
-    "roiFront": "1183,314,46,34",
+    "roiFront": "1188,220,46,34",
     "roiBack": "1150,131,100,360",
     "method": "Template matching",
     "threshold": 0.75,
@@ -11,8 +11,8 @@
   {
     "itemName": "enter2",
     "imageName": "md_enter2.png",
-    "roiFront": "461,265,44,156",
-    "roiBack": "428,220,100,258",
+    "roiFront": "933,150,73,125",
+    "roiBack": "893,47,116,244",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -29,7 +29,7 @@
   {
     "itemName": "battle_demon",
     "imageName": "md_battle_demon.png",
-    "roiFront": "1131,573,100,100",
+    "roiFront": "1133,595,98,54",
     "roiBack": "1085,536,165,161",
     "method": "Template matching",
     "threshold": 0.7,
@@ -47,8 +47,8 @@
   {
     "itemName": "boss_convene",
     "imageName": "md_boss_convene.png",
-    "roiFront": "247,146,47,52",
-    "roiBack": "228,127,88,85",
+    "roiFront": "251,155,47,52",
+    "roiBack": "228,127,88,90",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "集结"
@@ -92,7 +92,7 @@
   {
     "itemName": "crafting_card_star_1",
     "imageName": "md_crafting_card_star_1.png",
-    "roiFront": "217,156,87,92",
+    "roiFront": "214,152,87,92",
     "roiBack": "191,127,140,137",
     "method": "Template matching",
     "threshold": 0.8,
@@ -151,5 +151,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
+  },
+  {
+    "itemName": "boos_public",
+    "imageName": "md_boos_public.png",
+    "roiFront": "251,155,47,52",
+    "roiBack": "228,127,88,90",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "已公开"
   }
-]
+]

BIN
tasks/MetaDemon/md/md_back_check.png


BIN
tasks/MetaDemon/md/md_battle_demon.png


BIN
tasks/MetaDemon/md/md_boos_public.png


BIN
tasks/MetaDemon/md/md_boss_convene.png


BIN
tasks/MetaDemon/md/md_boss_empty.png


BIN
tasks/MetaDemon/md/md_boss_empty_1.png


BIN
tasks/MetaDemon/md/md_crafting_1.png


BIN
tasks/MetaDemon/md/md_crafting_card_star_1.png


BIN
tasks/MetaDemon/md/md_crafting_start.png


BIN
tasks/MetaDemon/md/md_enter2.png


BIN
tasks/MetaDemon/md/md_md_enter.png


BIN
tasks/MetaDemon/md/md_md_extreme.png


BIN
tasks/MetaDemon/md/md_md_find.png


BIN
tasks/MetaDemon/md/md_md_fire.png


BIN
tasks/MetaDemon/md/md_md_fire_common.png


BIN
tasks/MetaDemon/md/md_md_fire_power.png


BIN
tasks/MetaDemon/md/md_md_gift_box.png


BIN
tasks/MetaDemon/md/md_md_hard.png


BIN
tasks/MetaDemon/md/md_md_main.png


BIN
tasks/MetaDemon/md/md_md_win.png


BIN
tasks/MetaDemon/md/md_red_back.png


BIN
tasks/MetaDemon/md/md_right_enter.png


+ 74 - 33
tasks/MetaDemon/script_task.py

@@ -8,11 +8,16 @@ from time import sleep
 
 from module.base.timer import Timer
 from module.logger import logger
-from module.exception import TaskEnd
+from module.exception import GameStuckError, TaskEnd
 
 
 from tasks.Component.RightActivity.right_activity import RightActivity
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.GeneralBattle.battle import Battle
+from tasks.Component.GeneralBattle.battle_wait import (
+    BattleResult, HookSignal, PerTaskPreset, PrivateContext, PublicContext,
+    battle_wait_strategy, battle_wait_options, runtime,
+)
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.GameUi.game_ui import GameUi
@@ -69,7 +74,7 @@ class Star56(GameUi, MetaDemonAssets):
         return tmp if tmp else self.cached_default_group_team
 
 
-class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
+class ScriptTask(RightActivity, Battle, GeneralBattle, SwitchSoul, Star56):
 
     def run(self):
         if self.config.meta_demon.switch_soul.enable:
@@ -109,14 +114,15 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
                 continue
 
             # 先看自己有没有鬼王要打
-            if not self.appear(self.I_BOSS_EMPTY) and self.appear(self.I_BOSS_CONVENE):
+            if (not self.appear(self.I_BOSS_EMPTY) and
+                    (self.appear(self.I_BOSS_CONVENE) or self.appear(self.I_BOOS_PUBLIC))):
                 logger.info('Try to battle boss from self')
                 self.click(self.I_BOSS_EMPTY, interval=1.5)
                 battle_processing = True
                 if self.is_star56():
                     is_hard_boss = True
             # 看别人的是否给我共享鬼王
-            if not battle_processing:
+            if not battle_processing and self.config.meta_demon.meta_demon_config.auto_shared_boss:
                 if not self.appear(self.I_BOSS_EMPTY_1) and self.ocr_appear(self.O_BOSS_EMPTY_1):
                     logger.info('Try to battle boss 1 from others')
                     self.click(self.I_BOSS_EMPTY_1, interval=1.5)
@@ -248,46 +254,81 @@ class ScriptTask(RightActivity, GeneralBattle, SwitchSoul, Star56):
         return True
 
     def battle_boss(self, group: int = None, team: int = None) -> bool:
+        """
+        战斗流程不再自己写 while 循环,全部交给 battle_wait 的策略化钩子:
+          prepare/preset  准备阶段与预设队伍(5/6 星按推荐阵容切队)
+          success/failure 超鬼王自带的结算界面(I_MD_WIN / I_MD_BATTLE_FAILURE)
+          idle            战斗中给鬼王上标记
+        @param group: 预设组,与 team 同时为 None 时不切预设队伍
+        @param team:  预设队伍,与 group 同时为 None 时不切预设队伍
+        @return: True 战斗胜利,False 战斗失败
+        """
         logger.info('Battle boss')
+        if not self.ui_click(self.I_TEAM_LOCK, self.I_TEAM_UNLOCK, interval=1.5, timeout=5):
+            raise GameStuckError("MetaDemon team unlock timed out")
         self.ui_click_until_disappear(self.I_BATTLE_DEMON, interval=1.8)
+        # 任务级战斗计数:本场是第几场(和旧日志 Current count 对齐)
+        count = runtime.pub_ctx.per_task.count if runtime.pub_ctx else 0
+        logger.info(f'Current count: {count + 1}')
+
         battle_config = GeneralBattleConfig()
         battle_config.lock_team_enable = False
-        if group is None and team is None:
-            battle_config.preset_enable = False
-            success = self.run_general_battle(battle_config)
-            return True if success else False
         # 针对5/6星的挑战
-        else:
+        if group is not None and team is not None:
             battle_config.preset_enable = True
             battle_config.preset_group = group
             battle_config.preset_team = team
-            tmp_battle_count = self.current_count
-            self.current_count = 0
-            success = self.run_general_battle(battle_config)
-            self.current_count = tmp_battle_count + 1
-            return True if success else False
-
-    def battle_wait(self, random_click_swipt_enable: bool) -> bool:
-        # 重写
-        self.device.stuck_record_add('BATTLE_STATUS_S')
-        self.device.click_record_clear()
-        logger.info("Start battle process")
+            # 每只5/6星鬼王的推荐阵容不同,而预设队伍默认是按任务只切一次的,
+            # 这里只复位 preset 的任务级状态,per_task.count 保持累加
+            PerTaskPreset.reset_preset_state(self)
+
+        strategies, options = self.loadout_from_config(battle_config)
+        strategies['success'] = 'metademon'
+        strategies['failure'] = 'metademon'
+        strategies['idle'] = 'metademon'
+        options['completion'].check_imgs = [self.I_CRAFTING_1, self.I_FIND_DEMON, self.I_BATTLE_DEMON]
+
+        self.loadout_show((strategies, options))
         self.boss_mark_reset()
+        with battle_wait_strategy(**strategies), battle_wait_options(**options):
+            win = self.battle_wait()
+        logger.info(f'Battle boss win: {win}, current count: {runtime.pub_ctx.per_task.count}')
+        return win
+
+    # ------------------------------------------------------------------------------------------------------------------
+    # battle_wait 钩子:超鬼王自己的结算界面与战中行为
+    # ------------------------------------------------------------------------------------------------------------------
+    def _bw_success_metademon(self, pub: PublicContext, pri: PrivateContext) -> HookSignal:
+        if not self.appear(self.I_MD_WIN):
+            return HookSignal.CONTINUE
+        logger.info('Win battle')
         while 1:
             self.screenshot()
-            # if self.appear_then_click(self.I_WIN, interval=1):
-            #     continue
-            if self.appear(self.I_WIN):
-                logger.info('Win battle')
-                self.ui_click_until_disappear(self.I_WIN)
-                return True
-
-            if self.appear(self.I_MD_BATTLE_FAILURE):
-                logger.warning('False battle')
-                self.ui_click_until_disappear(self.I_MD_BATTLE_FAILURE)
-                return False
-            if self.boss_mark():
-                continue
+            if not self.appear(self.I_MD_WIN):
+                break
+            self.click(self.I_MD_WIN)
+            sleep(0.5)
+        pub.per_battle.success = BattleResult.SUCCESS
+        return runtime.hook_enabled_update(
+            enable=('completion',),
+            disable=('success', 'failure'),
+        )
+
+    def _bw_failure_metademon(self, pub: PublicContext, pri: PrivateContext) -> HookSignal:
+        if not self.appear(self.I_MD_BATTLE_FAILURE):
+            return HookSignal.CONTINUE
+        logger.warning('False battle')
+        self.ui_click_until_disappear(self.I_MD_BATTLE_FAILURE)
+        pub.per_battle.success = BattleResult.FAILURE
+        return runtime.hook_enabled_update(
+            enable=('completion',),
+            disable=('success', 'failure'),
+        )
+
+    def _bw_idle_metademon(self, pub: PublicContext, pri: PrivateContext) -> HookSignal:
+        if self.is_in_real_battle(False):
+            self.boss_mark()
+        return HookSignal.CONTINUE
 
 
 if __name__ == '__main__':

+ 15 - 0
tests/module/atom/test_roi_padding.py

@@ -3,6 +3,7 @@ import pytest
 
 from module.atom import image as image_module
 from module.atom.image import RuleImage
+from module.atom.animate import RuleAnimate
 
 
 @pytest.mark.parametrize('method', ['match', 'match_multi_scale', 'match_all', 'match_all_any'])
@@ -37,3 +38,17 @@ def test_emulator_without_padding_does_not_accept_shifted_template(monkeypatch):
     rule = RuleImage((11, 11, 10, 10), (11, 11, 10, 10), 'Template matching', 0.99, 'unused.png')
     rule._image = pixels
     assert not rule.match(screen)
+
+
+def test_animation_samples_fixed_region_after_a_desktop_match_moves(monkeypatch):
+    monkeypatch.setattr(image_module, 'ROI_MATCH_PAD', 2)
+    roi = (10, 10, 8, 8)
+    rule = RuleAnimate(RuleImage(roi, roi, 'Template matching', 0.99, 'unused.png'))
+    pixels = np.random.default_rng(23).integers(0, 256, (8, 8, 3), dtype=np.uint8)
+    first = np.zeros((32, 32, 3), dtype=np.uint8)
+    first[10:18, 10:18] = pixels
+    shifted = np.roll(first, 2, axis=1)
+    assert not rule.stable(first)
+    assert rule.stable(shifted)
+    assert rule.roi_front[:2] == [12, 10]
+    np.testing.assert_array_equal(rule._last_image, shifted[10:18, 10:18])

+ 57 - 0
tests/tasks/GameUi/test_exploration_marker.py

@@ -0,0 +1,57 @@
+"""Exploration marker recognition under observed map-layout shifts."""
+import json
+from pathlib import Path
+import unittest
+
+import numpy as np
+
+from module.atom.image import RuleImage
+from tasks.GameUi.assets import GameUiAssets
+
+
+ROOT = Path(__file__).resolve().parents[3]
+
+
+class ExplorationMarkerTests(unittest.TestCase):
+    def rule(self):
+        item = next(item for item in json.loads(
+            (ROOT / 'tasks/GameUi/page/image_exploration.json').read_text(encoding='utf-8'))
+                    if item['itemName'] == 'check_exploration')
+        return RuleImage(tuple(map(int, item['roiFront'].split(','))),
+                         tuple(map(int, item['roiBack'].split(','))),
+                         item['method'], item['threshold'],
+                         './tasks/GameUi/page/' + item['imageName'])
+
+    def frame(self, rule, x=1152, y=148):
+        frame = np.full((720, 1280, 3), 100, dtype=np.uint8)
+        height, width = rule.image.shape[:2]
+        frame[y:y + height, x:x + width] = rule.image
+        return frame
+
+    def test_detects_both_observed_horizontal_positions(self):
+        for x in (1152, 1166):
+            with self.subTest(x=x):
+                rule = self.rule()
+                self.assertTrue(rule.match(self.frame(rule, x=x)))
+                self.assertEqual(rule.roi_front[:2], [x, 148])
+
+    def test_old_search_box_reproduces_shifted_map_failure(self):
+        rule = self.rule()
+        rule.roi_back = (1150, 146, 25, 26)  # Original ROI plus global 2px padding.
+        self.assertFalse(rule.match(self.frame(rule, x=1166)))
+
+    def test_marker_elsewhere_does_not_classify_a_map(self):
+        rule = self.rule()
+        self.assertFalse(rule.match(self.frame(rule, x=900)))
+
+    def test_blank_frame_does_not_classify_a_map(self):
+        self.assertFalse(self.rule().match(np.full((720, 1280, 3), 100, dtype=np.uint8)))
+
+    def test_generated_asset_keeps_the_source_search_box(self):
+        source = self.rule()
+        self.assertEqual(GameUiAssets.I_CHECK_EXPLORATION.roi_back, source.roi_back)
+        self.assertEqual(GameUiAssets.I_CHECK_EXPLORATION.threshold, source.threshold)
+
+
+if __name__ == '__main__':
+    unittest.main()

+ 47 - 0
tests/tasks/MetaDemon/test_battle_flow.py

@@ -0,0 +1,47 @@
+import pytest
+
+from module.exception import GameStuckError
+from tasks.Component.GeneralBattle.battle_wait import runtime
+from tasks.MetaDemon import script_task
+
+
+@pytest.mark.parametrize('win', [True, False])
+def test_boss_battle_unlocks_and_finishes_on_result_screen(monkeypatch, win):
+    monkeypatch.setattr(runtime, 'pub_ctx', None)
+    monkeypatch.setattr(runtime, 'pri_ctx', {})
+    monkeypatch.setattr(runtime, 'task_owner', None)
+    monkeypatch.setattr(script_task, 'sleep', lambda _: None)
+    task = script_task.ScriptTask.__new__(script_task.ScriptTask)
+    result = task.I_MD_WIN if win else task.I_MD_BATTLE_FAILURE
+    visible = {task.I_TEAM_LOCK.name, task.I_BATTLE_DEMON.name}
+    clicks = []
+    frames = iter(range(18))
+    task.screenshot = lambda: next(frames)
+    task.appear = lambda rule, **kwargs: rule.name in visible
+    task.refresh_long_time = lambda: None
+    task.is_in_real_battle = lambda *args: False
+
+    def click(rule, **kwargs):
+        clicks.append(rule.name)
+        visible.remove(rule.name)
+        if rule is task.I_TEAM_LOCK:
+            visible.add(task.I_TEAM_UNLOCK.name)
+        elif rule is task.I_BATTLE_DEMON:
+            visible.add(result.name)
+        else:
+            assert rule is result
+            visible.add(task.I_FIND_DEMON.name)
+        return True
+
+    task.click = click
+    task.appear_then_click = lambda rule, **kwargs: task.appear(rule) and task.click(rule)
+    assert task.battle_boss() is win
+    assert clicks == [task.I_TEAM_LOCK.name, task.I_BATTLE_DEMON.name, result.name]
+    assert runtime.pub_ctx.per_task.count == 1
+
+
+def test_missing_unlock_confirmation_stops_before_challenging():
+    task = object.__new__(script_task.ScriptTask)
+    task.ui_click = lambda *args, **kwargs: False
+    with pytest.raises(GameStuckError, match='unlock'):
+        task.battle_boss()