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

Merge branch 'dev' of https://github.com/runhey/OnmyojiAutoScript into dev

Neptine 1 год назад
Родитель
Сommit
895cd87377

+ 2 - 2
tasks/AbyssShadows/assets.py

@@ -73,8 +73,6 @@ class AbyssShadowsAssets:
 	# 前往 
 	I_ABYSS_GOTO_ENEMY = RuleImage(roi_front=(1120,610,75,45), roi_back=(1120,610,75,45), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_goto_enemy.png")
 	# description 
-	I_CHANGE_AREA = RuleImage(roi_front=(993,610,63,61), roi_back=(993,610,63,61), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_change_area.png")
-	# description 
 	I_ENSURE_BUTTON = RuleImage(roi_front=(672,405,169,55), roi_back=(672,405,169,55), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_ensure_button.png")
 	# 进攻中 
 	I_IS_ATTACK = RuleImage(roi_front=(586,62,73,27), roi_back=(586,62,73,27), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_is_attack.png")
@@ -90,6 +88,8 @@ class AbyssShadowsAssets:
 	I_DRAGON_AREA = RuleImage(roi_front=(584,15,111,34), roi_back=(584,15,111,34), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_dragon_area.png")
 	# description 
 	I_WAIT_TO_START = RuleImage(roi_front=(588,64,70,26), roi_back=(588,64,70,26), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_wait_to_start.png")
+	# description 
+	I_EQUIPPING = RuleImage(roi_front=(1126,545,100,83), roi_back=(1126,545,100,83), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_equipping.png")
 
 
 	# List Rule Assets

+ 13 - 1
tasks/AbyssShadows/config.py

@@ -5,6 +5,10 @@
 # github    https://github.com/roarhill/oas
 
 from pydantic import BaseModel, Field
+from pygments.lexer import default
+from scripts.regsetup import description
+from sympy.testing.pytest import Failed
+
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 from tasks.Component.config_base import ConfigBase, Time
@@ -16,8 +20,16 @@ class AbyssShadowsTime(ConfigBase):
     custom_run_time_saturday: Time = Field(default=Time(hour=19, minute=0, second=0))
     custom_run_time_sunday: Time = Field(default=Time(hour=19, minute=0, second=0))
 
+class AbyssShadowsCombatTime(BaseModel):
+    # 设置战斗时间
+    CombatTime_enable: bool = Field(default=False, description="开启智能伤害")
+    boss_combat_time: int = Field(default=60, description="以秒为单位设置首领战斗时间,请合理设置")
+    general_combat_time: int = Field(default=60, description="以秒为单位设置副将战斗时间,请合理设置")
+    elite_combat_time: int = Field(default=60, description="以秒为单位设置精英战斗时间,请合理设置")
+
 class AbyssShadows(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     abyss_shadows_time: AbyssShadowsTime = Field(default_factory=AbyssShadowsTime)
+    abyss_shadows_combat_time: AbyssShadowsCombatTime = Field(default_factory=AbyssShadowsCombatTime)
     general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
-    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

+ 9 - 9
tasks/AbyssShadows/res/image.json

@@ -125,15 +125,6 @@
     "threshold": 0.8,
     "description": "前往"
   },
-  {
-    "itemName": "change_area",
-    "imageName": "res_change_area.png",
-    "roiFront": "993,610,63,61",
-    "roiBack": "993,610,63,61",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "description"
-  },
   {
     "itemName": "ensure_button",
     "imageName": "res_ensure_button.png",
@@ -205,5 +196,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
+  },
+  {
+    "itemName": "equipping",
+    "imageName": "res_equipping.png",
+    "roiFront": "1126,545,100,83",
+    "roiBack": "1126,545,100,83",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
   }
 ]

BIN
tasks/AbyssShadows/res/res_equipping.png


+ 146 - 37
tasks/AbyssShadows/script_task.py

@@ -7,6 +7,7 @@
 from datetime import datetime, timedelta
 import random
 import numpy as np
+import time
 from enum import Enum
 from cached_property import cached_property
 from time import sleep
@@ -124,42 +125,82 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
         self.wait_until_disappear(self.I_WAIT_TO_START)
         self.device.stuck_record_clear()
 
-        # 准备攻打精英、副将、首领
-        while 1:
-            # 点击战报按钮
-            find_list = [EmemyType.BOSS, EmemyType.GENERAL, EmemyType.ELITE]
-            for enemy_type in find_list:
-                # 寻找敌人并开始战斗,
-                if not self.find_enemy(enemy_type):
-                    logger.warning(f"Failed to find {enemy_type.name} enemy, exit")
+        # 未开启智能伤害准备攻打精英、副将、首领
+        if not cfg.abyss_shadows_combat_time.CombatTime_enable:
+            while 1:
+                # 点击战报按钮
+                find_list = [EmemyType.BOSS, EmemyType.GENERAL, EmemyType.ELITE]
+                for enemy_type in find_list:
+                    # 寻找敌人并开始战斗,
+                    if not self.find_enemy(enemy_type):
+                        logger.warning(f"Failed to find {enemy_type.name} enemy, exit")
+                        break
+                logger.info(f"Current fight times: boss {self.boss_fight_count} times, general {self.general_fight_count}  times, elite {self.elite_fight_count} times")
+                # 正常应该打完一个区域了,检查攻打次数,如没打够则切换到下一个区域,默认神龙 -> 孔雀 -> 白藏主 -> 黑豹
+                if self.boss_fight_count >= 2 and self.general_fight_count >= 4 and self.elite_fight_count >= 6:
+                    success = True
+                    break
+                else:
+                    #切换区域之前关闭战报
+                    self.appear_then_click(self.I_ABYSS_MAP_EXIT, interval=1)
+                    current_area = self.check_current_area()
+                    logger.info(f"Current area is {current_area}, switch to next area")
+                    if current_area == AreaType.DRAGON:
+                        self.change_area(AreaType.PEACOCK)
+                        continue
+                    elif current_area == AreaType.PEACOCK:
+                        self.change_area(AreaType.FOX)
+                        continue
+                    elif current_area == AreaType.FOX:
+                        self.change_area(AreaType.LEOPARD)
+                        continue
+                    else:
+                        logger.warning("All enemy types have been defeated, but not enough emeny to fight, exit")
+                        break
+
+        # 开启智能伤害
+        if cfg.abyss_shadows_combat_time.CombatTime_enable:
+            while True:
+                # 1. 先攻打 1 个 BOSS
+                if self.boss_fight_count < 2:
+                    self.boss_fight_count = self.fight_and_switch(EmemyType.BOSS, 2, self.boss_fight_count,
+                                                             lambda: self.switch_area())
+
+                # 2. 攻打 2 个 GENERAL
+                if self.general_fight_count < 4:
+                    self.general_fight_count = self.fight_and_switch(EmemyType.GENERAL, 4, self.general_fight_count,
+                                                                lambda: self.switch_area())
+
+                # 3. 攻打 3 个 ELITE
+                if self.elite_fight_count < 6:
+                    self.elite_fight_count = self.fight_and_switch(EmemyType.ELITE, 6, self.elite_fight_count,
+                                                              lambda: self.switch_area())
+
+                # 检查是否已完成所有任务
+                print(f"Current fight times: boss {self.boss_fight_count} times, general {self.general_fight_count} times, elite {self.elite_fight_count} times")
+                if self.boss_fight_count >= 2 and self.general_fight_count >= 4 and self.elite_fight_count >= 6:
+                    logger.info("All fights completed")
+                    success = True
                     break
-            logger.info(f"Current fight times: boss {self.boss_fight_count} times, general {self.general_fight_count}  times, elite {self.elite_fight_count} times")
-            # 正常应该打完一个区域了,检查攻打次数,如没打够则切换到下一个区域,默认神龙 -> 孔雀 -> 白藏主 -> 黑豹
-            if self.boss_fight_count >= 2 and self.general_fight_count >= 4 and self.elite_fight_count >= 6:
-                success = True
-                break
-            else:
-                current_area = self.check_current_area()
-                logger.info(f"Current area is {current_area}, switch to next area")
-                if current_area == AreaType.DRAGON:
-                    self.change_area(AreaType.PEACOCK)
-                    continue
-                elif current_area == AreaType.PEACOCK:
-                    self.change_area(AreaType.FOX)
-                    continue
-                elif current_area == AreaType.FOX:  
-                    self.change_area(AreaType.LEOPARD)
-                    continue
                 else:
+                    #没打满我也没办法就最后一张图,看看有没有剩余的吧没有也不想跑了
+                    find_list = [EmemyType.BOSS, EmemyType.GENERAL, EmemyType.ELITE]
+                    for enemy_type in find_list:
+                        # 寻找敌人并开始战斗,
+                        if not self.find_enemy(enemy_type):
+                            logger.warning(f"Failed to find {enemy_type.name} enemy, exit")
+                            break
+                    logger.info(f"Current fight times: boss {self.boss_fight_count} times, general {self.general_fight_count}  times, elite {self.elite_fight_count} times")
                     logger.warning("All enemy types have been defeated, but not enough emeny to fight, exit")
+                    success = True
                     break
-        
 
         # 保持好习惯,一个任务结束了就返回到庭院,方便下一任务的开始
         self.goto_main()
 
         # 设置下次运行时间
         if success:
+            print("我要重新设置时间了")
             if today == 4:
                 # 周五推迟到周六
                 logger.info(f"The next abyss shadows day is Saturday")
@@ -176,6 +217,47 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
             self.set_next_run(task='AbyssShadows', finish=True, server=True, success=False)
         raise TaskEnd
 
+
+
+    #攻击并进行区域切换
+    def fight_and_switch(self, enemy_type, required_count, fight_count, next_area_func):
+        while fight_count < required_count: # 0-2
+            if not self.find_enemy(enemy_type):
+                logger.warning(f"Failed to find {enemy_type.name} enemy, exit")
+                return fight_count
+            else:
+                if enemy_type == EmemyType.BOSS:
+                    fight_count += 1
+                elif enemy_type == EmemyType.GENERAL:
+                    fight_count += 2
+                elif enemy_type == EmemyType.ELITE:
+                    fight_count += 3
+            logger.info(
+                f"Current fight times: boss {self.boss_fight_count} times, general {self.general_fight_count} times, elite {self.elite_fight_count} times")
+
+            # 完成攻打后切换区域
+            current_area = self.check_current_area()
+            if fight_count < required_count and current_area != AreaType.LEOPARD:
+                next_area_func()
+        return fight_count
+
+    def switch_area(self):
+        #确保没有战报页面
+        self.appear_then_click(self.I_ABYSS_MAP_EXIT, interval=1)
+        current_area = self.check_current_area()
+        logger.info(f"Current area is {current_area}, switch to next area")
+        if current_area == AreaType.DRAGON:
+            self.change_area(AreaType.PEACOCK)
+        elif current_area == AreaType.PEACOCK:
+            self.change_area(AreaType.FOX)
+        elif current_area == AreaType.FOX:
+            self.change_area(AreaType.LEOPARD)
+        else:
+            logger.warning("All areas have been completed, exit")
+            raise StopIteration  # 退出循环
+
+
+
     def check_current_area(self) -> AreaType:
         ''' 获取当前区域
         :return AreaType
@@ -198,6 +280,9 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
         :return 
         '''
         while 1:
+            # 确保切换区域前不在战报页面
+            if self.appear_then_click(self.I_ABYSS_MAP_EXIT, interval=1):
+                continue
             self.screenshot()
             # 判断当前区域是否正确
             current_area = self.check_current_area()
@@ -208,7 +293,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
                 self.select_boss(area_name)
                 logger.info(f"Switch to {area_name.name}")
                 continue      
-            # 点击战报按钮
+            # 点击更换领域按钮
             if self.appear_then_click(self.I_CHANGE_AREA,interval=4):
                 logger.info(f"Click {self.I_CHANGE_AREA.name}")
                 continue
@@ -222,8 +307,6 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
         logger.info("Exiting abyss_shadows")
         self.ui_goto(page_main)
 
-       
-
     def goto_abyss_shadows(self) -> bool:
         ''' 进入狭间
         :return bool
@@ -307,7 +390,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
         logger.info(f"Run boss fight") 
         if self.click_emeny_area(CilckArea.BOSS):
             logger.info(f"Click {CilckArea.BOSS.name}")
-            self.run_general_battle_back()
+            self.run_general_battle_back(Monster_type="BOSS")
             self.boss_fight_count += 1
             logger.info(f'Fight, boss_fight_count {self.boss_fight_count} times')
         else:
@@ -328,7 +411,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
             if self.click_emeny_area(general):
                 logger.info(f"Click {general.name}")
                 self.general_fight_count += 1
-                self.run_general_battle_back()
+                self.run_general_battle_back(Monster_type="GENERAL")
                 logger.info(f'Fight, general_fight_count {self.general_fight_count} times')
         return True
 
@@ -347,7 +430,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
             if self.click_emeny_area(elite):
                 logger.info(f"Click {elite.name}")
                 self.elite_fight_count += 1
-                self.run_general_battle_back()
+                self.run_general_battle_back(Monster_type="ELITE")
                 logger.info(f'Fight, elite_fight_count {self.elite_fight_count} times')
         return True
 
@@ -418,20 +501,46 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
             
         return suceess
 
-    def run_general_battle_back(self) -> bool:
+    def run_general_battle_back(self, Monster_type: str) -> bool:
         """
         重写父类方法,因为狭间暗域的准备和战斗流程不一样
         进入挑战然后直接返回
         :param config:
         :return:
         """
+        cfg: AbyssShadows = self.config.abyss_shadows
         while 1:
+            #确保进入战斗
             self.screenshot()
-            if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
-                continue
-            if not self.appear(self.I_PRESET):
+            if self.wait_until_appear(self.I_EQUIPPING, wait_time=4):
+                self.click(self.I_EQUIPPING, interval=1.5)
+            if not self.appear(self.I_EQUIPPING):
                 break
-        logger.info(f"Click {self.I_PREPARE_HIGHLIGHT.name}")
+        logger.info(f"Click {self.I_EQUIPPING.name}")
+        logger.info(f"点击准备了")
+
+        # 进入战斗后,开始计时
+        start_time = time.time()
+        if cfg.abyss_shadows_combat_time.CombatTime_enable:
+            self.device.stuck_record_add('BATTLE_STATUS_S')
+            if Monster_type == "BOSS":  # BOSS战斗
+                combat_time = cfg.abyss_shadows_combat_time.boss_combat_time
+            elif Monster_type == "GENERAL":  # 是副将战斗
+                combat_time = cfg.abyss_shadows_combat_time.general_combat_time
+            elif Monster_type == "ELITE":  #  精英战斗
+                combat_time = cfg.abyss_shadows_combat_time.elite_combat_time
+            else:
+                combat_time = 60  # 默认为 60 秒
+            # 等待设定的战斗时间
+            while time.time() - start_time < combat_time:
+                self.screenshot()
+                if self.appear_then_click(self.I_WIN, interval=1.5):
+                    break
+            logger.info("Combat time ended, proceeding to exit.")
+            self.device.stuck_record_clear()
+        # 战斗提前结束这时没有返回按钮
+        if self.appear_then_click(self.I_WIN, interval=1.5):
+            return True
 
         # 点击返回
         while 1:

+ 3 - 3
tasks/Component/Costume/assets.py

@@ -38,15 +38,15 @@ class CostumeAssets:
 
 	# Image Rule Assets
 	# description 
-	I_CHECK_MAIN_11 = RuleImage(roi_front=(680,128,83,33), roi_back=(149,109,1099,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main11/main11_check_main_11.png")
+	I_CHECK_MAIN_11 = RuleImage(roi_front=(521,570,53,24), roi_back=(131,514,1099,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main11/main11_check_main_11.png")
 	# description 
 	I_MAIN_GOTO_EXPLORATION_11 = RuleImage(roi_front=(522,113,21,34), roi_back=(192,105,904,66), threshold=0.6, method="Template matching", file="./tasks/Component/Costume/main11/main11_main_goto_exploration_11.png")
 	#  
 	I_MAIN_GOTO_SUMMON_11 = RuleImage(roi_front=(946,111,20,37), roi_back=(500,102,623,68), threshold=0.6, method="Template matching", file="./tasks/Component/Costume/main11/main11_main_goto_summon_11.png")
 	# 町中 
-	I_MAIN_GOTO_TOWN_11 = RuleImage(roi_front=(701,164,36,20), roi_back=(262,145,999,78), threshold=0.7, method="Template matching", file="./tasks/Component/Costume/main11/main11_main_goto_town_11.png")
+	I_MAIN_GOTO_TOWN_11 = RuleImage(roi_front=(703,169,35,20), roi_back=(262,145,999,78), threshold=0.7, method="Template matching", file="./tasks/Component/Costume/main11/main11_main_goto_town_11.png")
 	# 宠物室 
-	I_PET_HOUSE_11 = RuleImage(roi_front=(946,335,40,35), roi_back=(729,323,440,69), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main11/main11_pet_house_11.png")
+	I_PET_HOUSE_11 = RuleImage(roi_front=(966,323,29,29), roi_back=(724,295,440,69), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main11/main11_pet_house_11.png")
 
 
 	# Image Rule Assets

+ 3 - 3
tasks/Component/Costume/costume_test.py

@@ -15,12 +15,12 @@ from module.logger import logger
 class ScriptTask(GeneralBattle, GameUi, SwitchSoul, PetsAssets, ):
 
     def run(self):
-        # 探索测试
-        self.ui_click(self.I_MAIN_GOTO_EXPLORATION, self.I_CHECK_EXPLORATION)
-        self.ui_click(self.I_UI_BACK_BLUE, self.I_CHECK_MAIN)
         # 町中测试
         self.ui_click(self.I_MAIN_GOTO_TOWN, self.I_CHECK_TOWN)
         self.ui_click(self.I_TOWN_GOTO_MAIN, self.I_CHECK_MAIN)
+        # 探索测试
+        self.ui_click(self.I_MAIN_GOTO_EXPLORATION, self.I_CHECK_EXPLORATION)
+        self.ui_click(self.I_UI_BACK_BLUE, self.I_CHECK_MAIN)
         # 召唤测试
         self.ui_click(self.I_MAIN_GOTO_SUMMON, self.I_CHECK_SUMMON)
         self.ui_click(self.I_SUMMON_GOTO_MAIN, self.I_CHECK_MAIN)

+ 5 - 5
tasks/Component/Costume/main11/image.json

@@ -2,8 +2,8 @@
   {
     "itemName": "check_main_11",
     "imageName": "main11_check_main_11.png",
-    "roiFront": "680,128,83,33",
-    "roiBack": "149,109,1099,100",
+    "roiFront": "521,570,53,24",
+    "roiBack": "131,514,1099,100",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -29,7 +29,7 @@
   {
     "itemName": "main_goto_town_11",
     "imageName": "main11_main_goto_town_11.png",
-    "roiFront": "701,164,36,20",
+    "roiFront": "703,169,35,20",
     "roiBack": "262,145,999,78",
     "method": "Template matching",
     "threshold": 0.7,
@@ -38,8 +38,8 @@
   {
     "itemName": "pet_house_11",
     "imageName": "main11_pet_house_11.png",
-    "roiFront": "946,335,40,35",
-    "roiBack": "729,323,440,69",
+    "roiFront": "966,323,29,29",
+    "roiBack": "724,295,440,69",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物室"

BIN
tasks/Component/Costume/main11/main11_check_main_11.png


BIN
tasks/Component/Costume/main11/main11_main_goto_exploration_11.png


BIN
tasks/Component/Costume/main11/main11_main_goto_summon_11.png


BIN
tasks/Component/Costume/main11/main11_main_goto_town_11.png


BIN
tasks/Component/Costume/main11/main11_pet_house_11.png


+ 9 - 8
tasks/GuildBanquet/script_task.py

@@ -43,10 +43,7 @@ class ScriptTask(GameUi, GuildBanquetAssets):
         # 第二天宴会日期及时间
         self.banquet_day_2 = self.get_key_from_value(WEEKDAYDICT, self.run_time.day_2.value)
         self.banquet_day_2_start_time = self.run_time.run_time_2
-        if not self.check_runtime():
-            # 超过10点则设置下次运行时间
-            self.plan_next_run()
-            raise TaskEnd
+        
         
         self.ui_get_current_page()
         self.ui_goto(page_guild)
@@ -58,12 +55,15 @@ class ScriptTask(GameUi, GuildBanquetAssets):
             logger.info("Start guild banquet!")
             self.device.stuck_record_add('BATTLE_STATUS_S')
         else:
-            # 如果没有找到FLAG,可能是宴会时间没开始,5分钟后尝试再次查找
-            time_now = datetime.now()
-            time_later = time_now + timedelta(minutes=5)
-            self.set_next_run(task='GuildBanquet',
+            # 如果没有找到FLAG,并且没超过晚上10点,可能是宴会时间没开始,5分钟后尝试再次查找,超过10点则直接退出
+            if self.check_runtime():
+                time_now = datetime.now()
+                time_later = time_now + timedelta(minutes=5)
+                self.set_next_run(task='GuildBanquet',
                               finish=True,
                               target=time_later)
+            self.ui_get_current_page()
+            self.ui_goto(page_main)
             raise TaskEnd
 
         last_check_time = 0  # 记录上次实际检测时间
@@ -124,6 +124,7 @@ class ScriptTask(GameUi, GuildBanquetAssets):
             self.set_next_run(task="GuildBanquet", success=False)
             logger.error("Guild banquet time config error, set next run fail")
             return False
+        return True
 
     def plan_next_run(self):
         # 安排次日宴会,便于复用