Эх сурвалжийг харах

feat(WantedQuests): Customize the battle order

ryland 2 жил өмнө
parent
commit
4deb58d067

+ 31 - 3
module/base/filter.py

@@ -1,3 +1,4 @@
+# https://github.com/LmeSzinc/AzurLaneAutoScript/blob/master/module/base/filter.py
 import re
 
 from module.logger import logger
@@ -20,8 +21,22 @@ class Filter:
         self.filter = []
 
     def load(self, string):
+        """
+        Load a filter string, filters are connected with ">"
+
+        There are also tons of unicode characters similar to ">"
+        > \u003E correct
+        > \uFF1E
+        ﹥ \uFE65
+        › \u203a
+        ˃ \u02c3
+        ᐳ \u1433
+        ❯ \u276F
+        """
         string = str(string)
-        self.filter_raw = [f.strip(' \t\r\n') for f in string.split('>')]
+        string = re.sub(r'[ \t\r\n]', '', string)
+        string = re.sub(r'[>﹥›˃ᐳ❯]', '>', string)
+        self.filter_raw = string.split('>')
         self.filter = [self.parse_filter(f) for f in self.filter_raw]
 
     def is_preset(self, filter):
@@ -31,7 +46,7 @@ class Filter:
         """
         Args:
             objs (list): List of objects and strings
-            func (callable): A function to filter object.
+            func (callable): A function that to filter object.
                 Function should receive an object as arguments, and return a bool.
                 True means add it to output.
 
@@ -62,6 +77,19 @@ class Filter:
 
         return out
 
+    def applys(self, objs, funcs):
+        """
+        Args:
+            objs (list): List of objects and strings
+            List[func(callable)] : A list of funciton that to filter object.
+                Function should receive an object as arguments, and return a bool.
+                True means add it to output.
+
+        Returns:
+            list: A list of objects and preset strings, such as [object, object, object, 'reset']
+        """
+        return self.apply(objs, func=lambda x: all(func(x)for func in funcs))
+
     def apply_filter_to_obj(self, obj, filter):
         """
         Args:
@@ -100,4 +128,4 @@ class Filter:
             logger.warning(f'Invalid filter: "{string}". This selector does not match the regex, nor a preset.')
             # Invalid filter will be ignored.
             # Return strange things and make it impossible to match
-            return ['1nVa1d'] + [None] * (len(self.attr) - 1)
+            return ['1nVa1d'] + [None] * (len(self.attr) - 1)

+ 2 - 0
tasks/WantedQuests/config.py

@@ -82,6 +82,8 @@ class WantedQuestsConfig(BaseModel):
     before_end: Time = Field(default=Time(0, 0, 0), description='before_end_help')
     invite_friend_name: str = Field(default=str(""), description="invite_friend_name_help")
     cooperation_type: CooperationSelectMaskDescription = Field(default=CooperationSelectMaskDescription.Any, description="cooperation_type_help")
+    # 找怪优先级  挑战 > 秘闻 > 探索
+    battle_priority: str = Field(default='挑战 > 秘闻 > 探索', description='battle_priority_help')
 
 
 

+ 10 - 6
tasks/WantedQuests/script_task.py

@@ -208,12 +208,16 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
                 return None
             result[1] = wq_destination
             result[2] = wq_number
-            if type_wq == '挑战':
-                result[0] = 0 if num_challenge >= 10 else -1
-            elif type_wq == '秘闻':
-                result[0] = 1
-            elif type_wq == '探索':
-                result[0] = 2
+            order_list = self.config.model.wanted_quests.wanted_quests_config.battle_priority
+            order_list = order_list.replace(' ', '').replace('\n', '')
+            order_list: list = re.split(r'>', order_list)
+            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
             logger.info(f'[Wanted Quests] type: {type_wq} destination: {wq_destination} number: {wq_number} ')
             return tuple(result) if result[0] != -1 else None