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

Merge branch 'runhey:dev' into dev

migsmiku 1 год назад
Родитель
Сommit
04dd923460

+ 5 - 1
dev_tools/assets_extract.py

@@ -408,7 +408,11 @@ class AllAssetsExtractor:
         self.task_paths = [x for x in self.task_paths if 'Component' not in x]
         self.task_paths.extend([str(x) for x in (self.task_path / 'Component').iterdir() if x.is_dir()])
 
-        process_map(self.work, self.task_paths, max_workers=1)
+        # process_map(self.work, self.task_paths, max_workers=1)
+        for task_path in self.task_paths:
+            me = AssetsExtractor(task_path)
+            me.extract()
+
 
     @staticmethod
     def work(task_path: str):

+ 1 - 1
module/config/config_manual.py

@@ -18,7 +18,7 @@ class ConfigManual:
         > TrueOrochi > RichMan
         > CollectiveMissions
         > Pets > TalismanPass > Delegation > Hyakkiyakou
-        > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss > FloatParade > Quiz > KittyShop
+        > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss > FloatParade > Quiz > KittyShop > DyeTrials
         """
 
     DEVICE_OVER_HTTP = False

+ 1 - 1
module/config/config_menu.py

@@ -40,7 +40,7 @@ class ConfigMenu:
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         # 活动的任务
-        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop']
+        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop', 'DyeTrials']
         # 开发工具
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
 

+ 2 - 0
module/config/config_model.py

@@ -56,6 +56,7 @@ from tasks.FrogBoss.config import FrogBoss
 from tasks.FloatParade.config import FloatParade
 from tasks.Quiz.config import Quiz
 from tasks.KittyShop.config import KittyShop
+from tasks.DyeTrials.config import DyeTrials
 # ----------------------------------------------------------------------------------------------------------------------
 
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
@@ -117,6 +118,7 @@ class ConfigModel(ConfigBase):
     float_parade: FloatParade = Field(default_factory=FloatParade)
     quiz: Quiz = Field(default_factory=Quiz)
     kitty_shop: KittyShop = Field(default_factory=KittyShop)
+    dye_trials: DyeTrials = Field(default_factory=DyeTrials)
 
     # 这些是肝帝专属
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)

+ 30 - 0
tasks/DyeTrials/assets.py

@@ -0,0 +1,30 @@
+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 DyeTrialsAssets: 
+
+
+	# Image Rule Assets
+	# 从庭院进入灵染试炼活动 
+	I_FP_ACCESS = RuleImage(roi_front=(1192,317,36,34), roi_back=(1000,101,261,472), threshold=0.8, method="Template matching", file="./tasks/DyeTrials/fp/fp_fp_access.png")
+	# 寻找切换按钮 
+	I_TOGGLE_BUTTON = RuleImage(roi_front=(1202,466,22,21), roi_back=(1090,127,176,377), threshold=0.7, method="Template matching", file="./tasks/DyeTrials/fp/fp_toggle_button.png")
+	# 进入灵染试炼战斗界面 
+	I_FP_ACCESS_1 = RuleImage(roi_front=(264,339,26,95), roi_back=(129,202,329,380), threshold=0.7, method="Template matching", file="./tasks/DyeTrials/fp/fp_fp_access_1.png")
+	# 挑战 
+	I_FP_CHALLENGE = RuleImage(roi_front=(1159,598,60,29), roi_back=(1159,598,60,29), threshold=0.8, method="Template matching", file="./tasks/DyeTrials/fp/fp_fp_challenge.png")
+	# description 
+	I_BATTLE_SUCCESS = RuleImage(roi_front=(435,147,100,100), roi_back=(435,147,100,100), threshold=0.8, method="Template matching", file="./tasks/DyeTrials/fp/battle_success.png")
+
+
+	# Ocr Rule Assets
+	# 战斗次数 
+	O_BATTLE_NUM = RuleOcr(roi=(1144,408,100,21), area=(1144,408,100,21), mode="DigitCounter", method="Default", keyword="", name="battle_num")
+
+

+ 13 - 0
tasks/DyeTrials/config.py

@@ -0,0 +1,13 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from pydantic import Field
+
+from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
+from tasks.Component.config_base import ConfigBase
+from tasks.Component.config_scheduler import Scheduler
+
+
+class DyeTrials(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

BIN
tasks/DyeTrials/fp/battle_success.png


BIN
tasks/DyeTrials/fp/fp_fp_access.png


BIN
tasks/DyeTrials/fp/fp_fp_access_1.png


BIN
tasks/DyeTrials/fp/fp_fp_challenge.png


BIN
tasks/DyeTrials/fp/fp_toggle_button.png


+ 48 - 0
tasks/DyeTrials/fp/image.json

@@ -0,0 +1,48 @@
+[
+  {
+    "itemName": "fp_access",
+    "imageName": "fp_fp_access.png",
+    "roiFront": "1192,317,36,34",
+    "roiBack": "1000,101,261,472",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "从庭院进入灵染试炼活动"
+  },
+  {
+    "itemName": "toggle_button",
+    "imageName": "fp_toggle_button.png",
+    "roiFront": "1202,466,22,21",
+    "roiBack": "1090,127,176,377",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "寻找切换按钮"
+  },
+  {
+    "itemName": "fp_access_1",
+    "imageName": "fp_fp_access_1.png",
+    "roiFront": "264,339,26,95",
+    "roiBack": "129,202,329,380",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "进入灵染试炼战斗界面"
+  },
+  {
+    "itemName": "fp_challenge",
+    "imageName": "fp_fp_challenge.png",
+    "roiFront": "1159,598,60,29",
+    "roiBack": "1159,598,60,29",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "挑战"
+  },
+  {
+    "itemName": "battle_success",
+    "imageName": "battle_success.png",
+    "roiFront": "435,147,100,100",
+    "roiBack": "435,147,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]
+

+ 11 - 0
tasks/DyeTrials/fp/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "battle_num",
+    "roiFront": "1144,408,100,21",
+    "roiBack": "1144,408,100,21",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "战斗次数"
+  }
+]

+ 101 - 0
tasks/DyeTrials/script_task.py

@@ -0,0 +1,101 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+from module.base.timer import Timer
+from module.exception import TaskEnd
+from module.logger import logger
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.DyeTrials.assets import DyeTrialsAssets
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_shikigami_records
+from tasks.Restart.assets import RestartAssets
+
+""" 灵染 试炼 """
+
+
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DyeTrialsAssets):
+
+    def run(self):
+
+        cfg = self.config.dye_trials
+
+        # 自动换御魂
+        if cfg.switch_soul_config.enable:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
+        if cfg.switch_soul_config.enable_switch_by_name:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+
+        self.get_all()
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+
+        self.set_next_run(task='DyeTrials', success=True, finish=True)
+        raise TaskEnd('DyeTrials')
+
+    def get_all(self):
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_FP_CHALLENGE):
+                break
+            if self.appear_then_click(self.I_FP_ACCESS, interval=0.8):
+                continue
+            if self.appear_then_click(self.I_FP_ACCESS_1, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_TOGGLE_BUTTON, interval=3):
+                continue
+        logger.info('Enter DyeTrials')
+        boss_timer = Timer(60)
+        boss_timer.start()
+        battle_num = 0
+        while 1:
+            self.screenshot()
+            time.sleep(0.1)
+            if boss_timer.reached():
+                self.config.notifier.push(title='超鬼王', message='识别超时退出')
+                break
+            # 获得奖励
+            if self.ui_reward_appear_click():
+                boss_timer.reset()
+            if self.appear_then_click(RestartAssets.I_HARVEST_CHAT_CLOSE):
+                boss_timer.reset()
+                continue
+            if self.appear(self.I_FP_CHALLENGE, interval=1):
+                cu, res, total = self.O_BATTLE_NUM.ocr(image=self.device.image)
+                if cu == total == 50 and cu + res == total:
+                    break
+                if battle_num >= 50:
+                    logger.info(f'Battle {battle_num}, enough battle, break')
+                    break
+                self.ui_click_until_disappear(self.I_FP_CHALLENGE)
+                battle_num += 1
+                logger.info(f'Battle num [{battle_num}]')
+                self.device.stuck_record_clear()
+                self.device.stuck_record_add('BATTLE_STATUS_S')
+                boss_timer.reset()
+                continue
+            if self.appear_then_click(self.I_BATTLE_SUCCESS, interval=1):
+                boss_timer.reset()
+                continue
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('DU')
+    d = Device(c)
+    t = ScriptTask(c, d)
+    t.screenshot()
+
+    t.run()

+ 11 - 0
tasks/WantedQuests/assets.py

@@ -52,6 +52,10 @@ class WantedQuestsAssets:
 	O_WQ_INFO_3 = RuleOcr(roi=(612,376,305,44), area=(612,376,305,44), mode="Single", method="Default", keyword="", name="wq_info_3")
 	# Ocr-description 
 	O_WQ_INFO_4 = RuleOcr(roi=(613,446,315,44), area=(613,446,315,44), mode="Single", method="Default", keyword="", name="wq_info_4")
+	# 怪物名称,如酒吞,阎魔等 
+	O_WQ_MONSTER_TYPE = RuleOcr(roi=(165,215,45,175), area=(165,215,45,175), mode="Full", method="Default", keyword="", name="wq_monster_type")
+	#  
+	O_WQ_TEXT_ALL = RuleOcr(roi=(20,140,110,390), area=(20,140,110,390), mode="Full", method="Default", keyword="", name="wq_text_all")
 
 
 	# Image Rule Assets
@@ -166,6 +170,8 @@ class WantedQuestsAssets:
 	I_WQ_TRACE_ONE_CHECK_OPENED = RuleImage(roi_front=(510,175,210,60), roi_back=(510,175,210,60), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_one_check_opened.png")
 	# 庭院悬赏任务界面 单个任务点开后的界面 是否为现世任务标志 
 	I_WQ_TRACE_ONE_REALWORLD = RuleImage(roi_front=(850,470,180,180), roi_back=(850,470,180,180), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_one_realworld.png")
+	# 探索界面,左侧任务列表右上角右下角标志 
+	I_WQ_LIST_TOP_BOTTOM_CHECK = RuleImage(roi_front=(120,125,25,425), roi_back=(120,125,25,425), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_list_top_bottom_check.png")
 
 
 	# Image Rule Assets
@@ -177,3 +183,8 @@ class WantedQuestsAssets:
 	I_WQ_NIAN = RuleImage(roi_front=(19,176,100,100), roi_back=(0,153,166,273), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_nian.png")
 
 
+	# Swipe Rule Assets
+	# 手指向上滑动 
+	S_WQ_LIST_UP = RuleSwipe(roi_front=(60,250,2,4), roi_back=(65,200,2,4), mode="default", name="wq_list_up")
+
+

+ 2 - 0
tasks/WantedQuests/config.py

@@ -92,6 +92,8 @@ class WantedQuestsConfig(BaseModel):
     battle_priority: str = Field(default='挑战 > 秘闻 > 探索', description='battle_priority_help')
     # 只完成协作任务
     cooperation_only: bool = Field(default=False, description="cooperation_only_help")
+    # 忽略任务的任务目标名称(“酒吞童子”等),多个用逗号“,,"分隔
+    unwanted_boss_names: str = Field(default='酒吞童子,阎魔', description='unwanted_boss_name_help')
 
 
 class WantedQuests(ConfigBase):

+ 15 - 11
tasks/WantedQuests/explore.py

@@ -43,6 +43,7 @@ class WQExplore(BaseExploration, HighLight):
                     if explore_only_boss:
                         raise ExploreWantedBoss
                     break
+                logger.info("点击探索")
                 self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
                 continue
             # 探索大世界
@@ -59,16 +60,16 @@ class WQExplore(BaseExploration, HighLight):
                 continue
             # 探索里面
             elif scene == Scene.MAIN:
-                if not explore_init:
-                    count=0
-                    while count<5:
-                        if self.appear(self.I_E_AUTO_ROTATE_ON):
-                            break
-                        if self.appear(self.I_E_AUTO_ROTATE_OFF, interval=1.5):
-                            self.click(self.I_E_AUTO_ROTATE_OFF)
-                            count+=1
-                    explore_init = True
-                    continue
+                # if not explore_init:
+                #     count = 0
+                #     while count < 5:
+                #         if self.appear(self.I_E_AUTO_ROTATE_ON):
+                #             break
+                #         if self.appear(self.I_E_AUTO_ROTATE_OFF, interval=1.5):
+                #             self.click(self.I_E_AUTO_ROTATE_OFF)
+                #             count += 1
+                #     explore_init = True
+                #     continue
                 # 小纸人
                 if self.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(self.I_BATTLE_REWARD):
@@ -84,6 +85,7 @@ class WQExplore(BaseExploration, HighLight):
                 if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
                     explore_only_boss = False
                     logger.info(f'Fight, minions cnt {self.minions_cnt}')
+                    continue
                 # 向后拉,寻找怪
                 if search_fail_cnt >= 4:
                     search_fail_cnt = 0
@@ -95,6 +97,8 @@ class WQExplore(BaseExploration, HighLight):
                         continue
                 else:
                     search_fail_cnt += 1
+            elif scene==Scene.BATTLE_PREPARE:
+                self.ui_click_until_disappear(self.I_PREPARE_HIGHLIGHT, interval=0.5)
             elif scene == Scene.UNKNOWN:
                 continue
 
@@ -107,4 +111,4 @@ if __name__ == '__main__':
     config = Config('oas1')
     device = Device(config)
     t = WQExplore(config, device)
-    t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)
+    t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)

+ 18 - 0
tasks/WantedQuests/ocr.json

@@ -142,5 +142,23 @@
     "method": "Default",
     "keyword": "",
     "description": "Ocr-description"
+  },
+  {
+    "itemName": "wq_monster_type",
+    "roiFront": "165,215,45,175",
+    "roiBack": "165,215,45,175",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "怪物名称,如酒吞,阎魔等"
+  },
+  {
+    "itemName": "wq_text_all",
+    "roiFront": "20,140,110,390",
+    "roiBack": "20,140,110,390",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": ""
   }
 ]

+ 213 - 66
tasks/WantedQuests/script_task.py

@@ -1,17 +1,16 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-import copy
-import re
 from datetime import timedelta, time, datetime
 from time import sleep
 from typing import List
 
+import re
 import cv2
 from cached_property import cached_property
-from markdown_it.rules_inline import image
 
 from module.atom.image import RuleImage
+from module.atom.ocr import RuleOcr
 from module.base.timer import Timer
 from module.exception import TaskEnd
 from module.logger import logger
@@ -26,9 +25,16 @@ from tasks.WantedQuests.explore import WQExplore, ExploreWantedBoss
 
 class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
     want_strategy_excluding: list[list] = []  # 不需要执行的
+    # 追踪界面(显示"前往"按钮的界面,左上角位置,神秘任务不好使)显示以下名称时,任务不再执行
+    unwanted_boss_name_list: list = []
 
     def run(self):
         con = self.config.model.wanted_quests
+        unwanted_boss_names = con.wanted_quests_config.unwanted_boss_names
+        if unwanted_boss_names is not None and unwanted_boss_names != '':
+            import re
+            self.unwanted_boss_name_list = re.split(r"[,,]", unwanted_boss_names)
+
         # 自动换御魂
         if con.switch_soul_config.enable:
             self.ui_get_current_page()
@@ -53,62 +59,110 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
 
         self.screenshot()
         number_challenge = self.O_WQ_NUMBER.ocr(self.device.image)
-        ocr_error_count = 0
+        error_count = 0
         while 1:
             self.screenshot()
+            if not self.is_wq_remained():
+                logger.info("no more wq remained")
+                break
             if self.appear(self.I_WQ_BOX):
+                logger.info("get reward")
                 self.ui_get_reward(self.I_WQ_BOX)
                 continue
             if self.appear(self.I_TREASURE_BOX_CLICK):
+                logger.info("get treasure")
                 self.ui_get_reward(self.I_TREASURE_BOX_CLICK)
                 continue
-            if ocr_error_count > 10:
-                logger.warning('OCR failed too many times, exit')
+            if error_count > 3:
+                logger.warning('failed too many times, exit')
                 break
-            if self.ocr_appear(self.O_WQ_TEXT_1, interval=1):
-                cu, re, total = self.O_WQ_NUM_1.ocr(self.device.image)
-                if cu == re == total == 0:
-                    logger.warning('OCR failed and have a try')
-                    ocr_error_count += 1
-                    # 尝试打一次
-                    unknown_num = self.O_WQ_NUM_UNKNOWN_1.ocr(self.device.image)
-                    if unknown_num > 14:
-                        self.execute_mission(self.O_WQ_TEXT_1, 1, number_challenge)
-                if cu > total:
-                    logger.warning('Current number of wanted quests is greater than total number')
-                    cu = cu % 10
-                if cu < total and re != 0:
-                    self.execute_mission(self.O_WQ_TEXT_1, min(total, 20), number_challenge)
-
-            if self.ocr_appear(self.O_WQ_TEXT_2, interval=1):
-                cu, re, total = self.O_WQ_NUM_2.ocr(self.device.image)
-                if cu == re == total == 0:
-                    logger.warning('OCR failed and have a try')
-                    ocr_error_count += 1
-                    # 尝试打一次
-                    unknown_num = self.O_WQ_NUM_UNKNOWN_2.ocr(self.device.image)
-                    if unknown_num > 14:
-                        self.execute_mission(self.O_WQ_TEXT_2, 1, number_challenge)
-                if cu > total:
-                    logger.warning('Current number of wanted quests is greater than total number')
-                    cu = cu % 10
-                if cu < total and re != 0:
-                    self.execute_mission(self.O_WQ_TEXT_2, min(total, 20), number_challenge)
-                continue
-
-            # 妖气封印或者年兽,那就四分钟后继续
-            if self.appear(self.I_WQ_D1111) or self.appear(self.I_WQ_NIAN):
-                logger.warning('Tiger is in the way, wait for 4 minutes')
-                logger.info('Time to wait for 4 minutes')
-                self.set_next_run('WantedQuests', target=datetime.now() + timedelta(minutes=4))
-                raise TaskEnd('WantedQuests')
-            if self.appear(self.I_WQ_CHECK_TASK):
+            cu, re, total, area = self.find_wq(self.device.image)
+            if re == -1:
+                error_count += 1
+                # 没找到任务 尝试上滑
+                self.swipe(self.S_WQ_LIST_UP, interval=1)
+                sleep(1)
                 continue
+            # 找到任务,执行
+            error_count=0
+            self.O_WQ_TEXT_ALL.area = area
+            self.execute_mission(self.O_WQ_TEXT_ALL, total - cu, number_challenge)
             sleep(1.5)
-            self.screenshot()
-            if not self.appear(self.I_WQ_CHECK_TASK):
-                logger.info('No wanted quests')
-                break
+
+
+
+        # region 旧代码
+        # # 第一个位置
+        # wq_1_done = False
+        # wq_2_done = False
+        # while 1:
+        #     self.screenshot()
+        #     if self.appear(self.I_WQ_BOX):
+        #         self.ui_get_reward(self.I_WQ_BOX)
+        #         continue
+        #     if self.appear(self.I_TREASURE_BOX_CLICK):
+        #         self.ui_get_reward(self.I_TREASURE_BOX_CLICK)
+        #         continue
+        #     if ocr_error_count > 10:
+        #         logger.warning('OCR failed too many times, exit')
+        #         break
+        #     # if self.ocr_appear(self.O_WQ_TEXT_1, interval=1):
+        #     if (not wq_1_done) and self.txt_ocr_appear(self.O_WQ_TEXT_1, r".*[封|野]印.*", self.device.image):
+        #         # cu, re, total = self.O_WQ_NUM_1.ocr(self.device.image)
+        #         cu, re, total = self.process_ocr(self.O_WQ_NUM_1, self.device.image)
+        #         if cu == re == total == 0:
+        #             logger.warning('OCR failed and have a try')
+        #             ocr_error_count += 1
+        #             # 尝试打一次
+        #             unknown_num = self.O_WQ_NUM_UNKNOWN_1.ocr(self.device.image)
+        #             if unknown_num > 14:
+        #                 self.execute_mission(self.O_WQ_TEXT_1, 1, number_challenge)
+        #         if total > 14:
+        #             logger.warning("Total number of wanted quests is greater than 14")
+        #             total = total % 10
+        #         if cu > total:
+        #             logger.warning('Current number of wanted quests is greater than total number')
+        #             cu = cu % 10
+        #         if cu < total and re != 0:
+        #             self.execute_mission(self.O_WQ_TEXT_1, min(total - cu, 20), number_challenge)
+        #         if cu == total:
+        #             wq_1_done = True
+        #
+        #     # if self.ocr_appear(self.O_WQ_TEXT_2, interval=1):
+        #     if self.txt_ocr_appear(self.O_WQ_TEXT_2, r".*[封|野]印.*", self.device.image):
+        #         # cu, re, total = self.O_WQ_NUM_2.ocr(self.device.image)
+        #         cu, re, total = self.process_ocr(self.O_WQ_NUM_2, self.device.image)
+        #         if cu == re == total == 0:
+        #             logger.warning('OCR failed and have a try')
+        #             ocr_error_count += 1
+        #             # 尝试打一次
+        #             unknown_num = self.O_WQ_NUM_UNKNOWN_2.ocr(self.device.image)
+        #             if unknown_num > 14:
+        #                 self.execute_mission(self.O_WQ_TEXT_2, 1, number_challenge)
+        #         if total > 14:
+        #             logger.warning("Total number of wanted quests is greater than 14")
+        #             total = total % 10
+        #         if cu > total:
+        #             logger.warning('Current number of wanted quests is greater than total number')
+        #             cu = cu % 10
+        #         if cu < total and re != 0:
+        #             self.execute_mission(self.O_WQ_TEXT_2, min(total - cu, 20), number_challenge)
+        #         continue
+        #
+        #     # 妖气封印或者年兽,那就四分钟后继续
+        #     if self.appear(self.I_WQ_D1111) or self.appear(self.I_WQ_NIAN):
+        #         logger.warning('Tiger is in the way, wait for 4 minutes')
+        #         logger.info('Time to wait for 4 minutes')
+        #         self.set_next_run('WantedQuests', target=datetime.now() + timedelta(minutes=4))
+        #         raise TaskEnd('WantedQuests')
+        #     if self.appear(self.I_WQ_CHECK_TASK):
+        #         continue
+        #     sleep(1.5)
+        #     self.screenshot()
+        #     if not self.appear(self.I_WQ_CHECK_TASK):
+        #         logger.info('No wanted quests')
+        #         break
+        # endregion
 
         self.next_run()
         raise TaskEnd('WantedQuests')
@@ -181,6 +235,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         if self.ui_get_current_page() != page_main:
             self.ui_goto(page_main)
         # 打开悬赏封印 界面
+        done_timer = Timer(5)
         while 1:
             self.screenshot()
             if self.appear(self.I_TRACE_ENABLE) or self.appear(self.I_TRACE_DISABLE):
@@ -192,11 +247,16 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             if self.special_main and self.click(self.C_SPECIAL_MAIN, interval=3):
                 logger.info('Click special main left to find wanted quests')
                 continue
-            if not (self.appear(self.I_WQ_INVITE_1) or self.appear(self.I_WQ_INVITE_2) or self.appear(
-                    self.I_WQ_INVITE_3)):
-                logger.info("there is no cooperation quest")
-                break
+            if self.appear(self.I_UI_BACK_RED):
+                if not done_timer.started():
+                    done_timer.start()
+            if done_timer.started() and done_timer.reached():
+                self.ui_click_until_disappear(self.I_UI_BACK_RED)
+                return False
         #
+        if not (self.appear(self.I_WQ_INVITE_1) or self.appear(self.I_WQ_INVITE_2) or self.appear(self.I_WQ_INVITE_3)):
+            logger.info("there is no cooperation quest")
+            return False
 
         # if self.appear(self.I_WQ_INVITE_1):
         #     self.trace_one(self.I_WQ_INVITE_1)
@@ -236,7 +296,8 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             # 防止点击后界面来不及刷新
             sleep(1.5)
         # 关闭单个任务的追踪界面
-        self.ui_click_until_smt_disappear(self.C_WQ_TRACE_ONE_CLOSE, stop=self.I_WQ_TRACE_ONE_CHECK_OPENED, interval=1.5)
+        self.ui_click_until_smt_disappear(self.C_WQ_TRACE_ONE_CLOSE, stop=self.I_WQ_TRACE_ONE_CHECK_OPENED,
+                                          interval=1.5)
 
     def execute_mission(self, ocr, num_want: int, num_challenge: int):
         """
@@ -269,12 +330,13 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
                 # "壹", "贰", "叁", "肆", "伍", "陆",
                 "柒", "捌", "玖", "拾", "番外"
             }
-            result = [-1, '', -1, GOTO_BUTTON[index], self.challenge]
+            # ,荒川之怒·壹,4,前往按钮,function
+            result = [-1, '', -1, GOTO_BUTTON[index], self.challenge, '']
             type_wq = OCR_WQ_TYPE[index].ocr(self.device.image)
             info_wq_1 = OCR_WQ_INFO[index].ocr(self.device.image)
             info_wq_1 = info_wq_1.replace(':', ':').replace('(', '(').replace(')', ')')
             info_wq_1 = info_wq_1.replace(':', ':')
-            match = re.match(r"^(.*?)\(数量:\s*(\d+)\)", info_wq_1)
+            match = re.match(r"^(.*?)[((]?数量[::]\s*(\d+)[))]", info_wq_1)
             if not match:
                 return None
             wq_destination = match.group(1)
@@ -290,6 +352,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             order_list: list = re.split(r'>', order_list)
             result[0] = order_list.index(type_wq) if type_wq in order_list else -1
             result[4] = name_funcs.get(type_wq, lambda: logger.warning('No task can be challenged'))
+            result[5] = type_wq
             logger.info(f'[Wanted Quests] type: {type_wq} destination: {wq_destination} number: {wq_number} ')
             return tuple(result) if result[0] != -1 else None
 
@@ -305,6 +368,13 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             logger.warning('This is a secret mission but not unlock')
             self.ui_click(self.I_TRACE_TRUE, self.I_TRACE_FALSE)
             return False
+        # 跳过不想打的
+        monster_name = self.O_WQ_MONSTER_TYPE.detect_text(self.device.image)
+        if monster_name in self.unwanted_boss_name_list:
+            #
+            logger.warning(f'unwanted {monster_name}')
+            self.ui_click(self.I_TRACE_TRUE, self.I_TRACE_FALSE)
+            return False
 
         info_wq_list = []
         for i in range(4):
@@ -314,10 +384,14 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         info_wq_list = [item for item in info_wq_list if item not in self.want_strategy_excluding]
         if not info_wq_list:
             logger.warning('No wanted quests can be challenged')
+            self.ui_click(self.I_TRACE_TRUE, self.I_TRACE_FALSE)
             return False
         # sort
         info_wq_list.sort(key=lambda x: x[0])
-        best_type, destination, once_number, goto_button, func = info_wq_list[0]
+        filtered = list(filter(lambda x: (x[5] == '秘闻' or x[5] == '挑战') and x[2] >= 3, info_wq_list))
+        if not filtered and len(filtered) != 0:
+            info_wq_list = filtered
+        best_type, destination, once_number, goto_button, func, _ = info_wq_list[0]
         do_number = 1 if once_number >= num_want else num_want // once_number + (1 if num_want % once_number > 0 else 0)
         try:
             func(goto_button, do_number)
@@ -464,7 +538,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         @param name:
         @return:
         """
-        self.ui_click(btn, self.I_WQ_INVITE_ENSURE, interval=2.5)
+        self.ui_click(btn, stop=self.I_WQ_INVITE_ENSURE, interval=2.5)
 
         # 选人
         self.O_WQ_INVITE_COLUMN_1.keyword = name
@@ -594,23 +668,96 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
 
         return True
 
+    def process_ocr(self, txt):
+        def detect_spliter(txt):
+            index = txt.find('/')
+            if index != -1:
+                return index
+            # 由于斜杠'/'经常被误识别为'7',且悬赏封印悬赏怪物总数没有与‘7’相关的数字
+            reg = re.compile(r'^(\d+)([7/])(\d+)$')
+            match = reg.match(txt)
+            if match:
+                return match.start(2)
+            return -1
+
+        index = detect_spliter(txt)
+        if index < 0:
+            return 0, 0, 0
+        return int(txt[:index]), 1, int(txt[index + 1:])
+
+    def txt_ocr_appear(self, ocr_item: RuleOcr, reg, img):
+        res = ocr_item.ocr(img)
+        regex = re.compile(reg)
+        ismatch = regex.match(res)
+        return ismatch is not None
+
+    def find_wq(self, img):
+        def calc_xywh(box):
+            rec_x, rec_y, rec_w, rec_h = box[0, 0], box[0, 1], box[1, 0] - box[0, 0], box[2, 1] - box[0, 1]
+            x = rec_x + self.O_WQ_TEXT_ALL.roi[0]
+            y = rec_y + self.O_WQ_TEXT_ALL.roi[1]
+            w = rec_w
+            h = rec_h
+            return [x, y, w, h]
+
+        res_list = self.O_WQ_TEXT_ALL.detect_and_ocr(img)
+        import re
+        reg_time = re.compile(r'^([01]?[0-9]|2[0-3]):([0-5]?[0-9]):?([0-5]?[0-9])?$')
+        reg_fengyin = re.compile(r'.*[封|野]印.*')
+        # 由于斜杠'/'经常被误识别为'7',且悬赏封印悬赏怪物总数没有与‘7’相关的数字
+        reg_progress = re.compile(r'^(\d+)([7/])(\d+)$')
+        # 没有检测到斜杠,符合格式:前N位与后N位相同,表示已完成
+        reg_XX = re.compile(r'^(\d+)\1$')
+        for index, res in enumerate(res_list):
+            if reg_fengyin.match(res.ocr_text):
+                continue
+            if reg_time.match(res.ocr_text):
+                continue
+            if (match := reg_progress.match(res.ocr_text)):
+                spliter_index = match.start(2)
+                xywh = calc_xywh(res.box)
+                self.O_WQ_TEXT_ALL.area = xywh
+                cu, re, total = int(res.ocr_text[:spliter_index]), 1, int(res.ocr_text[spliter_index + 1:])
+                # 识别结果规范性检查
+                if total > 14:
+                    logger.warning("Total number of wanted quests is greater than 14")
+                    total = total % 10
+                if cu > total:
+                    logger.warning('Current number of wanted quests is greater than total number')
+                    cu = cu % 10
+                if cu == total:
+                    # 该任务已完成,一般是悬赏任务,邀请人没有做导致的
+                    continue
+                return cu, re, total, xywh
+            # 例如:1414 66 1212
+            if reg_XX.match(res.ocr_text):
+                continue
+            # 什么都没匹配上,判断上一个识别结果如果为悬赏封印,那么认为该识别结果错误,尝试执行一次
+            last_index = (index - 1) if index > 0 else 0
+            if reg_fengyin.match(res_list[last_index].ocr_text):
+                return 0, 1, 3, calc_xywh(res_list[last_index].box)
+
+        return -1, -1, -1, [0, 0, 0, 0]
+
+    def is_wq_remained(self):
+        # 检测是否还存在任务
+        return self.appear(self.I_WQ_LIST_TOP_BOTTOM_CHECK)
+
+
 
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
+    import re
 
     c = Config('oas1')
     d = Device(c)
     t = ScriptTask(c, d)
-    t.run()
-    # img = cv2.imread(r"E:\highlight.png")
-    # img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
-    # t.device.image = img
-    # appear = t.appear_highlight(t.I_WQ_INVITE_DIFF_SVR_HIGHLIGHT)
+    # import cv2
     #
-    # img = cv2.imread(r"E:\normal.png")
+    # img = cv2.imread(r'E:\2.png')
     # img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
-    # t.device.image = img
-    # appear_normal = t.appear_highlight(t.I_WQ_INVITE_DIFF_SVR_HIGHLIGHT)
     #
-    # print(appear)
+    # res = t.find_wq(img)
+
+    t.run()

+ 9 - 0
tasks/WantedQuests/wq/image.json

@@ -142,5 +142,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "庭院悬赏任务界面 单个任务点开后的界面 是否为现世任务标志"
+  },
+  {
+    "itemName": "wq_list_top_bottom_check",
+    "imageName": "wq_list_top_bottom_check.png",
+    "roiFront": "120,125,25,425",
+    "roiBack": "120,125,25,425",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "探索界面,左侧任务列表右上角右下角标志"
   }
 ]

+ 9 - 0
tasks/WantedQuests/wq/swipe.json

@@ -0,0 +1,9 @@
+[
+  {
+    "itemName": "wq_list_up",
+    "roiFront": "60,250,2,4",
+    "roiBack": "65,200,2,4",
+    "mode": "default",
+    "description": "手指向上滑动"
+  }
+]

BIN
tasks/WantedQuests/wq/wq_list_top_bottom_check.png