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

add(HeroTest): 藤原道长PVE技能

Azur 9 месяцев назад
Родитель
Сommit
1b4960304d

+ 2 - 1
assets/i18n/zh-CN.json

@@ -3,7 +3,8 @@
   "kirin_battle_config": "麒麟战斗配置",
   "netherworld_battle_config": "阴界之门战斗配置",
   "hya_onmyoji": "切换阴阳师",
-  "hya_onmyoji_help": ""
+  "hya_onmyoji_help": "",
+  "skill_mode": "技能本模式"
 }
 
 

BIN
tasks/HeroTest/as/as_bcmj_lock.png


BIN
tasks/HeroTest/as/as_bcmj_unlock.png


BIN
tasks/HeroTest/as/as_hero2_skill1.png


BIN
tasks/HeroTest/as/as_hero2_skill2.png


BIN
tasks/HeroTest/as/as_hero2_skill3.png


BIN
tasks/HeroTest/as/as_hero2_skill4.png


BIN
tasks/HeroTest/as/as_hero2_skill5.png


BIN
tasks/HeroTest/as/as_hero2_skill6.png


BIN
tasks/HeroTest/as/as_real_money.png


+ 13 - 4
tasks/HeroTest/as/image.json

@@ -83,8 +83,8 @@
   {
     "itemName": "bcmj_lock",
     "imageName": "as_bcmj_lock.png",
-    "roiFront": "901,159,36,26",
-    "roiBack": "901,650,36,38",
+    "roiFront": "908,655,20,26",
+    "roiBack": "825,645,199,52",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "兵藏秘境阵容锁"
@@ -164,8 +164,8 @@
   {
     "itemName": "bcmj_unlock",
     "imageName": "as_bcmj_unlock.png",
-    "roiFront": "906,652,22,30",
-    "roiBack": "906,652,22,30",
+    "roiFront": "908,656,20,20",
+    "roiBack": "825,642,195,56",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "兵藏秘境的阵容未锁"
@@ -295,5 +295,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "御灵满级标志"
+  },
+  {
+    "itemName": "real_money",
+    "imageName": "as_real_money.png",
+    "roiFront": "536,320,24,30",
+    "roiBack": "466,155,530,411",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "真钱"
   }
 ]

+ 56 - 0
tasks/HeroTest/as/image_hero2_skill.json

@@ -0,0 +1,56 @@
+[
+  {
+    "itemName": "hero2_skill1",
+    "imageName": "as_hero2_skill1.png",
+    "roiFront": "825,358,61,36",
+    "roiBack": "47,340,1178,65",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "同调祝福"
+  },
+  {
+    "itemName": "hero2_skill2",
+    "imageName": "as_hero2_skill2.png",
+    "roiFront": "521,356,63,37",
+    "roiBack": "46,333,1174,82",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "韵迟祝福"
+  },
+  {
+    "itemName": "hero2_skill4",
+    "imageName": "as_hero2_skill4.png",
+    "roiFront": "1127,356,65,41",
+    "roiBack": "48,349,1173,57",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "叠辉祝福"
+  },
+  {
+    "itemName": "hero2_skill5",
+    "imageName": "as_hero2_skill5.png",
+    "roiFront": "217,358,65,37",
+    "roiBack": "46,334,1148,81",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "敛神祝福"
+  },
+  {
+    "itemName": "hero2_skill3",
+    "imageName": "as_hero2_skill3.png",
+    "roiFront": "520,358,62,38",
+    "roiBack": "41,346,1172,63",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "弥天祝福"
+  },
+  {
+    "itemName": "hero2_skill6",
+    "imageName": "as_hero2_skill6.png",
+    "roiFront": "427,356,62,38",
+    "roiBack": "48,342,1175,67",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "速度祝福"
+  }
+]

+ 19 - 2
tasks/HeroTest/assets.py

@@ -35,7 +35,7 @@ class HeroTestAssets:
 	# 兵藏秘境 
 	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,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=(908,655,20,26), roi_back=(825,645,199,52), 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")
 	# 兵藏秘境胜利 
@@ -53,7 +53,7 @@ class HeroTestAssets:
 	# 默认属性 
 	I_BCMJ__DEFALUT_ATTRIBUTE = RuleImage(roi_front=(1168,159,21,22), roi_back=(255,155,944,31), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj__defalut_attribute.png")
 	# 兵藏秘境的阵容未锁 
-	I_BCMJ_UNLOCK = RuleImage(roi_front=(906,652,22,30), roi_back=(906,652,22,30), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_unlock.png")
+	I_BCMJ_UNLOCK = RuleImage(roi_front=(908,656,20,20), roi_back=(825,642,195,56), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_unlock.png")
 	# 通过兵藏秘境确认重置按钮 
 	I_BCMJ_RESET_CONFIRM = RuleImage(roi_front=(668,399,180,70), roi_back=(668,399,180,70), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_bcmj_reset_confirm.png")
 	# 通过兵藏秘境取消重置按钮 
@@ -82,6 +82,23 @@ class HeroTestAssets:
 	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")
+	# 真钱 
+	I_REAL_MONEY = RuleImage(roi_front=(536,320,24,30), roi_back=(466,155,530,411), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_real_money.png")
+
+
+	# Image Rule Assets
+	# 同调祝福 
+	I_HERO2_SKILL1 = RuleImage(roi_front=(825,358,61,36), roi_back=(47,340,1178,65), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero2_skill1.png")
+	# 韵迟祝福 
+	I_HERO2_SKILL2 = RuleImage(roi_front=(521,356,63,37), roi_back=(46,333,1174,82), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero2_skill2.png")
+	# 叠辉祝福 
+	I_HERO2_SKILL4 = RuleImage(roi_front=(1127,356,65,41), roi_back=(48,349,1173,57), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero2_skill4.png")
+	# 敛神祝福 
+	I_HERO2_SKILL5 = RuleImage(roi_front=(217,358,65,37), roi_back=(46,334,1148,81), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero2_skill5.png")
+	# 弥天祝福 
+	I_HERO2_SKILL3 = RuleImage(roi_front=(520,358,62,38), roi_back=(41,346,1172,63), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero2_skill3.png")
+	# 速度祝福 
+	I_HERO2_SKILL6 = RuleImage(roi_front=(427,356,62,38), roi_back=(48,342,1175,67), threshold=0.8, method="Template matching", file="./tasks/HeroTest/as/as_hero2_skill6.png")
 
 
 	# Ocr Rule Assets

+ 9 - 1
tasks/HeroTest/config.py

@@ -10,6 +10,7 @@ from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase, Time, TimeDelta
 from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 
+
 class Layer(str, Enum):
     YANWU: str = "鬼兵演武"
     MIJING: str = "兵藏秘境"
@@ -17,12 +18,19 @@ class Layer(str, Enum):
     MENGXU: str = "梦虚秘境"
 
 
+class SkillMode(str, Enum):
+    PVE = 'PVE'
+    PVP = 'PVP'
+
+
 class HeroTestConfig(BaseModel):
     # 副本选择
     layer: Layer = Field(
         default=Layer.YANWU,
-        description="选择要打的关卡。\n兵藏秘境升级顺序八华斩->无畏 -> 暴击伤害 -> 默认祝福 -> 默认属性",
+        description="选择要打的关卡。\n兵藏秘境升级顺序八华斩->无畏 -> 暴击伤害 -> 默认祝福 -> 默认属性\n"
+                    "藤原道长矩阵博士攻略:https://www.bilibili.com/opus/1162129635334422531",
     )
+    skill_mode: SkillMode = Field(default=SkillMode.PVE, description="技能本技能偏向\n藤原道长使用攻略高配阵容,需自己配置好技能和祝福")
     # 限制时间
     limit_time: Time = Field(default=Time(minute=30), description="limit_time_help")
     # 限制次数

+ 102 - 94
tasks/HeroTest/script_task.py

@@ -3,6 +3,7 @@
 # github https://github.com/runhey
 from datetime import datetime, timedelta, time
 import random  # type: ignore
+from module.atom.image import RuleImage
 
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.HeroTest.assets import HeroTestAssets
@@ -11,7 +12,7 @@ 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 tasks.HeroTest.config import Layer, HeroTest, SkillMode
 from typing import Callable
 
 import tasks.GameUi.page as pages
@@ -21,7 +22,7 @@ class ScriptTask(GameUi, GeneralBattle, HeroTestAssets, SwitchSoul):
 
     conf: HeroTest
     page_hero_mode: pages.Page  # 当前英杰对应模式界面(经验or技能)
-    is_skill: bool = False
+    success: bool = True
 
     def run(self) -> None:
         self.conf = self.config.hero_test
@@ -49,125 +50,127 @@ class ScriptTask(GameUi, GeneralBattle, HeroTestAssets, SwitchSoul):
             self.ui_goto_page(self.page_hero_mode)
             if not self.can_run(self.conf.herotest.layer):
                 break
-            self.enter_battle()
+            entered = self.enter_battle()
+            if not entered:
+                break
             if self.run_general_battle(config=self.conf.general_battle):
                 logger.info("General battle success")
         self.close_exp_buff()
-        self.set_next_run(task="HeroTest", success=True)
+        self.set_next_run(task="HeroTest", success=self.success)
         raise TaskEnd
 
-    def enter_battle(self):
-        """进入战斗"""
+    def enter_battle(self) -> bool:
+        """进入战斗
+        :return: True:进入成功 False:进入失败
+        """
         logger.info("Click battle")
+        click_cnt, max_click = 0, random.randint(3, 4)
         while True:
             self.screenshot()
             if self.is_in_battle(False):
-                break  # 在战斗中则跳出循环
+                return True  # 成功进入战斗
+            if click_cnt >= max_click:  # 异常情况,怎么都无法进入
+                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(self.I_REAL_MONEY, interval=1):  # 这里因为门票不够而不是其他异常所以success默认还是true
+                logger.warning('Ticket is not enough')
+                return False
             if self.appear_then_click(self.O_FIRE, interval=1.6):  # 挑战按钮
                 self.device.stuck_record_clear()
+                click_cnt += 1
                 continue
+        logger.error('Battle cannot enter, maybe recognize failed')
+        self.success = False  # 进入失败且不知道发生了什么情况
+        return False
 
     def battle_wait(self, random_click_swipt_enable: bool) -> bool:
         self.device.stuck_record_add("BATTLE_STATUS_S")
         self.device.click_record_clear()
         logger.info("Start battle process")
-        win: bool = False
-        while 1:
+        win = None
+        # 处理不同模式下的结算界面
+        mode_wait_dict: dict[Layer, Callable] = {
+            Layer.MIJING: self.hero1_skill_wait,
+            Layer.MENGXU: self.hero2_skill_wait,
+        }
+        while True:
             self.screenshot()
-            if self.appear(self.I_WIN, threshold=0.8) or self.appear(self.I_DE_WIN):
+            if win is not None and self.appear(self.O_FIRE, interval=1.6):
+                break
+            if mode_wait_dict.get(self.conf.herotest.layer, None) is not None:
+                appeared = mode_wait_dict[self.conf.herotest.layer]()
+                if appeared:
+                    win = True
+                    continue
+            if win is not None:
+                self.click(pages.random_click(ltrb=(False, True, True, False)), interval=1.5)
+                continue
+            if self.appear(self.I_WIN, interval=1.5) or \
+                    self.appear(self.I_DE_WIN, interval=1.5) or \
+                    self.appear(self.I_REWARD, interval=1.5):
                 logger.info("Battle result is win")
-                if self.appear(self.I_DE_WIN):
-                    self.ui_click_until_disappear(self.I_DE_WIN)
                 win = True
-                break
-
+                continue
             # 如果出现失败 就点击,返回False
-            if self.appear(self.I_FALSE, threshold=0.8):
+            if self.appear(self.I_FALSE, interval=1.5):
                 logger.info("Battle result is false")
                 win = False
-                break
-
-            # 如果领奖励
-            if self.appear(self.I_REWARD, threshold=0.6):
-                win = True
-                break
-
-            # 如果领奖励出现金币
-            if self.appear(self.I_REWARD_GOLD, threshold=0.8):
-                win = True
-                break
+                continue
             # 如果开启战斗过程随机滑动
             if random_click_swipt_enable:
                 self.random_click_swipt()
+        return win
 
-        # 再次确认战斗结果
-        logger.info("Reconfirm the results of the battle")
-        while 1:
-            self.screenshot()
-            if win:
-                # 点击赢了
-                # self.C_WIN_2 在掉落物品过多的时候可能会点击到物品,导致脚本卡死
-                action_click = random.choice([self.C_WIN_1, self.C_WIN_3])
+    def hero1_skill_wait(self):
+        if self.wait_until_appear(self.I_BCMJ_SKILL_ADD_CONFIRM, wait_time=2):
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_BCMJ_SKILL_ADD1, interval=1):
+                    break
+                if self.appear_then_click(self.I_BCMJ_SKILL_ADD2, interval=1):
+                    break
+                if self.appear_then_click(self.I_BCMJ_BLESS, interval=1):
+                    break
                 if self.appear_then_click(
-                    self.I_WIN, action=action_click, interval=0.5
+                        self.I_BCMJ_PROPERTY_ADD_CRITICAL, interval=1
                 ):
-                    continue
-                if not self.appear(self.I_WIN):
                     break
-            else:
-                # 如果失败且 点击失败后
-                if self.appear_then_click(self.I_FALSE, threshold=0.6):
-                    continue
-                if not self.appear(self.I_FALSE, threshold=0.6):
-                    return False
-        # 最后保证能点击 获得奖励
-        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
-        else:
-            if self.wait_until_appear(self.I_BCMJ_SKILL_ADD_CONFIRM, wait_time=2):
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(self.I_BCMJ_SKILL_ADD1, interval=1):
-                        break
-                    if self.appear_then_click(self.I_BCMJ_SKILL_ADD2, interval=1):
-                        break
-                    if self.appear_then_click(self.I_BCMJ_BLESS, interval=1):
-                        break
-                    if self.appear_then_click(
-                        self.I_BCMJ_PROPERTY_ADD_CRITICAL, interval=1
-                    ):
-                        break
-                    if self.appear_then_click(
+                if self.appear_then_click(
                         self.I_BCMJ__DEFALUT_ATTRIBUTE, interval=1
-                    ):
-                        break
-                if self.appear_then_click(self.I_BCMJ_SKILL_ADD_CONFIRM, interval=1):
-                    return win
+                ):
+                    break
+            if self.appear_then_click(self.I_BCMJ_SKILL_ADD_CONFIRM, interval=1):
+                return True
+        return False
 
-        logger.info("Get reward")
-        while 1:
+    def hero2_skill_wait(self):
+        if not self.appear(self.I_BCMJ_SKILL_ADD_CONFIRM):
+            return False
+        # pve技能列表, 按优先级顺序
+        pve_skill = [
+            self.I_HERO2_SKILL1,  # 同调祝福
+            self.I_HERO2_SKILL2,  # 韵迟祝福
+            self.I_HERO2_SKILL3,  # 弥天祝福
+            self.I_HERO2_SKILL4,  # 叠辉祝福
+            self.I_HERO2_SKILL5,  # 敛神祝福
+            self.I_HERO2_SKILL6,  # 速度祝福
+        ]
+        # TODO: PVP
+        pvp_skill = []
+        target_skill_dict: dict[SkillMode, list] = {
+            SkillMode.PVE: pve_skill,
+            SkillMode.PVP: pvp_skill,
+        }
+        target_skills = target_skill_dict[self.conf.herotest.skill_mode]
+        while True:
             self.screenshot()
-            # 如果出现领奖励
-            # self.C_REWARD_2 在掉落物品过多的时候可能会点击到物品,导致脚本卡死
-            action_click = random.choice(
-                [self.C_REWARD_1, self.C_REWARD_3]
-            )
-            if self.appear_then_click(
-                self.I_REWARD, action=action_click, interval=1.5
-            ) or self.appear_then_click(
-                self.I_REWARD_GOLD, action=action_click, interval=1.5
-            ):
-                continue
-            if self.appear(self.O_FIRE, interval=2):
+            if any(self.appear_then_click(ts, interval=1) for ts in target_skills):
                 break
-
-        return win
+        self.ui_click_until_disappear(self.I_BCMJ_SKILL_ADD_CONFIRM, interval=1.5)
+        return True
 
     def switch_hero(self, layer: Layer):
         """切换英杰"""
@@ -197,24 +200,21 @@ class ScriptTask(GameUi, GeneralBattle, HeroTestAssets, SwitchSoul):
         check_func: dict[Layer, Callable] = {
             Layer.MIJING: self.check_art_war_card,
             Layer.CHUANCHENG: self.check_level_max,
+            Layer.MENGXU: self.check_art_war_card,
         }
         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:
             logger.info("Art war card is enough")
             return True
         cu = self.O_ART_WAR_CARD_PLUS.ocr(image=self.device.image)
-        # 转换为int
-        if cu != "":
-            cu = int(cu)
-        else:
-            cu = 0
+        cu = 0 if cu == '' else int(cu)
         if cu >= 1:
             logger.info("Art war card is not enough, but plus card is enough")
             return True
@@ -262,12 +262,22 @@ class ScriptTask(GameUi, GeneralBattle, HeroTestAssets, SwitchSoul):
 
     def check_and_lock_team(self):
         """检查并锁定阵容"""
+        lock_img = self.I_LOCK
+        unlock_img = self.I_UNLOCK
+        match self.conf.herotest.layer:
+            case Layer.YANWU | Layer.CHUANCHENG:
+                pass
+            case Layer.MIJING | Layer.MENGXU:
+                lock_img = self.I_BCMJ_LOCK
+                unlock_img = self.I_BCMJ_UNLOCK
+            case _:
+                raise ValueError(f'Unknown layer on lock: {self.conf.herotest.layer}')
         if self.conf.general_battle.lock_team_enable:
             logger.info("Lock team")
-            self.ui_click(self.I_UNLOCK, self.I_LOCK, interval=0.8)
+            self.ui_click(unlock_img, lock_img, interval=0.8)
         else:
             logger.info("Unlock team")
-            self.ui_click(self.I_LOCK, self.I_UNLOCK, interval=0.8)
+            self.ui_click(lock_img, unlock_img, interval=0.8)
 
     def init_pages(self):
         """初始化页面"""
@@ -278,14 +288,12 @@ class ScriptTask(GameUi, GeneralBattle, HeroTestAssets, SwitchSoul):
             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)
@@ -299,4 +307,4 @@ if __name__ == "__main__":
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.run()
+    t.check_and_lock_team()