Quellcode durchsuchen

feat(DailyTrifles): 每日一抽增加绘制每月神秘图案功能

stigma vor 1 Jahr
Ursprung
Commit
41c543e0c7

+ 31 - 0
module/device/method/adb.py

@@ -9,6 +9,7 @@ from lxml import etree
 
 from module.base.decorator import Config
 from module.device.connection import Connection
+from module.device.method.minitouch import smooth_path
 from module.device.method.utils import (RETRY_TRIES, retry_sleep, remove_prefix, handle_adb_error,
                                         ImageTruncated, PackageNotInstalled)
 from module.exception import RequestHumanTakeover, ScriptError
@@ -339,6 +340,36 @@ class Adb(Connection):
         hierarchy = etree.fromstring(content)
         return hierarchy
 
+    def draw_adb(self, points: list, interval=0.01):
+        """
+        通过多个点画连续线段,模拟连续触摸绘制
+
+        Args:
+            points: 点的列表,格式为 [(x1, y1), (x2, y2), ...]
+            interval: 移动间隔时间(秒)
+        """
+        if len(points) < 2:
+            logger.warning('至少需要2个点来画线')
+            return
+
+        # 平滑路径
+        smooth_points = smooth_path(points)
+
+        start_point = smooth_points[0]
+
+        # 按下起始点
+        self.adb_shell(['input', 'motionevent', 'DOWN', str(start_point[0]), str(start_point[1])])
+
+        # 移动到后续点
+        for i, point in enumerate(smooth_points[1:], start=1):
+            # 给点间隔
+            time.sleep(interval)
+            self.adb_shell(['input', 'motionevent', 'MOVE', str(point[0]), str(point[1])])
+
+        # 抬起手指
+        final_point = smooth_points[-1]
+        self.adb_shell(['input', 'motionevent', 'UP', str(final_point[0]), str(final_point[1])])
+
 
 if __name__ == "__main__":
     adb = Adb(config='oas1')

+ 47 - 0
module/device/method/minitouch.py

@@ -92,6 +92,53 @@ def insert_swipe(p0, p3, speed=15, min_distance=10):
 
     return points
 
+def smooth_path(points: list, min_distance: float = 30.0, offset_range: float = 3.0):
+    """
+    路径平滑,基于路径方向的垂直偏移
+    Args:
+        points: 原始点列表 [(x1, y1), (x2, y2), ...]
+        min_distance: 最小插点距离
+        offset_range: 垂直偏移范围
+
+    Returns:
+        list: 平滑后的点列表
+    """
+    if len(points) < 2:
+        return points
+
+    smooth_points = [points[0]]
+
+    for i in range(len(points) - 1):
+        start = np.array(points[i])
+        end = np.array(points[i + 1])
+
+        direction = end - start
+        distance = np.linalg.norm(direction)
+
+        if distance <= min_distance:
+            continue
+
+        # 归一化方向向量
+        unit_direction = direction / distance
+        # 计算垂直向量
+        perpendicular = np.array([-unit_direction[1], unit_direction[0]])
+
+        num_segments = int(distance / min_distance)
+
+        for j in range(1, num_segments + 1):
+            ratio = j / num_segments
+            interpolated = start + ratio * direction
+
+            # 垂直方向的随机偏移
+            perpendicular_offset = np.random.uniform(-offset_range, offset_range)
+            final_point = interpolated + perpendicular_offset * perpendicular
+
+            smooth_points.append((int(final_point[0]), int(final_point[1])))
+
+    if smooth_points[-1] != points[-1]:
+        smooth_points.append(points[-1])
+
+    return smooth_points
 
 class Command:
     def __init__(

+ 50 - 2
tasks/Component/Summon/summon.py

@@ -29,9 +29,54 @@ class Summon(BaseTask, SummonAssets):
             case _: target_swipe = self.S_RANDOM_SWIPE_1
         self.swipe(target_swipe, interval=0.5)
 
+    def summon_mystery_pattern(self):
+        """
+        每月神秘图案
+        :return:
+        """
+        # 目前只测试了7月的,其他月份的我是根据截图描的,可能需要调整
+        # 一月
+        jan = [(400, 119), (406, 525), (862, 123), (864, 521), (402, 121)]
+        # 二月、八月
+        febAndAug = [(471, 119), (467, 525)]
+        # 三月、九月
+        marAndSep = [(390, 304), (886, 302)]
+        # 四月、十月
+        aprAndOct = [(402, 526), (862, 125)]
+        # 五月、十一月
+        mayAndNov = [(414, 207), (648, 550), (870, 209)]
+        # 六月、十二月
+        junAndDec = [(413, 138), (850, 133), (856, 226), (415, 239), (416, 140), (531, 136), (535, 590), (791, 586),
+                     (760, 131)]
+        # 七月
+        jul = [(418, 124), (421, 504), (853, 511), (855, 128)]
+        # 月份字典
+        month_dict = {
+            1: jan,
+            2: febAndAug,
+            3: marAndSep,
+            4: aprAndOct,
+            5: mayAndNov,
+            6: junAndDec,
+            7: jul,
+            8: febAndAug,
+            9: marAndSep,
+            10: aprAndOct,
+            11: mayAndNov,
+            12: junAndDec
+        }
+        # 获取当前月份
+        current_month = time.localtime().tm_mon
+        current_pattern = month_dict.get(current_month, None)
+        if current_pattern is None:
+            logger.warning(f'不支持的月份: {current_month}')
+            return
+        self.screenshot()
+        self.device.draw_adb(current_pattern)
+
 
 
-    def summon_one(self):
+    def summon_one(self,draw_mystery_pattern=False):
         """
         确保在召唤界面,每日召唤一次
         召唤结束后回到 召唤主界面
@@ -81,7 +126,10 @@ class Summon(BaseTask, SummonAssets):
                     # 某些时候会点击到 “语言召唤”
                     if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
                         continue
-                    self.summon()
+                    if draw_mystery_pattern:
+                        self.summon_mystery_pattern()
+                    else:
+                        self.summon()
                     continue
             logger.info('Summon one success')
 

+ 2 - 0
tasks/DailyTrifles/config.py

@@ -16,6 +16,8 @@ class DailyTriflesConfig(BaseModel):
     one_summon: bool = Field(title='One Summon', default=False)
     # 召唤类型
     summon_type: SummonType = Field(default=SummonType.default, description='召唤类型')
+    # 是否绘制神秘图案
+    draw_mystery_pattern: bool = Field(title='Draw Mystery Pattern', default=False, description='是否绘制神秘图案')
     guild_wish: bool = Field(title='Guild Wish', default=False)
     friend_love: bool = Field(title='Friend Love', default=False)
     luck_msg: bool = Field(title='Luck Msg', default=False)

+ 22 - 4
tasks/DailyTrifles/script_task.py

@@ -44,12 +44,30 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
     def run_one_summon(self):
         self.ui_get_current_page()
         self.ui_goto(page_summon)
-        if self.config.daily_trifles.trifles_config.summon_type == SummonType.default:
-            self.summon_one()
-        elif self.config.daily_trifles.trifles_config.summon_type == SummonType.recall:
+        config=self.config.daily_trifles.trifles_config
+        if config.summon_type == SummonType.default:
+            self.summon_one(draw_mystery_pattern=config.draw_mystery_pattern)
+            self.check_time()
+        elif config.summon_type == SummonType.recall:
             self.summon_recall()
         self.back_summon_main()
 
+    def check_time(self):
+        config = self.config.daily_trifles.trifles_config
+        now = datetime.now()
+        next_run = now + self.config.daily_trifles.scheduler.success_interval
+        # 检查是否跨月(next_run的月份与当前月份不同)
+        if next_run.month != now.month:
+            # 跨月重置神秘图案触发状态
+            if not config.draw_mystery_pattern:
+                config.draw_mystery_pattern = True
+                logger.info(
+                    f"reset draw_mystery_pattern to True, next_run: {next_run}")
+        else:
+            # 如果还是在同一月份,则没必要再绘制神秘图案
+            config.draw_mystery_pattern = False
+        self.config.save()
+
     def summon_recall(self):
         """
         确保在召唤界面,每日召唤一次
@@ -293,4 +311,4 @@ if __name__ == '__main__':
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.run_store()
+    t.check_time()