Преглед изворни кода

feat(WeeklyTrifles):每周琐事新增执行惠比寿的摸鱼行动功能

- 默认仅仅使用全部存储按钮
- 会ocr当前福运御守数量,不足则不执行
- 因为是新增功能所以默认关闭
- 主要目的是让真蛇每周打一次即可获得全部奖励,同时避免周常活动遗漏
Hurry2 пре 2 месеци
родитељ
комит
60bf1268f6

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

@@ -137,5 +137,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": "默认使用全部存储按钮,主要目的是为了配合真蛇每周打一次即可获得俩次奖励(并不会节省体力)"
+}

+ 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)
-

+ 100 - 13
tasks/WeeklyTrifles/script_task.py

@@ -9,14 +9,25 @@ 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):
         con = self.config.weekly_trifles.trifles
+        if con.save_touch_fish:
+            self._save_touch_fish()
         if con.share_collect:
             self._share_collect()
         if con.share_area_boss:
@@ -29,7 +40,6 @@ class ScriptTask(GameUi, WeeklyTriflesAssets):
         self.set_next_run(task='WeeklyTrifles', success=True, finish=True)
         raise TaskEnd('WeeklyTrifles')
 
-
     def click_share(self, wechat) -> bool:
         """
         点击分享
@@ -52,12 +62,69 @@ 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)
+            cost_tickts = self.O_WT_SAVE_COST.ocr(self.device.image)
+            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:
+                    self.appear_then_click(self.I_WT_SAVE_ALL)
+                    cu_tickts = 0
+                    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:
+                    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):
         """
         图鉴分享
@@ -92,7 +159,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')
@@ -112,10 +181,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
@@ -124,6 +196,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.ui_get_current_page()
         self.ui_goto(page_area_boss)
@@ -205,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:
@@ -233,7 +307,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()
                 # 随机点击直到再次召唤出现或者超时
@@ -244,7 +320,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:
@@ -255,19 +333,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()
@@ -276,6 +364,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)
@@ -284,5 +373,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