Просмотр исходного кода

Merge upstream dev through 55c3b151 with cross-skin defense compatibility

Integrate d9c28f51..55c3b151 (17 commits including eight merges).
Adopt Xinyu Mingxiao scroll selection and saved-theme migration, a shared
masked guild entrance, the main16 town template, Yuehai Youxing multiscale
realm matching, the EXP bottle replacement, cross-skin reward regions,
and desktop activation-button score comparison. Include upstream offline
fixtures and regressions.

Expand the shared defense search region to (178,209,292,274), the union
of the prior and incoming regions. Upstream's x=260 boundary excludes the
cb1 defense template at x=216. Reproduced the missed match and added a
regression for all three banner skins at their original positions.
Add activation regressions for gray-button false positives and the
higher-scoring yellow animation state.

Retain the existing WantedQuests syntax fix as equivalent to a3e6e028.
Keep RuleGif detachment, task-local battle scene isolation and restoration,
and existing RuleImage.refresh cache invalidation (equivalent to upstream
replace_img changes). Other historical mail, raid, exploration, activity,
dialog and battle fixes remain preserved. No workflow changes in this merge.

Validation passed: 547 tests from tests/ and both FrogBoss suites, with
three existing dependency deprecation warnings. Fifteen Python syntax
checks, eleven production imports, nine JSONs, eight PNGs, 29 changed
asset/metadata rules and 116 synthetic matching cases passed.
git diff --check passed. No emulator or hosted workflow run.
unknown 1 неделя назад
Родитель
Сommit
096ccf5d71
32 измененных файлов с 670 добавлено и 73 удалено
  1. 1 0
      assets/i18n/zh-CN.json
  2. 1 1
      tasks/Component/Costume/assets.py
  3. 8 6
      tasks/Component/Costume/config.py
  4. 12 0
      tasks/Component/Costume/costume_base.py
  5. 1 1
      tasks/Component/Costume/costume_test_realm.py
  6. 1 1
      tasks/Component/Costume/main16/image.json
  7. BIN
      tasks/Component/Costume/main16/main16_main_goto_town_16.png
  8. 9 9
      tasks/Component/CostumeCarpBanner/assets.py
  9. 3 3
      tasks/Component/CostumeCarpBanner/cb1/image.json
  10. 3 3
      tasks/Component/CostumeCarpBanner/cb2/image.json
  11. 7 7
      tasks/Component/CostumeCarpBanner/cb3/image.json
  12. 15 0
      tasks/Component/CostumeTheme/assets.py
  13. 35 0
      tasks/Component/CostumeTheme/theme.py
  14. 11 0
      tasks/Component/CostumeTheme/theme2/image.json
  15. BIN
      tasks/Component/CostumeTheme/theme2/theme2_main_scroll_close_2.png
  16. 1 1
      tasks/GameUi/assets.py
  17. 1 1
      tasks/GameUi/page/image_main.json
  18. BIN
      tasks/GameUi/page/page_main_goto_guild_mask.png
  19. 8 8
      tasks/KekkaiActivation/a/image.json
  20. 8 8
      tasks/KekkaiActivation/assets.py
  21. 4 1
      tasks/KekkaiActivation/script_task.py
  22. 9 9
      tasks/KekkaiUtilize/assets.py
  23. 14 14
      tasks/KekkaiUtilize/realm/image.json
  24. BIN
      tasks/KekkaiUtilize/realm/realm_box_exp.png
  25. 109 0
      tests/tasks/Component/CostumeTheme/test_theme.py
  26. BIN
      tests/tasks/GameUi/fixtures/guild_search_closed.png
  27. BIN
      tests/tasks/GameUi/fixtures/guild_search_open.png
  28. 135 0
      tests/tasks/GameUi/test_shared_guild_mask.py
  29. 41 0
      tests/tasks/KekkaiActivation/test_activation_button.py
  30. BIN
      tests/tasks/KekkaiUtilize/fixtures/collected_bottle_animals.png
  31. BIN
      tests/tasks/KekkaiUtilize/fixtures/distant_realm_elements.png
  32. 233 0
      tests/tasks/KekkaiUtilize/test_realm_multiscale.py

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

@@ -153,6 +153,7 @@
   "ap100_green_mark_help": "100体爬塔绿标位置",
   "enable_ap100_anti_detect": "100体爬塔防检测",
   "enable_ap100_anti_detect_help": "100体爬塔战斗过程是否随机点击或滑动",
+  "costume_theme_xinyu_mingxiao": "新语明霄",
   "costume_battle_15": "灵狐寄愿",
   "costume_battle_scene_default": "默认",
   "costume_battle_scene_1": "鎏金圣域",

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

@@ -109,7 +109,7 @@ class CostumeAssets:
 	# 召唤屋
 	I_MAIN_GOTO_SUMMON_16 = RuleImage(roi_front=(981,218,28,24), roi_back=(930,170,130,150), threshold=0.55, method="Template matching", file="./tasks/Component/Costume/main16/main16_main_goto_summon_16.png")
 	# 町中
-	I_MAIN_GOTO_TOWN_16 = RuleImage(roi_front=(1014,346,14,34), roi_back=(960,300,100,120), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main16/main16_main_goto_town_16.png")
+	I_MAIN_GOTO_TOWN_16 = RuleImage(roi_front=(1012,340,21,42), roi_back=(960,300,100,120), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main16/main16_main_goto_town_16.png")
 	# 宠物屋
 	I_PET_HOUSE_16 = RuleImage(roi_front=(1256,402,20,58), roi_back=(1210,340,70,140), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main16/main16_pet_house_16.png")
 

+ 8 - 6
tasks/Component/Costume/config.py

@@ -39,6 +39,7 @@ class CarpBannerType(str, Enum):
 # 主题,就是庭院最右下角的展开按钮
 class ThemeType(str, Enum):
     COSTUME_THEME_DEFAULT = 'costume_theme_default'  # 伊始之卷
+    COSTUME_THEME_XINYU_MINGXIAO = 'costume_theme_xinyu_mingxiao'  # 新语明霄
 
 # 幕间,就是式神录这里
 class ShikigamiType(str, Enum):
@@ -104,9 +105,10 @@ class CostumeConfig(BaseModel):
             return RealmType.COSTUME_REALM_DEFAULT
         return v
 
-
-
-
-
-
-
+    @field_validator('costume_theme_type', mode='before')
+    @classmethod
+    def validate_theme(cls, v):
+        # Preserve selections saved by the earlier local numbered adaptation.
+        if v in ('costume_theme_1', 'costume_theme_2'):
+            return ThemeType.COSTUME_THEME_XINYU_MINGXIAO
+        return v

+ 12 - 0
tasks/Component/Costume/costume_base.py

@@ -15,6 +15,7 @@ from tasks.Component.Costume.config import (
     BattleType, BattleSceneType, CarpBannerType
 )
 from tasks.Component.Costume.assets import CostumeAssets
+from tasks.Component.CostumeTheme.theme import apply_theme
 from tasks.Component.CostumeBattle.assets import CostumeBattleAssets
 from tasks.Component.CostumeShikigami.assets import CostumeShikigamiAssets
 from tasks.Component.CostumeCarpBanner.assets import CostumeCarpBannerAssets
@@ -113,6 +114,17 @@ class CostumeBase:
         self.check_costume_battle(config.costume_battle_type)
         self.check_costume_battle_scene(config.costume_battle_scene_type)
         self.check_costume_shikigami(config.costume_shikigami_type)
+        self.check_costume_theme(config.costume_theme_type)
+
+    def check_costume_theme(self, theme_type: ThemeType):
+        apply_theme(theme_type)
+        if theme_type != ThemeType.COSTUME_THEME_DEFAULT:
+            # Supplementary labels are available before the UI rebuilds its translations.
+            labels = I18n.load_additions().get('zh-CN', {})
+            theme_name = labels.get(theme_type.value)
+            if not theme_name:
+                theme_name = I18n.trans_zh_cn(theme_type)
+            logger.info(f'Switch menu theme {theme_type} ({theme_name})')
 
     def replace_img(self,
                     asset_before: str,

+ 1 - 1
tasks/Component/Costume/costume_test_realm.py

@@ -62,7 +62,7 @@ if __name__ == '__main__':
     c = Config('oas1')
     d = Device(c)
     t = ScriptTask(c, d)
-    t.set_costume(RealmType.COSTUME_REALM_2)
+    t.set_costume(RealmType.COSTUME_REALM_DEFAULT)
     t.run()
 
 

+ 1 - 1
tasks/Component/Costume/main16/image.json

@@ -29,7 +29,7 @@
   {
     "itemName": "main_goto_town_16",
     "imageName": "main16_main_goto_town_16.png",
-    "roiFront": "1014,346,14,34",
+    "roiFront": "1012,340,21,42",
     "roiBack": "960,300,100,120",
     "method": "Template matching",
     "threshold": 0.8,

BIN
tasks/Component/Costume/main16/main16_main_goto_town_16.png


+ 9 - 9
tasks/Component/CostumeCarpBanner/assets.py

@@ -12,28 +12,28 @@ class CostumeCarpBannerAssets:
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_1 = RuleImage(roi_front=(572,272,21,33), roi_back=(530,220,202,267), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png")
+	I_SHI_GROWN_1 = RuleImage(roi_front=(572,272,21,33), roi_back=(560,250,130,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_grown_1.png")
 	# 结界卡 
-	I_SHI_CARD_1 = RuleImage(roi_front=(911,262,20,33), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png")
+	I_SHI_CARD_1 = RuleImage(roi_front=(911,262,20,33), roi_back=(760,250,220,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_card_1.png")
 	# 防守 
-	I_SHI_DEFENSE_1 = RuleImage(roi_front=(216,258,22,33), roi_back=(178,209,261,274), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png")
+	I_SHI_DEFENSE_1 = RuleImage(roi_front=(216,258,22,33), roi_back=(178,209,292,274), threshold=0.6, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb1/cb1_shi_defense_1.png")
 
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_2 = RuleImage(roi_front=(585,336,21,38), roi_back=(519,212,220,281), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_grown_2.png")
+	I_SHI_GROWN_2 = RuleImage(roi_front=(585,336,21,38), roi_back=(560,250,130,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_grown_2.png")
 	# 结界卡 
-	I_SHI_CARD_2 = RuleImage(roi_front=(871,341,20,36), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_card_2.png")
+	I_SHI_CARD_2 = RuleImage(roi_front=(871,341,20,36), roi_back=(760,250,220,220), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_card_2.png")
 	# 防守 
-	I_SHI_DEFENSE_2 = RuleImage(roi_front=(287,343,19,38), roi_back=(178,209,261,274), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_defense_2.png")
+	I_SHI_DEFENSE_2 = RuleImage(roi_front=(287,343,19,38), roi_back=(178,209,292,274), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb2/cb2_shi_defense_2.png")
 
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN_3 = RuleImage(roi_front=(600,277,19,34), roi_back=(519,212,220,281), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_grown_3.png")
+	I_SHI_GROWN_3 = RuleImage(roi_front=(600,277,19,34), roi_back=(560,250,130,220), threshold=0.5, method="Multi-scale template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_grown_3.png")
 	# 结界卡 
-	I_SHI_CARD_3 = RuleImage(roi_front=(899,281,21,40), roi_back=(823,210,252,297), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_card_3.png")
+	I_SHI_CARD_3 = RuleImage(roi_front=(899,281,21,40), roi_back=(760,250,220,220), threshold=0.5, method="Multi-scale template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_card_3.png")
 	# 防守 
-	I_SHI_DEFENSE_3 = RuleImage(roi_front=(298,279,19,38), roi_back=(178,209,261,274), threshold=0.5, method="Template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_defense_3.png")
+	I_SHI_DEFENSE_3 = RuleImage(roi_front=(298,279,19,38), roi_back=(178,209,292,274), threshold=0.5, method="Multi-scale template matching", file="./tasks/Component/CostumeCarpBanner/cb3/cb3_shi_defense_3.png")
 
 

+ 3 - 3
tasks/Component/CostumeCarpBanner/cb1/image.json

@@ -3,7 +3,7 @@
     "itemName": "shi_grown_1",
     "imageName": "cb1_shi_grown_1.png",
     "roiFront": "572,272,21,33",
-    "roiBack": "530,220,202,267",
+    "roiBack": "560,250,130,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "育成"
@@ -12,7 +12,7 @@
     "itemName": "shi_card_1",
     "imageName": "cb1_shi_card_1.png",
     "roiFront": "911,262,20,33",
-    "roiBack": "823,210,252,297",
+    "roiBack": "760,250,220,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "结界卡"
@@ -21,7 +21,7 @@
     "itemName": "shi_defense_1",
     "imageName": "cb1_shi_defense_1.png",
     "roiFront": "216,258,22,33",
-    "roiBack": "178,209,261,274",
+    "roiBack": "178,209,292,274",
     "method": "Template matching",
     "threshold": 0.6,
     "description": "防守"

+ 3 - 3
tasks/Component/CostumeCarpBanner/cb2/image.json

@@ -3,7 +3,7 @@
     "itemName": "shi_grown_2",
     "imageName": "cb2_shi_grown_2.png",
     "roiFront": "585,336,21,38",
-    "roiBack": "519,212,220,281",
+    "roiBack": "560,250,130,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "育成"
@@ -12,7 +12,7 @@
     "itemName": "shi_card_2",
     "imageName": "cb2_shi_card_2.png",
     "roiFront": "871,341,20,36",
-    "roiBack": "823,210,252,297",
+    "roiBack": "760,250,220,220",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "结界卡"
@@ -21,7 +21,7 @@
     "itemName": "shi_defense_2",
     "imageName": "cb2_shi_defense_2.png",
     "roiFront": "287,343,19,38",
-    "roiBack": "178,209,261,274",
+    "roiBack": "178,209,292,274",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "防守"

+ 7 - 7
tasks/Component/CostumeCarpBanner/cb3/image.json

@@ -3,8 +3,8 @@
     "itemName": "shi_grown_3",
     "imageName": "cb3_shi_grown_3.png",
     "roiFront": "600,277,19,34",
-    "roiBack": "519,212,220,281",
-    "method": "Template matching",
+    "roiBack": "560,250,130,220",
+    "method": "Multi-scale template matching",
     "threshold": 0.5,
     "description": "育成"
   },
@@ -12,8 +12,8 @@
     "itemName": "shi_card_3",
     "imageName": "cb3_shi_card_3.png",
     "roiFront": "899,281,21,40",
-    "roiBack": "823,210,252,297",
-    "method": "Template matching",
+    "roiBack": "760,250,220,220",
+    "method": "Multi-scale template matching",
     "threshold": 0.5,
     "description": "结界卡"
   },
@@ -21,9 +21,9 @@
     "itemName": "shi_defense_3",
     "imageName": "cb3_shi_defense_3.png",
     "roiFront": "298,279,19,38",
-    "roiBack": "178,209,261,274",
-    "method": "Template matching",
+    "roiBack": "178,209,292,274",
+    "method": "Multi-scale template matching",
     "threshold": 0.5,
     "description": "防守"
   }
-]
+]

+ 15 - 0
tasks/Component/CostumeTheme/assets.py

@@ -0,0 +1,15 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.atom.list import RuleList
+
+# This file was automatically generated by ./dev_tools/assets_extract.py.
+# Don't modify it manually.
+class CostumeThemeAssets:
+
+
+	# Image Rule Assets
+	# 新语明霄:收起状态卷轴
+	I_MAIN_SCROLL_CLOSE_2 = RuleImage(roi_front=(1190,632,48,58), roi_back=(1160,580,108,130), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeTheme/theme2/theme2_main_scroll_close_2.png")

+ 35 - 0
tasks/Component/CostumeTheme/theme.py

@@ -0,0 +1,35 @@
+"""庭院菜单主题。原地更新共享规则,保持导航图持有的对象引用有效。"""
+from copy import deepcopy
+
+from tasks.Component.Costume.config import ThemeType
+from tasks.Component.CostumeTheme.assets import CostumeThemeAssets
+from tasks.GameUi.assets import GameUiAssets
+
+
+_THEME_NAMES = (
+    'I_MAIN_SCROLL_CLOSE',
+    'I_MAIN_GOTO_COLLECTION', 'I_MAIN_GOTO_TRAVEL',
+    'I_MAIN_GOTO_TEAM', 'I_MAIN_GOTO_GUILD', 'I_MAIN_GOTO_MALL',
+    'I_MAIN_GOTO_DAILY', 'I_MAIN_GOTO_FRIENDS', 'I_MAIN_GOTO_ONMYODO',
+    'I_MAIN_GOTO_SHIKIGAMI_RECORDS',
+)
+# Capture pristine defaults before any task can select a menu theme.
+_DEFAULT_RULES = {name: deepcopy(getattr(GameUiAssets, name)) for name in _THEME_NAMES}
+_THEME_RULES = {
+    ThemeType.COSTUME_THEME_DEFAULT: _DEFAULT_RULES,
+    ThemeType.COSTUME_THEME_XINYU_MINGXIAO: {
+        # Entry icons use the shared GameUi defaults, not theme-specific copies.
+        **_DEFAULT_RULES,
+        'I_MAIN_SCROLL_CLOSE': CostumeThemeAssets.I_MAIN_SCROLL_CLOSE_2,
+    },
+}
+
+
+def apply_theme(theme_type: ThemeType) -> None:
+    rules = _THEME_RULES[theme_type]
+    for name, source in rules.items():
+        target = getattr(GameUiAssets, name)
+        # Reset cached image/name/features and match state as well as file/ROI.
+        # Do NOT replace the object: page transitions retain references to it.
+        target.__dict__.clear()
+        target.__dict__.update(deepcopy(source.__dict__))

+ 11 - 0
tasks/Component/CostumeTheme/theme2/image.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "main_scroll_close_2",
+    "imageName": "theme2_main_scroll_close_2.png",
+    "roiFront": "1190,632,48,58",
+    "roiBack": "1160,580,108,130",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "新语明霄:收起状态卷轴"
+  }
+]

BIN
tasks/Component/CostumeTheme/theme2/theme2_main_scroll_close_2.png


+ 1 - 1
tasks/GameUi/assets.py

@@ -126,7 +126,7 @@ class GameUiAssets:
 	# 庭院前往商店
 	I_MAIN_GOTO_MALL = RuleImage(roi_front=(664,661,40,18), roi_back=(601,613,163,78), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_mall.png")
 	# 庭院前往阴阳寮
-	I_MAIN_GOTO_GUILD = RuleImage(roi_front=(495,590,50,22), roi_back=(495,590,120,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_guild.png")
+	I_MAIN_GOTO_GUILD = RuleImage(roi_front=(495,590,50,22), roi_back=(495,590,120,100), threshold=0.7, method="Masked template matching", file="./tasks/GameUi/page/page_main_goto_guild.png")
 	# 庭院前往组队
 	I_MAIN_GOTO_TEAM = RuleImage(roi_front=(395,590,38,48), roi_back=(395,590,120,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_team.png")
 	# 庭院前往图鉴

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

@@ -85,7 +85,7 @@
     "imageName": "page_main_goto_guild.png",
     "roiFront": "495,590,50,22",
     "roiBack": "495,590,120,100",
-    "method": "Template matching",
+    "method": "Masked template matching",
     "threshold": 0.7,
     "description": "庭院前往阴阳寮"
   },

BIN
tasks/GameUi/page/page_main_goto_guild_mask.png


+ 8 - 8
tasks/KekkaiActivation/a/image.json

@@ -3,7 +3,7 @@
     "itemName": "a_harvest_fish4",
     "imageName": "a_a_harvest_fish4.png",
     "roiFront": "897,159,48,40",
-    "roiBack": "872,128,140,181",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "斗鱼收获奖励4星"
@@ -12,7 +12,7 @@
     "itemName": "a_harvest_exp",
     "imageName": "a_a_harvest_exp.png",
     "roiFront": "891,153,49,43",
-    "roiBack": "865,121,152,183",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "一般的收获奖励"
@@ -156,7 +156,7 @@
     "itemName": "a_harvest_kaiko_4",
     "imageName": "a_a_harvest_kaiko_4.png",
     "roiFront": "894,164,48,41",
-    "roiBack": "867,132,148,187",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "太鼓4"
@@ -165,7 +165,7 @@
     "itemName": "a_harvest_kaiko_3",
     "imageName": "a_a_harvest_kaiko_3.png",
     "roiFront": "893,163,47,42",
-    "roiBack": "865,136,148,178",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -174,7 +174,7 @@
     "itemName": "a_harvest_kaiko_6",
     "imageName": "a_a_harvest_kaiko_6.png",
     "roiFront": "898,160,45,38",
-    "roiBack": "868,129,146,184",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "太鼓6"
@@ -183,7 +183,7 @@
     "itemName": "a_harvest_fish_6",
     "imageName": "a_a_harvest_fish_6.png",
     "roiFront": "898,159,45,38",
-    "roiBack": "869,131,165,184",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "斗鱼6"
@@ -192,7 +192,7 @@
     "itemName": "a_harvest_moon_3",
     "imageName": "a_a_harvest_moon_3.png",
     "roiFront": "897,159,46,40",
-    "roiBack": "869,127,155,184",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "太阴3"
@@ -210,7 +210,7 @@
     "itemName": "a_harvest_fish_3",
     "imageName": "a_a_harvest_fish_3.png",
     "roiFront": "891,165,57,39",
-    "roiBack": "854,128,160,174",
+    "roiBack": "750,90,250,230",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "斗鱼3"

+ 8 - 8
tasks/KekkaiActivation/assets.py

@@ -31,9 +31,9 @@ class KekkaiActivationAssets:
 
 	# Image Rule Assets
 	# 斗鱼收获奖励4星 
-	I_A_HARVEST_FISH4 = RuleImage(roi_front=(897,159,48,40), roi_back=(872,128,140,181), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish4.png")
+	I_A_HARVEST_FISH4 = RuleImage(roi_front=(897,159,48,40), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish4.png")
 	# 一般的收获奖励 
-	I_A_HARVEST_EXP = RuleImage(roi_front=(891,153,49,43), roi_back=(865,121,152,183), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_exp.png")
+	I_A_HARVEST_EXP = RuleImage(roi_front=(891,153,49,43), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_exp.png")
 	# "结界卡" 
 	I_A_CARDS_REALM = RuleImage(roi_front=(0,0,100,100), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_cards_realm.png")
 	# description 
@@ -65,19 +65,19 @@ class KekkaiActivationAssets:
 	# description 
 	I_A_CHECK_CARD = RuleImage(roi_front=(513,32,260,49), roi_back=(513,32,260,49), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_check_card.png")
 	# 太鼓4 
-	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(867,132,148,187), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
+	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
 	# description 
-	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(865,136,148,178), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
+	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
 	# 太鼓6 
-	I_A_HARVEST_KAIKO_6 = RuleImage(roi_front=(898,160,45,38), roi_back=(868,129,146,184), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_6.png")
+	I_A_HARVEST_KAIKO_6 = RuleImage(roi_front=(898,160,45,38), roi_back=(750,90,250,230), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_6.png")
 	# 斗鱼6 
-	I_A_HARVEST_FISH_6 = RuleImage(roi_front=(898,159,45,38), roi_back=(869,131,165,184), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_6.png")
+	I_A_HARVEST_FISH_6 = RuleImage(roi_front=(898,159,45,38), roi_back=(750,90,250,230), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_6.png")
 	# 太阴3 
-	I_A_HARVEST_MOON_3 = RuleImage(roi_front=(897,159,46,40), roi_back=(869,127,155,184), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_moon_3.png")
+	I_A_HARVEST_MOON_3 = RuleImage(roi_front=(897,159,46,40), roi_back=(750,90,250,230), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_moon_3.png")
 	# 卸下 
 	I_A_DEMOUNT = RuleImage(roi_front=(939,575,55,47), roi_back=(903,551,107,91), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_demount.png")
 	# 斗鱼3 
-	I_A_HARVEST_FISH_3 = RuleImage(roi_front=(891,165,57,39), roi_back=(854,128,160,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_3.png")
+	I_A_HARVEST_FISH_3 = RuleImage(roi_front=(891,165,57,39), roi_back=(750,90,250,230), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_3.png")
 
 
 	# Image Rule Assets

+ 4 - 1
tasks/KekkaiActivation/script_task.py

@@ -115,7 +115,10 @@ class ScriptTask(KU, KekkaiActivationAssets):
             # 不稳定太,等待动画结束
             if not card_status and not card_effect:
                 # 黄色的 ”激活“
-                if self.appear(self.I_A_ACTIVATE_YELLOW, threshold=0.95):
+                # https://github.com/runhey/OnmyojiAutoScript/issues/2013
+                if self.appear(self.I_A_ACTIVATE_YELLOW, threshold=0.95)\
+                        and self.appear(self.I_A_ACTIVATE_GRAY)\
+                        and self.I_A_ACTIVATE_YELLOW.last_score > self.I_A_ACTIVATE_GRAY.last_score:
                     continue
                 if self.appear(self.I_A_DEMOUNT):
                     # 现在在动画里面

+ 9 - 9
tasks/KekkaiUtilize/assets.py

@@ -38,27 +38,27 @@ class KekkaiUtilizeAssets:
 
 	# Image Rule Assets
 	# 育成 
-	I_SHI_GROWN = RuleImage(roi_front=(595,291,35,38), roi_back=(530,220,202,267), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_grown.png")
+	I_SHI_GROWN = RuleImage(roi_front=(595,291,35,38), roi_back=(560,250,130,220), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_grown.png")
 	# 结界卡 
-	I_SHI_CARD = RuleImage(roi_front=(891,300,31,55), roi_back=(823,210,252,297), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_card.png")
+	I_SHI_CARD = RuleImage(roi_front=(891,300,31,55), roi_back=(760,250,220,220), threshold=0.6, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_card.png")
 	# description 
-	I_SHI_DEFENSE = RuleImage(roi_front=(303,308,34,52), roi_back=(178,209,261,274), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_defense.png")
+	I_SHI_DEFENSE = RuleImage(roi_front=(303,308,34,52), roi_back=(178,209,292,274), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_shi_defense.png")
 	# 收取经验(没有满的图) 
-	I_CARD_EXP = RuleImage(roi_front=(889,151,57,54), roi_back=(829,33,231,257), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_card_exp.png")
+	I_CARD_EXP = RuleImage(roi_front=(889,151,57,54), roi_back=(750,90,250,230), threshold=0.8, method="Multi-scale template matching", file="./tasks/KekkaiUtilize/realm/realm_card_exp.png")
 	# 收取体力(没有满) 
-	I_BOX_AP = RuleImage(roi_front=(815,435,57,51), roi_back=(744,336,395,216), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_ap.png")
+	I_BOX_AP = RuleImage(roi_front=(815,435,57,51), roi_back=(790,285,295,240), threshold=0.7, method="Multi-scale template matching", file="./tasks/KekkaiUtilize/realm/realm_box_ap.png")
 	# 收取盒子的经验(没有满) 
-	I_BOX_EXP = RuleImage(roi_front=(893,440,42,45), roi_back=(792,334,359,232), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp.png")
+	I_BOX_EXP = RuleImage(roi_front=(893,440,41,64), roi_back=(875,285,255,240), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp.png")
 	# 结界皮肤 
-	I_REALM_SHIN = RuleImage(roi_front=(175,460,54,58), roi_back=(22,359,393,328), threshold=0.9, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_realm_shin.png")
+	I_REALM_SHIN = RuleImage(roi_front=(175,460,54,58), roi_back=(140,270,270,285), threshold=0.9, method="Multi-scale template matching", file="./tasks/KekkaiUtilize/realm/realm_realm_shin.png")
 	# 寄养别人的经验 
-	I_UTILIZE_EXP = RuleImage(roi_front=(583,144,58,43), roi_back=(513,43,280,309), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_utilize_exp.png")
+	I_UTILIZE_EXP = RuleImage(roi_front=(583,144,58,43), roi_back=(500,65,220,280), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_utilize_exp.png")
 	# 取出 
 	I_AP_EXTRACT = RuleImage(roi_front=(592,501,100,75), roi_back=(592,501,100,75), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_ap_extract.png")
 	# 提取 
 	I_EXP_EXTRACT = RuleImage(roi_front=(592,448,100,73), roi_back=(592,448,100,73), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_exp_extract.png")
 	# 盒子经验满 
-	I_BOX_EXP_MAX = RuleImage(roi_front=(889,430,61,64), roi_back=(796,326,405,330), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp_max.png")
+	I_BOX_EXP_MAX = RuleImage(roi_front=(889,430,61,64), roi_back=(875,285,255,240), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp_max.png")
 	# 种树活动关闭标识 
 	I_PLANT_TREE_CLOSE = RuleImage(roi_front=(777,91,36,34), roi_back=(711,52,169,125), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_plant_tree_close.png")
 

+ 14 - 14
tasks/KekkaiUtilize/realm/image.json

@@ -3,7 +3,7 @@
     "itemName": "shi_grown",
     "imageName": "realm_shi_grown.png",
     "roiFront": "595,291,35,38",
-    "roiBack": "530,220,202,267",
+    "roiBack": "560,250,130,220",
     "method": "Template matching",
     "threshold": 0.6,
     "description": "育成"
@@ -12,7 +12,7 @@
     "itemName": "shi_card",
     "imageName": "realm_shi_card.png",
     "roiFront": "891,300,31,55",
-    "roiBack": "823,210,252,297",
+    "roiBack": "760,250,220,220",
     "method": "Template matching",
     "threshold": 0.6,
     "description": "结界卡"
@@ -21,7 +21,7 @@
     "itemName": "shi_defense",
     "imageName": "realm_shi_defense.png",
     "roiFront": "303,308,34,52",
-    "roiBack": "178,209,261,274",
+    "roiBack": "178,209,292,274",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"
@@ -30,8 +30,8 @@
     "itemName": "card_exp",
     "imageName": "realm_card_exp.png",
     "roiFront": "889,151,57,54",
-    "roiBack": "829,33,231,257",
-    "method": "Template matching",
+    "roiBack": "750,90,250,230",
+    "method": "Multi-scale template matching",
     "threshold": 0.8,
     "description": "收取经验(没有满的图)"
   },
@@ -39,16 +39,16 @@
     "itemName": "box_ap",
     "imageName": "realm_box_ap.png",
     "roiFront": "815,435,57,51",
-    "roiBack": "744,336,395,216",
-    "method": "Template matching",
+    "roiBack": "790,285,295,240",
+    "method": "Multi-scale template matching",
     "threshold": 0.7,
     "description": "收取体力(没有满)"
   },
   {
     "itemName": "box_exp",
     "imageName": "realm_box_exp.png",
-    "roiFront": "893,440,42,45",
-    "roiBack": "792,334,359,232",
+    "roiFront": "893,440,41,64",
+    "roiBack": "875,285,255,240",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "收取盒子的经验(没有满)"
@@ -57,8 +57,8 @@
     "itemName": "realm_shin",
     "imageName": "realm_realm_shin.png",
     "roiFront": "175,460,54,58",
-    "roiBack": "22,359,393,328",
-    "method": "Template matching",
+    "roiBack": "140,270,270,285",
+    "method": "Multi-scale template matching",
     "threshold": 0.9,
     "description": "结界皮肤"
   },
@@ -66,7 +66,7 @@
     "itemName": "utilize_exp",
     "imageName": "realm_utilize_exp.png",
     "roiFront": "583,144,58,43",
-    "roiBack": "513,43,280,309",
+    "roiBack": "500,65,220,280",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "寄养别人的经验"
@@ -93,7 +93,7 @@
     "itemName": "box_exp_max",
     "imageName": "realm_box_exp_max.png",
     "roiFront": "889,430,61,64",
-    "roiBack": "796,326,405,330",
+    "roiBack": "875,285,255,240",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "盒子经验满"
@@ -107,4 +107,4 @@
     "threshold": 0.8,
     "description": "种树活动关闭标识"
   }
-]
+]

BIN
tasks/KekkaiUtilize/realm/realm_box_exp.png


+ 109 - 0
tests/tasks/Component/CostumeTheme/test_theme.py

@@ -0,0 +1,109 @@
+"""Offline regression tests; no device or game interaction."""
+import unittest
+from unittest.mock import patch
+from module.server.i18n import I18n
+import json
+from pathlib import Path
+from copy import deepcopy
+
+from tasks.Component.Costume.config import CostumeConfig, ThemeType
+from tasks.Component.Costume.costume_base import CostumeBase
+from tasks.Component.CostumeTheme.theme import apply_theme, _THEME_NAMES
+from tasks.GameUi.assets import GameUiAssets
+
+
+class ThemeTests(unittest.TestCase):
+    def setUp(self):
+        apply_theme(ThemeType.COSTUME_THEME_DEFAULT)
+
+    def tearDown(self):
+        apply_theme(ThemeType.COSTUME_THEME_DEFAULT)
+
+    def test_enum_schema_and_default(self):
+        self.assertEqual(CostumeConfig().costume_theme_type, ThemeType.COSTUME_THEME_DEFAULT)
+        self.assertEqual(CostumeConfig(costume_theme_type='costume_theme_xinyu_mingxiao').costume_theme_type,
+                         ThemeType.COSTUME_THEME_XINYU_MINGXIAO)
+        schema = CostumeConfig.model_json_schema()
+        self.assertIn('costume_theme_xinyu_mingxiao', schema['$defs']['ThemeType']['enum'])
+
+    def test_shared_references_are_updated_and_default_restores(self):
+        refs = {name: getattr(GameUiAssets, name) for name in _THEME_NAMES}
+        defaults = {name: (rule.file, tuple(rule.roi_front), rule.roi_back) for name, rule in refs.items()}
+        for rule in refs.values():
+            _ = rule.image  # Prime old image cache before changing theme.
+            _ = rule.name
+        CostumeBase().check_costume_theme(ThemeType.COSTUME_THEME_XINYU_MINGXIAO)
+        for name, rule in refs.items():
+            self.assertIs(rule, getattr(GameUiAssets, name))
+            if name == 'I_MAIN_SCROLL_CLOSE':
+                self.assertIn('/CostumeTheme/theme2/', rule.file)
+            else:
+                self.assertEqual((rule.file, tuple(rule.roi_front), rule.roi_back), defaults[name])
+            self.assertIsNone(rule._image)
+            self.assertNotIn('name', rule.__dict__)
+            self.assertEqual(rule.image.shape[:2], (rule.roi_front[3], rule.roi_front[2]))
+        CostumeBase().check_costume_theme(ThemeType.COSTUME_THEME_DEFAULT)
+        for name, rule in refs.items():
+            self.assertEqual((rule.file, tuple(rule.roi_front), rule.roi_back), defaults[name])
+            self.assertIsNone(rule._image)
+
+    def test_reapply_resets_match_position_without_mutating_source(self):
+        apply_theme(ThemeType.COSTUME_THEME_XINYU_MINGXIAO)
+        rule = GameUiAssets.I_MAIN_SCROLL_CLOSE
+        original = tuple(rule.roi_front)
+        rule.roi_front[0] = 0
+        apply_theme(ThemeType.COSTUME_THEME_XINYU_MINGXIAO)
+        self.assertEqual(tuple(rule.roi_front), original)
+
+    def test_only_scroll_has_theme_specific_material(self):
+        from tasks.Component.CostumeTheme.assets import CostumeThemeAssets
+        folder = Path(__file__).resolve().parents[4] / 'tasks/Component/CostumeTheme/theme2'
+        items = json.loads((folder / 'image.json').read_text(encoding='utf-8'))
+        self.assertEqual([item['itemName'] for item in items], ['main_scroll_close_2'])
+        self.assertEqual({p.name for p in folder.glob('*.png')},
+                         {'theme2_main_scroll_close_2.png'})
+        self.assertEqual({name for name in vars(CostumeThemeAssets) if name.startswith('I_')},
+                         {'I_MAIN_SCROLL_CLOSE_2'})
+
+    def test_previous_local_selections_are_preserved(self):
+        for value in ('costume_theme_1', 'costume_theme_2'):
+            config = CostumeConfig(costume_theme_type=value)
+            self.assertEqual(config.costume_theme_type, ThemeType.COSTUME_THEME_XINYU_MINGXIAO)
+            self.assertEqual(config.model_dump(mode='json')['costume_theme_type'],
+                             'costume_theme_xinyu_mingxiao')
+
+    def test_theme_log_uses_supplementary_label_before_ui_translation_update(self):
+        theme = ThemeType.COSTUME_THEME_XINYU_MINGXIAO
+        with patch.object(I18n, 'load_additions', return_value={
+                'zh-CN': {theme.value: '新语明霄'}}), \
+             patch.object(I18n, 'trans_zh_cn', return_value=theme.value) as fallback, \
+             patch('tasks.Component.Costume.costume_base.logger') as log:
+            CostumeBase().check_costume_theme(theme)
+        fallback.assert_not_called()
+        log.info.assert_called_once_with(f'Switch menu theme {theme} (新语明霄)')
+
+    def test_theme_log_falls_back_when_supplementary_label_is_missing(self):
+        theme = ThemeType.COSTUME_THEME_XINYU_MINGXIAO
+        with patch.object(I18n, 'load_additions', return_value={}), \
+             patch.object(I18n, 'trans_zh_cn', return_value='已有运行时翻译') as fallback, \
+             patch('tasks.Component.Costume.costume_base.logger') as log:
+            CostumeBase().check_costume_theme(theme)
+        fallback.assert_called_once_with(theme)
+        log.info.assert_called_once_with(f'Switch menu theme {theme} (已有运行时翻译)')
+
+    def test_invalid_theme_does_not_mutate_rules(self):
+        for selected in (ThemeType.COSTUME_THEME_DEFAULT, ThemeType.COSTUME_THEME_XINYU_MINGXIAO):
+            with self.subTest(selected=selected):
+                apply_theme(selected)
+                refs = {name: getattr(GameUiAssets, name) for name in _THEME_NAMES}
+                states = {name: deepcopy(rule.__dict__) for name, rule in refs.items()}
+                with self.assertRaises(KeyError):
+                    apply_theme('not_a_theme')
+                for name, ref in refs.items():
+                    with self.subTest(rule=name):
+                        self.assertIs(getattr(GameUiAssets, name), ref)
+                        self.assertEqual(ref.__dict__, states[name])
+
+
+if __name__ == '__main__':
+    unittest.main()

BIN
tests/tasks/GameUi/fixtures/guild_search_closed.png


BIN
tests/tasks/GameUi/fixtures/guild_search_open.png


+ 135 - 0
tests/tasks/GameUi/test_shared_guild_mask.py

@@ -0,0 +1,135 @@
+"""Offline tests for the shared courtyard guild entrance (no device required).
+
+Fixtures contain only the 120x100 guild search area at (495,590), cropped from
+user-provided new-theme open/closed screenshots after 1280x720 normalization.
+The original-template and altered-background cases are synthetic controls,
+not real screenshots of the default theme.
+"""
+import hashlib
+import json
+import unittest
+from copy import deepcopy
+from pathlib import Path
+
+import cv2
+import numpy as np
+
+from module.atom.image import RuleImage, set_roi_match_padding
+from tasks.GameUi.assets import GameUiAssets
+from tasks.Component.Costume.config import ThemeType
+from tasks.Component.CostumeTheme.theme import apply_theme
+
+ROOT = Path(__file__).resolve().parents[3]
+FIXTURES = Path(__file__).resolve().parent / 'fixtures'
+OTHER_ENTRANCES = ('COLLECTION', 'TRAVEL', 'TEAM', 'MALL', 'DAILY', 'FRIENDS',
+                   'ONMYODO', 'SHIKIGAMI_RECORDS')
+
+
+class SharedGuildMaskTests(unittest.TestCase):
+    def setUp(self):
+        apply_theme(ThemeType.COSTUME_THEME_DEFAULT)
+        set_roi_match_padding(0)
+
+    def tearDown(self):
+        apply_theme(ThemeType.COSTUME_THEME_DEFAULT)
+        set_roi_match_padding(0)
+
+    def rule(self, method='Masked template matching'):
+        source = GameUiAssets.I_MAIN_GOTO_GUILD
+        return RuleImage(tuple(source.roi_front), source.roi_back, method,
+                         source.threshold, source.file)
+
+    def frame(self, state):
+        crop = cv2.cvtColor(cv2.imread(str(FIXTURES / ('guild_search_' + state + '.png'))),
+                            cv2.COLOR_BGR2RGB)
+        frame = np.full((720, 1280, 3), 100, dtype=np.uint8)
+        frame[590:690, 495:615] = crop
+        return frame
+
+    def test_shared_source_and_mask_contract(self):
+        items = json.loads((ROOT / 'tasks/GameUi/page/image_main.json').read_text(encoding='utf-8'))
+        item = next(x for x in items if x['itemName'] == 'main_goto_guild')
+        rule = self.rule()
+        self.assertEqual(item['method'], 'Masked template matching')
+        self.assertEqual(GameUiAssets.I_MAIN_GOTO_GUILD.method, item['method'])
+        self.assertEqual(rule.threshold, 0.7)
+        self.assertEqual(rule.roi_back, (495, 590, 120, 100))
+        self.assertEqual(rule.mask.shape, rule.image.shape[:2])
+        self.assertEqual(set(np.unique(rule.mask)), {0, 255})
+        self.assertGreater(np.count_nonzero(rule.mask), 200)
+        self.assertLess(np.count_nonzero(rule.mask), rule.mask.size)
+        self.assertEqual(hashlib.sha256((ROOT / rule.file.removeprefix('./')).read_bytes()).hexdigest(),
+                         'b7cbc4f76c6eef129e955b9b3d89a376a721b9930e4295011e98363bdd80a5d9')
+
+    def test_new_theme_open_hits_at_guild_not_another_icon(self):
+        for pad in (0, 2):
+            with self.subTest(padding=pad):
+                set_roi_match_padding(pad)
+                rule = self.rule()
+                self.assertTrue(rule.match(self.frame('open')))
+                self.assertGreater(rule.last_score, 0.9)
+                self.assertEqual(rule.roi_front[:2], [556, 610])
+
+    def test_plain_matching_reproduces_reported_failure(self):
+        rule = self.rule('Template matching')
+        self.assertFalse(rule.match(self.frame('open')))
+        self.assertAlmostEqual(rule.last_score, 0.52842, places=4)
+
+    def test_closed_scroll_is_not_a_guild_entrance(self):
+        for pad in (0, 2):
+            with self.subTest(padding=pad):
+                set_roi_match_padding(pad)
+                rule = self.rule()
+                self.assertFalse(rule.match(self.frame('closed')))
+                self.assertLess(rule.last_score, rule.threshold)
+
+    def test_original_template_synthetic_control(self):
+        rule = self.rule()
+        frame = np.full((720, 1280, 3), 100, dtype=np.uint8)
+        frame[610:632, 556:606] = rule.image
+        self.assertTrue(rule.match(frame))
+        self.assertGreater(rule.last_score, 0.999)
+        self.assertEqual(rule.roi_front[:2], [556, 610])
+
+    def test_ignored_background_changes_do_not_change_result(self):
+        rng = np.random.default_rng(1862)
+        for variant in ('black', 'white', 'noise'):
+            with self.subTest(background=variant):
+                rule = self.rule()
+                icon = rule.image.copy()
+                background = (rng.integers(0, 256, icon.shape, dtype=np.uint8)
+                              if variant == 'noise' else
+                              np.full_like(icon, 0 if variant == 'black' else 255))
+                icon[rule.mask == 0] = background[rule.mask == 0]
+                frame = np.full((720, 1280, 3), 100, dtype=np.uint8)
+                frame[610:632, 556:606] = icon
+                self.assertTrue(rule.match(frame))
+                self.assertGreater(rule.last_score, 0.999)
+                self.assertEqual(rule.roi_front[:2], [556, 610])
+
+    def test_other_entrance_icons_do_not_match_guild(self):
+        for name in OTHER_ENTRANCES:
+            with self.subTest(icon=name):
+                rule = self.rule()
+                icon = deepcopy(getattr(GameUiAssets, 'I_MAIN_GOTO_' + name)).image
+                h, w = icon.shape[:2]
+                frame = np.full((720, 1280, 3), 100, dtype=np.uint8)
+                frame[610:610+h, 535:535+w] = icon
+                self.assertFalse(rule.match(frame))
+
+    def test_theme_switch_keeps_shared_mask_and_navigation_reference(self):
+        from tasks.GameUi.default_pages import page_main
+        ref = GameUiAssets.I_MAIN_GOTO_GUILD
+        transitions = [t for t in page_main.transitions if t.action is ref]
+        self.assertTrue(transitions)
+        for theme in (ThemeType.COSTUME_THEME_XINYU_MINGXIAO, ThemeType.COSTUME_THEME_DEFAULT):
+            apply_theme(theme)
+            self.assertIs(GameUiAssets.I_MAIN_GOTO_GUILD, ref)
+            self.assertEqual(ref.method, 'Masked template matching')
+            self.assertIsNotNone(ref.mask)
+            self.assertTrue(all(t.action is ref for t in transitions))
+            self.assertTrue(ref.match(self.frame('open')))
+
+
+if __name__ == '__main__':
+    unittest.main()

+ 41 - 0
tests/tasks/KekkaiActivation/test_activation_button.py

@@ -0,0 +1,41 @@
+from copy import deepcopy
+from datetime import timedelta
+from types import SimpleNamespace
+
+import pytest
+
+from tasks.KekkaiActivation import script_task
+
+
+@pytest.mark.parametrize('yellow_score,gray_score,screened', [
+    (0.96, 0.99, True),
+    (0.99, 0.96, False),
+])
+def test_gray_activation_button_does_not_block_card_selection(
+        monkeypatch, yellow_score, gray_score, screened):
+    monkeypatch.setattr(script_task.time, 'sleep', lambda _: None)
+    task = object.__new__(script_task.ScriptTask)
+    task.I_A_ACTIVATE_YELLOW = deepcopy(task.I_A_ACTIVATE_YELLOW)
+    task.I_A_ACTIVATE_GRAY = deepcopy(task.I_A_ACTIVATE_GRAY)
+    task.goto_cards = lambda: None
+    task.screenshot = lambda: None
+    statuses, effects = iter([False, True]), iter([False, True])
+    task.check_card_status = lambda: next(statuses)
+    task.check_card_effect = lambda: next(effects)
+    task.ocr_time = lambda: timedelta(minutes=5)
+    task.set_next_run = lambda *args, **kwargs: None
+    selections = []
+    task.screening_card = selections.append
+
+    def appear(rule, **kwargs):
+        if rule is task.I_A_ACTIVATE_YELLOW:
+            rule.last_score = yellow_score
+            return yellow_score >= kwargs['threshold']
+        if rule is task.I_A_ACTIVATE_GRAY:
+            rule.last_score = gray_score
+            return True
+        return False
+
+    task.appear = appear
+    assert task.run_activation(SimpleNamespace(card_type='selected type')) is False
+    assert selections == (['selected type'] if screened else [])

BIN
tests/tasks/KekkaiUtilize/fixtures/collected_bottle_animals.png


BIN
tests/tasks/KekkaiUtilize/fixtures/distant_realm_elements.png


+ 233 - 0
tests/tasks/KekkaiUtilize/test_realm_multiscale.py

@@ -0,0 +1,233 @@
+"""Offline regression tests for shared realm assets and distant carp banners."""
+from copy import deepcopy
+import json
+from pathlib import Path
+import unittest
+from unittest.mock import patch
+
+import cv2
+import numpy as np
+
+from module.atom.image import RuleImage, set_roi_match_padding
+from tasks.Component.Costume.config import CarpBannerType
+from tasks.Component.Costume.costume_base import CostumeBase
+from tasks.Component.CostumeCarpBanner.assets import CostumeCarpBannerAssets
+from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
+
+ROOT = Path(__file__).resolve().parents[3]
+TARGETS = {
+    'I_SHI_GROWN': (599, 293, 45, 65),
+    'I_SHI_CARD': (777, 288, 50, 72),
+    'I_SHI_DEFENSE': (410, 288, 45, 80),
+    'I_REALM_SHIN': (308, 300, 85, 85),
+    'I_CARD_EXP': (770, 158, 70, 68),
+    'I_BOX_AP': (880, 312, 65, 65),
+    'I_BOX_EXP': (937, 312, 52, 70),
+}
+ORIGINAL_REGIONS = {
+    'I_SHI_GROWN': (519, 212, 220, 281),
+    'I_SHI_CARD': (823, 210, 252, 297),
+    'I_SHI_DEFENSE': (178, 209, 261, 274),
+    'I_REALM_SHIN': (22, 359, 393, 328),
+    'I_CARD_EXP': (829, 33, 231, 257),
+    'I_BOX_AP': (744, 336, 395, 216),
+    'I_BOX_EXP': (792, 334, 359, 232),
+}
+
+
+class Probe(CostumeBase, KekkaiUtilizeAssets):
+    """Only rule replacement is exercised; no Config or Device is created."""
+    pass
+
+
+def screenshot():
+    fixture = Path(__file__).parent / 'fixtures/distant_realm_elements.png'
+    crop = cv2.cvtColor(cv2.imdecode(np.fromfile(fixture, dtype=np.uint8), cv2.IMREAD_COLOR),
+                       cv2.COLOR_BGR2RGB)
+    image = np.zeros((720, 1280, 3), dtype=np.uint8)
+    image[150:460, 300:1000] = crop
+    return image
+
+
+def configured_rules():
+    probe = Probe()
+    for name in TARGETS:
+        setattr(probe, name, deepcopy(getattr(KekkaiUtilizeAssets, name)))
+    with patch('tasks.Component.Costume.costume_base.I18n.trans_zh_cn', return_value='carp'):
+        probe.check_costume_carpbanner(CarpBannerType.COSTUME_CARPBANNER_3)
+    return {name: getattr(probe, name) for name in TARGETS}
+
+
+class RealmMultiScaleTests(unittest.TestCase):
+    def tearDown(self):
+        set_roi_match_padding(0)
+
+    def test_all_seven_visible_elements_match_at_correct_locations(self):
+        for padding in (0, 2):
+            set_roi_match_padding(padding)
+            for name, rule in configured_rules().items():
+                with self.subTest(padding=padding, name=name):
+                    self.assertTrue(rule.match(screenshot(), threshold=0.6 if name == 'I_BOX_EXP' else None))
+                    x, y, w, h = rule.roi_front
+                    ex, ey, ew, eh = TARGETS[name]
+                    self.assertTrue(ex <= x + w / 2 < ex + ew)
+                    self.assertTrue(ey <= y + h / 2 < ey + eh)
+                    self.assertEqual(rule.last_scale, None if name == 'I_BOX_EXP' else
+                                     (0.6 if name.startswith('I_SHI_') else 1.0))
+
+    def test_missing_target_is_not_accepted(self):
+        for padding in (0, 2):
+            set_roi_match_padding(padding)
+            for name, rule in configured_rules().items():
+                with self.subTest(padding=padding, name=name):
+                    image = screenshot()
+                    x, y, w, h = TARGETS[name]
+                    image[y-5:y+h+5, x-5:x+w+5] = 0
+                    self.assertFalse(rule.match(image, threshold=0.6 if name == 'I_BOX_EXP' else None), (name, rule.last_score, rule.roi_front))
+
+    def test_empty_screen_has_no_matches(self):
+        for name, rule in configured_rules().items():
+            with self.subTest(name=name):
+                self.assertFalse(rule.match(np.zeros((720, 1280, 3), dtype=np.uint8)))
+
+    def test_cross_skin_search_regions(self):
+        expected = {
+            'I_SHI_DEFENSE': (178, 209, 292, 274),
+            'I_SHI_GROWN': (560, 250, 130, 220),
+            'I_SHI_CARD': (760, 250, 220, 220),
+            'I_REALM_SHIN': (140, 270, 270, 285),
+            'I_CARD_EXP': (750, 90, 250, 230),
+            'I_BOX_AP': (790, 285, 295, 240),
+            'I_BOX_EXP': (875, 285, 255, 240),
+            'I_BOX_EXP_MAX': (875, 285, 255, 240),
+            'I_UTILIZE_EXP': (500, 65, 220, 280),
+        }
+        for name, roi in expected.items():
+            self.assertEqual(tuple(getattr(KekkaiUtilizeAssets, name).roi_back), roi)
+            if name.startswith('I_SHI_'):
+                for skin in range(1, 4):
+                    self.assertEqual(tuple(getattr(CostumeCarpBannerAssets,
+                                                  name + '_' + str(skin)).roi_back), roi)
+
+    def test_collected_bottle_does_not_match_white_animals_at_task_threshold(self):
+        fixture = Path(__file__).parent / 'fixtures/collected_bottle_animals.png'
+        crop = cv2.cvtColor(cv2.imdecode(np.fromfile(fixture, dtype=np.uint8),
+                                      cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)
+        image = np.zeros((720, 1280, 3), dtype=np.uint8)
+        image[280:640, 790:1150] = crop
+        for padding in (0, 2):
+            set_roi_match_padding(padding)
+            for name in ('I_BOX_EXP', 'I_BOX_EXP_MAX'):
+                for roi in ((875, 285, 255, 240), (790, 480, 350, 150)):
+                    rule = deepcopy(getattr(KekkaiUtilizeAssets, name))
+                    rule.roi_back = roi
+                    self.assertFalse(rule.match(image, threshold=0.6),
+                                     (name, roi, rule.last_score))
+
+    def test_bottle_click_dimensions_match_replacement_template(self):
+        rule = deepcopy(KekkaiUtilizeAssets.I_BOX_EXP)
+        height, width = rule.image.shape[:2]
+        self.assertEqual(tuple(rule.roi_front[2:]), (width, height))
+        self.assertTrue(rule.match(screenshot(), threshold=0.6))
+
+    def test_runtime_rules_keep_original_templates_and_thresholds(self):
+        defaults = {'I_REALM_SHIN': 0.9, 'I_CARD_EXP': 0.8,
+                    'I_BOX_AP': 0.7, 'I_BOX_EXP': 0.7}
+        for name, rule in configured_rules().items():
+            with self.subTest(name=name):
+                if name.startswith('I_SHI_'):
+                    source = getattr(CostumeCarpBannerAssets, name + '_3')
+                    self.assertEqual(rule.file, source.file)
+                    self.assertEqual(rule.threshold, 0.5)
+                else:
+                    self.assertEqual(rule.file, getattr(KekkaiUtilizeAssets, name).file)
+                    self.assertEqual(rule.threshold, defaults[name])
+                self.assertEqual(rule.method, 'Template matching' if name == 'I_BOX_EXP'
+                                 else 'Multi-scale template matching')
+
+    def test_original_size_templates_remain_recognizable(self):
+        for name, rule in configured_rules().items():
+            with self.subTest(name=name):
+                image = np.zeros((720, 1280, 3), dtype=np.uint8)
+                x, y, _, _ = rule.roi_back
+                template = rule.image
+                h, w = template.shape[:2]
+                image[y+10:y+10+h, x+10:x+10+w] = template
+                self.assertTrue(rule.match(image))
+                self.assertEqual(rule.last_scale, None if name == 'I_BOX_EXP' else 1.0)
+                self.assertEqual(rule.roi_front, [x+10, y+10, w, h])
+
+    def test_banner_defense_matches_at_each_skins_original_position(self):
+        for skin in range(1, 4):
+            for padding in (0, 2):
+                with self.subTest(skin=skin, padding=padding):
+                    set_roi_match_padding(padding)
+                    rule = deepcopy(getattr(CostumeCarpBannerAssets, f'I_SHI_DEFENSE_{skin}'))
+                    image = np.zeros((720, 1280, 3), dtype=np.uint8)
+                    self.assertFalse(rule.match(image))
+                    x, y, w, h = rule.roi_front
+                    image[y:y+h, x:x+w] = rule.image
+                    self.assertTrue(rule.match(image))
+                    self.assertEqual(rule.roi_front, [x, y, w, h])
+
+    def test_replacement_copies_method_and_clears_cached_dispatch(self):
+        probe = Probe()
+        probe.I_SHI_GROWN = deepcopy(KekkaiUtilizeAssets.I_SHI_GROWN)
+        target = probe.I_SHI_GROWN
+        self.assertTrue(target.is_template_match)
+        self.assertFalse(target.is_multi_scale_template_match)
+        _ = target.image
+        source = CostumeCarpBannerAssets.I_SHI_GROWN_3
+        probe.replace_img('I_SHI_GROWN', source)
+        self.assertIs(probe.I_SHI_GROWN, target)
+        self.assertIsNone(target._image)
+        self.assertFalse(target.is_template_match)
+        self.assertTrue(target.is_multi_scale_template_match)
+        self.assertTrue(target.match(screenshot()))
+        self.assertEqual(source.roi_front, [600, 277, 19, 34])
+        self.assertIsNot(target.roi_front, source.roi_front)
+
+    def test_replacement_can_return_to_original_matching_method(self):
+        probe = Probe()
+        probe.I_SHI_GROWN = deepcopy(KekkaiUtilizeAssets.I_SHI_GROWN)
+        probe.replace_img('I_SHI_GROWN', CostumeCarpBannerAssets.I_SHI_GROWN_3)
+        self.assertTrue(probe.I_SHI_GROWN.is_multi_scale_template_match)
+        probe.replace_img('I_SHI_GROWN', KekkaiUtilizeAssets.I_SHI_GROWN)
+        self.assertTrue(probe.I_SHI_GROWN.is_template_match)
+        self.assertFalse(probe.I_SHI_GROWN.is_multi_scale_template_match)
+
+    def test_replacement_can_preserve_fixed_search_region(self):
+        probe = Probe()
+        probe.I_SHI_GROWN = deepcopy(KekkaiUtilizeAssets.I_SHI_GROWN)
+        original = probe.I_SHI_GROWN.roi_back
+        probe.replace_img('I_SHI_GROWN', CostumeCarpBannerAssets.I_SHI_GROWN_3,
+                          rp_roi_back=False)
+        self.assertEqual(probe.I_SHI_GROWN.roi_back, original)
+
+    def test_manual_realm_tool_references_existing_enum_members(self):
+        import ast
+        from tasks.Component.Costume.config import RealmType
+        tool = ROOT / 'tasks/Component/Costume/costume_test_realm.py'
+        tree = ast.parse(tool.read_text(encoding='utf-8'))
+        members = [node.attr for node in ast.walk(tree)
+                   if isinstance(node, ast.Attribute)
+                   and isinstance(node.value, ast.Name)
+                   and node.value.id == 'RealmType']
+        self.assertTrue(members)
+        for member in members:
+            self.assertIn(member, RealmType.__members__)
+
+    def test_generated_classes_match_json(self):
+        for rel, assets in [('tasks/KekkaiUtilize/realm/image.json', KekkaiUtilizeAssets),
+                            ('tasks/Component/CostumeCarpBanner/cb3/image.json',
+                             CostumeCarpBannerAssets)]:
+            for row in json.loads((ROOT / rel).read_text(encoding='utf-8')):
+                with self.subTest(file=rel, name=row['itemName']):
+                    rule = getattr(assets, 'I_' + row['itemName'].upper())
+                    self.assertEqual(rule.method, row['method'])
+                    self.assertEqual(tuple(rule.roi_back), tuple(map(int, row['roiBack'].split(','))))
+                    self.assertEqual(rule.threshold, row['threshold'])
+
+
+if __name__ == '__main__':
+    unittest.main()