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

Merge pull request #802 from ChengRanORZ/fix_wq

Fix wq
huangrunheng 1 год назад
Родитель
Сommit
aac67f5cb0

+ 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 = [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()])
         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
     @staticmethod
     def work(task_path: str):
     def work(task_path: str):

+ 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")
 	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 
 	# 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_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
 	# 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_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_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
 	# 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")
 	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')
     battle_priority: str = Field(default='挑战 > 秘闻 > 探索', description='battle_priority_help')
     # 只完成协作任务
     # 只完成协作任务
     cooperation_only: bool = Field(default=False, description="cooperation_only_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):
 class WantedQuests(ConfigBase):

+ 15 - 11
tasks/WantedQuests/explore.py

@@ -43,6 +43,7 @@ class WQExplore(BaseExploration, HighLight):
                     if explore_only_boss:
                     if explore_only_boss:
                         raise ExploreWantedBoss
                         raise ExploreWantedBoss
                     break
                     break
+                logger.info("点击探索")
                 self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
                 self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
                 continue
                 continue
             # 探索大世界
             # 探索大世界
@@ -59,16 +60,16 @@ class WQExplore(BaseExploration, HighLight):
                 continue
                 continue
             # 探索里面
             # 探索里面
             elif scene == Scene.MAIN:
             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.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(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):
                 if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
                     explore_only_boss = False
                     explore_only_boss = False
                     logger.info(f'Fight, minions cnt {self.minions_cnt}')
                     logger.info(f'Fight, minions cnt {self.minions_cnt}')
+                    continue
                 # 向后拉,寻找怪
                 # 向后拉,寻找怪
                 if search_fail_cnt >= 4:
                 if search_fail_cnt >= 4:
                     search_fail_cnt = 0
                     search_fail_cnt = 0
@@ -95,6 +97,8 @@ class WQExplore(BaseExploration, HighLight):
                         continue
                         continue
                 else:
                 else:
                     search_fail_cnt += 1
                     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:
             elif scene == Scene.UNKNOWN:
                 continue
                 continue
 
 
@@ -107,4 +111,4 @@ if __name__ == '__main__':
     config = Config('oas1')
     config = Config('oas1')
     device = Device(config)
     device = Device(config)
     t = WQExplore(config, device)
     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",
     "method": "Default",
     "keyword": "",
     "keyword": "",
     "description": "Ocr-description"
     "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": ""
   }
   }
 ]
 ]

+ 207 - 66
tasks/WantedQuests/script_task.py

@@ -1,17 +1,16 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
-import copy
-import re
 from datetime import timedelta, time, datetime
 from datetime import timedelta, time, datetime
 from time import sleep
 from time import sleep
 from typing import List
 from typing import List
 
 
+import re
 import cv2
 import cv2
 from cached_property import cached_property
 from cached_property import cached_property
-from markdown_it.rules_inline import image
 
 
 from module.atom.image import RuleImage
 from module.atom.image import RuleImage
+from module.atom.ocr import RuleOcr
 from module.base.timer import Timer
 from module.base.timer import Timer
 from module.exception import TaskEnd
 from module.exception import TaskEnd
 from module.logger import logger
 from module.logger import logger
@@ -26,9 +25,16 @@ from tasks.WantedQuests.explore import WQExplore, ExploreWantedBoss
 
 
 class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
 class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
     want_strategy_excluding: list[list] = []  # 不需要执行的
     want_strategy_excluding: list[list] = []  # 不需要执行的
+    # 追踪界面(显示"前往"按钮的界面,左上角位置,神秘任务不好使)显示以下名称时,任务不再执行
+    unwanted_boss_name_list: list = []
 
 
     def run(self):
     def run(self):
         con = self.config.model.wanted_quests
         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:
         if con.switch_soul_config.enable:
             self.ui_get_current_page()
             self.ui_get_current_page()
@@ -53,62 +59,110 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
 
 
         self.screenshot()
         self.screenshot()
         number_challenge = self.O_WQ_NUMBER.ocr(self.device.image)
         number_challenge = self.O_WQ_NUMBER.ocr(self.device.image)
-        ocr_error_count = 0
+        error_count = 0
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
+            if not self.is_wq_remained():
+                logger.info("no more wq remained")
+                break
             if self.appear(self.I_WQ_BOX):
             if self.appear(self.I_WQ_BOX):
+                logger.info("get reward")
                 self.ui_get_reward(self.I_WQ_BOX)
                 self.ui_get_reward(self.I_WQ_BOX)
                 continue
                 continue
             if self.appear(self.I_TREASURE_BOX_CLICK):
             if self.appear(self.I_TREASURE_BOX_CLICK):
+                logger.info("get treasure")
                 self.ui_get_reward(self.I_TREASURE_BOX_CLICK)
                 self.ui_get_reward(self.I_TREASURE_BOX_CLICK)
                 continue
                 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
                 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
                 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)
             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()
         self.next_run()
         raise TaskEnd('WantedQuests')
         raise TaskEnd('WantedQuests')
@@ -181,6 +235,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         if self.ui_get_current_page() != page_main:
         if self.ui_get_current_page() != page_main:
             self.ui_goto(page_main)
             self.ui_goto(page_main)
         # 打开悬赏封印 界面
         # 打开悬赏封印 界面
+        done_timer = Timer(5)
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_TRACE_ENABLE) or self.appear(self.I_TRACE_DISABLE):
             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):
             if self.special_main and self.click(self.C_SPECIAL_MAIN, interval=3):
                 logger.info('Click special main left to find wanted quests')
                 logger.info('Click special main left to find wanted quests')
                 continue
                 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):
         # if self.appear(self.I_WQ_INVITE_1):
         #     self.trace_one(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)
             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):
     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)
             type_wq = OCR_WQ_TYPE[index].ocr(self.device.image)
             info_wq_1 = OCR_WQ_INFO[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(':', ':').replace('(', '(').replace(')', ')')
             info_wq_1 = info_wq_1.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:
             if not match:
                 return None
                 return None
             wq_destination = match.group(1)
             wq_destination = match.group(1)
@@ -290,6 +352,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             order_list: list = re.split(r'>', order_list)
             order_list: list = re.split(r'>', order_list)
             result[0] = order_list.index(type_wq) if type_wq in order_list else -1
             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[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} ')
             logger.info(f'[Wanted Quests] type: {type_wq} destination: {wq_destination} number: {wq_number} ')
             return tuple(result) if result[0] != -1 else None
             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')
             logger.warning('This is a secret mission but not unlock')
             self.ui_click(self.I_TRACE_TRUE, self.I_TRACE_FALSE)
             self.ui_click(self.I_TRACE_TRUE, self.I_TRACE_FALSE)
             return 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 = []
         info_wq_list = []
         for i in range(4):
         for i in range(4):
@@ -317,7 +387,10 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             return False
             return False
         # sort
         # sort
         info_wq_list.sort(key=lambda x: x[0])
         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)
         do_number = 1 if once_number >= num_want else num_want // once_number + (1 if num_want % once_number > 0 else 0)
         try:
         try:
             func(goto_button, do_number)
             func(goto_button, do_number)
@@ -464,7 +537,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         @param name:
         @param name:
         @return:
         @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
         self.O_WQ_INVITE_COLUMN_1.keyword = name
@@ -594,23 +667,91 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
 
 
         return True
         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+)$')
+        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
+            # 什么都没匹配上,判断上一个识别结果如果为悬赏封印,那么认为该识别结果错误,尝试执行一次
+            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__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device
+    import re
 
 
     c = Config('oas1')
     c = Config('oas1')
     d = Device(c)
     d = Device(c)
     t = ScriptTask(c, d)
     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)
     # 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",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "庭院悬赏任务界面 单个任务点开后的界面 是否为现世任务标志"
     "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