Переглянути джерело

add: Improve parameter verification

Azure 1 рік тому
батько
коміт
f88216ca76

+ 3 - 3
tasks/ActivityShikigami/config.py

@@ -21,17 +21,17 @@ class ShikigamiType(str, Enum):
 class SwitchSoulConfig(BaseModel):
 class SwitchSoulConfig(BaseModel):
     # 切换门票爬塔御魂
     # 切换门票爬塔御魂
     enable_switch_pass: bool = Field(default=False, description='是否切换门票爬塔御魂')
     enable_switch_pass: bool = Field(default=False, description='是否切换门票爬塔御魂')
-    pass_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设使用该值')
+    pass_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设也使用该值')
     enable_switch_pass_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
     enable_switch_pass_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
     pass_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
     pass_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
     # 切换体力爬塔御魂
     # 切换体力爬塔御魂
     enable_switch_ap: bool = Field(default=False, description='是否切换体力爬塔御魂')
     enable_switch_ap: bool = Field(default=False, description='是否切换体力爬塔御魂')
-    ap_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设使用该值')
+    ap_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设也使用该值')
     enable_switch_ap_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
     enable_switch_ap_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
     ap_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
     ap_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
     # 切换boss爬塔御魂
     # 切换boss爬塔御魂
     enable_switch_boss: bool = Field(default=False, description='是否切换boss爬塔御魂')
     enable_switch_boss: bool = Field(default=False, description='是否切换boss爬塔御魂')
-    boss_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设使用该值')
+    boss_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设也使用该值')
     enable_switch_boss_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
     enable_switch_boss_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
     boss_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
     boss_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
 
 

+ 12 - 5
tasks/ActivityShikigami/script_task.py

@@ -23,7 +23,7 @@ from tasks.GameUi.page import page_main, page_shikigami_records, page_climb_act,
 
 
 
 
 def get_run_order_list(climb_conf: GeneralClimb) -> list[str]:
 def get_run_order_list(climb_conf: GeneralClimb) -> list[str]:
-    if climb_conf.run_sequence is None or climb_conf.run_sequence == '':
+    if not climb_conf.run_sequence or len(climb_conf.run_sequence.split(',')) == 1:
         raise ValueError('Run sequence now is empty, must set it')
         raise ValueError('Run sequence now is empty, must set it')
     run_order_list = [climb_type.strip() for climb_type in climb_conf.run_sequence.split(',')]
     run_order_list = [climb_type.strip() for climb_type in climb_conf.run_sequence.split(',')]
     return [climb_type for climb_type in run_order_list if getattr(climb_conf, f'enable_{climb_type}')]
     return [climb_type for climb_type in run_order_list if getattr(climb_conf, f'enable_{climb_type}')]
@@ -161,7 +161,10 @@ class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
             self.ui_get_current_page()
             self.ui_get_current_page()
             self.ui_goto(page_shikigami_records)
             self.ui_goto(page_shikigami_records)
         if enable_by_name:
         if enable_by_name:
-            group, team = getattr(conf, f"{self.climb_type}_group_team_name", '-1,-1').split(",")
+            group_name = getattr(conf, f"{self.climb_type}_group_team_name", '-1,-1')
+            if not group_name or len(group_name.split(',')) != 2:
+                raise ValueError('switch soul by name must be 2 length')
+            group, team = group_name.split(",")
             self.run_switch_soul_by_name(group, team)
             self.run_switch_soul_by_name(group, team)
         elif enable_switch:
         elif enable_switch:
             group_team = getattr(conf, f"{self.climb_type}_group_team", '-1,-1')
             group_team = getattr(conf, f"{self.climb_type}_group_team", '-1,-1')
@@ -194,7 +197,7 @@ class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
 
 
     def switch_buff(self, climb_conf: GeneralClimb):
     def switch_buff(self, climb_conf: GeneralClimb):
         buffs = getattr(climb_conf, f'{self.climb_type}_buff', None)
         buffs = getattr(climb_conf, f'{self.climb_type}_buff', None)
-        if not buffs:
+        if not buffs or len(buffs.split(',')) == 1:
             logger.info('Not set buff, skip')
             logger.info('Not set buff, skip')
             return
             return
         buff_list = [buff.strip() for buff in buffs.split(',')]
         buff_list = [buff.strip() for buff in buffs.split(',')]
@@ -273,7 +276,8 @@ class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
         :param climb_conf: 爬塔配置
         :param climb_conf: 爬塔配置
         :return: 限制次数
         :return: 限制次数
         """
         """
-        return getattr(climb_conf, f'{self.climb_type}_limit', 0)
+        limit = getattr(climb_conf, f'{self.climb_type}_limit', 0)
+        return 0 if not limit else limit
 
 
     def switch_next(self) -> bool:
     def switch_next(self) -> bool:
         """
         """
@@ -318,7 +322,10 @@ class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
         from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig as gbc
         from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig as gbc
         conf = self.config.activity_shikigami
         conf = self.config.activity_shikigami
         enable_preset = getattr(conf.general_battle, f'enable_{self.climb_type}_preset', False)
         enable_preset = getattr(conf.general_battle, f'enable_{self.climb_type}_preset', False)
-        group, team = getattr(conf.switch_soul_config, f'{self.climb_type}_group_team', '1,1').split(',')
+        group_team = getattr(conf.switch_soul_config, f'{self.climb_type}_group_team')
+        if enable_preset and (not group_team or len(group_team.split(',')) != 2):
+            raise ValueError('Enable preset but group team not set correct!')
+        group, team = group_team.split(',')
         return gbc(lock_team_enable=not enable_preset,
         return gbc(lock_team_enable=not enable_preset,
                    preset_enable=enable_preset,
                    preset_enable=enable_preset,
                    preset_group=group if enable_preset else 1,
                    preset_group=group if enable_preset else 1,