Ver Fonte

add(HeroTest): 藤原道长英杰试炼经验本

Azur há 9 meses atrás
pai
commit
6bee5768ca

+ 5 - 1
tasks/GameUi/assets.py

@@ -113,7 +113,7 @@ class GameUiAssets:
 	# 百鬼奕 
 	I_TOWN_GOTO_HYAKKISEN = RuleImage(roi_front=(192,145,48,67), roi_back=(86,130,447,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_town_goto_hyakkisen.png")
 	# description 
-	I_CHECK_DUEL = RuleImage(roi_front=(155,20,64,38), roi_back=(140,10,110,74), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_duel.png")
+	I_CHECK_DUEL = RuleImage(roi_front=(110,10,64,38), roi_back=(79,1,110,74), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_duel.png")
 	# description 
 	I_CHECK_DEMON_ENCOUNTER = RuleImage(roi_front=(26,658,42,43), roi_back=(2,619,100,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_demon_encounter.png")
 	# 检查狩猎战界面 
@@ -207,6 +207,10 @@ class GameUiAssets:
 	I_ACT_LIST_GOTO_ACT = RuleImage(roi_front=(971,506,156,60), roi_back=(925,458,272,166), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_act_list_goto_act.png")
 	# 活动列表页标志 
 	I_CHECK_ACT_LIST = RuleImage(roi_front=(60,617,79,66), roi_back=(19,555,163,164), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_act_list.png")
+	# 英杰试炼左上角标志 
+	I_CHECK_HERO_TEST = RuleImage(roi_front=(148,10,133,48), roi_back=(137,0,157,71), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_hero_test.png")
+	# 探索前往英杰试炼 
+	I_EXPLORATION_GOTO_HERO_TEST = RuleImage(roi_front=(837,630,58,56), roi_back=(7,605,1272,113), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_exploration_goto_hero_test.png")
 
 
 	# Image Rule Assets

+ 4 - 0
tasks/GameUi/page.py

@@ -113,6 +113,10 @@ page_exploration.link(button=G.I_EXPLORATION_GOTO_SIX_GATES, destination=page_si
 page_bondling_fairyland = Page(G.I_CHECK_BONDLING_FAIRYLAND)
 page_bondling_fairyland.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
 page_exploration.link(button=G.I_EXPLORATION_GOTO_BONDLING_FAIRYLAND, destination=page_bondling_fairyland)
+# 英杰试炼 hero test
+page_hero_test = Page(G.I_CHECK_HERO_TEST)
+page_hero_test.link(button=G.I_BACK_YOLLOW, destination=page_exploration)
+page_exploration.link(button=G.I_EXPLORATION_GOTO_HERO_TEST, destination=page_hero_test)
 
 # ************************************* 町中部分 *****************************************#
 # 斗技 duel

BIN
tasks/GameUi/page/page_check_hero_test.png


BIN
tasks/GameUi/page/page_exploration_goto_hero_test.png


+ 18 - 0
tasks/GameUi/page/page_img_supplement.json

@@ -70,5 +70,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "活动列表页标志"
+  },
+  {
+    "itemName": "check_hero_test",
+    "imageName": "page_check_hero_test.png",
+    "roiFront": "148,10,133,48",
+    "roiBack": "137,0,157,71",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "英杰试炼左上角标志"
+  },
+  {
+    "itemName": "exploration_goto_hero_test",
+    "imageName": "page_exploration_goto_hero_test.png",
+    "roiFront": "837,630,58,56",
+    "roiBack": "7,605,1272,113",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "探索前往英杰试炼"
   }
 ]

BIN
tasks/HeroTest/as/as_check_hero1.png


BIN
tasks/HeroTest/as/as_check_hero1_exp.png


BIN
tasks/HeroTest/as/as_check_hero1_skill.png


BIN
tasks/HeroTest/as/as_check_hero2.png


BIN
tasks/HeroTest/as/as_check_hero2_exp.png


BIN
tasks/HeroTest/as/as_check_hero2_skill.png


BIN
tasks/HeroTest/as/as_enter_ccsl.png


BIN
tasks/HeroTest/as/as_enter_mxmj.png


BIN
tasks/HeroTest/as/as_hero_exp_max.png


BIN
tasks/HeroTest/as/as_lock.png


BIN
tasks/HeroTest/as/as_switch_hero1.png


BIN
tasks/HeroTest/as/as_switch_hero2.png


BIN
tasks/HeroTest/as/as_unlock.png


+ 8 - 0
tasks/HeroTest/as/click.json

@@ -0,0 +1,8 @@
+[
+  {
+    "itemName": "switch_hero_btn",
+    "roiFront": "54,113,52,55",
+    "roiBack": "8,64,156,161",
+    "description": "切换英杰按钮"
+  }
+]

+ 105 - 6
tasks/HeroTest/as/image.json

@@ -56,8 +56,8 @@
   {
     "itemName": "unlock",
     "imageName": "as_unlock.png",
-    "roiFront": "817,648,33,31",
-    "roiBack": "817,648,33,31",
+    "roiFront": "824,651,20,25",
+    "roiBack": "734,632,286,71",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "解锁阵容"
@@ -65,11 +65,11 @@
   {
     "itemName": "lock",
     "imageName": "as_lock.png",
-    "roiFront": "816,644,36,38",
-    "roiBack": "816,644,36,38",
+    "roiFront": "822,650,23,26",
+    "roiBack": "736,638,283,71",
     "method": "Template matching",
     "threshold": 0.8,
-    "description": "description"
+    "description": "阵容锁定状态"
   },
   {
     "itemName": "bcmj",
@@ -83,7 +83,7 @@
   {
     "itemName": "bcmj_lock",
     "imageName": "as_bcmj_lock.png",
-    "roiFront": "901,159.5,36,26",
+    "roiFront": "901,159,36,26",
     "roiBack": "901,650,36,38",
     "method": "Template matching",
     "threshold": 0.8,
@@ -196,5 +196,104 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "周一点击确认开始挑战"
+  },
+  {
+    "itemName": "check_hero2",
+    "imageName": "as_check_hero2.png",
+    "roiFront": "52,113,57,58",
+    "roiBack": "3,62,157,151",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "藤原道长副本标志"
+  },
+  {
+    "itemName": "switch_hero1",
+    "imageName": "as_switch_hero1.png",
+    "roiFront": "176,113,251,360",
+    "roiBack": "0,0,1279,718",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "切换源赖光"
+  },
+  {
+    "itemName": "check_hero1",
+    "imageName": "as_check_hero1.png",
+    "roiFront": "52,109,55,66",
+    "roiBack": "19,79,127,130",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "源赖光副本标志"
+  },
+  {
+    "itemName": "switch_hero2",
+    "imageName": "as_switch_hero2.png",
+    "roiFront": "507,126,254,352",
+    "roiBack": "0,0,1274,714",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "切换藤原道长"
+  },
+  {
+    "itemName": "enter_ccsl",
+    "imageName": "as_enter_ccsl.png",
+    "roiFront": "302,243,41,149",
+    "roiBack": "252,161,148,303",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进入传承试炼标志"
+  },
+  {
+    "itemName": "enter_mxmj",
+    "imageName": "as_enter_mxmj.png",
+    "roiFront": "1075,331,40,138",
+    "roiBack": "1051,302,92,190",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进入梦虚秘境标志"
+  },
+  {
+    "itemName": "check_hero1_exp",
+    "imageName": "as_check_hero1_exp.png",
+    "roiFront": "36,466,63,69",
+    "roiBack": "0,427,137,145",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "鬼兵演武页面标志"
+  },
+  {
+    "itemName": "check_hero1_skill",
+    "imageName": "as_check_hero1_skill.png",
+    "roiFront": "27,237,338,142",
+    "roiBack": "0,139,423,322",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "兵藏秘境标志"
+  },
+  {
+    "itemName": "check_hero2_exp",
+    "imageName": "as_check_hero2_exp.png",
+    "roiFront": "33,465,63,65",
+    "roiBack": "12,448,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "传承试炼页面标志"
+  },
+  {
+    "itemName": "check_hero2_skill",
+    "imageName": "as_check_hero2_skill.png",
+    "roiFront": "24,308,250,92",
+    "roiBack": "0,282,362,143",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "梦虚秘境页面标志"
+  },
+  {
+    "itemName": "hero_exp_max",
+    "imageName": "as_hero_exp_max.png",
+    "roiFront": "175,493,20,20",
+    "roiBack": "162,481,106,37",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "御灵满级标志"
   }
 ]

+ 9 - 0
tasks/HeroTest/as/ocr.json

@@ -25,5 +25,14 @@
     "method": "Default",
     "keyword": "",
     "description": "兵道帖机密"
+  },
+  {
+    "itemName": "fire",
+    "roiFront": "1130,585,92,55",
+    "roiBack": "1126,576,100,99",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "挑战",
+    "description": "挑战按钮"
   }
 ]

+ 33 - 4
tasks/HeroTest/assets.py

@@ -10,6 +10,11 @@ from module.atom.list import RuleList
 class HeroTestAssets: 
 
 
+	# Click Rule Assets
+	# 切换英杰按钮 
+	C_SWITCH_HERO_BTN = RuleClick(roi_front=(54,113,52,55), roi_back=(8,64,156,161), name="switch_hero_btn")
+
+
 	# Image Rule Assets
 	# 进入活动第一步 
 	I_ONE = RuleImage(roi_front=(633,106,88,105), roi_back=(633,106,88,105), threshold=0.7, method="Template matching", file="./tasks/HeroTest/as/as_one.png")
@@ -24,13 +29,13 @@ class HeroTestAssets:
 	# 挑战按钮 
 	I_BATTLE = RuleImage(roi_front=(1129,588,99,49), roi_back=(1129,588,99,49), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_battle.png")
 	# 解锁阵容 
-	I_UNLOCK = RuleImage(roi_front=(817,648,33,31), roi_back=(817,648,33,31), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_unlock.png")
-	# description 
-	I_LOCK = RuleImage(roi_front=(816,644,36,38), roi_back=(816,644,36,38), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_lock.png")
+	I_UNLOCK = RuleImage(roi_front=(824,651,20,25), roi_back=(734,632,286,71), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_unlock.png")
+	# 阵容锁定状态 
+	I_LOCK = RuleImage(roi_front=(822,650,23,26), roi_back=(736,638,283,71), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_lock.png")
 	# 兵藏秘境 
 	I_BCMJ = RuleImage(roi_front=(1086,350,45,131), roi_back=(1086,350,45,131), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj.png")
 	# 兵藏秘境阵容锁 
-	I_BCMJ_LOCK = RuleImage(roi_front=(901,159.5,36,26), roi_back=(901,650,36,38), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_lock.png")
+	I_BCMJ_LOCK = RuleImage(roi_front=(901,159,36,26), roi_back=(901,650,36,38), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_lock.png")
 	# 兵藏秘境挑战 
 	I_BCMJ_BATTLE = RuleImage(roi_front=(1131,598,92,50), roi_back=(1131,598,92,50), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_battle.png")
 	# 兵藏秘境胜利 
@@ -55,6 +60,28 @@ class HeroTestAssets:
 	I_BCMJ_RESET_CLOSE = RuleImage(roi_front=(429,397,186,71), roi_back=(429,397,186,71), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_reset_close.png")
 	# 周一点击确认开始挑战 
 	I_START_CHALLENGE = RuleImage(roi_front=(685,407,142,47), roi_back=(685,407,142,47), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_start_challenge.png")
+	# 藤原道长副本标志 
+	I_CHECK_HERO2 = RuleImage(roi_front=(52,113,57,58), roi_back=(3,62,157,151), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_check_hero2.png")
+	# 切换源赖光 
+	I_SWITCH_HERO1 = RuleImage(roi_front=(176,113,251,360), roi_back=(0,0,1279,718), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_switch_hero1.png")
+	# 源赖光副本标志 
+	I_CHECK_HERO1 = RuleImage(roi_front=(52,109,55,66), roi_back=(19,79,127,130), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_check_hero1.png")
+	# 切换藤原道长 
+	I_SWITCH_HERO2 = RuleImage(roi_front=(507,126,254,352), roi_back=(0,0,1274,714), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_switch_hero2.png")
+	# 进入传承试炼标志 
+	I_ENTER_CCSL = RuleImage(roi_front=(302,243,41,149), roi_back=(252,161,148,303), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_enter_ccsl.png")
+	# 进入梦虚秘境标志 
+	I_ENTER_MXMJ = RuleImage(roi_front=(1075,331,40,138), roi_back=(1051,302,92,190), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_enter_mxmj.png")
+	# 鬼兵演武页面标志 
+	I_CHECK_HERO1_EXP = RuleImage(roi_front=(36,466,63,69), roi_back=(0,427,137,145), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_check_hero1_exp.png")
+	# 兵藏秘境标志 
+	I_CHECK_HERO1_SKILL = RuleImage(roi_front=(27,237,338,142), roi_back=(0,139,423,322), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_check_hero1_skill.png")
+	# 传承试炼页面标志 
+	I_CHECK_HERO2_EXP = RuleImage(roi_front=(33,465,63,65), roi_back=(12,448,100,100), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_check_hero2_exp.png")
+	# 梦虚秘境页面标志 
+	I_CHECK_HERO2_SKILL = RuleImage(roi_front=(24,308,250,92), roi_back=(0,282,362,143), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_check_hero2_skill.png")
+	# 御灵满级标志 
+	I_HERO_EXP_MAX = RuleImage(roi_front=(175,493,20,20), roi_back=(162,481,106,37), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero_exp_max.png")
 
 
 	# Ocr Rule Assets
@@ -64,5 +91,7 @@ class HeroTestAssets:
 	O_ART_WAR_CARD = RuleOcr(roi=(712,21,98,36), area=(712,21,98,36), mode="DigitCounter", method="Default", keyword="", name="art_war_card")
 	# 兵道帖机密 
 	O_ART_WAR_CARD_PLUS = RuleOcr(roi=(916,25,90,29), area=(916,25,90,29), mode="SINGLE", method="Default", keyword="", name="art_war_card_plus")
+	# 挑战按钮 
+	O_FIRE = RuleOcr(roi=(1130,585,92,55), area=(1126,576,100,99), mode="Single", method="Default", keyword="挑战", name="fire")
 
 

+ 3 - 1
tasks/HeroTest/config.py

@@ -13,13 +13,15 @@ from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 class Layer(str, Enum):
     YANWU: str = "鬼兵演武"
     MIJING: str = "兵藏秘境"
+    CHUANCHENG: str = "传承试炼"
+    MENGXU: str = "梦虚秘境"
 
 
 class HeroTestConfig(BaseModel):
     # 副本选择
     layer: Layer = Field(
         default=Layer.YANWU,
-        description="选择要打的关卡,兵藏秘境默认不开经验加成。\n升级顺序八华斩->无畏 -> 暴击伤害 -> 默认祝福 -> 默认属性",
+        description="选择要打的关卡。\n兵藏秘境升级顺序八华斩->无畏 -> 暴击伤害 -> 默认祝福 -> 默认属性",
     )
     # 限制时间
     limit_time: Time = Field(default=Time(minute=30), description="limit_time_help")

+ 140 - 177
tasks/HeroTest/script_task.py

@@ -4,156 +4,73 @@
 from datetime import datetime, timedelta, time
 import random  # type: ignore
 
-from tasks.Component.BaseActivity.base_activity import BaseActivity
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.HeroTest.assets import HeroTestAssets
-from tasks.GameUi.page import page_main, page_shikigami_records
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_exploration
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 
 from module.logger import logger
 from module.exception import TaskEnd
+from tasks.HeroTest.config import Layer, HeroTest
+from typing import Callable
 
+import tasks.GameUi.page as pages
 
-class ScriptTask(GameUi, BaseActivity, HeroTestAssets, SwitchSoul):
 
-    is_update = False
-    is_skill = False
+class ScriptTask(GameUi, GeneralBattle, HeroTestAssets, SwitchSoul):
 
-    def run(self) -> None:
-
-        config = self.config.hero_test
-        global is_update
-        global is_skill
-         # 自动换御魂
-        if config.switch_soul_config.enable:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul(config.switch_soul_config.switch_group_team)
-        if config.switch_soul_config.enable_switch_by_name:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul_by_name(config.switch_soul_config.group_name, config.switch_soul_config.team_name)
-
-        if config.herotest.layer.value == "鬼兵演武":
-            is_update = True
-            is_skill = False
-        if config.herotest.layer.value == "兵藏秘境":
-            is_skill = True
-            is_update = False
+    conf: HeroTest
+    page_hero_mode: pages.Page  # 当前英杰对应模式界面(经验or技能)
+    is_skill: bool = False
 
-        self.limit_time: timedelta = config.herotest.limit_time
+    def run(self) -> None:
+        self.conf = self.config.hero_test
+        self.limit_time: timedelta = self.conf.herotest.limit_time
         if isinstance(self.limit_time, time):
             self.limit_time = timedelta(
                 hours=self.limit_time.hour,
                 minutes=self.limit_time.minute,
                 seconds=self.limit_time.second,
             )
-        self.limit_count = config.herotest.limit_count
-
-        self.ui_get_current_page()
-        self.ui_goto(page_main)
-
-        # 启动经验加成
-        exp_50_buff_enable = config.herotest.exp_50_buff_enable_help
-        exp_100_buff_enable = config.herotest.exp_100_buff_enable_help
-        if exp_50_buff_enable or exp_100_buff_enable:
-            self.open_buff()
-            self.exp_100(exp_100_buff_enable)
-            self.exp_50(exp_50_buff_enable)
-            self.close_buff()
-
-        self.ui_goto(page_exploration)
-        self.home_main()
-        # 设定是否锁定阵容
-        if is_update:
-            if config.general_battle.lock_team_enable:
-                logger.info("Lock team")
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_UNLOCK, interval=1):
-                        continue
-                    if self.appear(self.I_LOCK):
-                        break
-            else:
-                logger.info("Unlock team")
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_LOCK, interval=1):
-                        continue
-                    if self.appear(self.I_UNLOCK):
-                        break
-        elif is_skill:
-            if config.general_battle.lock_team_enable:
-                logger.info("Lock team")
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_BCMJ_UNLOCK, interval=1):
-                        continue
-                    if self.appear(self.I_BCMJ_LOCK):
-                        break
-            else:
-                logger.info("Unlock team")
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_BCMJ_LOCK, interval=1):
-                        continue
-                    if self.appear(self.I_BCMJ_UNLOCK):
-                        break
-
-        while 1:
-            # 1
-            if (
-                self.limit_time is not None
-                and self.limit_time + self.start_time < datetime.now()
-            ):
+        self.limit_count = self.conf.herotest.limit_count
+        self.check_and_switch_soul()
+        self.open_exp_buff()
+        self.switch_hero(self.conf.herotest.layer)
+        self.init_pages()
+        self.ui_goto_page(self.page_hero_mode)
+        self.check_and_lock_team()
+        while True:
+            if self.limit_time is not None and self.limit_time + self.start_time < datetime.now():
                 logger.info("Time out")
                 break
             if self.current_count >= self.limit_count:
                 logger.info("Count out")
                 break
-            # 2
-            if is_update:
-                self.wait_until_appear(self.I_BATTLE)
-            if is_skill:
-                self.wait_until_appear(self.I_BCMJ_BATTLE)
-
-            # 如果是兵藏秘境 看看是否有兵道帖
-            if is_skill:
-                if not self.check_art_war_card():
-                    logger.info("Art war card is not enough")
-                    break
-            # 点击战斗
-            logger.info("Click battle")
-            while 1:
-                self.screenshot()
-                if is_update:
-                    if self.appear_then_click(self.I_BATTLE, interval=2):
-                        self.device.stuck_record_clear()
-                        continue
-                    if not self.appear(self.I_BATTLE):
-                        break
-                elif is_skill:
-                    if not self.check_art_war_card():
-                        logger.info("Art war card is not nough")
-                        break
-                    if self.appear_then_click(self.I_START_CHALLENGE, interval=1):
-                        continue
-                    if self.appear_then_click(self.I_BCMJ_RESET_CONFIRM, interval=1):
-                        continue
-                    if self.appear_then_click(self.I_BCMJ_BATTLE, interval=2):
-                        self.device.stuck_record_clear()
-                        continue
-                    if not self.appear(self.I_BCMJ_BATTLE):
-                        break
-
-            if self.run_general_battle(config=config.general_battle):
+            self.ui_goto_page(self.page_hero_mode)
+            if not self.can_run(self.conf.herotest.layer):
+                break
+            self.enter_battle()
+            if self.run_general_battle(config=self.conf.general_battle):
                 logger.info("General battle success")
-
-        self.main_home()
+        self.close_exp_buff()
         self.set_next_run(task="HeroTest", success=True)
         raise TaskEnd
 
+    def enter_battle(self):
+        """进入战斗"""
+        logger.info("Click battle")
+        while True:
+            self.screenshot()
+            if self.is_in_battle(False):
+                break  # 在战斗中则跳出循环
+            if self.appear_then_click(self.I_START_CHALLENGE, interval=1):  # 兵藏秘境确认挑战
+                continue
+            if self.appear_then_click(self.I_BCMJ_RESET_CONFIRM, interval=1):  # 兵藏秘境确认重置
+                continue
+            if self.appear_then_click(self.O_FIRE, interval=1.6):  # 挑战按钮
+                self.device.stuck_record_clear()
+                continue
+
     def battle_wait(self, random_click_swipt_enable: bool) -> bool:
         self.device.stuck_record_add("BATTLE_STATUS_S")
         self.device.click_record_clear()
@@ -208,7 +125,7 @@ class ScriptTask(GameUi, BaseActivity, HeroTestAssets, SwitchSoul):
                 if not self.appear(self.I_FALSE, threshold=0.6):
                     return False
         # 最后保证能点击 获得奖励
-        if not is_skill and not self.wait_until_appear(self.I_REWARD, wait_time=2):
+        if not self.is_skill and not self.wait_until_appear(self.I_REWARD, wait_time=2):
             # 有些的战斗没有下面的奖励,所以直接返回
             logger.info("There is no reward, Exit battle")
             return win
@@ -247,12 +164,41 @@ class ScriptTask(GameUi, BaseActivity, HeroTestAssets, SwitchSoul):
                 self.I_REWARD_GOLD, action=action_click, interval=1.5
             ):
                 continue
-            if not self.appear(self.I_REWARD) and not self.appear(self.I_REWARD_GOLD):
+            if self.appear(self.O_FIRE, interval=2):
                 break
 
         return win
 
-    def check_art_war_card(self):
+    def switch_hero(self, layer: Layer):
+        """切换英杰"""
+        self.ui_goto_page(pages.page_hero_test)
+        switch_hero_dict: dict = {
+            Layer.YANWU: (self.I_CHECK_HERO1, self.I_SWITCH_HERO1),  # 源赖光
+            Layer.MIJING: (self.I_CHECK_HERO1, self.I_SWITCH_HERO1),  # 源赖光
+            Layer.CHUANCHENG: (self.I_CHECK_HERO2, self.I_SWITCH_HERO2),  # 藤原道长
+            Layer.MENGXU: (self.I_CHECK_HERO2, self.I_SWITCH_HERO2),  # 藤原道长
+        }
+        check_hero_img, switch_hero_img = switch_hero_dict[layer]
+        while True:
+            if self.appear(check_hero_img, interval=1):
+                break
+            self.ui_click(self.C_SWITCH_HERO_BTN, switch_hero_img, interval=0.5)
+            self.appear_then_click(switch_hero_img, interval=0.5)
+
+    def can_run(self, layer: Layer) -> bool:
+        """检查是否可以运行
+        :return: True(default): can run, False: cannot run
+        """
+        check_func: dict[Layer, Callable] = {
+            Layer.MIJING: self.check_art_war_card,
+            Layer.CHUANCHENG: self.check_level_max,
+        }
+        if check_func.get(layer, None) is not None:
+            return check_func[layer]()
+        return True
+
+    def check_art_war_card(self) -> bool:
+        """兵藏秘境 看看是否有兵道帖"""
         self.screenshot()
         cu = self.O_ART_WAR_CARD.ocr(image=self.device.image)
         if cu[0] >= 1:
@@ -267,60 +213,77 @@ class ScriptTask(GameUi, BaseActivity, HeroTestAssets, SwitchSoul):
         if cu >= 1:
             logger.info("Art war card is not enough, but plus card is enough")
             return True
+        logger.warning("Art war card is not enough")
         return False
 
-    def home_main(self) -> bool:
-        """
-        从庭院到活动的爬塔界面
-        :return:
-        """
-        logger.hr("Enter HeroTest", 2)
-        global is_update
-        global is_skill
-        while 1:
-            self.screenshot()
-            if is_update:
-                if self.appear(self.I_BATTLE):
-                    break
-            if is_skill:
-                if self.appear(self.I_BCMJ_BATTLE):
-                    break
-            if self.appear_then_click(self.I_TWO, interval=1):
-                continue
-            if is_update:
-                if self.appear_then_click(self.I_GBB, interval=1):
-                    continue
-            if is_skill:
-                if self.appear_then_click(self.I_BCMJ, interval=1):
-                    continue
+    def check_level_max(self):
+        """检查御灵等级是否已经满级"""
+        self.screenshot()
+        if self.appear(self.I_HERO_EXP_MAX):
+            logger.info('Experience is already maxed out, exit battle')
+            return False
+        return True
 
-    def main_home(self) -> bool:
-        """
-        从活动的爬塔界面到庭院
-        :return:
-        """
-        logger.hr("Exit HeroTest", 2)
-        global is_update
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_UI_BACK_RED, interval=2):
-                continue
-            if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=2):
-                continue
-            if self.appear_then_click(self.I_BACK, interval=2):
-                continue
-            if self.appear_then_click(self.I_GBB_BACK, interval=2):
-                continue
-            self.ui_get_current_page()
-            self.ui_goto(page_main)
-            if is_update:
-                # 关闭经验加成
-                self.open_buff()
-                self.exp_100(False)
-                self.exp_50(False)
-                self.close_buff()
-            break
+    def check_and_switch_soul(self):
+        """检查并切换御魂"""
+        if self.conf.switch_soul_config.enable:
+            self.ui_goto_page(pages.page_shikigami_records)
+            self.run_switch_soul(self.conf.switch_soul_config.switch_group_team)
+        if self.conf.switch_soul_config.enable_switch_by_name:
+            self.ui_goto_page(pages.page_shikigami_records)
+            self.run_switch_soul_by_name(self.conf.switch_soul_config.group_name, self.conf.switch_soul_config.team_name)
+
+    def open_exp_buff(self):
+        """启用经验加成"""
+        exp_50_buff_enable = self.conf.herotest.exp_50_buff_enable_help
+        exp_100_buff_enable = self.conf.herotest.exp_100_buff_enable_help
+        if exp_50_buff_enable or exp_100_buff_enable:
+            self.ui_goto_page(pages.page_main)
+            self.open_buff()
+            self.exp_100(exp_100_buff_enable)
+            self.exp_50(exp_50_buff_enable)
+            self.close_buff()
+
+    def close_exp_buff(self):
+        """关闭经验加成"""
+        exp_50_buff_enable = self.conf.herotest.exp_50_buff_enable_help
+        exp_100_buff_enable = self.conf.herotest.exp_100_buff_enable_help
+        if exp_50_buff_enable or exp_100_buff_enable:
+            self.ui_goto_page(pages.page_main)
+            self.open_buff()
+            self.exp_100(False)
+            self.exp_50(False)
+            self.close_buff()
+
+    def check_and_lock_team(self):
+        """检查并锁定阵容"""
+        if self.conf.general_battle.lock_team_enable:
+            logger.info("Lock team")
+            self.ui_click(self.I_UNLOCK, self.I_LOCK, interval=0.8)
+        else:
+            logger.info("Unlock team")
+            self.ui_click(self.I_LOCK, self.I_UNLOCK, interval=0.8)
 
+    def init_pages(self):
+        """初始化页面"""
+        match self.conf.herotest.layer:
+            case Layer.YANWU:
+                self.page_hero_mode = pages.Page(self.I_CHECK_HERO1_EXP)
+                pages.page_hero_test.link(button=self.I_GBB, destination=self.page_hero_mode)
+            case Layer.MIJING:
+                self.page_hero_mode = pages.Page(self.I_CHECK_HERO1_SKILL)
+                pages.page_hero_test.link(button=self.I_BCMJ, destination=self.page_hero_mode)
+                self.is_skill = True
+            case Layer.CHUANCHENG:
+                self.page_hero_mode = pages.Page(self.I_CHECK_HERO2_EXP)
+                pages.page_hero_test.link(button=self.I_ENTER_CCSL, destination=self.page_hero_mode)
+            case Layer.MENGXU:
+                self.page_hero_mode = pages.Page(self.I_CHECK_HERO2_SKILL)
+                pages.page_hero_test.link(button=self.I_ENTER_MXMJ, destination=self.page_hero_mode)
+                self.is_skill = True
+            case _:
+                raise ValueError(f'Unknown Layer {Layer}')
+        self.page_hero_mode.link(button=self.I_BACK_YOLLOW, destination=pages.page_hero_test)
 
 
 if __name__ == "__main__":

+ 1 - 4
tasks/base_task.py

@@ -184,7 +184,7 @@ class BaseTask(GlobalGameAssets, CostumeBase):
         return appear
 
     def appear_then_click(self,
-                          target: RuleImage | RuleGif,
+                          target: RuleImage | RuleGif | RuleOcr,
                           action: Union[RuleClick, RuleLongClick] = None,
                           interval: float = None,
                           threshold: float = None,
@@ -198,9 +198,6 @@ class BaseTask(GlobalGameAssets, CostumeBase):
         :param threshold:
         :return: True or False
         """
-        if not isinstance(target, RuleImage) and not isinstance(target, RuleGif):
-            return False
-
         appear = self.appear(target, interval=interval, threshold=threshold)
         if appear and not action:
             x, y = target.coord()