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

fix(GeneralBattle): Avoid accidental clicks on battle result controls
- add exclusion-aware random clicking with rejection and complement sampling
- exclude battle result controls while collecting rewards
- detect gold snake skins and integrate the strategy into EvoZone and RyouToppa
- add result-screen assets and regression tests

neptine 2 месяцев назад
Родитель
Сommit
00888a40f2

+ 122 - 0
module/atom/click.py

@@ -1,6 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
+import random
 import numpy as np
 
 from module.base.decorator import cached_property
@@ -72,3 +73,124 @@ class RuleClick:
             y = 720
 
         self.roi_front = x, y, w, h
+
+
+class RuleClickExclude(RuleClick):
+    """Randomly click within the screen while excluding other click regions."""
+
+    SCREEN_WIDTH = 1280
+    SCREEN_HEIGHT = 720
+
+    def __init__(self, clicks, strategy: str | None = None, distribution: str | None = None,
+                 max_attempts: int = 100, name: str = 'exclude_random_click') -> None:
+        """
+        初始化排除区域随机点击规则。
+
+        :param clicks: 需要排除的 RuleClick,或 RuleClick 序列;使用其 roi_back 作为排除区域
+        :param strategy: 取点策略,None 时在初始化时随机选择 rejection 或 complement
+        :param distribution: 坐标分布,None 时在初始化时随机选择 uniform 或 normal
+        :param max_attempts: 拒绝采样的最大尝试次数,耗尽后自动使用补集矩形采样
+        :param name: 点击规则名称,用于 BaseTask.click 的间隔计时器
+        :raises TypeError: clicks 不是 RuleClick 或 RuleClick 序列
+        :raises ValueError: strategy、distribution 或 max_attempts 参数无效,或排除区域覆盖整个屏幕
+        """
+        super().__init__((0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT),
+                         (0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT), name=name)
+        if strategy is None:
+            strategy = random.choice(('rejection', 'complement'))
+        if distribution is None:
+            distribution = random.choice(('uniform', 'normal'))
+        if strategy not in ('rejection', 'complement'):
+            raise ValueError("strategy must be 'rejection' or 'complement'")
+        if distribution not in ('uniform', 'normal'):
+            raise ValueError("distribution must be 'uniform' or 'normal'")
+        if max_attempts < 1:
+            raise ValueError('max_attempts must be positive')
+
+        if isinstance(clicks, RuleClick):
+            clicks = (clicks,)
+        self.clicks = tuple(clicks)
+        if not all(isinstance(click, RuleClick) for click in self.clicks):
+            raise TypeError('clicks must contain RuleClick instances')
+        self.strategy = strategy
+        self.distribution = distribution
+        self.max_attempts = max_attempts
+        self._excluded = tuple(
+            rect for click in self.clicks
+            for rect in (self._clip_roi(click.roi_back),)
+            if rect is not None
+        )
+        self._allowed = self._build_complement()
+        if not self._allowed:
+            raise ValueError('Excluded regions cover the whole screen')
+
+    def __str__(self):
+        click_names = ', '.join(click.name for click in self.clicks) or 'none'
+        return (
+            f'{self.name}(strategy={self.strategy}, '
+            f'distribution={self.distribution}, clicks=[{click_names}])'
+        )
+
+    __repr__ = __str__
+
+    @classmethod
+    def _clip_roi(cls, roi):
+        x, y, w, h = roi
+        left, top = max(0, x), max(0, y)
+        right, bottom = min(cls.SCREEN_WIDTH, x + w), min(cls.SCREEN_HEIGHT, y + h)
+        if left >= right or top >= bottom:
+            return None
+        return left, top, right - left, bottom - top
+
+    def _is_excluded(self, x, y):
+        return any(left <= x < left + width and top <= y < top + height
+                   for left, top, width, height in self._excluded)
+
+    def _build_complement(self):
+        x_edges = {0, self.SCREEN_WIDTH}
+        y_edges = {0, self.SCREEN_HEIGHT}
+        for x, y, width, height in self._excluded:
+            x_edges.update((x, x + width))
+            y_edges.update((y, y + height))
+
+        x_edges, y_edges = sorted(x_edges), sorted(y_edges)
+        allowed = []
+        for x1, x2 in zip(x_edges, x_edges[1:]):
+            for y1, y2 in zip(y_edges, y_edges[1:]):
+                if not self._is_excluded(x1, y1):
+                    allowed.append((x1, y1, x2 - x1, y2 - y1))
+        return allowed
+
+    def _sample_axis(self, start, size, distribution):
+        if size == 1:
+            return start
+        if distribution == 'uniform':
+            return random.randrange(start, start + size)
+        return max(start, min(start + size - 1,
+                              random_normal_distribution_int(start, start + size)))
+
+    def _sample_point(self, rect, distribution):
+        x, y, width, height = rect
+        return self._sample_axis(x, width, distribution), self._sample_axis(y, height, distribution)
+
+    def _coord_rejection(self, distribution):
+        for _ in range(self.max_attempts):
+            point = self._sample_point((0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT), distribution)
+            if not self._is_excluded(*point):
+                return point
+        return self._coord_complement(distribution)
+
+    def _coord_complement(self, distribution):
+        total = sum(width * height for _, _, width, height in self._allowed)
+        offset = random.randrange(total)
+        for rect in self._allowed:
+            area = rect[2] * rect[3]
+            if offset < area:
+                return self._sample_point(rect, distribution)
+            offset -= area
+        raise RuntimeError('Unable to select a click region')
+
+    def coord(self) -> tuple:
+        if self.strategy == 'rejection':
+            return self._coord_rejection(self.distribution)
+        return self._coord_complement(self.distribution)

+ 0 - 1
tasks/AbyssShadows/config.py

@@ -7,7 +7,6 @@
 from pydantic import BaseModel, Field
 # from pygments.lexer import default
 # from scripts.regsetup import description
-from sympy.testing.pytest import Failed
 
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig

+ 1 - 1
tasks/BudokaiTournament/assets.py

@@ -11,7 +11,7 @@ class BudokaiTournamentAssets:
 
 
 	# Click Rule Assets
-	# Close cultivation drills boss detail
+	# Close cultivation drills boss detail 
 	C_BOSS_DETAIL_CLOSE = RuleClick(roi_front=(1182,73,47,43), roi_back=(1182,73,47,43), name="boss_detail_close")
 
 

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

@@ -166,3 +166,80 @@ class GeneralBattleAssets:
 	S_BATTLE_RANDOM_RIGHT = RuleSwipe(roi_front=(719,138,417,392), roi_back=(237,163,387,394), mode="default", name="battle_random_right")
 
 
+	# Click Rule Assets
+	# 右上角的聊天信息 
+	C_END_MESSAGE_RIGHT_TOP = RuleClick(roi_front=(846,4,404,34), roi_back=(846,4,404,34), name="end_message_right_top")
+	# description 
+	C_END_BUFF_AREA_1 = RuleClick(roi_front=(150,638,295,41), roi_back=(150,638,295,41), name="end_buff_area_1")
+	# description 
+	C_END_BUFF_AREA_2 = RuleClick(roi_front=(457,635,273,43), roi_back=(457,635,273,43), name="end_buff_area_2")
+	# 給地鬼的 
+	C_END_AREA_BOSS = RuleClick(roi_front=(1093,550,127,120), roi_back=(1093,550,127,120), name="end_area_boss")
+	# description 
+	C_END_BUFF_AREA_3 = RuleClick(roi_front=(764,636,282,42), roi_back=(764,636,282,42), name="end_buff_area_3")
+	# 记录通关时间的按钮 
+	C_END_SOUL_RECORD = RuleClick(roi_front=(317,561,53,49), roi_back=(317,561,53,49), name="end_soul_record")
+	# 战斗数据详细 
+	C_END_SOUL_DETAILS = RuleClick(roi_front=(383,559,52,49), roi_back=(383,559,52,49), name="end_soul_details")
+	# 单人好友头像 
+	C_END_FRIENDS_1 = RuleClick(roi_front=(581,402,118,135), roi_back=(581,402,118,135), name="end_friends_1")
+	# 多人好友头像第一个 
+	C_END_FRIENDS_21 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_friends_21")
+	# description 
+	C_END_FRIENDS_22 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_friends_22")
+	# description 
+	C_END_FRIENDS_31 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_friends_31")
+	# description 
+	C_END_FRIENDS_32 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_friends_32")
+	# description 
+	C_END_FRIENDS_23 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_friends_23")
+
+
+	# Click Rule Assets
+	# description 
+	C_END_1_1 = RuleClick(roi_front=(266,175,100,100), roi_back=(266,175,100,100), name="end_1_1")
+	# description 
+	C_END_1_2 = RuleClick(roi_front=(400,174,100,100), roi_back=(400,174,100,100), name="end_1_2")
+	# description 
+	C_END_1_3 = RuleClick(roi_front=(536,173,100,100), roi_back=(536,173,100,100), name="end_1_3")
+	# description 
+	C_END_1_4 = RuleClick(roi_front=(671,173,100,100), roi_back=(671,173,100,100), name="end_1_4")
+	# description 
+	C_END_1_5 = RuleClick(roi_front=(805,174,100,100), roi_back=(805,174,100,100), name="end_1_5")
+	# description 
+	C_END_1_6 = RuleClick(roi_front=(942,175,100,100), roi_back=(942,175,100,100), name="end_1_6")
+	# description 
+	C_END_2_1 = RuleClick(roi_front=(266,310,100,100), roi_back=(266,310,100,100), name="end_2_1")
+	# description 
+	C_END_2_2 = RuleClick(roi_front=(401,310,100,100), roi_back=(401,310,100,100), name="end_2_2")
+	# description 
+	C_END_2_3 = RuleClick(roi_front=(536,309,100,100), roi_back=(536,309,100,100), name="end_2_3")
+	# description 
+	C_END_2_4 = RuleClick(roi_front=(671,311,100,100), roi_back=(671,311,100,100), name="end_2_4")
+	# description 
+	C_END_2_5 = RuleClick(roi_front=(806,310,100,100), roi_back=(806,310,100,100), name="end_2_5")
+	# description 
+	C_END_2_6 = RuleClick(roi_front=(942,312,100,100), roi_back=(942,312,100,100), name="end_2_6")
+	# description 
+	C_END_3_1 = RuleClick(roi_front=(266,444,100,100), roi_back=(266,444,100,100), name="end_3_1")
+	# description 
+	C_END_3_2 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_3_2")
+	# description 
+	C_END_3_3 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_3_3")
+	# description 
+	C_END_3_4 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_3_4")
+	# description 
+	C_END_3_5 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_3_5")
+	# description 
+	C_END_3_6 = RuleClick(roi_front=(0,0,100,100), roi_back=(0,0,100,100), name="end_3_6")
+	# 其实贪吃鬼这个点了也是没事儿 
+	C_END_GREED = RuleClick(roi_front=(138,16,512,93), roi_back=(138,16,512,93), name="end_greed")
+
+
+	# Image Rule Assets
+	# description 
+	I_END_FIX_1 = RuleImage(roi_front=(896,251,218,64), roi_back=(119,66,1136,620), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gw/gw_end_fix_1.png")
+	# description 
+	I_END_FIX_2 = RuleImage(roi_front=(800,251,100,33), roi_back=(32,90,1137,547), threshold=0.7, method="Template matching", file="./tasks/Component/GeneralBattle/gw/gw_end_fix_2.png")
+
+

+ 67 - 14
tasks/Component/GeneralBattle/battle_wait.py

@@ -7,9 +7,11 @@ from functools import wraps
 from dataclasses import dataclass
 from typing import TypeVar, ParamSpec, Callable
 from enum import Enum, auto
+from cached_property import cached_property
 
 from module.logger import logger
 from module.base.timer import Timer
+from module.atom.click import RuleClickExclude
 
 from tasks.base_task import BaseTask
 
@@ -298,6 +300,40 @@ class battle_wait_strategy:
 
 
 class BattleWait(BaseTask):
+    # build in
+    # ------------------------------------------------------------------------------------------------------------------
+    # @property
+    # def reward_exclude_click(self):
+    #     if not hasattr(self, '_reward_exclude_click'):
+    #         self._reward_exclude_click = RuleClickExclude(
+    #             [self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3]
+    #         )
+    #     return self._reward_exclude_click
+    @cached_property
+    def exclude_button_stage_1(self):
+        return ['C_END_MESSAGE_RIGHT_TOP', 'C_END_BUFF_AREA_1', 'C_END_BUFF_AREA_2',
+                'C_END_SOUL_RECORD', 'C_END_SOUL_DETAILS', 'C_END_FRIENDS_1'
+                ]
+
+    @cached_property
+    def exclude_button_stage_2(self):
+        return []
+
+    def reward_exclude_click(self, areas: list[str] = None, name: str = 'success_exclude_click') -> RuleClickExclude:
+        inputs = []
+        for area in areas:
+            click = getattr(self, area, None)
+            if click is None:
+                raise ValueError(f'Unknown success exclusion click: {area!r}')
+            inputs.append(click)
+        return RuleClickExclude(inputs, name=name)
+
+    def reward_exclude_click_1(self, areas: list[str] = None) -> RuleClickExclude:
+        return self.reward_exclude_click(areas, name='reward_exclude_click_1')
+
+    def reward_exclude_click_2(self, areas: list[str] = None) -> RuleClickExclude:
+        return self.reward_exclude_click(areas, name='reward_exclude_click_2')
+
     # build in
     # ------------------------------------------------------------------------------------------------------------------
     def _bw_setup_default(self, bw_ctx: BattleWaitContext) -> HookSignal:
@@ -307,6 +343,17 @@ class BattleWait(BaseTask):
         self.device.stuck_record_add('BATTLE_STATUS_S')
         self.device.click_record_clear()
         logger.info('Start battle process')
+        options: dict[str, dict] = getattr(bw_ctx, 'options', None) or {}
+        success_options = options.get('success') or {}
+        if not isinstance(success_options, dict):
+            raise TypeError("battle wait option 'success' must be a dict")
+        excludes = success_options.get('excludes')
+        exclude_stage_1 = excludes if excludes is not None else self.exclude_button_stage_1
+        exclude_stage_2 = excludes if excludes is not None else self.exclude_button_stage_2
+        self._reward_exclude_click_1 = self.reward_exclude_click_1(exclude_stage_1)
+        self._reward_exclude_click_2 = self.reward_exclude_click_2(exclude_stage_2)
+        # print(self._reward_exclude_click_1)
+        # print(self._reward_exclude_click_2)
         return HookSignal.DONE
 
     def _bw_completion_default(self, bw_ctx: BattleWaitContext) -> HookSignal:
@@ -319,29 +366,33 @@ class BattleWait(BaseTask):
         return HookSignal.CONTINUE
 
     def _bw_success_default(self, bw_ctx: BattleWaitContext) -> HookSignal:
+
+
         if self.appear_then_click(self.I_WIN, interval=0.8):
+            self.click(self._reward_exclude_click_1)
             return HookSignal.CONTINUE
-        appear_ghost, appear_reward, appear_gold = (
+        appear_ghost, appear_reward, appear_gold, appear_skin = (
             self.appear(self.I_GREED_GHOST),
             self.appear(self.I_REWARD),
-            self.appear(self.I_REWARD_GOLD)
+            self.appear(self.I_REWARD_GOLD),
+            self.appear(self.I_REWARD_GOLD_SNAKE_SKIN)
         )
-        if not any([appear_ghost, appear_reward, appear_gold]):
+        if not any([appear_ghost, appear_reward, appear_gold, appear_skin]):
             return HookSignal.CONTINUE
         logger.info('Win battle')
         timer = Timer(20).start()
         while 1:
             self.screenshot()
 
-            _appear_ghost, _appear_reward, _appear_gold = (
+            _appear_ghost, _appear_reward, _appear_gold, _appear_skin = (
                 self.appear(self.I_GREED_GHOST, threshold=0.6),
                 self.appear(self.I_REWARD),
-                self.appear(self.I_REWARD_GOLD)
+                self.appear(self.I_REWARD_GOLD),
+                self.appear(self.I_REWARD_GOLD_SNAKE_SKIN)
             )
-            # logger.info(f'_appear_ghost: {_appear_ghost} _appear_reward: {_appear_reward} _appear_gold: {_appear_gold}')
-            if any([_appear_ghost, _appear_reward, _appear_gold]):
-                action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
-                self.click(action_click, interval=1.5)
+            # logger.info(f'_appear_ghost: {_appear_ghost} _appear_reward: {_appear_reward} _appear_gold: {_appear_gold} _appear_skin: {_appear_skin}')
+            if any([_appear_ghost, _appear_reward, _appear_gold, _appear_skin]):
+                self.click(self._reward_exclude_click_2, interval=1.5)
             else:
                 logger.info('Get all reward')
                 bw_ctx.success = True
@@ -368,6 +419,8 @@ class BattleWait(BaseTask):
         return HookSignal.CONTINUE
 
     def _bw_randomclick_default(self, bw_ctx: BattleWaitContext) -> HookSignal:
+        if not self.is_in_battle(is_screenshot=False):
+            return HookSignal.CONTINUE
         if 0 <= random.randint(0, 500) <= 20:  # 百分之4的概率
             rand_type = random.randint(0, 2)
             match rand_type:
@@ -386,6 +439,11 @@ class BattleWait(BaseTask):
     # custom
     # ------------------------------------------------------------------------------------------------------------------
     def _bw_success_soul(self, bw_ctx: BattleWaitContext) -> HookSignal:
+        options: dict[str, dict] = getattr(bw_ctx, 'options', None) or {}
+        success_options = options.get('success') or {}
+        if not isinstance(success_options, dict):
+            raise TypeError("battle wait option 'success' must be a dict")
+        action_click = self.reward_exclude_click(success_options.get('excludes'))
         if self.appear_then_click(self.I_WIN, interval=0.8):
             return HookSignal.CONTINUE
         appear_ghost, appear_reward, appear_gold, appear_skin = (
@@ -409,7 +467,6 @@ class BattleWait(BaseTask):
             )
             # logger.info(f'_appear_ghost: {_appear_ghost} _appear_reward: {_appear_reward} _appear_gold: {_appear_gold} _appear_skin: {_appear_skin}')
             if any([_appear_ghost, _appear_reward, _appear_gold, _appear_skin]):
-                action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
                 self.click(action_click, interval=1.5)
             else:
                 logger.info('Get all reward')
@@ -546,7 +603,3 @@ if __name__ == '__main__':
 
 
 
-
-
-
-

+ 80 - 0
tasks/Component/GeneralBattle/gw/click.json

@@ -0,0 +1,80 @@
+[
+  {
+    "itemName": "end_message_right_top",
+    "roiFront": "846,4,404,34",
+    "roiBack": "846,4,404,34",
+    "description": "右上角的聊天信息"
+  },
+  {
+    "itemName": "end_buff_area_1",
+    "roiFront": "150,638,295,41",
+    "roiBack": "150,638,295,41",
+    "description": "description"
+  },
+  {
+    "itemName": "end_buff_area_2",
+    "roiFront": "457,635,273,43",
+    "roiBack": "457,635,273,43",
+    "description": "description"
+  },
+  {
+    "itemName": "end_area_boss",
+    "roiFront": "1093,550,127,120",
+    "roiBack": "1093,550,127,120",
+    "description": "給地鬼的"
+  },
+  {
+    "itemName": "end_buff_area_3",
+    "roiFront": "764,636,282,42",
+    "roiBack": "764,636,282,42",
+    "description": "description"
+  },
+  {
+    "itemName": "end_soul_record",
+    "roiFront": "317,561,53,49",
+    "roiBack": "317,561,53,49",
+    "description": "记录通关时间的按钮"
+  },
+  {
+    "itemName": "end_soul_details",
+    "roiFront": "383,559,52,49",
+    "roiBack": "383,559,52,49",
+    "description": "战斗数据详细"
+  },
+  {
+    "itemName": "end_friends_1",
+    "roiFront": "581,402,118,135",
+    "roiBack": "581,402,118,135",
+    "description": "单人好友头像"
+  },
+  {
+    "itemName": "end_friends_21",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "多人好友头像第一个"
+  },
+  {
+    "itemName": "end_friends_22",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_friends_31",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_friends_32",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_friends_23",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  }
+]

+ 116 - 0
tasks/Component/GeneralBattle/gw/click2.json

@@ -0,0 +1,116 @@
+[
+  {
+    "itemName": "end_1_1",
+    "roiFront": "266,175,100,100",
+    "roiBack": "266,175,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_1_2",
+    "roiFront": "400,174,100,100",
+    "roiBack": "400,174,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_1_3",
+    "roiFront": "536,173,100,100",
+    "roiBack": "536,173,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_1_4",
+    "roiFront": "671,173,100,100",
+    "roiBack": "671,173,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_1_5",
+    "roiFront": "805,174,100,100",
+    "roiBack": "805,174,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_1_6",
+    "roiFront": "942,175,100,100",
+    "roiBack": "942,175,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_2_1",
+    "roiFront": "266,310,100,100",
+    "roiBack": "266,310,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_2_2",
+    "roiFront": "401,310,100,100",
+    "roiBack": "401,310,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_2_3",
+    "roiFront": "536,309,100,100",
+    "roiBack": "536,309,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_2_4",
+    "roiFront": "671,311,100,100",
+    "roiBack": "671,311,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_2_5",
+    "roiFront": "806,310,100,100",
+    "roiBack": "806,310,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_2_6",
+    "roiFront": "942,312,100,100",
+    "roiBack": "942,312,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_3_1",
+    "roiFront": "266,444,100,100",
+    "roiBack": "266,444,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_3_2",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_3_3",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_3_4",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_3_5",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_3_6",
+    "roiFront": "0,0,100,100",
+    "roiBack": "0,0,100,100",
+    "description": "description"
+  },
+  {
+    "itemName": "end_greed",
+    "roiFront": "138,16,512,93",
+    "roiBack": "138,16,512,93",
+    "description": "其实贪吃鬼这个点了也是没事儿"
+  }
+]

BIN
tasks/Component/GeneralBattle/gw/gw_end_fix_1.png


BIN
tasks/Component/GeneralBattle/gw/gw_end_fix_2.png


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

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "end_fix_1",
+    "imageName": "gw_end_fix_1.png",
+    "roiFront": "896,251,218,64",
+    "roiBack": "119,66,1136,620",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "end_fix_2",
+    "imageName": "gw_end_fix_2.png",
+    "roiFront": "800,251,100,33",
+    "roiBack": "32,90,1137,547",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "description"
+  }
+]

+ 9 - 0
tasks/EvoZone/script_task.py

@@ -13,6 +13,8 @@ from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_main, page_awake_zones, page_shikigami_records
 from tasks.EvoZone.assets import EvoZoneAssets
 from tasks.EvoZone.config import EvoZone, UserStatus, KirinType
+from tasks.Component.GeneralBattle.battle_wait import battle_wait_strategy
+
 from module.logger import logger
 from module.exception import TaskEnd
 
@@ -328,6 +330,13 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         pass
 
 
+    @battle_wait_strategy()
+    # @battle_wait_strategy(options={'success': {}})
+    def battle_wait(self, *args, **kwargs):
+        return self.battle_wait_with_strategy(*args, **kwargs)
+
+
+
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device

+ 1 - 1
tasks/Restart/assets.py

@@ -139,7 +139,7 @@ class RestartAssets:
 	O_LOGIN_NETWORK = RuleOcr(roi=(534,649,189,39), area=(210,492,100,100), mode="Single", method="Default", keyword="正在连接服务器", name="login_network")
 	# Ocr-description 
 	O_LOGIN_ENTER_GAME = RuleOcr(roi=(589,544,101,107), area=(558,574,154,49), mode="Single", method="Default", keyword="进入", name="login_enter_game")
-	# Ocr-description 
+	# 兼容原先的进入游戏 
 	O_LOGIN_ENTER_GAME_ORIGIN = RuleOcr(roi=(550,567,176,56), area=(558,574,154,49), mode="Single", method="Default", keyword="进入游戏", name="login_enter_game_origin")
 	# 点击屏幕跳过 
 	O_LOGIN_SKIP_1 = RuleOcr(roi=(1046,35,130,37), area=(1046,35,130,37), mode="Single", method="Default", keyword="点击屏幕跳过", name="login_skip_1")

+ 5 - 0
tasks/RyouToppa/script_task.py

@@ -12,6 +12,7 @@ from tasks.Component.config_base import ConfigBase, Time
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_realm_raid, page_main, page_kekkai_toppa, page_shikigami_records
 from tasks.RealmRaid.assets import RealmRaidAssets
+from tasks.Component.GeneralBattle.battle_wait import battle_wait_strategy
 
 from module.logger import logger
 from module.exception import TaskEnd
@@ -327,6 +328,10 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
                 click_failure_count += 1
                 continue
 
+    @battle_wait_strategy()
+    def battle_wait(self, *args, **kwargs):
+        return self.battle_wait_with_strategy(*args, **kwargs)
+
 
 if __name__ == "__main__":
     from module.config.config import Config

+ 82 - 0
tests/module/atom/test_click.py

@@ -0,0 +1,82 @@
+import pytest
+
+from module.atom.click import RuleClick, RuleClickExclude
+
+
+def test_exclude_click_string_contains_excluded_click_names():
+    first = RuleClick((0, 0, 1, 1), (100, 100, 20, 20), name='first')
+    second = RuleClick((0, 0, 1, 1), (200, 200, 20, 20), name='second')
+    click = RuleClickExclude([first, second], strategy='complement', distribution='uniform')
+
+    assert 'first' in str(click)
+    assert 'second' in str(click)
+    assert repr(click) == str(click)
+
+
+@pytest.mark.parametrize('strategy', ['rejection', 'complement'])
+@pytest.mark.parametrize('distribution', ['uniform', 'normal'])
+def test_exclude_click_strategies_and_distributions(strategy, distribution):
+    excluded = RuleClick((0, 0, 1, 1), (100, 100, 200, 150))
+    click = RuleClickExclude(excluded, strategy=strategy, distribution=distribution)
+
+    assert isinstance(click, RuleClick)
+    for _ in range(200):
+        x, y = click.coord()
+        assert 0 <= x < 1280
+        assert 0 <= y < 720
+        assert not (100 <= x < 300 and 100 <= y < 250)
+
+
+def test_exclude_click_uses_union_of_overlapping_roi_back_regions():
+    clicks = [
+        RuleClick((0, 0, 1, 1), (100, 100, 200, 150)),
+        RuleClick((0, 0, 1, 1), (250, 150, 200, 150)),
+    ]
+    click = RuleClickExclude(clicks, strategy='complement', distribution='uniform')
+
+    for _ in range(200):
+        x, y = click.coord()
+        assert not (
+            (100 <= x < 300 and 100 <= y < 250)
+            or (250 <= x < 450 and 150 <= y < 300)
+        )
+
+
+def test_exclude_click_clips_roi_back_to_screen():
+    excluded = RuleClick((0, 0, 1, 1), (-100, -100, 200, 200))
+    click = RuleClickExclude(excluded, strategy='complement', distribution='uniform')
+
+    for _ in range(100):
+        x, y = click.coord()
+        assert x >= 100 or y >= 100
+
+
+def test_rejection_sampling_falls_back_to_complement(monkeypatch):
+    excluded = RuleClick((0, 0, 1, 1), (0, 0, 1279, 720))
+    click = RuleClickExclude(excluded, strategy='rejection', distribution='uniform', max_attempts=1)
+    sample_point = click._sample_point
+    monkeypatch.setattr(
+        click,
+        '_sample_point',
+        lambda rect, distribution: (1, 1)
+        if rect == (0, 0, 1280, 720) else sample_point(rect, distribution),
+    )
+
+    x, y = click.coord()
+    assert x == 1279
+    assert 0 <= y < 720
+
+
+def test_strategy_and_distribution_are_selected_once_at_initialization(monkeypatch):
+    choices = iter(['rejection', 'normal'])
+    monkeypatch.setattr('module.atom.click.random.choice', lambda values: next(choices))
+    click = RuleClickExclude([])
+
+    assert click.strategy == 'rejection'
+    assert click.distribution == 'normal'
+
+
+def test_excluded_regions_covering_screen_are_rejected():
+    excluded = RuleClick((0, 0, 1, 1), (0, 0, 1280, 720))
+    with pytest.raises(ValueError, match='cover the whole screen'):
+        RuleClickExclude(excluded)

+ 21 - 0
tests/test_ocr_filter.py

@@ -0,0 +1,21 @@
+from types import SimpleNamespace
+
+from module.ocr.base_ocr import BaseCor
+
+
+def boxed_text(text: str):
+    return SimpleNamespace(ocr_text=text)
+
+
+def test_exact_filter_does_not_match_a_partial_nickname():
+    target = object.__new__(BaseCor)
+    results = [boxed_text('赈早见琥珀主'), boxed_text('龙鸣蚀心')]
+
+    assert target.filter(results, '你的心', exact=True) is None
+
+
+def test_exact_filter_matches_the_complete_nickname():
+    target = object.__new__(BaseCor)
+    results = [boxed_text('轻芋'), boxed_text('你的心')]
+
+    assert target.filter(results, '你的心', exact=True) == [1]