Răsfoiți Sursa

fix(WantedQuests): Customize the battle order

ryland 2 ani în urmă
părinte
comite
b1af154074
1 a modificat fișierele cu 11 adăugiri și 19 ștergeri
  1. 11 19
      tasks/WantedQuests/script_task.py

+ 11 - 19
tasks/WantedQuests/script_task.py

@@ -177,14 +177,19 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         OCR_WQ_TYPE = [self.O_WQ_TYPE_1, self.O_WQ_TYPE_2, self.O_WQ_TYPE_3, self.O_WQ_TYPE_4]
         OCR_WQ_TYPE = [self.O_WQ_TYPE_1, self.O_WQ_TYPE_2, self.O_WQ_TYPE_3, self.O_WQ_TYPE_4]
         OCR_WQ_INFO = [self.O_WQ_INFO_1, self.O_WQ_INFO_2, self.O_WQ_INFO_3, self.O_WQ_INFO_4]
         OCR_WQ_INFO = [self.O_WQ_INFO_1, self.O_WQ_INFO_2, self.O_WQ_INFO_3, self.O_WQ_INFO_4]
         GOTO_BUTTON = [self.I_GOTO_1, self.I_GOTO_2, self.I_GOTO_3, self.I_GOTO_4]
         GOTO_BUTTON = [self.I_GOTO_1, self.I_GOTO_2, self.I_GOTO_3, self.I_GOTO_4]
+        name_funcs: dict = {
+            '挑战': self.challenge,
+            '探索': self.explore,
+            '秘闻': self.secret
+        }
 
 
         def extract_info(index: int) -> tuple or None:
         def extract_info(index: int) -> tuple or None:
             """
             """
             提取每一个地点的信息
             提取每一个地点的信息
             :param index: 从零开始
             :param index: 从零开始
             :return:
             :return:
-            (type, destination, number, goto_button)
-            (类型, 地点层级,可以打败的数量,前往按钮)
+            (type, destination, number, goto_button, func)
+            (类型, 地点层级,可以打败的数量,前往按钮, func)
             类型: 挑战0, 秘闻1, 探索2
             类型: 挑战0, 秘闻1, 探索2
             """
             """
             layer_limit = {
             layer_limit = {
@@ -192,7 +197,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
                 # "壹", "贰", "叁", "肆", "伍", "陆",
                 # "壹", "贰", "叁", "肆", "伍", "陆",
                 "柒", "捌", "玖", "拾"
                 "柒", "捌", "玖", "拾"
             }
             }
-            result = [-1, '', -1, GOTO_BUTTON[index]]
+            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(')', ')')
@@ -212,12 +217,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             order_list = order_list.replace(' ', '').replace('\n', '')
             order_list = order_list.replace(' ', '').replace('\n', '')
             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
-            # if type_wq == '挑战':
-            #     result[0] = 0 if num_challenge >= 10 else -1
-            # elif type_wq == '秘闻':
-            #     result[0] = 1
-            # elif type_wq == '探索':
-            #     result[0] = 2
+            result[4] = name_funcs.get(type_wq, lambda: logger.warning('No task can be challenged'))
             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
 
 
@@ -245,18 +245,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 = info_wq_list[0]
+        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:
-            match best_type:
-                case 0:
-                    self.challenge(goto_button, do_number)
-                case 1:
-                    self.secret(goto_button, do_number)
-                case 2:
-                    self.explore(goto_button, do_number)
-                case _:
-                    logger.warning('No wanted quests can be challenged')
+            func(goto_button, do_number)
         except ExploreWantedBoss:
         except ExploreWantedBoss:
             logger.warning('The extreme case. The quest only needs to challenge one final boss, so skip it')
             logger.warning('The extreme case. The quest only needs to challenge one final boss, so skip it')
             self.want_strategy_excluding.append(info_wq_list[0])
             self.want_strategy_excluding.append(info_wq_list[0])