فهرست منبع

Merge branch 'dev' into m2d

huangrunheng 2 ماه پیش
والد
کامیت
b881e353d6
27فایلهای تغییر یافته به همراه432 افزوده شده و 34 حذف شده
  1. 4 2
      assets/i18n/zh-CN.json
  2. 26 0
      module/atom/gif.py
  3. 3 3
      tasks/Component/Costume/assets.py
  4. 12 5
      tasks/Component/Costume/costume_base.py
  5. 1 1
      tasks/Component/Costume/costume_test.py
  6. 6 6
      tasks/Component/Costume/main17/image.json
  7. BIN
      tasks/Component/Costume/main17/main17_pet_house_17_a.png
  8. BIN
      tasks/Component/Costume/main17/main17_pet_house_17_b.png
  9. BIN
      tasks/Component/Costume/main17/main17_pet_house_17_c.png
  10. 18 0
      tasks/Component/SwitchOnmyoji/switch_onmyoji.py
  11. BIN
      tasks/GameUi/page/page_main_goto_summon.png
  12. 30 0
      tasks/WeeklyTrifles/assets.py
  13. 12 4
      tasks/WeeklyTrifles/config.py
  14. 103 13
      tasks/WeeklyTrifles/script_task.py
  15. 92 0
      tasks/WeeklyTrifles/touch_fish/image.json
  16. 20 0
      tasks/WeeklyTrifles/touch_fish/ocr.json
  17. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_check_touch_fish.png
  18. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_guild_goto_tf.png
  19. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_fold_window.png
  20. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_happy_get.png
  21. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_last_save.png
  22. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_open_fold_window.png
  23. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_save_all.png
  24. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_confirm.png
  25. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_goto_main.png
  26. BIN
      tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_save_success.png
  27. 105 0
      tests/test_switch_onmyoji.py

+ 4 - 2
assets/i18n/zh-CN.json

@@ -138,5 +138,7 @@
   "enable_ap100_anti_detect": "100体爬塔防检测",
   "enable_ap100_anti_detect_help": "100体爬塔战斗过程是否随机点击或滑动",
   "costume_battle_15": "灵狐寄愿",
-  "costume_shikigami_12": "拾光之窗"
-}
+  "costume_shikigami_12": "拾光之窗",
+  "save_touch_fish": "惠比寿的摸鱼行动",
+  "save_touch_fish_help": "默认使用全部存储按钮,主要目的是为了配合真蛇每周打一次即可获得俩次奖励(并不会节省体力)"
+}

+ 26 - 0
module/atom/gif.py

@@ -1,6 +1,8 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
+import types
+
 import numpy as np
 
 from module.atom.image import RuleImage
@@ -10,6 +12,30 @@ from module.atom.image import RuleImage
 class RuleGif:
     # 大部分实现同RuleImage 的接口
 
+    @staticmethod
+    def attach_to(image_obj: RuleImage, targets: list[RuleImage]) -> None:
+        """
+        把GIF的多帧匹配行为原地挂载到一个RuleImage实例上
+
+        与replace_img的原地换属性同思路: 不换对象、不换引用,
+        持有该对象引用的Page/寻路会立即生效
+        :param image_obj: 被挂载的RuleImage实例
+        :param targets: 多帧RuleImage, 顺序即匹配优先级
+        """
+        # GIF状态
+        image_obj.targets = targets
+        image_obj.roi_front = [0, 0, 0, 0]
+        image_obj.roi_back = targets[0].roi_back
+        image_obj.appear_target = targets[0]
+        image_obj.name = targets[0].name
+        image_obj._match_init = False
+        # 方法级替换: 把RuleGif的所有公开方法绑定到该实例上
+        for name, attr in RuleGif.__dict__.items():
+            if name.startswith('_'):
+                continue
+            if isinstance(attr, types.FunctionType):
+                setattr(image_obj, name, types.MethodType(attr, image_obj))
+
     @property
     def name(self) -> str:
         return self.targets[0].name

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

@@ -140,11 +140,11 @@ class CostumeAssets:
 	# 町中 c 
 	I_MAIN_GOTO_TOWN_17_C = RuleImage(roi_front=(1008,343,29,43), roi_back=(960,300,100,120), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_main_goto_town_17_c.png")
 	# 宠物屋 a 
-	I_PET_HOUSE_17_A = RuleImage(roi_front=(1226,423,34,37), roi_back=(1191,340,89,152), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_a.png")
+	I_PET_HOUSE_17_A = RuleImage(roi_front=(1249,404,23,56), roi_back=(1231,340,49,154), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_a.png")
 	# 宠物屋 b 
-	I_PET_HOUSE_17_B = RuleImage(roi_front=(1221,422,33,39), roi_back=(1191,366,89,116), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_b.png")
+	I_PET_HOUSE_17_B = RuleImage(roi_front=(1251,417,19,45), roi_back=(1231,366,49,124), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_b.png")
 	# 宠物屋 c 
-	I_PET_HOUSE_17_C = RuleImage(roi_front=(1226,417,42,45), roi_back=(1210,340,70,140), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_c.png")
+	I_PET_HOUSE_17_C = RuleImage(roi_front=(1248,406,19,59), roi_back=(1228,340,52,176), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_c.png")
 
 
 	# Image Rule Assets

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

@@ -32,6 +32,14 @@ main_costume_model[getattr(MainType, "COSTUME_MAIN_17")] = {
     'I_MAIN_GOTO_TOWN': ['I_MAIN_GOTO_TOWN_17_A', 'I_MAIN_GOTO_TOWN_17_B', 'I_MAIN_GOTO_TOWN_17_C'],
     'I_PET_HOUSE': ['I_PET_HOUSE_17_A', 'I_PET_HOUSE_17_B', 'I_PET_HOUSE_17_C'],
 }
+main_costume_model[getattr(MainType, "COSTUME_MAIN_13")] = {
+    'I_CHECK_MAIN': ['I_CHECK_MAIN_13',],
+    'I_MAIN_GOTO_EXPLORATION': ['I_MAIN_GOTO_EXPLORATION_13', ],
+    'I_MAIN_GOTO_SUMMON': ['I_MAIN_GOTO_SUMMON_13',],
+    'I_MAIN_GOTO_TOWN': ['I_MAIN_GOTO_TOWN_13',],
+    'I_PET_HOUSE': ['I_PET_HOUSE_13',],
+}
+
 
 
 # 鲤鱼旗皮肤
@@ -104,9 +112,6 @@ class CostumeBase:
         asset_before_object.threshold = asset_after.threshold
         asset_before_object.file = asset_after.file
 
-    def set_asset(self, asset_before: str, rule: RuleImage | RuleGif) -> None:
-        setattr(self, asset_before, rule)
-
     def check_costume_main(self, main_type: MainType):
         if main_type == MainType.COSTUME_MAIN:
             return
@@ -114,8 +119,10 @@ class CostumeBase:
         costume_assets = CostumeAssets()
         for key, value in main_costume_model[main_type].items():
             if isinstance(value, list):
+                if not hasattr(self, key):
+                    continue
                 rules: list[RuleImage] = [getattr(costume_assets, item) for item in value]
-                self.set_asset(key, RuleGif(rules))
+                RuleGif.attach_to(getattr(self, key), rules)
             else:
                 assert_value: RuleImage = getattr(costume_assets, value)
                 self.replace_img(key, assert_value)
@@ -167,4 +174,4 @@ class CostumeBase:
 
 if __name__ == '__main__':
     c = CostumeBase()
-    c.check_costume_main(MainType.COSTUME_MAIN_2)
+    c.check_costume_main(MainType.COSTUME_MAIN_13)

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

@@ -20,7 +20,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, PetsAssets, ):
         self.ui_click(self.I_TOWN_GOTO_MAIN, self.I_CHECK_MAIN)
         # 探索测试
         self.ui_click(self.I_MAIN_GOTO_EXPLORATION, self.I_CHECK_EXPLORATION)
-        self.ui_click(self.I_UI_BACK_BLUE, self.I_CHECK_MAIN)
+        self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MAIN)
         # 召唤测试
         self.ui_click(self.I_MAIN_GOTO_SUMMON, self.I_CHECK_SUMMON)
         self.ui_click(self.I_SUMMON_GOTO_MAIN, self.I_CHECK_MAIN)

+ 6 - 6
tasks/Component/Costume/main17/image.json

@@ -110,8 +110,8 @@
   {
     "itemName": "pet_house_17_a",
     "imageName": "main17_pet_house_17_a.png",
-    "roiFront": "1226,423,34,37",
-    "roiBack": "1191,340,89,152",
+    "roiFront": "1249,404,23,56",
+    "roiBack": "1231,340,49,154",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物屋 a"
@@ -119,8 +119,8 @@
   {
     "itemName": "pet_house_17_b",
     "imageName": "main17_pet_house_17_b.png",
-    "roiFront": "1221,422,33,39",
-    "roiBack": "1191,366,89,116",
+    "roiFront": "1251,417,19,45",
+    "roiBack": "1231,366,49,124",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物屋 b"
@@ -128,8 +128,8 @@
   {
     "itemName": "pet_house_17_c",
     "imageName": "main17_pet_house_17_c.png",
-    "roiFront": "1226,417,42,45",
-    "roiBack": "1210,340,70,140",
+    "roiFront": "1248,406,19,59",
+    "roiBack": "1228,340,52,176",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物屋 c"

BIN
tasks/Component/Costume/main17/main17_pet_house_17_a.png


BIN
tasks/Component/Costume/main17/main17_pet_house_17_b.png


BIN
tasks/Component/Costume/main17/main17_pet_house_17_c.png


+ 18 - 0
tasks/Component/SwitchOnmyoji/switch_onmyoji.py

@@ -1,4 +1,6 @@
 from module.atom.image import RuleImage
+from module.base.timer import Timer
+from module.exception import ScriptError
 from tasks.Component.SwitchOnmyoji.assets import SwitchOnmyojiAssets
 from tasks.Component.SwitchOnmyoji.config import Onmyoji
 from tasks.base_task import BaseTask
@@ -6,6 +8,10 @@ from module.logger import logger
 
 
 class SwitchOnmyoji(BaseTask, SwitchOnmyojiAssets):
+    # 上限用来给两个 while 循环兜底:资源坐标过期或页面不对时不再无限点,
+    # 改为抛出带上下文的 ScriptError,让上层决定重启还是人工接管。
+    SWITCH_TAB_TIMEOUT = 20
+    SWITCH_BATTLE_TIMEOUT = 20
 
     def switch_onmyoji(self, onmyoji: Onmyoji):
         """
@@ -29,7 +35,14 @@ class SwitchOnmyoji(BaseTask, SwitchOnmyojiAssets):
         :param battle_dict: 角色与战斗图标的映射
         :param check_img: 检查是否回到主界面的图标
         """
+        # 两个循环都必须在超时后抛出,而不是继续点击
+        tab_timer = Timer(self.SWITCH_TAB_TIMEOUT).start()
         while True:
+            if tab_timer.reached():
+                raise ScriptError('Switch onmyoji: cannot reach the role list, '
+                                  'the onmyoji tab was not opened after '
+                                  f'{self.SWITCH_TAB_TIMEOUT}s. '
+                                  'Check whether the onmyoji/hero assets still match the game UI')
             self.screenshot()
             if any(self.appear(battle_icon) for battle_icon in battle_dict.values()):
                 break
@@ -37,7 +50,12 @@ class SwitchOnmyoji(BaseTask, SwitchOnmyojiAssets):
         battle_img = battle_dict.get(role, None)
         if not battle_img:
             raise ValueError('Incorrect role type')
+        battle_timer = Timer(self.SWITCH_BATTLE_TIMEOUT).start()
         while True:
+            if battle_timer.reached():
+                raise ScriptError(f'Switch onmyoji: cannot select {role}, '
+                                  'the role list stayed unconfirmed after '
+                                  f'{self.SWITCH_BATTLE_TIMEOUT}s')
             self.screenshot()
             if self.appear(check_img, interval=0.8):
                 break

BIN
tasks/GameUi/page/page_main_goto_summon.png


+ 30 - 0
tasks/WeeklyTrifles/assets.py

@@ -79,3 +79,33 @@ class WeeklyTriflesAssets:
 	I_WT_SE_RANK = RuleImage(roi_front=(1017,572,45,44), roi_back=(989,556,103,81), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/secret/secret_wt_se_rank.png")
 
 
+	# Image Rule Assets
+	# 前往摸鱼页面 
+	I_GUILD_GOTO_TF = RuleImage(roi_front=(30,433,88,30), roi_back=(7,153,227,329), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_guild_goto_tf.png")
+	# 关闭首次进入弹窗 
+	I_WT_HAPPY_GET = RuleImage(roi_front=(736,461,119,35), roi_back=(736,461,119,35), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_happy_get.png")
+	# 全部保存本周次数 
+	I_WT_SAVE_ALL = RuleImage(roi_front=(1115,598,79,74), roi_back=(1115,598,79,74), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_save_all.png")
+	# 摸鱼行动页面标志 
+	I_CHECK_TOUCH_FISH = RuleImage(roi_front=(1082,20,27,27), roi_back=(1082,20,27,27), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_check_touch_fish.png")
+	# 返回庭院 
+	I_WT_TF_GOTO_MAIN = RuleImage(roi_front=(93,17,42,39), roi_back=(0,0,198,82), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_goto_main.png")
+	# 打开折叠窗口 
+	I_WT_OPEN_FOLD_WINDOW = RuleImage(roi_front=(28,155,21,21), roi_back=(28,155,21,21), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_open_fold_window.png")
+	# 已经打开的折叠窗口 
+	I_WT_FOLD_WINDOW = RuleImage(roi_front=(261,155,21,21), roi_back=(261,155,21,21), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_fold_window.png")
+	# 确认储存的按钮 
+	I_WT_TF_CONFIRM = RuleImage(roi_front=(672,588,139,56), roi_back=(672,588,139,56), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_confirm.png")
+	# 储存成功的标志 
+	I_WT_TF_SAVE_SUCCESS = RuleImage(roi_front=(942,243,62,25), roi_back=(871,212,219,70), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_save_success.png")
+	# 上周存储界面 
+	I_WT_LAST_SAVE = RuleImage(roi_front=(590,78,99,24), roi_back=(540,58,213,59), threshold=0.8, method="Template matching", file="./tasks/WeeklyTrifles/touch_fish/touch_fish_wt_last_save.png")
+
+
+	# Ocr Rule Assets
+	# 现有福运御守数量 
+	O_WT_LUCKY_TICKETS = RuleOcr(roi=(1145,16,95,32), area=(1145,16,95,32), mode="DigitCounter", method="Default", keyword="", name="wt_lucky_tickets")
+	# 全部储存需要的御守数量 
+	O_WT_SAVE_COST = RuleOcr(roi=(1162,676,35,24), area=(1156,670,52,40), mode="Digit", method="Default", keyword="", name="wt_save_cost")
+
+

+ 12 - 4
tasks/WeeklyTrifles/config.py

@@ -7,18 +7,26 @@ from pydantic import BaseModel, Field
 from tasks.Component.config_scheduler import Scheduler as BaseScheduler
 from tasks.Component.config_base import ConfigBase, TimeDelta
 
+
 class Scheduler(BaseScheduler):
-    success_interval: TimeDelta = Field(default=TimeDelta(days=7), description='success_interval_help')
-    failure_interval: TimeDelta = Field(default=TimeDelta(days=7), description='failure_interval_help')
+    success_interval: TimeDelta = Field(
+        default=TimeDelta(days=7), description='success_interval_help'
+    )
+    failure_interval: TimeDelta = Field(
+        default=TimeDelta(days=7), description='failure_interval_help'
+    )
+
 
 class Trifles(BaseModel):
     share_collect: bool = Field(default=True, description='share_collect_help')
     share_area_boss: bool = Field(default=True, description='share_area_boss_help')
     share_secret: bool = Field(default=True, description='share_secret_help')
-    broken_amulet: int = Field(title='Broken Amulet', default=100, description='trifles_broken_amulet_help')
+    save_touch_fish: bool = Field(default=False, description='save_touch_fish_help')
+    broken_amulet: int = Field(
+        title='Broken Amulet', default=100, description='trifles_broken_amulet_help'
+    )
 
 
 class WeeklyTrifles(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     trifles: Trifles = Field(default_factory=Trifles)
-

+ 103 - 13
tasks/WeeklyTrifles/script_task.py

@@ -9,10 +9,19 @@ from module.logger import logger
 from module.base.timer import Timer
 
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_main, page_collection, page_area_boss, page_secret_zones, page_summon, random_click
-from tasks.WeeklyTrifles.config import Trifles
+from tasks.GameUi.page import (
+    page_main,
+    page_collection,
+    page_area_boss,
+    page_secret_zones,
+    page_summon,
+    page_guild,
+    page_touch_fish,
+    random_click,
+)
 from tasks.WeeklyTrifles.assets import WeeklyTriflesAssets
 
+
 class ScriptTask(GameUi, WeeklyTriflesAssets):
 
     def run(self):
@@ -23,13 +32,14 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
             self._share_area_boss()
         if con.share_secret:
             self._share_secret()
+        if con.save_touch_fish:
+            self._save_touch_fish()
         if con.broken_amulet:
             self._broken_amulet(con.broken_amulet)
 
         self.set_next_run(task='WeeklyTrifles', success=True, finish=True)
         raise TaskEnd('WeeklyTrifles')
 
-
     def click_share(self, wechat) -> bool:
         """
         点击分享
@@ -52,12 +62,72 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
             if self.ui_reward_appear_click():
                 logger.info('Get reward')
                 return True
-            if self.appear_then_click(self.I_WT_QR_CODE, self.C_WT_WECHAT, interval=4.8):
+            if self.appear_then_click(
+                self.I_WT_QR_CODE, self.C_WT_WECHAT, interval=4.8
+            ):
                 continue
             if get_timer.reached():
                 logger.warning('Share timeout. The reward may have been obtained')
                 return False
 
+    def _save_touch_fish(self):
+        """
+        惠比寿的摸鱼行动
+        :return:
+        """
+        logger.hr('Touch fish start')
+        self.ui_get_current_page()
+        self.ui_goto(page_guild)
+        # 防止入口被折叠
+        while 1:
+            # 等个折叠窗口展开动画
+            sleep(1)
+            self.screenshot()
+            if self.appear_then_click(self.I_WT_OPEN_FOLD_WINDOW):
+                continue
+            if self.appear(self.I_WT_FOLD_WINDOW):
+                break
+        # 保存次数,后续做了也会邮件返还福运御守
+        self.ui_goto(page_touch_fish)
+        self.screenshot()
+        if self.appear(self.I_WT_SAVE_ALL):
+            cu_tickts, _, _ = self.O_WT_LUCKY_TICKETS.ocr(self.device.image)
+            logger.info(f"当前的福运御守数量:{cu_tickts}")
+            cost_tickts = self.O_WT_SAVE_COST.ocr(self.device.image)
+            logger.info(f"全部存储需要花费的福运御守数量:{cost_tickts}")
+            not_save_flag = True
+            get_timer = Timer(7)
+            get_timer.start()
+            while 1:
+                sleep(0.5)
+                self.screenshot()
+                if self.appear(self.I_WT_LAST_SAVE):
+                    self.click(
+                        random_click(ltrb=(True, False, False, False)), interval=1.5
+                    )
+                    continue
+                if self.appear_then_click(self.I_WT_HAPPY_GET):
+                    continue
+                if cu_tickts >= cost_tickts and not_save_flag:
+                    self.appear_then_click(self.I_WT_SAVE_ALL)
+                    not_save_flag = False
+                    continue
+                if self.appear_then_click(self.I_WT_TF_CONFIRM):
+                    continue
+                if self.appear(self.I_WT_TF_SAVE_SUCCESS) and not self.appear(
+                    self.I_WT_SAVE_ALL
+                ):
+                    logger.info('Touch fish save success')
+                    break
+                if cu_tickts < cost_tickts and not_save_flag:
+                    logger.warning('Touch fish tickts not enough, exit!')
+                    break
+                if get_timer.reached():
+                    logger.warning('Touch fish timeout, exit!')
+                    break
+        logger.hr('Touch fish finished')
+        self.ui_goto(page_main)
+
     def _share_collect(self):
         """
         图鉴分享
@@ -91,7 +161,9 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
                 logger.info('Get reward')
                 break
 
-            if self.appear_then_click(self.I_WT_QR_CODE, self.C_WT_WECHAT, interval=2.8):
+            if self.appear_then_click(
+                self.I_WT_QR_CODE, self.C_WT_WECHAT, interval=2.8
+            ):
                 continue
             if get_timer.reached():
                 logger.warning('Share timeout. The reward may have been obtained')
@@ -111,10 +183,13 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
         地鬼分享
         :return:
         """
+
         def back_boss():
             while 1:
                 self.screenshot()
-                if self.appear(self.I_WT_DAY_BATTLE) or self.appear(self.I_CHECK_EXPLORATION):
+                if self.appear(self.I_WT_DAY_BATTLE) or self.appear(
+                    self.I_CHECK_EXPLORATION
+                ):
                     break
                 if self.appear_then_click(self.I_UI_BACK_RED, interval=1):
                     continue
@@ -123,6 +198,7 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
                 if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
                     continue
             logger.info('Back to boss')
+
         logger.hr('Share area boss')
         self.goto_page(page_area_boss)
 
@@ -202,6 +278,7 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
         :param dest_num:
         :return:
         """
+
         def exit_amulet():
             self.wait_until_appear(self.I_BM_CONFIRM, wait_time=3)
             while 1:
@@ -229,7 +306,9 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
             if real_num <= 0:
                 exit_amulet()
                 return
-            if self.appear_then_click(self.I_BM_ENTER, interval=1) or self.appear_then_click(self.I_BM_AGAIN, interval=1):
+            if self.appear_then_click(
+                self.I_BM_ENTER, interval=1
+            ) or self.appear_then_click(self.I_BM_AGAIN, interval=1):
                 sleep(0.4)  # 等待动画开始
                 timeout_timer = Timer(5).start()
                 # 随机点击直到再次召唤出现或者超时
@@ -240,7 +319,9 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
                     if self.appear(self.I_BM_AGAIN, interval=0.8):
                         break
                 else:
-                    logger.warning(f'Wait for again timeout:Count[{count}], Remain[{real_num}]')
+                    logger.warning(
+                        f'Wait for again timeout:Count[{count}], Remain[{real_num}]'
+                    )
                     exit_amulet()
                     return
             else:
@@ -251,19 +332,29 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
             x_50, _, _, _ = self.O_BA_TIMES.ocr(self.device.image, '50次')
             self.I_BMT_CHECK.match(self.device.image)
             x_check, y_check, width_check, height_check = self.I_BMT_CHECK.roi_front
-            selected_10 = min(abs(x_10 - x_check), abs(x_50 - x_check)) == abs(x_10 - x_check)
+            selected_10 = min(abs(x_10 - x_check), abs(x_50 - x_check)) == abs(
+                x_10 - x_check
+            )
             logger.info(f'Current selected {"10" if selected_10 else "50"} amulet')
             count += 10 if selected_10 else 50
             logger.info(f'Broken amulet:Count[{count}], Remain[{real_num}]')
             # 一次50票不超过限制且当前选择的是10票则切换50票
             if count + 50 < dest_num and selected_10:
                 logger.hr('Switch to 50 amulet')
-                self.device.click(x=x_50 - width_check // 2, y=y_check + height_check // 2, control_name='Click_50')
+                self.device.click(
+                    x=x_50 - width_check // 2,
+                    y=y_check + height_check // 2,
+                    control_name='Click_50',
+                )
                 self.device.click_record_clear()
             # 一次50票会超过限制且当前选择的是50票则切换10票
             if count + 50 >= dest_num and not selected_10:
                 logger.hr('Switch to 10 amulet')
-                self.device.click(x=x_10 - width_check // 2, y=y_check + height_check // 2, control_name='Click_10')
+                self.device.click(
+                    x=x_10 - width_check // 2,
+                    y=y_check + height_check // 2,
+                    control_name='Click_10',
+                )
                 self.device.click_record_clear()
         # 正常结束且还有票, 则执行一次退出
         exit_amulet()
@@ -272,6 +363,7 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
+
     c = Config('oas1')
     d = Device(c)
     t = ScriptTask(c, d)
@@ -280,5 +372,3 @@ if __name__ == '__main__':
     # t._share_collect()
     t._share_area_boss()
     # t.click_share(t.I_WT_SE_WECHAT)
-
-

+ 92 - 0
tasks/WeeklyTrifles/touch_fish/image.json

@@ -0,0 +1,92 @@
+[
+  {
+    "itemName": "guild_goto_tf",
+    "imageName": "touch_fish_guild_goto_tf.png",
+    "roiFront": "30,433,88,30",
+    "roiBack": "7,153,227,329",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "前往摸鱼页面"
+  },
+  {
+    "itemName": "wt_happy_get",
+    "imageName": "touch_fish_wt_happy_get.png",
+    "roiFront": "736,461,119,35",
+    "roiBack": "736,461,119,35",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "关闭首次进入弹窗"
+  },
+  {
+    "itemName": "wt_save_all",
+    "imageName": "touch_fish_wt_save_all.png",
+    "roiFront": "1115,598,79,74",
+    "roiBack": "1115,598,79,74",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "全部保存本周次数"
+  },
+  {
+    "itemName": "check_touch_fish",
+    "imageName": "touch_fish_check_touch_fish.png",
+    "roiFront": "1082,20,27,27",
+    "roiBack": "1082,20,27,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "摸鱼行动页面标志"
+  },
+  {
+    "itemName": "wt_tf_goto_main",
+    "imageName": "touch_fish_wt_tf_goto_main.png",
+    "roiFront": "93,17,42,39",
+    "roiBack": "0,0,198,82",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "返回庭院"
+  },
+  {
+    "itemName": "wt_open_fold_window",
+    "imageName": "touch_fish_wt_open_fold_window.png",
+    "roiFront": "28,155,21,21",
+    "roiBack": "28,155,21,21",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "打开折叠窗口"
+  },
+  {
+    "itemName": "wt_fold_window",
+    "imageName": "touch_fish_wt_fold_window.png",
+    "roiFront": "261,155,21,21",
+    "roiBack": "261,155,21,21",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "已经打开的折叠窗口"
+  },
+  {
+    "itemName": "wt_tf_confirm",
+    "imageName": "touch_fish_wt_tf_confirm.png",
+    "roiFront": "672,588,139,56",
+    "roiBack": "672,588,139,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "确认储存的按钮"
+  },
+  {
+    "itemName": "wt_tf_save_success",
+    "imageName": "touch_fish_wt_tf_save_success.png",
+    "roiFront": "942,243,62,25",
+    "roiBack": "871,212,219,70",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "储存成功的标志"
+  },
+  {
+    "itemName": "wt_last_save",
+    "imageName": "touch_fish_wt_last_save.png",
+    "roiFront": "590,78,99,24",
+    "roiBack": "540,58,213,59",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "上周存储界面"
+  }
+]

+ 20 - 0
tasks/WeeklyTrifles/touch_fish/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "wt_lucky_tickets",
+    "roiFront": "1145,16,95,32",
+    "roiBack": "1145,16,95,32",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "现有福运御守数量"
+  },
+  {
+    "itemName": "wt_save_cost",
+    "roiFront": "1162,676,35,24",
+    "roiBack": "1156,670,52,40",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "全部储存需要的御守数量"
+  }
+]

BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_check_touch_fish.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_guild_goto_tf.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_fold_window.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_happy_get.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_last_save.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_open_fold_window.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_save_all.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_confirm.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_goto_main.png


BIN
tasks/WeeklyTrifles/touch_fish/touch_fish_wt_tf_save_success.png


+ 105 - 0
tests/test_switch_onmyoji.py

@@ -0,0 +1,105 @@
+"""SwitchOnmyoji must have a bounded exit path.
+
+Both loops in `SwitchOnmyoji.switch_role` used to be unconditional `while True`.
+When the onmyoji/hero tab cannot be reached (stale asset coordinates after a
+game UI update, emulator showing a different page, ...), they kept clicking
+forever until the global `GameStuckError` watchdog fired roughly two minutes
+later, discarding all context about what actually went wrong.
+
+These tests pin the exit conditions: a loop that never finds its target has to
+raise a named, catchable `ScriptError` instead of spinning, and the happy path
+must keep working unchanged.
+"""
+import pytest
+
+from module.base.timer import Timer
+from module.exception import ScriptError
+from tasks.Component.SwitchOnmyoji.config import Onmyoji
+from tasks.Component.SwitchOnmyoji.switch_onmyoji import SwitchOnmyoji
+
+
+class ScriptedSwitch(SwitchOnmyoji):
+    """Double that replays a fixed sequence of `appear` results.
+
+    `screenshot` and every click are no-ops, so the test exercises the real
+    loop control flow of `switch_role` without a Config, a Device or a game.
+    """
+
+    def __init__(self, appear_results, timeout=0):
+        # deliberately skip BaseTask.__init__: it needs a real Config/Device
+        self._appear_results = list(appear_results)
+        self._appear_calls = 0
+        self.switch_clicks = 0
+        self.battle_clicks = 0
+        self.ui_clicks = 0
+        # override the real 20s guards so the test does not have to wait
+        self.SWITCH_TAB_TIMEOUT = timeout
+        self.SWITCH_BATTLE_TIMEOUT = timeout
+
+    def _next_appear(self, button):
+        self._appear_calls += 1
+        if not self._appear_results:
+            return False
+        return self._appear_results.pop(0)
+
+    def screenshot(self):
+        pass
+
+    def appear(self, button, interval=None, **kwargs):
+        return self._next_appear(button)
+
+    def appear_then_click(self, button, interval=None, **kwargs):
+        self.switch_clicks += 1
+        return True
+
+    def click(self, button, interval=None, **kwargs):
+        self.battle_clicks += 1
+        return True
+
+    def ui_click(self, button1, button2, interval=None, **kwargs):
+        self.ui_clicks += 1
+        return True
+
+
+def test_switch_role_raises_when_battle_list_never_appears():
+    task = ScriptedSwitch(appear_results=[])
+
+    with pytest.raises(ScriptError):
+        task.switch_role(role=None, battle_dict={'x': object()}, check_img=object())
+
+
+def test_switch_role_raises_when_check_icon_never_appears():
+    # battle icon visible, confirm icon never does
+    task = ScriptedSwitch(appear_results=[True])
+
+    with pytest.raises(ScriptError):
+        task.switch_role(role=Onmyoji.KAGURA, battle_dict={Onmyoji.KAGURA: object()}, check_img=object())
+
+
+def test_switch_role_still_switches_when_the_flow_is_healthy():
+    # appear order: battle icon, then confirm icon -> no extra clicks needed
+    task = ScriptedSwitch(appear_results=[True, True])
+
+    task.switch_role(role=Onmyoji.KAGURA, battle_dict={Onmyoji.KAGURA: object()}, check_img=object())
+
+    assert task.switch_clicks == 0
+    assert task.battle_clicks == 0
+    assert task.ui_clicks == 0
+
+
+def test_switch_role_clicks_the_battle_icon_when_confirm_icon_is_absent():
+    # appear order: battle icon, not-confirm, battle icon -> ui_click back path
+    task = ScriptedSwitch(appear_results=[True, False, True])
+
+    task.switch_role(role=Onmyoji.KAGURA, battle_dict={Onmyoji.KAGURA: object()}, check_img=object())
+
+    assert task.switch_clicks == 0
+    assert task.ui_clicks == 1
+
+
+def test_timeouts_are_not_shared_between_instances():
+    a = ScriptedSwitch(appear_results=[])
+    b = ScriptedSwitch(appear_results=[])
+
+    assert a.SWITCH_TAB_TIMEOUT is not None
+    assert b.SWITCH_TAB_TIMEOUT is not None