Browse Source

Merge pull request #521 from runhey/dev

Dev
huangrunheng 2 years ago
parent
commit
720b6fd004
67 changed files with 1273 additions and 73 deletions
  1. 29 1
      config/template.json
  2. 2 2
      module/atom/animate.py
  3. 31 3
      module/base/filter.py
  4. 1 1
      module/config/config_manual.py
  5. 1 1
      module/config/config_menu.py
  6. 2 0
      module/config/config_model.py
  7. 5 1
      module/server/script_websocket.py
  8. BIN
      tasks/AbyssShadows/__pycache__/assets.cpython-310.pyc
  9. BIN
      tasks/AbyssShadows/__pycache__/config.cpython-310.pyc
  10. BIN
      tasks/AbyssShadows/__pycache__/script_task.cpython-310.pyc
  11. 105 0
      tasks/AbyssShadows/assets.py
  12. 23 0
      tasks/AbyssShadows/config.py
  13. 92 0
      tasks/AbyssShadows/res/click.json
  14. 209 0
      tasks/AbyssShadows/res/image.json
  15. 23 0
      tasks/AbyssShadows/res/list.json
  16. BIN
      tasks/AbyssShadows/res/res_abyss_dragon.png
  17. BIN
      tasks/AbyssShadows/res/res_abyss_fire.png
  18. BIN
      tasks/AbyssShadows/res/res_abyss_fox.png
  19. BIN
      tasks/AbyssShadows/res/res_abyss_goto_enemy.png
  20. BIN
      tasks/AbyssShadows/res/res_abyss_leopard.png
  21. BIN
      tasks/AbyssShadows/res/res_abyss_map.png
  22. BIN
      tasks/AbyssShadows/res/res_abyss_map_exit.png
  23. BIN
      tasks/AbyssShadows/res/res_abyss_navigation.png
  24. BIN
      tasks/AbyssShadows/res/res_abyss_peacock.png
  25. BIN
      tasks/AbyssShadows/res/res_abyss_shadows.png
  26. BIN
      tasks/AbyssShadows/res/res_abyss_shiki.png
  27. BIN
      tasks/AbyssShadows/res/res_change_area.png
  28. BIN
      tasks/AbyssShadows/res/res_dragon_area.png
  29. BIN
      tasks/AbyssShadows/res/res_ensure_button.png
  30. BIN
      tasks/AbyssShadows/res/res_fox_area.png
  31. BIN
      tasks/AbyssShadows/res/res_is_attack.png
  32. BIN
      tasks/AbyssShadows/res/res_leopard_area.png
  33. BIN
      tasks/AbyssShadows/res/res_open_abyss_shadows_abyss.png
  34. BIN
      tasks/AbyssShadows/res/res_peacock_area.png
  35. BIN
      tasks/AbyssShadows/res/res_ryou_shenshe.png
  36. BIN
      tasks/AbyssShadows/res/res_to_abyss_shadows.png
  37. BIN
      tasks/AbyssShadows/res/res_wait_to_start.png
  38. BIN
      tasks/AbyssShadows/res/scene_ryou.png
  39. 9 0
      tasks/AbyssShadows/res/swipe.json
  40. 470 0
      tasks/AbyssShadows/script_task.py
  41. BIN
      tasks/ActivityShikigami/as/as_battle.png
  42. BIN
      tasks/ActivityShikigami/as/as_fire.png
  43. BIN
      tasks/ActivityShikigami/as/as_shi.png
  44. 4 4
      tasks/ActivityShikigami/as/image.json
  45. 2 2
      tasks/ActivityShikigami/as/ocr.json
  46. 4 4
      tasks/ActivityShikigami/assets.py
  47. 4 4
      tasks/ActivityShikigami/script_task.py
  48. 2 0
      tasks/AreaBoss/assets.py
  49. 6 0
      tasks/AreaBoss/config_boss.py
  50. BIN
      tasks/AreaBoss/res/ab_ji_floor_ten.png
  51. 9 0
      tasks/AreaBoss/res/image.json
  52. 26 7
      tasks/AreaBoss/script_task.py
  53. 5 0
      tasks/Component/GeneralRoom/general_room.py
  54. 3 3
      tasks/Component/SwitchSoul/switch_soul.py
  55. 3 1
      tasks/Exploration/base.py
  56. 6 0
      tasks/Exploration/solo.py
  57. 1 0
      tasks/Exploration/version.py
  58. 7 0
      tasks/Hyakkiyakou/config.py
  59. 1 1
      tasks/Hyakkiyakou/script_task.py
  60. 3 2
      tasks/Hyakkiyakou/slave/hya_device.py
  61. 5 2
      tasks/Hyakkiyakou/slave/hya_slave.py
  62. 5 1
      tasks/WantedQuests/assets.py
  63. 2 0
      tasks/WantedQuests/config.py
  64. 105 0
      tasks/WantedQuests/explore.py
  65. 18 0
      tasks/WantedQuests/ocr.json
  66. 49 32
      tasks/WantedQuests/script_task.py
  67. 1 1
      tasks/WantedQuests/wq/image.json

+ 29 - 1
config/template.json

@@ -902,6 +902,33 @@
       "netherworld_group_team": "-1,-1"
     }
   },
+  "abyss_shadows": {
+    "scheduler": {
+      "enable": false,
+      "next_run": "2023-01-01 00:00:00",
+      "priority": 5,
+      "success_interval": "01 00:00:00",
+      "failure_interval": "01 00:00:00",
+      "server_update": "09:00:00",
+      "float_time": "00:00:00"
+    },
+    "general_battle_config": {
+      "lock_team_enable": false,
+      "preset_enable": false,
+      "preset_group": 1,
+      "preset_team": 1,
+      "green_enable": false,
+      "green_mark": "green_left1",
+      "random_click_swipt_enable": false
+    },
+    "switch_soul_config": {
+      "enable": false,
+      "switch_group_team": "-1,-1",
+      "enable_switch_by_name": false,
+      "group_name": "",
+      "team_name": ""
+    }
+  },
   "dokan": {
     "scheduler": {
       "enable": true,
@@ -960,5 +987,6 @@
         "random_click_swipt_enable": false
       }
     }
-  } 
+    
+  }
 }

+ 2 - 2
module/atom/animate.py

@@ -15,8 +15,8 @@ class RuleAnimate(RuleImage):
                  name: str = None):
         if isinstance(rule, RuleImage):
             roi_front = rule.roi_front
-            roi_back = Path(rule.file).stem.upper()
-            self._name = rule.file
+            roi_back = rule.roi_back
+            self._name = Path(rule.file).stem.upper()
             threshold = threshold
         elif isinstance(rule, RuleClick) or isinstance(rule, RuleLongClick):
             roi_front = rule.roi_front

+ 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)

+ 1 - 1
module/config/config_manual.py

@@ -11,7 +11,7 @@ class ConfigManual:
         Restart > SoulsTidy
         > KekkaiUtilize > KekkaiActivation > DemonEncounter
         > AreaBoss > GoldYoukai > ExperienceYoukai > Nian > Tako > RealmRaid > RyouToppa > DailyTrifles > Exploration
-        > Dokan > Hunt 
+        > Dokan > AbyssShadows > Hunt 
         > Orochi > OrochiMoans > OrochiJudgement > Sougenbi > FallenSun > EternitySea > SixRealms
         > ActivityShikigami > WantedQuests
         > BondlingFairyland > EvoZone > GoryouRealm > HeroTest

+ 1 - 1
module/config/config_menu.py

@@ -35,7 +35,7 @@ class ConfigMenu:
         ]
         # 阴阳寮
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'Dokan', 'CollectiveMissions',
-                              'Hunt']
+                              'Hunt' , 'AbyssShadows']
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         # 活动的任务

+ 2 - 0
module/config/config_model.py

@@ -45,6 +45,7 @@ from tasks.SixRealms.config import SixRealms
 from tasks.RealmRaid.config import RealmRaid
 from tasks.CollectiveMissions.config import CollectiveMissions
 from tasks.Hunt.config import Hunt
+from tasks.AbyssShadows.config import AbyssShadows
 
 # 这一部分是活动的配置-----------------------------------------------------------------------------------------------------
 from tasks.ActivityShikigami.config import ActivityShikigami
@@ -131,6 +132,7 @@ class ConfigModel(ConfigBase):
     collective_missions: CollectiveMissions = Field(default_factory=CollectiveMissions)
     hunt: Hunt = Field(default_factory=Hunt)
     dokan: Dokan = Field(default_factory=Dokan)
+    abyss_shadows: AbyssShadows = Field(default_factory=AbyssShadows)
 
     # @validator('script')
     # def script_validator(cls, v):

+ 5 - 1
module/server/script_websocket.py

@@ -30,7 +30,11 @@ class ScriptWSManager:
     async def broadcast_log(self, log: str):
         # 广播日志
         for connection in self.active_connections:
-            await connection.send_text(log)
+            try:
+                await connection.send_text(log)
+            except RuntimeError as e:
+                print(e)
+                self.active_connections.remove(connection)
 
 
 

BIN
tasks/AbyssShadows/__pycache__/assets.cpython-310.pyc


BIN
tasks/AbyssShadows/__pycache__/config.cpython-310.pyc


BIN
tasks/AbyssShadows/__pycache__/script_task.cpython-310.pyc


+ 105 - 0
tasks/AbyssShadows/assets.py

@@ -0,0 +1,105 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.atom.list import RuleList
+
+# This file was automatically generated by ./dev_tools/assets_extract.py.
+# Don't modify it manually.
+class AbyssShadowsAssets: 
+
+
+	# Click Rule Assets
+	# 首领 
+	C_BOSS_CLICK_AREA = RuleClick(roi_front=(679,164,83,54), roi_back=(679,164,83,54), name="boss_click_area")
+	# 副将1 
+	C_GENERAL_1_CLICK_AREA = RuleClick(roi_front=(539,306,64,56), roi_back=(539,306,64,56), name="general_1_click_area")
+	# 副将2 
+	C_GENERAL_2_CLICK_AREA = RuleClick(roi_front=(856,293,58,50), roi_back=(856,293,58,50), name="general_2_click_area")
+	# 精英1 
+	C_ELITE_1_CLICK_AREA = RuleClick(roi_front=(453,418,54,45), roi_back=(453,418,54,45), name="elite_1_click_area")
+	# 精英2 
+	C_ELITE_2_CLICK_AREA = RuleClick(roi_front=(694,420,58,44), roi_back=(694,420,58,44), name="elite_2_click_area")
+	# 精英3 
+	C_ELITE_3_CLICK_AREA = RuleClick(roi_front=(938,413,60,44), roi_back=(938,413,60,44), name="elite_3_click_area")
+	# 前往阵眼 
+	C_CHANGE_ZONE = RuleClick(roi_front=(1000,606,54,54), roi_back=(1000,606,54,54), name="change_zone")
+	# 神龙暗域 
+	C_DRAGON_AREA = RuleClick(roi_front=(123,150,75,66), roi_back=(123,150,75,66), name="dragon_area")
+	# 孔雀暗域 
+	C_PEACOCK_AREA = RuleClick(roi_front=(125,278,74,62), roi_back=(125,278,74,62), name="peacock_area")
+	# 白藏主暗域 
+	C_FOX_AREA = RuleClick(roi_front=(126,409,79,74), roi_back=(126,409,79,74), name="fox_area")
+	# 黑豹暗域 
+	C_LEOPARD_AREA = RuleClick(roi_front=(122,537,81,76), roi_back=(122,537,81,76), name="leopard_area")
+	# 狭间_神龙入口 
+	C_ABYSS_DRAGON = RuleClick(roi_front=(232.5,196,55,151), roi_back=(190,147,140,283), name="abyss_dragon")
+	# 狭间_孔雀入口 
+	C_ABYSS_PEACOCK = RuleClick(roi_front=(526,189,48,165), roi_back=(476,138,145,312), name="abyss_peacock")
+	# 狭间_白藏主入口 
+	C_ABYSS_FOX = RuleClick(roi_front=(822,184,49,144), roi_back=(789,130,148,249), name="abyss_fox")
+	# 狭间_黑豹入口 
+	C_ABYSS_LEOPARD = RuleClick(roi_front=(1140,190,50,162), roi_back=(1093,143,138,297), name="abyss_leopard")
+
+
+	# Image Rule Assets
+	# 阴阳竂->神社 
+	I_RYOU_SHENSHE = RuleImage(roi_front=(872,659,62,25), roi_back=(872,659,62,25), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_ryou_shenshe.png")
+	# 神社->狭间暗域 
+	I_RYOU_ABYSS_SHADOWS = RuleImage(roi_front=(707,492,110,27), roi_back=(707,492,110,27), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_ryou_abyss_shadows.png")
+	# 狭间_神龙入口 
+	I_ABYSS_DRAGON = RuleImage(roi_front=(227,211,55,151), roi_back=(190,147,140,283), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_dragon.png")
+	# 狭间_孔雀入口 
+	I_ABYSS_PEACOCK = RuleImage(roi_front=(521,152,48,165), roi_back=(465,104,145,312), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_peacock.png")
+	# 狭间_白藏主入口 
+	I_ABYSS_FOX = RuleImage(roi_front=(815,174,49,144), roi_back=(789,130,148,249), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_fox.png")
+	# 狭间_黑豹入口 
+	I_ABYSS_LEOPARD = RuleImage(roi_front=(1142,166,50,162), roi_back=(1093,143,138,297), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_leopard.png")
+	# 战报 
+	I_ABYSS_NAVIGATION = RuleImage(roi_front=(1200,372,50,44), roi_back=(1200,372,50,44), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_navigation.png")
+	# 式神录 
+	I_ABYSS_SHIKI = RuleImage(roi_front=(1199,462,47,53), roi_back=(1199,462,47,53), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_shiki.png")
+	# 狭间暗域 
+	I_ABYSS_SHADOWS = RuleImage(roi_front=(711,489,107,38), roi_back=(711,489,107,38), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_shadows.png")
+	# 开启狭间暗域 
+	I_OPEN_ABYSS_SHADOWS = RuleImage(roi_front=(1133,602,74,58), roi_back=(1133,602,74,58), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_open_abyss_shadows.png")
+	# 战报页面 
+	I_ABYSS_MAP = RuleImage(roi_front=(306,147,170,48), roi_back=(306,147,170,48), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_map.png")
+	# 战报退出按钮 
+	I_ABYSS_MAP_EXIT = RuleImage(roi_front=(1154,96,32,32), roi_back=(1154,96,32,32), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_map_exit.png")
+	# 挑战按钮 
+	I_ABYSS_FIRE = RuleImage(roi_front=(1121,605,77,50), roi_back=(1121,605,77,50), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_abyss_fire.png")
+	# 前往 
+	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")
+	# description 
+	I_PEACOCK_AREA = RuleImage(roi_front=(577,14,127,36), roi_back=(577,14,127,36), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_peacock_area.png")
+	# 黑豹领域 
+	I_LEOPARD_AREA = RuleImage(roi_front=(589,13,104,39), roi_back=(589,13,104,39), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_leopard_area.png")
+	# 白藏主领域 
+	I_FOX_AREA = RuleImage(roi_front=(581,18,121,29), roi_back=(581,18,121,29), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_fox_area.png")
+	# 更换领域 
+	I_CHANGE_AREA = RuleImage(roi_front=(511,20,27,27), roi_back=(511,20,27,27), threshold=0.8, method="Template matching", file="./tasks/AbyssShadows/res/res_change_area.png")
+	# 神龙领域 
+	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")
+
+
+	# List Rule Assets
+	# 这个是当前活跃的竂活动列表界面 
+	L_RYOU_ACTIVITY_LIST = RuleList(folder="./tasks/AbyssShadows/res", direction="vertical", mode="ocr", roi_back=(35,157,37,250), size=(42, 27), 
+					 array=["道馆", "首领", "狭间"])
+
+
+	# Swipe Rule Assets
+	# 滑到狭间 
+	S_TO_ABBSY_SHADOWS = RuleSwipe(roi_front=(752,395,62,66), roi_back=(758,193,62,48), mode="default", name="to_abbsy_shadows")
+
+

+ 23 - 0
tasks/AbyssShadows/config.py

@@ -0,0 +1,23 @@
+# This Python file uses the following encoding: utf-8
+# @brief    Configurations for Ryou Dokan Toppa (阴阳竂道馆突破配置)
+# @author   jackyhwei
+# @note     draft version without full test
+# github    https://github.com/roarhill/oas
+
+from pydantic import BaseModel, Field
+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
+from tasks.Component.config_scheduler import Scheduler
+
+class AbyssShadowsTime(ConfigBase):
+    # 自定义运行时间
+    custom_run_time_friday: Time = Field(default=Time(hour=19, minute=0, second=0))
+    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 AbyssShadows(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    abyss_shadows_time: AbyssShadowsTime = Field(default_factory=AbyssShadowsTime)
+    general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

+ 92 - 0
tasks/AbyssShadows/res/click.json

@@ -0,0 +1,92 @@
+[
+  {
+    "itemName": "boss_click_area",
+    "roiFront": "679,164,83,54",
+    "roiBack": "679,164,83,54",
+    "description": "首领"
+  },
+  {
+    "itemName": "general_1_click_area",
+    "roiFront": "539,306,64,56",
+    "roiBack": "539,306,64,56",
+    "description": "副将1"
+  },
+  {
+    "itemName": "general_2_click_area",
+    "roiFront": "856,293,58,50",
+    "roiBack": "856,293,58,50",
+    "description": "副将2"
+  },
+  {
+    "itemName": "elite_1_click_area",
+    "roiFront": "453,418,54,45",
+    "roiBack": "453,418,54,45",
+    "description": "精英1"
+  },
+  {
+    "itemName": "elite_2_click_area",
+    "roiFront": "694,420,58,44",
+    "roiBack": "694,420,58,44",
+    "description": "精英2"
+  },
+  {
+    "itemName": "elite_3_click_area",
+    "roiFront": "938,413,60,44",
+    "roiBack": "938,413,60,44",
+    "description": "精英3"
+  },
+  {
+    "itemName": "change_zone",
+    "roiFront": "1000,606,54,54",
+    "roiBack": "1000,606,54,54",
+    "description": "前往阵眼"
+  },
+  {
+    "itemName": "dragon_area",
+    "roiFront": "123,150,75,66",
+    "roiBack": "123,150,75,66",
+    "description": "神龙暗域"
+  },
+  {
+    "itemName": "peacock_area",
+    "roiFront": "125,278,74,62",
+    "roiBack": "125,278,74,62",
+    "description": "孔雀暗域"
+  },
+  {
+    "itemName": "fox_area",
+    "roiFront": "126,409,79,74",
+    "roiBack": "126,409,79,74",
+    "description": "白藏主暗域"
+  },
+  {
+    "itemName": "leopard_area",
+    "roiFront": "122,537,81,76",
+    "roiBack": "122,537,81,76",
+    "description": "黑豹暗域"
+  },
+  {
+    "itemName": "abyss_dragon",
+    "roiFront": "232.5,196,55,151",
+    "roiBack": "190,147,140,283",
+    "description": "狭间_神龙入口"
+  },
+  {
+    "itemName": "abyss_peacock",
+    "roiFront": "526,189,48,165",
+    "roiBack": "476,138,145,312",
+    "description": "狭间_孔雀入口"
+  },
+  {
+    "itemName": "abyss_fox",
+    "roiFront": "822,184,49,144",
+    "roiBack": "789,130,148,249",
+    "description": "狭间_白藏主入口"
+  },
+  {
+    "itemName": "abyss_leopard",
+    "roiFront": "1140,190,50,162",
+    "roiBack": "1093,143,138,297",
+    "description": "狭间_黑豹入口"
+  }
+]

+ 209 - 0
tasks/AbyssShadows/res/image.json

@@ -0,0 +1,209 @@
+[
+  {
+    "itemName": "ryou_shenshe",
+    "imageName": "res_ryou_shenshe.png",
+    "roiFront": "872,659,62,25",
+    "roiBack": "872,659,62,25",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "阴阳竂->神社"
+  },
+  {
+    "itemName": "ryou_abyss_shadows",
+    "imageName": "res_ryou_abyss_shadows.png",
+    "roiFront": "707,492,110,27",
+    "roiBack": "707,492,110,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "神社->狭间暗域"
+  },
+  {
+    "itemName": "abyss_dragon",
+    "imageName": "res_abyss_dragon.png",
+    "roiFront": "227,211,55,151",
+    "roiBack": "190,147,140,283",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_神龙入口"
+  },
+  {
+    "itemName": "abyss_peacock",
+    "imageName": "res_abyss_peacock.png",
+    "roiFront": "521,152,48,165",
+    "roiBack": "465,104,145,312",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_孔雀入口"
+  },
+  {
+    "itemName": "abyss_fox",
+    "imageName": "res_abyss_fox.png",
+    "roiFront": "815,174,49,144",
+    "roiBack": "789,130,148,249",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_白藏主入口"
+  },
+  {
+    "itemName": "abyss_leopard",
+    "imageName": "res_abyss_leopard.png",
+    "roiFront": "1142,166,50,162",
+    "roiBack": "1093,143,138,297",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间_黑豹入口"
+  },
+  {
+    "itemName": "abyss_navigation",
+    "imageName": "res_abyss_navigation.png",
+    "roiFront": "1200,372,50,44",
+    "roiBack": "1200,372,50,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战报"
+  },
+  {
+    "itemName": "abyss_shiki",
+    "imageName": "res_abyss_shiki.png",
+    "roiFront": "1199,462,47,53",
+    "roiBack": "1199,462,47,53",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "式神录"
+  },
+  {
+    "itemName": "abyss_shadows",
+    "imageName": "res_abyss_shadows.png",
+    "roiFront": "711,489,107,38",
+    "roiBack": "711,489,107,38",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "狭间暗域"
+  },
+  {
+    "itemName": "open_abyss_shadows",
+    "imageName": "res_open_abyss_shadows.png",
+    "roiFront": "1133,602,74,58",
+    "roiBack": "1133,602,74,58",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "开启狭间暗域"
+  },
+  {
+    "itemName": "abyss_map",
+    "imageName": "res_abyss_map.png",
+    "roiFront": "306,147,170,48",
+    "roiBack": "306,147,170,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战报页面"
+  },
+  {
+    "itemName": "abyss_map_exit",
+    "imageName": "res_abyss_map_exit.png",
+    "roiFront": "1154,96,32,32",
+    "roiBack": "1154,96,32,32",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战报退出按钮"
+  },
+  {
+    "itemName": "abyss_fire",
+    "imageName": "res_abyss_fire.png",
+    "roiFront": "1121,605,77,50",
+    "roiBack": "1121,605,77,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "挑战按钮"
+  },
+  {
+    "itemName": "abyss_goto_enemy",
+    "imageName": "res_abyss_goto_enemy.png",
+    "roiFront": "1120,610,75,45",
+    "roiBack": "1120,610,75,45",
+    "method": "Template matching",
+    "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",
+    "roiFront": "672,405,169,55",
+    "roiBack": "672,405,169,55",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "is_attack",
+    "imageName": "res_is_attack.png",
+    "roiFront": "586,62,73,27",
+    "roiBack": "586,62,73,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进攻中"
+  },
+  {
+    "itemName": "peacock_area",
+    "imageName": "res_peacock_area.png",
+    "roiFront": "577,14,127,36",
+    "roiBack": "577,14,127,36",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "leopard_area",
+    "imageName": "res_leopard_area.png",
+    "roiFront": "589,13,104,39",
+    "roiBack": "589,13,104,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "黑豹领域"
+  },
+  {
+    "itemName": "fox_area",
+    "imageName": "res_fox_area.png",
+    "roiFront": "581,18,121,29",
+    "roiBack": "581,18,121,29",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "白藏主领域"
+  },
+  {
+    "itemName": "change_area",
+    "imageName": "res_change_area.png",
+    "roiFront": "511,20,27,27",
+    "roiBack": "511,20,27,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "更换领域"
+  },
+  {
+    "itemName": "dragon_area",
+    "imageName": "res_dragon_area.png",
+    "roiFront": "584,15,111,34",
+    "roiBack": "584,15,111,34",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "神龙领域"
+  },
+  {
+    "itemName": "wait_to_start",
+    "imageName": "res_wait_to_start.png",
+    "roiFront": "588,64,70,26",
+    "roiBack": "588,64,70,26",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 23 - 0
tasks/AbyssShadows/res/list.json

@@ -0,0 +1,23 @@
+{
+    "name": "ryou_activity_list",
+    "direction": "vertical",
+    "type": "ocr",
+    "roiBack": "35,157,37,250",
+    "description": "这个是当前活跃的竂活动列表界面",
+    "list": [
+      {
+        "itemName": "道馆",
+        "roiFront": "33,253,42,26"
+      },
+      {
+        "itemName": "首领",
+        "roiFront": "34,433,43,28",
+        "description": "首领退治"
+      },
+      {
+        "itemName": "狭间",
+        "roiFront": "34,523,43,28",
+        "description": "狭间暗域"
+      }
+    ]
+  }

BIN
tasks/AbyssShadows/res/res_abyss_dragon.png


BIN
tasks/AbyssShadows/res/res_abyss_fire.png


BIN
tasks/AbyssShadows/res/res_abyss_fox.png


BIN
tasks/AbyssShadows/res/res_abyss_goto_enemy.png


BIN
tasks/AbyssShadows/res/res_abyss_leopard.png


BIN
tasks/AbyssShadows/res/res_abyss_map.png


BIN
tasks/AbyssShadows/res/res_abyss_map_exit.png


BIN
tasks/AbyssShadows/res/res_abyss_navigation.png


BIN
tasks/AbyssShadows/res/res_abyss_peacock.png


BIN
tasks/AbyssShadows/res/res_abyss_shadows.png


BIN
tasks/AbyssShadows/res/res_abyss_shiki.png


BIN
tasks/AbyssShadows/res/res_change_area.png


BIN
tasks/AbyssShadows/res/res_dragon_area.png


BIN
tasks/AbyssShadows/res/res_ensure_button.png


BIN
tasks/AbyssShadows/res/res_fox_area.png


BIN
tasks/AbyssShadows/res/res_is_attack.png


BIN
tasks/AbyssShadows/res/res_leopard_area.png


BIN
tasks/AbyssShadows/res/res_open_abyss_shadows_abyss.png


BIN
tasks/AbyssShadows/res/res_peacock_area.png


BIN
tasks/AbyssShadows/res/res_ryou_shenshe.png


BIN
tasks/AbyssShadows/res/res_to_abyss_shadows.png


BIN
tasks/AbyssShadows/res/res_wait_to_start.png


BIN
tasks/AbyssShadows/res/scene_ryou.png


+ 9 - 0
tasks/AbyssShadows/res/swipe.json

@@ -0,0 +1,9 @@
+[
+  {
+    "itemName": "to_abbsy_shadows",
+    "roiFront": "752,395,62,66",
+    "roiBack": "758,193,62,48",
+    "mode": "default",
+    "description": "滑到狭间"
+  }
+]

+ 470 - 0
tasks/AbyssShadows/script_task.py

@@ -0,0 +1,470 @@
+# This Python file uses the following encoding: utf-8
+# @brief    Ryou Dokan Toppa (阴阳竂道馆突破功能)
+# @author   jackyhwei
+# @note     draft version without full test
+# github    https://github.com/roarhill/oas
+
+from datetime import datetime, timedelta
+import random
+import numpy as np
+from enum import Enum
+from cached_property import cached_property
+from time import sleep
+
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.config_base import ConfigBase, Time
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_kekkai_toppa, page_shikigami_records, page_guild
+from tasks.RealmRaid.assets import RealmRaidAssets
+
+from module.logger import logger
+from module.exception import TaskEnd
+from module.atom.image_grid import ImageGrid
+from module.base.utils import point2str
+from module.base.timer import Timer
+from module.exception import GamePageUnknownError
+from pathlib import Path
+from tasks.AbyssShadows.config import AbyssShadows
+from tasks.AbyssShadows.assets import AbyssShadowsAssets
+
+class AreaType:
+    """ 暗域类型 """
+    DRAGON = AbyssShadowsAssets.I_ABYSS_DRAGON  # 神龙暗域
+    PEACOCK = AbyssShadowsAssets.I_ABYSS_PEACOCK  # 孔雀暗域
+    FOX = AbyssShadowsAssets.I_ABYSS_FOX  # 白藏主暗域
+    LEOPARD = AbyssShadowsAssets.I_ABYSS_LEOPARD # 黑豹暗域
+
+    @cached_property
+    def name(self) -> str:
+        """
+
+        :return:
+        """
+        return Path(self.file).stem.upper()
+
+    def __str__(self):
+        return self.name
+
+    __repr__ = __str__
+
+class EmemyType(Enum):
+
+    """ 敌人类型 """
+    BOSS = 1  #  首领
+    GENERAL = 2  #  副将
+    ELITE = 3  #  精英
+
+
+class CilckArea:
+    """ 点击区域 """
+    GENERAL_1 = AbyssShadowsAssets.C_GENERAL_1_CLICK_AREA
+    GENERAL_2 = AbyssShadowsAssets.C_GENERAL_2_CLICK_AREA
+    ELITE_1 = AbyssShadowsAssets.C_ELITE_1_CLICK_AREA
+    ELITE_2 = AbyssShadowsAssets.C_ELITE_2_CLICK_AREA
+    ELITE_3 = AbyssShadowsAssets.C_ELITE_3_CLICK_AREA
+    BOSS= AbyssShadowsAssets.C_BOSS_CLICK_AREA
+
+    @cached_property
+    def name(self) -> str:
+        """
+
+        :return:
+        """
+        return Path(self.file).stem.upper()
+
+    def __str__(self):
+        return self.name
+
+    __repr__ = __str__
+
+
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
+    
+
+    boss_fight_count = 0  # 首领战斗次数
+    general_fight_count = 0  # 副将战斗次数
+    elite_fight_count = 0  # 精英战斗次数
+    
+    def run(self):
+        """ 狭间暗域主函数
+
+        :return:
+        """
+        cfg: AbyssShadows = self.config.abyss_shadows
+
+        if cfg.switch_soul_config.enable:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
+        if cfg.switch_soul_config.enable_switch_by_name:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
+        today = datetime.now().weekday()
+        if today not in [4, 5, 6]:
+            logger.info(f"Today is not abyss shadows day, exit")
+            self.set_next_run(task='AbyssShadows', finish=False, server=True, success=False)
+            raise TaskEnd
+        success = True
+        # 进入狭间
+        self.goto_abyss_shadows()
+        # 第一次默认选择神龙暗域
+        if not self.select_boss(AreaType.DRAGON):
+            logger.warning("Failed to enter abyss shadows")
+            self.goto_main()
+            self.set_next_run(task='AbyssShadows', finish=False, server=True, success=False)
+            raise TaskEnd
+        
+        # 等待可进攻时间  
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        # 集结中图片
+        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")
+                    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:
+                    logger.warning("All enemy types have been defeated, but not enough emeny to fight, exit")
+                    break
+        
+
+        # 保持好习惯,一个任务结束了就返回到庭院,方便下一任务的开始
+        self.goto_main()
+
+        # 设置下次运行时间
+        if success:
+            custom_time = None
+            if today == 4:
+                # 周五推迟到周六
+                logger.info(f"The next abyss shadows day is Saturday")
+                custom_time = cfg.abyss_shadows_time.custom_run_time_saturday
+                target_time = (datetime.now() + timedelta(days=1)).replace(hour=custom_time.hour, minute=custom_time.minute, second=custom_time.second)
+            elif today == 5:
+                # 周六推迟到周日
+                logger.info(f"The next abyss shadows day is Sunday")
+                custom_time = cfg.abyss_shadows_time.custom_run_time_sunday
+                target_time = (datetime.now() + timedelta(days=1)).replace(hour=custom_time.hour, minute=custom_time.minute, second=custom_time.second)
+            elif today == 6:
+                # 周日推迟到下周五
+                logger.info(f"The next abyss shadows day is Friday")
+                custom_time = cfg.abyss_shadows_time.custom_run_time_friday
+                target_time = (datetime.now() + timedelta(days=5)).replace(hour=custom_time.hour, minute=custom_time.minute, second=custom_time.second)
+            self.set_next_run(task='AbyssShadows', target=target_time)
+        else:
+            self.set_next_run(task='AbyssShadows', finish=True, server=True, success=False)
+        raise TaskEnd
+
+    def check_current_area(self) -> AreaType:
+        ''' 获取当前区域
+        :return AreaType
+        '''
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_PEACOCK_AREA):
+                return AreaType.PEACOCK
+            elif self.appear(self.I_DRAGON_AREA):
+                return AreaType.DRAGON
+            elif self.appear(self.I_FOX_AREA):
+                return AreaType.FOX
+            elif self.appear(self.I_LEOPARD_AREA):
+                return AreaType.LEOPARD
+            else:
+                continue
+
+    def change_area(self, area_name: AreaType) -> bool:
+        ''' 切换到下个区域
+        :return 
+        '''
+        while 1:
+            self.screenshot()
+            # 判断当前区域是否正确
+            current_area = self.check_current_area()
+            if current_area == area_name:
+                break
+            # 切换区域界面
+            if self.appear(self.I_ABYSS_DRAGON):
+                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
+                  
+        return True
+    
+    def goto_main(self):
+        ''' 保持好习惯,一个任务结束了就返回庭院,方便下一任务的开始或者是出错重启
+        '''
+        self.ui_get_current_page()
+        logger.info("Exiting abyss_shadows")
+        self.ui_goto(page_main)
+
+       
+
+    def goto_abyss_shadows(self) -> bool:
+        ''' 进入狭间
+        :return bool
+        '''
+        self.ui_get_current_page()
+        logger.info("Entering abyss_shadows")
+        self.ui_goto(page_guild)
+        
+        while 1:
+            self.screenshot()
+            # 进入神社
+            if self.appear_then_click(self.I_RYOU_SHENSHE,interval=1):
+                logger.info("Enter Shenshe")
+                continue
+            # 查找狭间
+            if not self.appear(self.I_ABYSS_SHADOWS, threshold=0.8):
+                self.swipe(self.S_TO_ABBSY_SHADOWS,interval=3)
+                continue
+            # 进入狭间
+            if self.appear_then_click(self.I_ABYSS_SHADOWS):
+                logger.info("Enter abyss_shadows")
+                break
+        return True
+ 
+    def select_boss(self, area_name: AreaType) -> bool:
+        ''' 选择暗域类型
+        :return 
+        '''
+        click_times = 0
+        while 1:
+            self.screenshot()
+            # 区域图片与入口图片不一致,使用点击进去
+            
+            if self.appear(self.I_ABYSS_DRAGON):
+                match area_name:
+                    case AreaType.DRAGON: is_click = self.click(self.C_ABYSS_DRAGON,interval=2)
+                    case AreaType.PEACOCK: is_click = self.click(self.C_ABYSS_PEACOCK,interval=2)
+                    case AreaType.FOX: is_click = self.click(self.C_ABYSS_FOX,interval=2)
+                    case AreaType.LEOPARD: is_click = self.click(self.C_ABYSS_LEOPARD,interval=2)
+                if is_click:
+                    click_times += 1
+                    logger.info(f"Click {area_name.name} {click_times} times")
+                if click_times >= 3:
+                    logger.info(f"select boss: {area_name.name} failed")
+                    return False
+                continue
+            if self.appear(self.I_ABYSS_NAVIGATION):
+                break
+        return True
+
+    def find_enemy(self, enemy_type: EmemyType) -> bool:
+        ''' 寻找敌人,并开始寻路进入战斗
+        :return 是否找到敌人,若目标已死亡则返回False,否则返回True
+        True 找到敌人,并已经战斗完成
+        '''
+        print(f"Find enemy: {enemy_type}")
+        while 1:
+            self.screenshot()
+            # 点击战报按钮
+            if self.appear(self.I_ABYSS_MAP):
+                break
+            if self.appear_then_click(self.I_ABYSS_NAVIGATION,interval=1):
+                continue
+ 
+        match enemy_type:
+            case EmemyType.BOSS: success = self.run_boss_fight()
+            case EmemyType.GENERAL: success = self.run_general_fight()
+            case EmemyType.ELITE: success = self.run_elite_fight()
+            
+        return success    
+
+    def run_boss_fight(self) -> bool:
+        ''' 首领战斗
+        只要进入了战斗都返回成功
+        :return 
+        '''
+        if self.boss_fight_count >= 2:
+            logger.info(f"boss fight count {self.boss_fight_count} times, skip")
+            return True
+        success = True
+        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.boss_fight_count += 1
+            logger.info(f'Fight, boss_fight_count {self.boss_fight_count} times')
+        else:
+            success = False
+        return success
+
+    def run_general_fight(self) -> bool:
+        ''' 副将战斗
+        :return 
+        '''
+        general_list = [CilckArea.GENERAL_1, CilckArea.GENERAL_2]
+        logger.info(f"Run general fight") 
+        for general in general_list:
+            # 副将战斗次数达到4个时,退出循环
+            if self.general_fight_count >= 4:
+                logger.info(f"general fight count {self.general_fight_count} times, skip")
+                break
+            if self.click_emeny_area(general):
+                logger.info(f"Click {general.name}")
+                self.general_fight_count += 1
+                self.run_general_battle_back()
+                logger.info(f'Fight, general_fight_count {self.general_fight_count} times')
+        return True
+
+
+    def run_elite_fight(self) -> bool:
+        ''' 精英战斗
+        :return 
+        '''
+        elite_list = [CilckArea.ELITE_1, CilckArea.ELITE_2, CilckArea.ELITE_3]
+        logger.info(f"Run elite fight")  
+        for elite in elite_list:
+            # 精英战斗次数达到6个时,退出循环
+            if self.elite_fight_count >= 6:
+                logger.info(f"Elite fight count {self.elite_fight_count} times, skip")
+                break
+            if self.click_emeny_area(elite):
+                logger.info(f"Click {elite.name}")
+                self.elite_fight_count += 1
+                self.run_general_battle_back()
+                logger.info(f'Fight, elite_fight_count {self.elite_fight_count} times')
+        return True
+
+    def click_emeny_area(self, click_area: CilckArea) -> bool:
+        suceess = True
+        ''' 点击敌人区域
+        
+        :return 
+        '''
+        logger.info(f"Click emeny area: {click_area.name}")
+        # 点击战报
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_ABYSS_NAVIGATION, interval=1.5):
+                logger.info(f"Click {self.I_ABYSS_NAVIGATION.name}")
+                continue
+            if self.appear(self.I_ABYSS_MAP):
+                logger.info(f"Find abyss map, exit")
+                break
+        click_times = 0
+        # 点击攻打区域
+        while 1:
+            self.screenshot()
+            
+            # 如果点3次还没进去就表示目标已死亡,跳过
+            if click_times >= 3:
+                logger.warning(f"Failed to click {click_area}")
+                return 
+            # 出现前往按钮就退出
+            if self.appear(self.I_ABYSS_GOTO_ENEMY):
+                break
+            if self.click(click_area,interval=1.5):
+                click_times += 1
+                continue
+            if self.appear_then_click(self.I_ENSURE_BUTTON,interval=1):
+                continue
+            # TODO 有时出现bug,点了前往之后不动,需要再点一次,带解决
+
+        
+        # 点击前往按钮
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_ABYSS_GOTO_ENEMY,interval=1):
+                # 点击敌人后,如果是不同区域会确认框,点击确认                
+                if self.appear_then_click(self.I_ENSURE_BUTTON, interval=1):
+                    logger.info(f"Click {self.I_ENSURE_BUTTON.name}")
+                # 跑动画比较花时间
+                sleep(3)
+                continue
+            if self.appear(self.I_ABYSS_FIRE):
+                break
+        logger.info(f"Click {self.I_ABYSS_GOTO_ENEMY.name}")
+        
+        # 点击战斗按钮
+        self.wait_until_appear(self.I_ABYSS_FIRE)
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_ABYSS_FIRE,interval=1):
+                  
+                logger.info(f"Click {self.I_ABYSS_FIRE.name}")        
+                # 挑战敌人后,如果是奖励次数上限,会出现确认框   
+                if self.appear_then_click(self.I_ENSURE_BUTTON, interval=1):
+                    logger.info(f"Click {self.I_ENSURE_BUTTON.name}")
+                continue
+            if self.appear(self.I_PREPARE_HIGHLIGHT):
+                break
+            
+        return suceess
+
+    def run_general_battle_back(self) -> bool:
+        """
+        重写父类方法,因为狭间暗域的准备和战斗流程不一样
+        进入挑战然后直接返回
+        :param config:
+        :return:
+        """
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
+                continue
+            if not self.appear(self.I_PRESET):
+                break
+        logger.info(f"Click {self.I_PREPARE_HIGHLIGHT.name}")
+
+        # 点击返回
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXIT, interval=1.5):
+                continue
+            if self.appear(self.I_EXIT_ENSURE):
+                break
+        logger.info(f"Click {self.I_EXIT.name}")
+
+        # 点击返回确认
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_WIN, interval=1.5):
+                continue
+            if self.appear(self.I_ABYSS_NAVIGATION):
+                break
+        logger.info(f"Click {self.I_EXIT_ENSURE.name}")
+
+        return True
+
+
+
+if __name__ == "__main__":
+    from module.config.config import Config
+    from module.device.device import Device
+
+    config = Config('zhu')
+    device = Device(config)
+    t = ScriptTask(config, device)
+    t.run()

BIN
tasks/ActivityShikigami/as/as_battle.png


BIN
tasks/ActivityShikigami/as/as_fire.png


BIN
tasks/ActivityShikigami/as/as_shi.png


+ 4 - 4
tasks/ActivityShikigami/as/image.json

@@ -2,7 +2,7 @@
   {
     "itemName": "shi",
     "imageName": "as_shi.png",
-    "roiFront": "524,205,33,34",
+    "roiFront": "545,254,33,34",
     "roiBack": "64,115,1110,427",
     "method": "Template matching",
     "threshold": 0.7,
@@ -20,8 +20,8 @@
   {
     "itemName": "battle",
     "imageName": "as_battle.png",
-    "roiFront": "290,209,35,145",
-    "roiBack": "248,146,138,315",
+    "roiFront": "1080,229,35,145",
+    "roiBack": "1028,155,138,315",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "进入爬塔"
@@ -56,7 +56,7 @@
   {
     "itemName": "fire",
     "imageName": "as_fire.png",
-    "roiFront": "1134,587,84,78",
+    "roiFront": "1134,579,84,78",
     "roiBack": "1107,522,142,174",
     "method": "Template matching",
     "threshold": 0.8,

+ 2 - 2
tasks/ActivityShikigami/as/ocr.json

@@ -1,8 +1,8 @@
 [
   {
     "itemName": "remain_ap",
-    "roiFront": "1155,668,87,25",
-    "roiBack": "1155,668,87,25",
+    "roiFront": "1150,673,88,25",
+    "roiBack": "1150,673,88,25",
     "mode": "DigitCounter",
     "method": "Default",
     "keyword": "",

+ 4 - 4
tasks/ActivityShikigami/assets.py

@@ -34,11 +34,11 @@ class ActivityShikigamiAssets:
 
 	# Image Rule Assets
 	# 进入活动 
-	I_SHI = RuleImage(roi_front=(524,205,33,34), roi_back=(64,115,1110,427), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_shi.png")
+	I_SHI = RuleImage(roi_front=(545,254,33,34), roi_back=(64,115,1110,427), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_shi.png")
 	# 左上角返回 
 	I_BACK_GREEN = RuleImage(roi_front=(23,27,44,44), roi_back=(23,27,44,44), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_back_green.png")
 	# 进入爬塔 
-	I_BATTLE = RuleImage(roi_front=(290,209,35,145), roi_back=(248,146,138,315), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_battle.png")
+	I_BATTLE = RuleImage(roi_front=(1080,229,35,145), roi_back=(1028,155,138,315), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_battle.png")
 	# 归鹿之途 
 	I_DRUM = RuleImage(roi_front=(885,310,29,145), roi_back=(860,244,87,232), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_drum.png")
 	# 上锁图标 
@@ -46,7 +46,7 @@ class ActivityShikigamiAssets:
 	# 还未上锁图片 
 	I_UNLOCK = RuleImage(roi_front=(823,654,28,28), roi_back=(776,610,112,87), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_unlock.png")
 	# 点击战斗 
-	I_FIRE = RuleImage(roi_front=(1134,587,84,78), roi_back=(1107,522,142,174), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_fire.png")
+	I_FIRE = RuleImage(roi_front=(1134,579,84,78), roi_back=(1107,522,142,174), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_fire.png")
 	# 体力按钮 
 	I_AP = RuleImage(roi_front=(1127,509,23,24), roi_back=(1092,487,103,71), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_ap.png")
 	# 活动体力 
@@ -63,7 +63,7 @@ class ActivityShikigamiAssets:
 
 	# Ocr Rule Assets
 	# 体力的数量检测 
-	O_REMAIN_AP = RuleOcr(roi=(1155,668,87,25), area=(1155,668,87,25), mode="DigitCounter", method="Default", keyword="", name="remain_ap")
+	O_REMAIN_AP = RuleOcr(roi=(1150,673,88,25), area=(1150,673,88,25), mode="DigitCounter", method="Default", keyword="", name="remain_ap")
 	# 活动体力的剩余检测 
 	O_REMAIN_AP_ACTIVITY = RuleOcr(roi=(909,25,95,30), area=(909,25,95,30), mode="DigitCounter", method="Default", keyword="", name="remain_ap_activity")
 	# 还有多少次购买体力的机会 

+ 4 - 4
tasks/ActivityShikigami/script_task.py

@@ -46,12 +46,12 @@ class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
         self.ui_goto(page_main)
         self.home_main()
 
-        # # 2024-04-04 ---------------------start
-        # config.general_climb.ap_mode = ApMode.AP_GAME
-        # # 2024-04-04 ---------------------end
+        # # 2024-11-06 ---------------------start
+        config.general_climb.ap_mode = ApMode.AP_GAME
         # 选择是游戏的体力还是活动的体力
         current_ap = config.general_climb.ap_mode
-        self.switch(current_ap)
+        # self.switch(current_ap)
+        # # 2024-11-06 ---------------------end
 
         # 设定是否锁定阵容
         if config.general_battle.lock_team_enable:

+ 2 - 0
tasks/AreaBoss/assets.py

@@ -97,6 +97,8 @@ class AreaBossAssets:
 	I_AB_JI_FLOOR_LIST_CHECK = RuleImage(roi_front=(390,150,60,290), roi_back=(390,150,60,290), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_list_check.png")
 	# 极地鬼 一层 
 	I_AB_JI_FLOOR_ONE = RuleImage(roi_front=(390,150,60,290), roi_back=(390,150,60,290), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_one.png")
+	# 极地鬼 十层 
+	I_AB_JI_FLOOR_TEN = RuleImage(roi_front=(390,370,60,40), roi_back=(390,370,60,40), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_ten.png")
 	# 小组内未取得名次 
 	I_AB_GROUP_RANK_NONE = RuleImage(roi_front=(890,415,95,85), roi_back=(890,415,95,85), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_rank_none.png")
 

+ 6 - 0
tasks/AreaBoss/config_boss.py

@@ -5,6 +5,10 @@ from enum import Enum
 from datetime import datetime, time
 from pydantic import BaseModel, ValidationError, validator, Field
 
+class AreaBossFloor(str, Enum):
+    ONE = '一星'
+    TEN = '十星'
+    DEFAULT = '不更改'
 
 class Boss(BaseModel):
     boss_number: int = Field(title='Boss Number',
@@ -14,5 +18,7 @@ class Boss(BaseModel):
                              ge=1, le=3)
     # 是否查找当日悬赏鬼王
     boss_reward: bool = Field(default=False, description='boss_reward_help')
+    # 悬赏默认打较简单的一星鬼王,若想要更高悬赏奖励可自行更改为十星或不更改(保留已勾选DEBUFF)
+    reward_floor: AreaBossFloor = Field(default=AreaBossFloor.ONE, description='reward_floor_help')
     # 是否使用收藏的
     use_collect: bool = Field(default=False, description='use_collect_help')

BIN
tasks/AreaBoss/res/ab_ji_floor_ten.png


+ 9 - 0
tasks/AreaBoss/res/image.json

@@ -179,6 +179,15 @@
     "threshold": 0.8,
     "description": "极地鬼 一层"
   },
+  {
+    "itemName": "ab_ji_floor_ten",
+    "imageName": "ab_ji_floor_ten.png",
+    "roiFront": "390,370,60,40",
+    "roiBack": "390,370,60,40",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "极地鬼 十层"
+  },
   {
     "itemName": "ab_group_rank_none",
     "imageName": "ab_rank_none.png",

+ 26 - 7
tasks/AreaBoss/script_task.py

@@ -12,7 +12,7 @@ from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_area_boss, page_shikigami_records
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.AreaBoss.assets import AreaBossAssets
-
+from tasks.AreaBoss.config_boss import AreaBossFloor
 from module.logger import logger
 from module.exception import TaskEnd
 from module.atom.image import RuleImage
@@ -45,7 +45,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         self.ui_goto(page_area_boss)
 
         self.open_filter()
-        # 以挑战鬼王数量
+        # 已挑战鬼王数量
         boss_fought = 0
         if con.boss_reward:
             self.fight_reward_boss()
@@ -77,7 +77,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
 
     def go_back(self) -> None:
         """
-        返回, 要求这个时候是出现在  地狱鬼王的主界面
+        返回, 要求这个时候是出现在地域鬼王的主界面
         :return:
         """
         # 点击返回
@@ -120,7 +120,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
             if not self.appear(self.I_AB_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
                 break
         if not self.run_general_battle(self.config.area_boss.general_battle):
-            logger.info("地狱鬼王第2只战斗失败")
+            logger.info("地域鬼王第2只战斗失败")
         # 红色关闭
         logger.info("Script close red")
         self.wait_until_appear(self.I_AB_CLOSE_RED)
@@ -138,6 +138,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
                     False       挑战失败
         @rtype:
         """
+        reward_floor = self.config.area_boss.boss.reward_floor
         if not self.appear(self.I_AB_FILTER_OPENED):
             self.open_filter()
 
@@ -162,8 +163,11 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
                         return False
                 # 切换到 极地鬼
                 self.switch_difficulty(True)
-
-            self.switch_to_floor_1()
+            # 调整悬赏层数
+            match reward_floor:
+                case AreaBossFloor.ONE: self.switch_to_floor_1()
+                case AreaBossFloor.TEN: self.switch_to_floor_10()
+                case AreaBossFloor.DEFAULT: logger.info("Not change floor")
         result = True
         if not self.start_fight():
             result = False
@@ -230,17 +234,32 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
             self.screenshot()
             if self.appear(self.I_AB_JI_FLOOR_ONE):
                 self.click(self.I_AB_JI_FLOOR_ONE)
+                logger.info("Switch to floor 1")
                 break
             self.swipe(self.S_AB_FLOOR_DOWN, interval=1)
             # 等待滑动动画
             self.wait_until_appear(self.I_AB_JI_FLOOR_ONE, False, 1)
 
+    def switch_to_floor_10(self):
+        """
+            更改层数为十层
+        """
+        # 打开选择列表
+        self.ui_click(self.C_AB_JI_FLOOR_SELECTED, self.I_AB_JI_FLOOR_LIST_CHECK, interval=3)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_AB_JI_FLOOR_TEN):
+                self.click(self.I_AB_JI_FLOOR_TEN)
+                logger.info("Switch to floor 10")
+                break
+            self.wait_until_appear(self.I_AB_JI_FLOOR_TEN, False, 1)
+
     def fight_reward_boss(self):
         index = self.get_hot_in_reward()
         self.open_filter()
         # 滑动到最顶层
         if index < 3:
-            logger.info("swipe to top")
+            logger.info("Swipe to top")
             for i in range(random.randint(1, 3)):
                 self.swipe(self.S_AB_FILTER_DOWN)
         #

+ 5 - 0
tasks/Component/GeneralRoom/general_room.py

@@ -133,6 +133,11 @@ class GeneralRoom(BaseTask, GeneralRoomAssets):
 
             if self.ocr_appear(self.O_GR_ZONES_NAME):
                 break
+            # https://github.com/runhey/OnmyojiAutoScript/issues/488
+            # 只能说朴实无华
+            text_ocr = self.O_GR_ZONES_NAME.ocr(self.device.image)
+            if name == '石距' and name in text_ocr:
+                break
             if click_timer.reached():
                 click_timer.reset()
                 self.device.click(x=pos[0] + randint(-5, 5), y=pos[1] + randint(-5, 5))

+ 3 - 3
tasks/Component/SwitchSoul/switch_soul.py

@@ -253,11 +253,11 @@ class SwitchSoul(BaseTask, SwitchSoulAssets):
         for i in range(5):
             sleep(0.8)
             self.screenshot()
-            self.O_SS_TEAM_NAME.keyword = teamName
-            if self.ocr_appear_click_by_rule(self.O_SS_TEAM_NAME, self.I_SOU_CLICK_PRESENT, interval=1):
-                continue
             if self.appear_then_click(self.I_SOU_SWITCH_SURE, interval=1):
                 break
+            self.O_SS_TEAM_NAME.keyword = teamName
+            if self.ocr_appear_click_by_rule(self.O_SS_TEAM_NAME, self.I_SOU_CLICK_PRESENT, interval=1.5):
+                continue
         logger.info(f'Switch soul_one group {groupName} team {teamName}')
 
     def ocr_appear_click_by_rule(self,

+ 3 - 1
tasks/Exploration/base.py

@@ -37,7 +37,7 @@ class Scene(Enum):
 
 
 
-class BaseExploration(GeneralBattle, GeneralRoom, GeneralInvite, ReplaceShikigami, GameUi, SwitchSoul, ExplorationAssets):
+class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, ReplaceShikigami, SwitchSoul, ExplorationAssets):
     minions_cnt = 0
 
     @cached_property
@@ -105,6 +105,7 @@ class BaseExploration(GeneralBattle, GeneralRoom, GeneralInvite, ReplaceShikigam
         self.ui_goto(page_exploration)
 
     def post_process(self):
+        self.wait_until_stable(self.I_UI_BACK_RED)
         self.ui_get_current_page()
         self.ui_goto(page_main)
         con = self._config.exploration_config
@@ -341,6 +342,7 @@ class BaseExploration(GeneralBattle, GeneralRoom, GeneralInvite, ReplaceShikigam
 
     def fire(self, button) -> bool:
         self.ui_click_until_disappear(button, interval=3)
+        self.screenshot()
         if (self.appear(self.I_E_SETTINGS_BUTTON) or
                 self.appear(self.I_E_AUTO_ROTATE_ON) or
                 self.appear(self.I_E_AUTO_ROTATE_OFF)):

+ 6 - 0
tasks/Exploration/solo.py

@@ -193,6 +193,9 @@ class SoloExploration(BaseExploration):
                         logger.warning('Exit team')
                         self.quit_explore()
                         continue
+                else:
+                    logger.warning('Team emoji appear again, clear friend_leave_timer')
+                    friend_leave_timer = Timer(10)
                 # boss
                 if self.appear(self.I_BOSS_BATTLE_BUTTON):
                     if self.fire(self.I_BOSS_BATTLE_BUTTON):
@@ -277,6 +280,9 @@ class SoloExploration(BaseExploration):
                         wait_timer = Timer(50)
                         wait_timer.start()
                         continue
+                else:
+                    logger.warning('Team emoji appear again, clear friend_leave_timer')
+                    friend_leave_timer = Timer(10)
             #
             elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
                 self.check_take_over_battle(is_screenshot=False, config=self._config.general_battle_config)

+ 1 - 0
tasks/Exploration/version.py

@@ -56,6 +56,7 @@ class HighlightGif(RuleGif):
     def pre_process(self, image):
         return highlight(image)
 
+
 class HighLight(BaseTask, ExplorationAssets):
 
     @cached_property

+ 7 - 0
tasks/Hyakkiyakou/config.py

@@ -13,6 +13,10 @@ class InferenceEngine(str, Enum):
     ONNXRUNTIME = 'Onnxruntime'
     TENSORRT = 'TensorRT'
 
+class ScreenshotMethod(str, Enum):
+    WINDOW_BACKGROUND = 'window_background'
+    NEMU_IPC = 'nemu_ipc'
+
 
 class HyakkiyakouConfig(ConfigBase):
     hya_limit_time: Time = Field(default=Time(minute=20), description='hya_limit_time_help')
@@ -52,6 +56,9 @@ class DebugConfig(ConfigBase):
     hya_save_result: bool = Field(default=False, description='hya_save_result_help')
     # 单独的设定截屏间隔, 单位ms
     hya_interval: float = Field(default=300, description='hya_interval_help')
+    # 单独的截屏设置
+    hya_screenshot_method: ScreenshotMethod = Field(default=ScreenshotMethod.WINDOW_BACKGROUND,
+                                                    description='hya_screenshot')
 
 
 class Hyakkiyakou(ConfigBase):

+ 1 - 1
tasks/Hyakkiyakou/script_task.py

@@ -178,7 +178,7 @@ class ScriptTask(GameUi, HyaSlave):
         if self._config.debug_config.hya_show:
             self.debugger.show_start()
         while 1:
-            self.fast_screenshot()
+            self.fast_screenshot(screenshot=self._config.debug_config.hya_screenshot_method)
             if self.appear(self.I_HEND):
                 break
             if not self.appear(self.I_CHECK_RUN):

+ 3 - 2
tasks/Hyakkiyakou/slave/hya_device.py

@@ -7,6 +7,7 @@ from module.base.utils import point2str
 from module.exception import RequestHumanTakeover, GameStuckError
 from tasks.base_task import BaseTask
 
+from tasks.Hyakkiyakou.config import ScreenshotMethod
 
 def image_black(img) -> bool:
     for y, x in [(0, 0), (719, 1279), (719, 0), (0, 1279)]:
@@ -26,10 +27,10 @@ class HyaDevice(BaseTask):
     hya_screenshot_interval = Timer(0.2)  # 300ms
     hya_fs_check_timer = Timer(5 * 60)  # 五分钟跑不完就应该是出问题了
 
-    def fast_screenshot(self):
+    def fast_screenshot(self, screenshot: ScreenshotMethod):
         self.hya_screenshot_interval.wait()
         self.hya_screenshot_interval.reset()
-        self.device.image = self.device.screenshot_window_background()
+        self.device.image = self.device.screenshot_window_background() if screenshot == ScreenshotMethod.WINDOW_BACKGROUND else self.device.screenshot_nemu_ipc()
         if image_black(self.device.image):
             logger.error('Screenshot image is black, try again')
             raise RequestHumanTakeover('Screenshot image is black, try again')

+ 5 - 2
tasks/Hyakkiyakou/slave/hya_slave.py

@@ -226,8 +226,6 @@ class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
             if not self._invite_friend(False):
                 raise RequestHumanTakeover('Invite friend failed')
 
-
-
     def _invite_friend(self, same: bool = True) -> bool:
         if not same:
             logger.info('Invite different server friend')
@@ -264,6 +262,8 @@ class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
     def reset_state(self):
         self.slave_state = [250, 36, 10,
                           HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0]
+
+
 def covert_rgb():
     images_folders: Path = Path(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240614T214216')
     save_folders = images_folders.parent / 'save14'
@@ -275,6 +275,7 @@ def covert_rgb():
         img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
         cv2.imwrite(str(save_folders / file.name), img)
 
+
 def test_predict_res():
     import timeit
     from module.config.config import Config
@@ -295,6 +296,7 @@ def test_predict_res():
     # total time is 36.2ms on my computer /cpu:AMD Ryzen 5 3550H with Radeon Vega Mobile
     # 0.362ms per predict_res
 
+
 def test_predict_bean():
     import timeit
     from module.config.config import Config
@@ -313,6 +315,7 @@ def test_predict_bean():
     # print(f"执行总的时间: {execution_time * 1000} ms")
     # total time is 17.9ms on my computer in 100 times
 
+
 def test_predict_buff():
     import timeit
     from module.config.config import Config

+ 5 - 1
tasks/WantedQuests/assets.py

@@ -30,6 +30,10 @@ class WantedQuestsAssets:
 	O_WQ_NUM_1 = RuleOcr(roi=(32,260,72,27), area=(32,260,72,27), mode="DigitCounter", method="Default", keyword="", name="wq_num_1")
 	# Ocr-description 
 	O_WQ_NUM_2 = RuleOcr(roi=(34,406,65,24), area=(34,406,65,24), mode="DigitCounter", method="Default", keyword="", name="wq_num_2")
+	# 备用识别1 
+	O_WQ_NUM_UNKNOWN_1 = RuleOcr(roi=(32,260,72,27), area=(32,260,72,27), mode="Digit", method="Default", keyword="", name="wq_num_unknown_1")
+	# 备用识别2 
+	O_WQ_NUM_UNKNOWN_2 = RuleOcr(roi=(34,406,65,24), area=(34,406,65,24), mode="Digit", method="Default", keyword="", name="wq_num_unknown_2")
 	# Ocr-description 
 	O_WQ_TYPE_1 = RuleOcr(roi=(544,238,55,36), area=(544,238,55,36), mode="Single", method="Default", keyword="", name="wq_type_1")
 	# Ocr-description 
@@ -125,7 +129,7 @@ class WantedQuestsAssets:
 
 	# Image Rule Assets
 	# 封印 
-	I_WQ_SEAL = RuleImage(roi_front=(244,181,40,40), roi_back=(56,152,664,396), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_seal.png")
+	I_WQ_SEAL = RuleImage(roi_front=(244,181,40,40), roi_back=(56,93,664,455), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_seal.png")
 	# 勾号 
 	I_WQ_DONE = RuleImage(roi_front=(248,183,37,39), roi_back=(107,147,570,389), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_done.png")
 	# 一键追踪 

+ 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')
 
 
 

+ 105 - 0
tasks/WantedQuests/explore.py

@@ -0,0 +1,105 @@
+from cached_property import cached_property
+
+from module.atom.image import RuleImage
+from module.atom.animate import RuleAnimate
+from module.base.timer import Timer
+from module.logger import logger
+
+from tasks.Exploration.base import BaseExploration, Scene
+from tasks.Exploration.version import HighLight
+
+
+class ExploreWantedBoss(Exception):
+    # 出现一种情况,要求的怪是仅仅最后的Boss,其他小怪不是
+    pass
+
+
+class WQExplore(BaseExploration, HighLight):
+    _cnt_exploration: int = 0
+
+    @cached_property
+    def _match_end(self):
+        return RuleAnimate(self.I_SWIPE_END)
+
+    def explore(self, goto: RuleImage, num: int):
+        logger.info(f'Start exploring with number: {num}')
+        explore_init = False
+        explore_only_boss: bool = True
+        _cnt_exploration = 0
+        search_fail_cnt = 0
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_UI_BACK_RED) and self.appear(self.I_E_EXPLORATION_CLICK):
+                break
+            if self.appear_then_click(goto, interval=2):
+                continue
+
+        while 1:
+            scene = self.get_current_scene(reuse_screenshot=False)
+            # 进入探索
+            if scene == Scene.ENTRANCE:
+                if _cnt_exploration >= num:
+                    logger.info('Execution exploration end')
+                    self.ui_click_until_disappear(self.I_UI_BACK_RED)
+                    if explore_only_boss:
+                        raise ExploreWantedBoss
+                    break
+                self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
+                continue
+            # 探索大世界
+            elif scene == Scene.WORLD:
+                self.wait_until_stable(
+                    self.I_CHECK_EXPLORATION,
+                    timer=Timer(limit=0.5, count=2),
+                    timeout=Timer(2, count=10)
+                )
+                curr_scene = self.get_current_scene(reuse_screenshot=False)
+                if curr_scene == Scene.WORLD and _cnt_exploration >= num:
+                    logger.info('All Done')
+                    break
+                continue
+            # 探索里面
+            elif scene == Scene.MAIN:
+                if not explore_init:
+                    self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
+                    explore_init = True
+                    continue
+                # 小纸人
+                if self.appear(self.I_BATTLE_REWARD):
+                    if self.ui_get_reward(self.I_BATTLE_REWARD):
+                        continue
+                # boss
+                if self.appear(self.I_BOSS_BATTLE_BUTTON):
+                    if self.fire(self.I_BOSS_BATTLE_BUTTON):
+                        logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
+                        _cnt_exploration += 1
+                        explore_only_boss = False
+                    continue
+                # 小怪
+                if self.appear(self.TEMPLATE_GIF) and self.fire(self.TEMPLATE_GIF):
+                    explore_only_boss = False
+                    logger.info(f'Fight, minions cnt {self.minions_cnt}')
+                # 向后拉,寻找怪
+                if search_fail_cnt >= 4:
+                    search_fail_cnt = 0
+                    if self._match_end.stable(self.device.image):
+                        _cnt_exploration += 1
+                        self.quit_explore()
+                        continue
+                    if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
+                        continue
+                else:
+                    search_fail_cnt += 1
+            elif scene == Scene.UNKNOWN:
+                continue
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    from tasks.WantedQuests.assets import WantedQuestsAssets
+
+    config = Config('oas1')
+    device = Device(config)
+    t = WQExplore(config, device)
+    t.explore(goto=WantedQuestsAssets.I_GOTO_1, num=2)

+ 18 - 0
tasks/WantedQuests/ocr.json

@@ -53,6 +53,24 @@
     "keyword": "",
     "description": "Ocr-description"
   },
+  {
+    "itemName": "wq_num_unknown_1",
+    "roiFront": "32,260,72,27",
+    "roiBack": "32,260,72,27",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "备用识别1"
+  },
+  {
+    "itemName": "wq_num_unknown_2",
+    "roiFront": "34,406,65,24",
+    "roiBack": "34,406,65,24",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "备用识别2"
+  },
   {
     "itemName": "wq_type_1",
     "roiFront": "544,238,55,36",

+ 49 - 32
tasks/WantedQuests/script_task.py

@@ -22,12 +22,14 @@ from tasks.Secret.script_task import ScriptTask as SecretScriptTask
 from tasks.WantedQuests.config import WantedQuestsConfig, CooperationType, CooperationSelectMask, \
     CooperationSelectMaskDescription
 from tasks.WantedQuests.assets import WantedQuestsAssets
+from tasks.WantedQuests.explore import WQExplore, ExploreWantedBoss
 from tasks.Component.Costume.config import MainType
 from typing import List
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 
 
-class ScriptTask(SecretScriptTask, GeneralInvite, WantedQuestsAssets, SwitchSoul):
+class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
+    want_strategy_excluding: list[list] = []  # 不需要执行的
 
     def run(self):
         con = self.config.model.wanted_quests
@@ -62,24 +64,32 @@ class ScriptTask(SecretScriptTask, GeneralInvite, WantedQuestsAssets, SwitchSoul
             if self.ocr_appear(self.O_WQ_TEXT_1, interval=1):
                 cu, re, total = self.O_WQ_NUM_1.ocr(self.device.image)
                 if cu == re == total == 0:
-                    logger.warning('OCR failed and skip this round')
+                    logger.warning('OCR failed and have a try')
                     ocr_error_count += 1
+                    # 尝试打一次
+                    unknown_num = self.O_WQ_NUM_UNKNOWN_1.ocr(self.device.image)
+                    if unknown_num > 14:
+                        self.execute_mission(self.O_WQ_TEXT_1, 1, number_challenge)
                 if cu > total:
                     logger.warning('Current number of wanted quests is greater than total number')
                     cu = cu % 10
                 if cu < total and re != 0:
-                    self.execute_mission(self.O_WQ_TEXT_1, total, number_challenge)
+                    self.execute_mission(self.O_WQ_TEXT_1, min(total, 20), number_challenge)
 
             if self.ocr_appear(self.O_WQ_TEXT_2, interval=1):
                 cu, re, total = self.O_WQ_NUM_2.ocr(self.device.image)
                 if cu == re == total == 0:
-                    logger.warning('OCR failed and skip this round')
+                    logger.warning('OCR failed and have a try')
                     ocr_error_count += 1
+                    # 尝试打一次
+                    unknown_num = self.O_WQ_NUM_UNKNOWN_2.ocr(self.device.image)
+                    if unknown_num > 14:
+                        self.execute_mission(self.O_WQ_TEXT_2, 1, number_challenge)
                 if cu > total:
                     logger.warning('Current number of wanted quests is greater than total number')
                     cu = cu % 10
                 if cu < total and re != 0:
-                    self.execute_mission(self.O_WQ_TEXT_2, total, number_challenge)
+                    self.execute_mission(self.O_WQ_TEXT_2, min(total, 20), number_challenge)
                 continue
 
             if self.appear(self.I_WQ_CHECK_TASK):
@@ -101,16 +111,16 @@ class ScriptTask(SecretScriptTask, GeneralInvite, WantedQuestsAssets, SwitchSoul
         time_delta = timedelta(hours=-before_end.hour, minutes=-before_end.minute, seconds=-before_end.second)
         now_datetime = datetime.now()
         now_time = now_datetime.time()
-        if time(hour=6) <= now_time < time(hour=18):
-            # 如果是在6点到18点之间,那就设定下一次运行的时间为第二天的6点 + before_end
-            next_run_datetime = datetime.combine(now_datetime.date() + timedelta(days=1), time(hour=6))
+        if time(hour=5) <= now_time < time(hour=18):
+            # 如果是在5点到18点之间,那就设定下一次运行的时间为第二天的5点 + before_end
+            next_run_datetime = datetime.combine(now_datetime.date() + timedelta(days=1), time(hour=5))
             next_run_datetime = next_run_datetime + time_delta
         elif time(hour=18) <= now_time < time(hour=23, minute=59, second=59):
             # 如果是在18点到23点59分59秒之间,那就设定下一次运行的时间为第二天的18点 + before_end
             next_run_datetime = datetime.combine(now_datetime.date() + timedelta(days=1), time(hour=18))
             next_run_datetime = next_run_datetime + time_delta
         else:
-            # 如果是在0点到6点之间,那就设定下一次运行的时间为今天的18点 + before_end
+            # 如果是在0点到5点之间,那就设定下一次运行的时间为今天的18点 + before_end
             next_run_datetime = datetime.combine(now_datetime.date(), time(hour=18))
             next_run_datetime = next_run_datetime + time_delta
         self.set_next_run(task='WantedQuests', target=next_run_datetime)
@@ -167,17 +177,27 @@ class ScriptTask(SecretScriptTask, GeneralInvite, WantedQuestsAssets, SwitchSoul
         OCR_WQ_TYPE = [self.O_WQ_TYPE_1, self.O_WQ_TYPE_2, self.O_WQ_TYPE_3, self.O_WQ_TYPE_4]
         OCR_WQ_INFO = [self.O_WQ_INFO_1, self.O_WQ_INFO_2, self.O_WQ_INFO_3, self.O_WQ_INFO_4]
         GOTO_BUTTON = [self.I_GOTO_1, self.I_GOTO_2, self.I_GOTO_3, self.I_GOTO_4]
+        name_funcs: dict = {
+            '挑战': self.challenge,
+            '探索': self.explore,
+            '秘闻': self.secret
+        }
 
         def extract_info(index: int) -> tuple or None:
             """
             提取每一个地点的信息
             :param index: 从零开始
             :return:
-            (type, destination, number, goto_button)
-            (类型, 地点层级,可以打败的数量,前往按钮)
-            类型: 探索0, 挑战1, 秘闻2
+            (type, destination, number, goto_button, func)
+            (类型, 地点层级,可以打败的数量,前往按钮, func)
+            类型: 挑战0, 秘闻1, 探索2
             """
-            result = [-1, '', -1, GOTO_BUTTON[index]]
+            layer_limit = {
+                # 低层不限制
+                # "壹", "贰", "叁", "肆", "伍", "陆",
+                "柒", "捌", "玖", "拾"
+            }
+            result = [-1, '', -1, GOTO_BUTTON[index], self.challenge]
             type_wq = OCR_WQ_TYPE[index].ocr(self.device.image)
             info_wq_1 = OCR_WQ_INFO[index].ocr(self.device.image)
             info_wq_1 = info_wq_1.replace(':', ':').replace('(', '(').replace(')', ')')
@@ -187,14 +207,17 @@ class ScriptTask(SecretScriptTask, GeneralInvite, WantedQuestsAssets, SwitchSoul
                 return None
             wq_destination = match.group(1)
             wq_number = int(match.group(2))
+            # 跳过高层秘闻
+            if wq_destination[-1] in layer_limit:
+                logger.warning('This secret layer is too high')
+                return None
             result[1] = wq_destination
             result[2] = wq_number
-            if type_wq == '探索':
-                result[0] = -1
-            elif type_wq == '挑战':
-                result[0] = 1 if num_challenge >= 10 else -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
+            result[4] = name_funcs.get(type_wq, lambda: logger.warning('No task can be challenged'))
             logger.info(f'[Wanted Quests] type: {type_wq} destination: {wq_destination} number: {wq_number} ')
             return tuple(result) if result[0] != -1 else None
 
@@ -216,25 +239,19 @@ class ScriptTask(SecretScriptTask, GeneralInvite, WantedQuestsAssets, SwitchSoul
             info_wq = extract_info(i)
             if info_wq:
                 info_wq_list.append(info_wq)
+        info_wq_list = [item for item in info_wq_list if item not in self.want_strategy_excluding]
         if not info_wq_list:
             logger.warning('No wanted quests can be challenged')
             return False
         # sort
         info_wq_list.sort(key=lambda x: x[0])
-        best_type, destination, once_number, goto_button = info_wq_list[0]
+        best_type, destination, once_number, goto_button, func = info_wq_list[0]
         do_number = 1 if once_number >= num_want else num_want // once_number + (1 if num_want % once_number > 0 else 0)
-        match best_type:
-            case 0:
-                self.explore(goto_button, do_number)
-            case 1:
-                self.challenge(goto_button, do_number)
-            case 2:
-                self.secret(goto_button, do_number)
-            case _:
-                logger.warning('No wanted quests can be challenged')
-
-    def explore(self, goto, num):
-        self.challenge(goto, num)
+        try:
+            func(goto_button, do_number)
+        except ExploreWantedBoss:
+            logger.warning('The extreme case. The quest only needs to challenge one final boss, so skip it')
+            self.want_strategy_excluding.append(info_wq_list[0])
 
     def challenge(self, goto, num):
         self.ui_click(goto, self.I_WQC_FIRE)

+ 1 - 1
tasks/WantedQuests/wq/image.json

@@ -3,7 +3,7 @@
     "itemName": "wq_seal",
     "imageName": "wq_wq_seal.png",
     "roiFront": "244,181,40,40",
-    "roiBack": "56,152,664,396",
+    "roiBack": "56,93,664,455",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "封印"