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

feat(Dokan): add dokan toppa support

jackyhwei 2 лет назад
Родитель
Сommit
3a94429094
43 измененных файлов с 1098 добавлено и 21 удалено
  1. 1 1
      module/config/config_manual.py
  2. 1 1
      module/config/config_menu.py
  3. 36 9
      module/config/config_model.py
  4. 3 0
      module/config/i18n/zh_CN.ts
  5. 2 2
      module/logger.py
  6. 111 0
      tasks/Dokan/assets.py
  7. 35 0
      tasks/Dokan/config.py
  8. 32 0
      tasks/Dokan/res/click.json
  9. BIN
      tasks/Dokan/res/dokan_attacking.png
  10. BIN
      tasks/Dokan/res/gb_prepare_dark.png
  11. BIN
      tasks/Dokan/res/gb_prepare_highlight.png
  12. 275 0
      tasks/Dokan/res/image.json
  13. 23 0
      tasks/Dokan/res/list.json
  14. 48 0
      tasks/Dokan/res/ocr.json
  15. BIN
      tasks/Dokan/res/res_dokan_boss_waiting.png
  16. BIN
      tasks/Dokan/res/res_ryou_dokan.png
  17. BIN
      tasks/Dokan/res/res_ryou_dokan_battle_over.png
  18. BIN
      tasks/Dokan/res/res_ryou_dokan_cd.png
  19. BIN
      tasks/Dokan/res/res_ryou_dokan_cd1.png
  20. BIN
      tasks/Dokan/res/res_ryou_dokan_check.png
  21. BIN
      tasks/Dokan/res/res_ryou_dokan_cheering.png
  22. BIN
      tasks/Dokan/res/res_ryou_dokan_cheering_attacking_sama.png
  23. BIN
      tasks/Dokan/res/res_ryou_dokan_cheering_gray.png
  24. BIN
      tasks/Dokan/res/res_ryou_dokan_cheering_scores.png
  25. BIN
      tasks/Dokan/res/res_ryou_dokan_failed_vote_no.png.png
  26. BIN
      tasks/Dokan/res/res_ryou_dokan_fighting.png
  27. BIN
      tasks/Dokan/res/res_ryou_dokan_finished.png
  28. BIN
      tasks/Dokan/res/res_ryou_dokan_gathering.png
  29. BIN
      tasks/Dokan/res/res_ryou_dokan_in_field.png
  30. BIN
      tasks/Dokan/res/res_ryou_dokan_in_field2.png
  31. BIN
      tasks/Dokan/res/res_ryou_dokan_priority.png
  32. BIN
      tasks/Dokan/res/res_ryou_dokan_priority_0.png
  33. BIN
      tasks/Dokan/res/res_ryou_dokan_priority_1.png
  34. BIN
      tasks/Dokan/res/res_ryou_dokan_priority_2.png
  35. BIN
      tasks/Dokan/res/res_ryou_dokan_priority_3.png
  36. BIN
      tasks/Dokan/res/res_ryou_dokan_priority_4.png
  37. BIN
      tasks/Dokan/res/res_ryou_dokan_start_challenge.png
  38. BIN
      tasks/Dokan/res/res_ryou_dokan_start_challenge2.png
  39. BIN
      tasks/Dokan/res/res_ryou_dokan_win.png
  40. BIN
      tasks/Dokan/res/res_ryou_shenshe.png
  41. BIN
      tasks/Dokan/res/scene_ryou.png
  42. 526 0
      tasks/Dokan/script_task.py
  43. 5 8
      tasks/Restart/config.py

+ 1 - 1
module/config/config_manual.py

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

+ 1 - 1
module/config/config_menu.py

@@ -27,7 +27,7 @@ class ConfigMenu:
         # 很肝的任务
         self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',]
         # 阴阳寮
-        self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'CollectiveMissions',
+        self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'Dokan', 'CollectiveMissions',
                               'Hunt']
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']

+ 36 - 9
module/config/config_model.py

@@ -16,6 +16,7 @@ from module.logger import logger
 from tasks.Component.config_base import ConfigBase, TimeDelta
 from tasks.Exploration.config import Exploration
 from tasks.RyouToppa.config import RyouToppa
+from tasks.Dokan.config import Dokan
 from tasks.Script.config import Script
 from tasks.Restart.config import Restart
 from tasks.GlobalGame.config import GlobalGame
@@ -118,6 +119,7 @@ class ConfigModel(ConfigBase):
     # 阴阳寮
     collective_missions: CollectiveMissions = Field(default_factory=CollectiveMissions)
     hunt: Hunt = Field(default_factory=Hunt)
+    dokan: Dokan = Field(default_factory=Dokan)
 
     # @validator('script')
     # def script_validator(cls, v):
@@ -321,16 +323,9 @@ class ConfigModel(ConfigBase):
                 result.append(item)
             return result
 
-
-
-
-
-
-
         schema = task.schema()
         groups = extract_groups(schema)
 
-
         result: dict[str, list] = {}
         for key, value in task.dict().items():
             result[key] = merge_value(groups[key], value, schema["definitions"])
@@ -343,7 +338,6 @@ class ConfigModel(ConfigBase):
         group = convert_to_underscore(group)
         argument = convert_to_underscore(argument)
 
-
         # pandtic验证
         if isinstance(value, str) and len(value) == 8:
             try:
@@ -375,6 +369,12 @@ class ConfigModel(ConfigBase):
         if argument_object is None:
             logger.error(f'Set arg {task}.{group}.{argument}.{value} failed')
             return False
+        
+        # XXX temp implementation to enable oasx control the datetime configuration globally rather than a single task
+        if task == "restart" and group == "task_config" and argument == "reset_task_datetime_enable" and value == True:
+            date_time = self.restart.task_config.reset_task_datetime
+            logger.info(f"reset_task_datetime={date_time}")
+            self.reset_datetime_for_all_enabled_tasks(date_time)
 
         # 设置参数
         try:
@@ -386,7 +386,34 @@ class ConfigModel(ConfigBase):
             logger.error(e)
             return False
 
-
+    def replace_next_run(self, d, dt: datetime):
+        for k, v in d.items():
+            if isinstance(v, dict):
+                self.replace_next_run(v, dt=dt)
+            elif k == "next_run":
+                d[k] = dt
+                # convert value to datetime if it's a str
+                if isinstance(v, str):
+                    current_time = datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
+                    if current_time != dt:
+                        d[k] = dt.strftime("%Y-%m-%d %H:%M:%S")
+                # already a datetime value
+                elif isinstance(v, datetime) and v != dt:
+                    d[k] = dt.strftime("%Y-%m-%d %H:%M:%S")
+
+    def reset_datetime_for_all_enabled_tasks(self, task_datetime: datetime):
+        logger.warn(f"trying to reset datetime of all tasks to: {task_datetime}")
+        # logger.info(f"current config: {self.dict()}")
+        data = self.dict()
+        self.replace_next_run(data, task_datetime)
+        # logger.info(f"new config: {data}")
+
+        # write to json config  file
+        self.write_json(self.config_name, data)
+
+        # reload from the newly modified json config file
+        data = self.read_json(self.config_name)
+        super().__init__(**data)
 
 if __name__ == "__main__":
     try:

+ 3 - 0
module/config/i18n/zh_CN.ts

@@ -173,6 +173,7 @@
 	<message><source>GlobalGame</source><translation>全局游戏设置</translation></message>
 	<message><source>RealmRaid</source><translation>个人突破</translation></message>
 	<message><source>RyouToppa</source><translation>寮突破</translation></message>
+	<message><source>Dokan</source><translation>道馆</translation></message>
 	<message><source>Exploration</source><translation>探索</translation></message>
 	<message><source>List Rule</source><translation>列表规则</translation></message>
 	<message><source>Activity Task</source><translation>限时活动</translation></message>
@@ -219,6 +220,7 @@
 	<message><source>GlobalGame</source><translation>全局游戏设置</translation></message>
 	<message><source>RealmRaid</source><translation>个人突破</translation></message>
 	<message><source>RyouToppa</source><translation>寮突破</translation></message>
+	<message><source>Dokan</source><translation>道馆</translation></message>
 	<message><source>Exploration</source><translation>探索</translation></message>
 	<message><source>List Rule</source><translation>列表规则</translation></message>
 	<message><source>Activity Task</source><translation>限时活动</translation></message>
@@ -418,6 +420,7 @@ window_background >>> DroidCast_raw >  ADB_nc >> DroidCast > uiautomator2 ~= ADB
 	<message><source>Buy Ap Activity</source><translation>游戏体力不足是否需要话勾玉购买</translation></message>
 	<message><source>buy_ap_activity_help</source><translation>该设置只有是设定为活动次数时有效</translation></message>
 	<message><source>activity_toggle_help</source><translation>该设置只有是设定为活动次数时有效</translation></message>
+	<message><source>dokan_attack_priority_help</source><translation>道馆攻击优先顺序</translation></message>
 </context>
 <context>
     <name>Args</name>

+ 2 - 2
module/logger.py

@@ -166,9 +166,9 @@ logger_debug = False
 logger = logging.getLogger('oas')
 logger.setLevel(logging.DEBUG if logger_debug else logging.INFO)
 file_formatter = logging.Formatter(
-    fmt='%(asctime)s.%(msecs)03d | %(levelname)8s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
+    fmt='%(asctime)s.%(msecs)03d | %(filename)s:%(lineno)d | %(levelname)8s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
 console_formatter = logging.Formatter(
-    fmt='%(asctime)s.%(msecs)03d │ %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
+    fmt='%(asctime)s.%(msecs)03d | %(filename)s:%(lineno)d│ %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
 flutter_formatter = logging.Formatter(
     fmt='| %(asctime)s.%(msecs)03d | %(message)08s', datefmt='%H:%M:%S')
 

+ 111 - 0
tasks/Dokan/assets.py

@@ -0,0 +1,111 @@
+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 DokanAssets: 
+
+	C_DOKAN_RANDOM_CLICK_AREA = RuleClick(roi_front=(142,294,107,555), roi_back=(142,294,107,555), name="dokan_random_click_area")
+	C_DOKAN_RANDOM_CLICK_AREA1 = RuleClick(roi_front=(42,594,10,100), roi_back=(42,594,10,100), name="dokan_random_click_area1")
+	C_DOKAN_RANDOM_CLICK_AREA2 = RuleClick(roi_front=(1122,360,10,40), roi_back=(1122,360,10,40), name="dokan_random_click_area2")
+	C_DOKAN_RANDOM_CLICK_AREA3 = RuleClick(roi_front=(333,44,107,20), roi_back=(333,44,107,20), name="dokan_random_click_area3")
+	C_DOKAN_READY_FOR_BATLLE = RuleClick(roi_front=(42,94,1207,543), roi_back=(42,94,1207,543), name="dokan_ready_for_battle")
+
+	# 阴阳竂-》神社
+	I_RYOU_SHENSHE = RuleImage(roi_front=(872,672,54,28), roi_back=(872,672,54,28), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_shenshe.png")
+	# 神社-》道馆
+	I_RYOU_DOKAN = RuleImage(roi_front=(476,173,62,24), roi_back=(476,173,62,24), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan.png")
+
+	# 是否已经成功进入道馆,上面中间的“道馆突破”文字
+	I_RYOU_DOKAN_CHECK = RuleImage(roi_front=(567,15,144,42), roi_back=(567,15,144,42), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_check.png")
+	# 优先攻击
+	I_RYOU_DOKAN_PRIORITY = RuleImage(roi_front=(666,672,58,25), roi_back=(666,672,58,25), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
+	# 优先攻击选项:见习
+	I_RYOU_DOKAN_PRIORITY_0 = RuleImage(roi_front=(98,170,94,43), roi_back=(98,170,94,43), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
+	# 优先攻击选项:初级
+	I_RYOU_DOKAN_PRIORITY_1 = RuleImage(roi_front=(342,175,96,42), roi_back=(342,175,96,42), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
+	# 优先攻击选项:中级
+	I_RYOU_DOKAN_PRIORITY_2 = RuleImage(roi_front=(585,175,89,35), roi_back=(585,175,89,35), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
+	# 优先攻击选项:高级
+	I_RYOU_DOKAN_PRIORITY_3 = RuleImage(roi_front=(830,175,88,41), roi_back=(830,175,88,41), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
+	# 优先攻击选项:黑脸
+	I_RYOU_DOKAN_PRIORITY_4 = RuleImage(roi_front=(1072,178,94,39), roi_back=(1072,178,94,39), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
+
+	# 状态:集结等待中
+	I_RYOU_DOKAN_GATHERING = RuleImage(roi_front=(653,76,46,26), roi_back=(653,76,46,26), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_gathering.png")
+	# 状态:检查右下角有没有挑战?通常是失败了,并退出来到集结界面,可重新开始点击右下角挑战进入战斗
+	I_RYOU_DOKAN_START_CHALLENGE = RuleImage(roi_front=(1125,555,103,72), roi_back=(1125,555,103,72), threshold=0.95, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_start_challenge2.png")
+	I_RYOU_DOKAN_START_CHALLENGE2 = RuleImage(roi_front=(1132,572,89,43), roi_back=(1132,572,89,43), threshold=0.95, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_start_challenge.png")
+	# 状态:达到失败次数,CD中
+	I_RYOU_DOKAN_CD = RuleImage(roi_front=(1122,566,117,74), roi_back=(1122,566,117,74), threshold=0.9, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_cd.png")
+	# 状态:进入战斗,待开始,右下角图标
+	I_RYOU_DOKAN_IN_FIELD = RuleImage(roi_front=(1128,536,100,100), roi_back=(1128,536,100,100), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_in_field.png")
+	# 馆主战等待中
+	I_DOKAN_BOSS_WAITING = RuleImage(roi_front=(603,148,130,32), roi_back=(603,148,130,32), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_dokan_boss_waiting.png")
+	# 状态:道馆胜利
+	I_RYOU_DOKAN_WIN = RuleImage(roi_front=(628,60,45,33), roi_back=(628,60,45,33), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_win.png")
+	# 状态:进入战斗,待开始,右下角图标。
+	I_RYOU_DOKAN_IN_FIELD2 = RuleImage(roi_front=(1131,562,88,48), roi_back=(1131,562,88,48), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_in_field2.png")
+	# 状态:战斗结算,可能是打完小朋友了,也可能是失败了。
+	I_RYOU_DOKAN_BATTLE_OVER = RuleImage(roi_front=(571,503,106,49), roi_back=(571,503,106,49), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_battle_over.png")
+
+
+	# 状态:战斗中,左上角的加油图标
+	I_RYOU_DOKAN_FIGHTING = RuleImage(roi_front=(374,38,74,19), roi_back=(374,38,74,19), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_fighting.png")
+	# 状态:加油中,左下角有鼓
+	I_RYOU_DOKAN_CHEERING = RuleImage(roi_front=(58,598,72,32), roi_back=(58,598,72,32), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_cheering.png")
+	# 状态:加油中,左下角有鼓,灰色的鼓
+	I_RYOU_DOKAN_CHEERING_GRAY = RuleImage(roi_front=(58,601,84,35), roi_back=(58,601,84,35), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_cheering_gray.png")
+	# 状态:道馆已经结束
+	I_RYOU_DOKAN_FINISHED = RuleImage(roi_front=(633,78,67,24), roi_back=(633,78,67,24), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_finished.png")
+	# 状态:道馆挑战失败,投票NO(暂不考虑)
+	# I_RYOU_DOKAN_FAILED_VOTE_NO = RuleImage(roi_front=(832,279,130,43), roi_back=(1,1,1055,718), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_failed_vote_no.png")
+	# 场景检测:阴阳竂
+	I_SCENE_RYOU = RuleImage(roi_front=(1161,674,75,31), roi_back=(1161,674,75,31), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/scene_ryou.png")
+
+	# 进入加油相关:道馆积分按钮
+	I_RYOU_DOKAN_CHEERING_SCORES = RuleImage(roi_front=(832,279,130,43), roi_back=(1,1,1055,718), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_scores.png")
+	# 进入加油相关:攻击中的竂友
+	I_RYOU_DOKAN_CHEERING_ATTACKING_SAMA = RuleImage(roi_front=(832,279,130,43), roi_back=(1,1,1055,718), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_cheering_scores.png")
+
+
+	# activity list
+	L_RYOU_ACTIVITY_LIST = RuleList(folder="./tasks/Dokan/res", direction="vertical", mode="ocr", 
+								  roi_back=(35,157,37,250), 
+								  size=(42, 90), 
+								  array=["集体", "阴阳", "首领", "道馆", "狭间", "结界"])
+
+	# Ocr Rule Assets
+	# 道馆地图,毛估的坐标。1280*720, 1280-540=740, 720-260=460
+	O_DOKAN_MAP = RuleOcr(roi=(270,130,740,460), area=(270,130,740,460), mode="Full", method="Default", keyword="万", name="dokan_map")
+	# 道馆里找文字:后开战
+	O_DOKAN_GATHERING = RuleOcr(roi=(653,76,46,26), area=(653,76,46,26), mode="Single", method="Default", keyword="开战", name="dokan_gathering")
+	# 道馆里找文字:剩余突破时间
+	O_DOKAN_ATTACKING = RuleOcr(roi=(1122,546,92,51), area=(1122,546,92,51), mode="Single", method="Default", keyword="剩余", name="dokan_attacking")
+	# 道馆里找文字:后挑战馆主
+	O_DOKAN_BOSS_WAITING = RuleOcr(roi=(603,148,130,32), area=(603,148,130,32), mode="Single", method="Default", keyword="馆主", name="dokan_boss_waiting")
+	# 道馆里找文字:后关闭
+	O_DOKAN_SUCCEEDED = RuleOcr(roi=(1122,546,92,51), area=(1122,546,92,51), mode="Single", method="Default", keyword="关闭", name="dokan_succeeded")
+
+	# # Click Rule Assets
+	# # area1 
+	# C_AREA_1 = RuleClick(roi_front=(533,162,177,74), roi_back=(533,162,177,74), name="area_1")
+	# # area2 
+	# C_AREA_2 = RuleClick(roi_front=(863,164,181,71), roi_back=(863,164,181,71), name="area_2")
+	# # 在点击进攻后如果未进入战斗画面则点击的安全区域 
+	# C_SAFE_AREA = RuleClick(roi_front=(182,213,160,229), roi_back=(182,213,160,229), name="safe_area")
+
+	# Image Rule Assets
+	# I_DAILY_NAV = RuleImage(roi_front=(1, 291, 22, 63), roi_back=(1, 291, 22, 63), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_daily_nav.png")
+	# I_DAILY_DAILY = RuleImage(roi_front=(179, 127, 26, 52), roi_back=(179, 127, 26, 52), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_daily_daily.png")
+	# I_RYOU_DOKAN_CHECK2 = RuleImage(roi_front=(673,146,63,32), roi_back=(421,127,325,134), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_check2.png")
+
+	# # Ocr Rule Assets
+	# # 日常活动-前往
+	# O_GOTO = RuleOcr(roi=(604,501,63,29), area=(604,501,63,29), mode="Single", method="Default", keyword="前往", name="goto")
+
+

+ 35 - 0
tasks/Dokan/config.py

@@ -0,0 +1,35 @@
+# 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 enum import Enum
+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 DokanConfig(BaseModel):
+    # # 寮管理开启道馆
+    # dokan_declare_war: bool = Field(default=False, description='dokan_declare_war_help')
+    # # 选择哪一个竂
+    # dokan_declear_war_priority: int = Field(default=0, description='dokan_declear_war_priority_help')
+
+    # 攻击优先顺序: 见习=0,初级=1...
+    dokan_attack_priority: int = Field(default=0, description='dokan_attack_priority_help')
+
+    # 失败CD后自动加油
+    dokan_auto_cheering_while_cd: bool = Field(default=False, description='dokan_auto_cheering_while_cd_help')
+
+    # 正式进攻会设定 2s - 10s 的随机延迟,避免攻击间隔及其相近被检测为脚本。
+    random_delay: bool = Field(default=False, description='random_delay_help')
+
+class Dokan(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    dokan_config: DokanConfig = Field(default_factory=DokanConfig)
+    general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

+ 32 - 0
tasks/Dokan/res/click.json

@@ -0,0 +1,32 @@
+[
+  {
+    "itemName": "dokan_random_click_area",
+    "roiFront": "142,294,107,555",
+    "roiBack": "142,294,107,555",
+    "description": "道馆随机点击安全区域"
+  },
+  {
+    "itemName": "dokan_random_click_area1",
+    "roiFront": "42,594,10,100",
+    "roiBack": "42,594,10,100",
+    "description": "道馆随机点击安全区域1:竂友突破信息"
+  },
+  {
+    "itemName": "dokan_random_click_area2",
+    "roiFront": "1122,360,10,40",
+    "roiBack": "1122,360,10,40",
+    "description": "道馆随机点击安全区域2:切换查看队伍模式"
+  },
+  {
+    "itemName": "dokan_random_click_area3",
+    "roiFront": "333,44,107,20",
+    "roiBack": "333,44,107,20",
+    "description": "道馆随机点击安全区域3"
+  },
+  {
+    "itemName": "dokan_ready_for_battle",
+    "roiFront": "42,94,1207,543",
+    "roiBack": "42,94,1207,543",
+    "description": "准备战斗"
+  }
+]

BIN
tasks/Dokan/res/dokan_attacking.png


BIN
tasks/Dokan/res/gb_prepare_dark.png


BIN
tasks/Dokan/res/gb_prepare_highlight.png


+ 275 - 0
tasks/Dokan/res/image.json

@@ -0,0 +1,275 @@
+[
+  {
+    "itemName": "ryou_shenshe",
+    "imageName": "res_ryou_shenshe.png",
+    "roiFront": "476,173,62,24",
+    "roiBack": "476,173,62,24",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "阴阳竂->神社"
+  },
+  {
+    "itemName": "ryou_dokan",
+    "imageName": "res_ryou_dokan.png",
+    "roiFront": "476,173,62,24",
+    "roiBack": "476,173,62,24",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "神社->道馆"
+  },
+  {
+    "itemName": "ryou_dokan_ryou_select",
+    "imageName": "res_ryou_dokan_ryou_select.png",
+    "roiFront": "567,15,144,42",
+    "roiBack": "567,15,144,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "[]选择竂"
+  },
+  {
+    "itemName": "ryou_dokan_ryou_list",
+    "imageName": "res_ryou_dokan_ryou_list.png",
+    "roiFront": "567,15,144,42",
+    "roiBack": "567,15,144,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "可选的竂列表"
+  },
+  {
+    "itemName": "ryou_dokan_check",
+    "imageName": "res_ryou_dokan_check.png",
+    "roiFront": "567,15,144,42",
+    "roiBack": "567,15,144,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "是否已经成功进入道馆,上面中间的“道馆突破”文字"
+  },
+  {
+    "itemName": "ryou_dokan_attack_priority",
+    "imageName": "res_ryou_dokan_attack_priority.png",
+    "roiFront": "567,15,144,42",
+    "roiBack": "567,15,144,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "优先攻击选项"
+  },
+  {
+    "itemName": "ryou_dokan_attack_priority_0",
+    "imageName": "res_ryou_dokan_attack_priority_0.png",
+    "roiFront": "98,170,94,43",
+    "roiBack": "98,170,94,43",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "优先攻击: 见习"
+  },
+  {
+    "itemName": "ryou_dokan_attack_priority_1",
+    "imageName": "res_ryou_dokan_attack_priority_1.png",
+    "roiFront": "342,175,96,42",
+    "roiBack": "342,175,96,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "优先攻击: 初级"
+  },
+  {
+    "itemName": "ryou_dokan_attack_priority_2",
+    "imageName": "res_ryou_dokan_attack_priority_2.png",
+    "roiFront": "585,175,89,35",
+    "roiBack": "585,175,89,35",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "优先攻击: 中级"
+  },
+  {
+    "itemName": "ryou_dokan_attack_priority_3",
+    "imageName": "res_ryou_dokan_attack_priority_3.png",
+    "roiFront": "830,175,88,41",
+    "roiBack": "830,175,88,41",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "优先攻击: 高级"
+  },
+  {
+    "itemName": "ryou_dokan_attack_priority_4",
+    "imageName": "res_ryou_dokan_attack_priority_4.png",
+    "roiFront": "1072,178,94,39",
+    "roiBack": "1072,178,94,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "优先攻击: 黑脸"
+  },
+
+
+  {
+    "itemName": "ryou_dokan_gathering",
+    "imageName": "res_ryou_dokan_gathering.png",
+    "roiFront": "653,76,46,26",
+    "roiBack": "653,76,46,26",
+    "method": "Template matching",
+    "threshold": 0.85,
+    "description": "状态:集结等待中。检查右下角的挑战是不是灰色的。FIXME 黄色和灰色的挑战截图总是傻傻分不清,先改用OCR"
+  },
+  {
+    "itemName": "ryou_dokan_start_challenge",
+    "imageName": "res_ryou_dokan_start_challenge.png",
+    "roiFront": "1132,572,89,43",
+    "roiBack": "1132,572,89,43",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:检查右下角有没有挑战?通常是失败了,并退出来到集结界面,可重新开始点击右下角挑战进入战斗"
+  },
+  {
+    "itemName": "ryou_dokan_cd1",
+    "imageName": "res_ryou_dokan_cd1.png",
+    "roiFront": "1068,500,146,27",
+    "roiBack": "1068,500,146,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:达到失败次数,CD中。挑战次数恢复倒数"
+  },
+  {
+    "itemName": "ryou_dokan_cd",
+    "imageName": "res_ryou_dokan_cd.png",
+    "roiFront": "1122,566,117,74",
+    "roiBack": "1122,566,117,74",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:达到失败次数,CD中。观战按钮"
+  },
+  {
+    "itemName": "ryou_dokan_in_field",
+    "imageName": "res_ryou_dokan_in_field.png",
+    "roiFront": "1128,536,100,100",
+    "roiBack": "1128,536,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:进入战斗,待开始,右下角图标。TODO 欠截图。"
+  },
+  {
+    "itemName": "dokan_boss_waiting",
+    "imageName": "res_dokan_boss_waiting.png",
+    "roiFront": "603,148,130,32",
+    "roiBack": "603,148,130,32",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "馆主战等待中"
+  },
+
+  {
+    "itemName": "ryou_dokan_win",
+    "imageName": "res_ryou_dokan_win.png",
+    "roiFront": "628,60,45,33",
+    "roiBack": "628,60,45,33",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:道馆胜利"
+  },
+
+  {
+    "itemName": "ryou_dokan_in_field2",
+    "imageName": "res_ryou_dokan_in_field2.png",
+    "roiFront": "1131,562,88,48",
+    "roiBack": "1131,562,88,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:进入战斗,待开始,右下角图标。"
+  },
+  {
+    "itemName": "ryou_dokan_battle_over",
+    "imageName": "res_ryou_dokan_battle_over.png",
+    "roiFront": "571,503,106,49",
+    "roiBack": "571,503,106,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:战斗结算,可能是打完小朋友了,也可能是失败了。"
+  },
+
+  {
+    "itemName": "ryou_dokan_fighting",
+    "imageName": "res_ryou_dokan_fighting.png",
+    "roiFront": "232,36,42,19",
+    "roiBack": "232,36,42,19",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:战斗中,左上角的加油图标"
+  },
+  {
+    "itemName": "ryou_dokan_cheering",
+    "imageName": "res_ryou_dokan_cheering.png",
+    "roiFront": "68,597,69,33",
+    "roiBack": "68,597,69,33",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:加油中,左下角有鼓"
+  },
+  {
+    "itemName": "ryou_dokan_cheering_gray",
+    "imageName": "res_ryou_dokan_cheering_gray.png",
+    "roiFront": "59,600,81,38",
+    "roiBack": "59,600,81,38",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:加油中,左下角有鼓,灰色的鼓"
+  },
+  {
+    "itemName": "ryou_dokan_finished",
+    "imageName": "res_ryou_dokan_finished.png",
+    "roiFront": "658,649,91,27",
+    "roiBack": "658,649,91,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:道馆已经结束"
+  },
+  {
+    "itemName": "ryou_dokan_failed_vote_no",
+    "imageName": "res_ryou_dokan_failed_vote_no.png",
+    "roiFront": "567,15,144,42",
+    "roiBack": "567,15,144,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "状态:道馆挑战失败,投票NO"
+  },
+
+  
+
+  
+  {
+    "itemName": "ryou_dokan_cheering_scores",
+    "imageName": "res_ryou_dokan_cheering_scores.png",
+    "roiFront": "157,100,35,39",
+    "roiBack": "157,100,35,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进入加油相关:道馆战报按钮"
+  },
+  {
+    "itemName": "ryou_dokan_cheering_attacking_sama",
+    "imageName": "res_ryou_dokan_cheering_attacking_sama.png",
+    "roiFront": "948,182,56,295",
+    "roiBack": "948,182,56,295",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进入加油相关:前往战斗中的竂友"
+  },
+
+
+  {
+    "itemName": "scene_ryou",
+    "imageName": "scene_ryou.png",
+    "roiFront": "1161,674,75,31",
+    "roiBack": "1161,674,75,31",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:阴阳竂"
+  },
+  {
+    "itemName": "scene_ryou",
+    "imageName": "scene_ryou.png",
+    "roiFront": "1161,674,75,31",
+    "roiBack": "1161,674,75,31",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:阴阳竂"
+  }
+
+]

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

@@ -0,0 +1,23 @@
+{
+    "name": "layer_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": "狭间暗域"
+      }
+    ]
+  }

+ 48 - 0
tasks/Dokan/res/ocr.json

@@ -0,0 +1,48 @@
+[
+  {
+    "itemName": "dokan_map",
+    "roiFront": "1122,546,92,51",
+    "roiBack": "1122,546,92,51",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "万",
+    "description": "道馆地图里找文字:万"
+  },
+  {
+    "itemName": "dokan_gathering",
+    "roiFront": "535,75,211,29",
+    "roiBack": "535,75,211,29",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "开战",
+    "description": "道馆里找文字:后开战"
+  },
+  {
+    "itemName": "dokan_attacking",
+    "roiFront": "1122,546,92,51",
+    "roiBack": "1122,546,92,51",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "剩余",
+    "description": "道馆里找文字:剩余突破时间"
+  },
+  {
+    "itemName": "dokan_boss_waiting",
+    "roiFront": "603,148,130,32",
+    "roiBack": "603,148,130,32",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "馆主",
+    "description": "道馆里找文字:后挑战馆主"
+  },
+  {
+    "itemName": "dokan_succeeded",
+    "roiFront": "1122,546,92,51",
+    "roiBack": "1122,546,92,51",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "关闭",
+    "description": "道馆里找文字:后关闭"
+  }
+
+]

BIN
tasks/Dokan/res/res_dokan_boss_waiting.png


BIN
tasks/Dokan/res/res_ryou_dokan.png


BIN
tasks/Dokan/res/res_ryou_dokan_battle_over.png


BIN
tasks/Dokan/res/res_ryou_dokan_cd.png


BIN
tasks/Dokan/res/res_ryou_dokan_cd1.png


BIN
tasks/Dokan/res/res_ryou_dokan_check.png


BIN
tasks/Dokan/res/res_ryou_dokan_cheering.png


BIN
tasks/Dokan/res/res_ryou_dokan_cheering_attacking_sama.png


BIN
tasks/Dokan/res/res_ryou_dokan_cheering_gray.png


BIN
tasks/Dokan/res/res_ryou_dokan_cheering_scores.png


BIN
tasks/Dokan/res/res_ryou_dokan_failed_vote_no.png.png


BIN
tasks/Dokan/res/res_ryou_dokan_fighting.png


BIN
tasks/Dokan/res/res_ryou_dokan_finished.png


BIN
tasks/Dokan/res/res_ryou_dokan_gathering.png


BIN
tasks/Dokan/res/res_ryou_dokan_in_field.png


BIN
tasks/Dokan/res/res_ryou_dokan_in_field2.png


BIN
tasks/Dokan/res/res_ryou_dokan_priority.png


BIN
tasks/Dokan/res/res_ryou_dokan_priority_0.png


BIN
tasks/Dokan/res/res_ryou_dokan_priority_1.png


BIN
tasks/Dokan/res/res_ryou_dokan_priority_2.png


BIN
tasks/Dokan/res/res_ryou_dokan_priority_3.png


BIN
tasks/Dokan/res/res_ryou_dokan_priority_4.png


BIN
tasks/Dokan/res/res_ryou_dokan_start_challenge.png


BIN
tasks/Dokan/res/res_ryou_dokan_start_challenge2.png


BIN
tasks/Dokan/res/res_ryou_dokan_win.png


BIN
tasks/Dokan/res/res_ryou_shenshe.png


BIN
tasks/Dokan/res/scene_ryou.png


+ 526 - 0
tasks/Dokan/script_task.py

@@ -0,0 +1,526 @@
+# 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
+
+import sys
+from pathlib import Path
+
+# 获取当前文件的目录
+current_dir = Path(__file__).resolve().parent
+# 获取上级目录
+upper_dir = current_dir.parent.parent
+# print(sys.path)
+sys.path.append(str(upper_dir))
+# print(sys.path)
+
+from enum import Enum
+import time
+from datetime import datetime, timedelta
+import random
+
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.Dokan.assets import DokanAssets
+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 tasks.Dokan.config import DokanConfig, Dokan
+
+class DokanScene(Enum):
+    # 未知界面
+    RYOU_DOKAN_SCENE_UNKNOWN = 0
+    # 进入道馆,集结中
+    RYOU_DOKAN_SCENE_GATHERING = 1
+    # 进入战场,等待用户点击开始战斗
+    RYOU_DOKAN_SCENE_IN_FIELD = 2
+    # 通常是失败了,并退出来到集结界面,可重新开始点击右下角挑战进入战斗
+    RYOU_DOKAN_SCENE_START_CHALLENGE = 3
+    # 失败次数超过上限,CD中
+    RYOU_DOKAN_SCENE_CD = 4
+    # 战斗进行中
+    RYOU_DOKAN_SCENE_FIGHTING = 5
+    # 加油进行中
+    RYOU_DOKAN_SCENE_CHEERING = 6
+    # 道馆失败投票保留
+    RYOU_DOKAN_SCENE_FAILED_VOTE_NO = 7
+    # 阴阳竂
+    RYOU_DOKAN_RYOU = 8
+    # 战斗结算,可能是打完小朋友了,也可能是失败了。
+    RYOU_DOKAN_SCENE_BATTLE_OVER = 9
+    # 等待BOSS战
+    RYOU_DOKAN_SCENE_BOSS_WAITING = 10
+    # 道馆结束
+    RYOU_DOKAN_SCENE_FINISHED = 99
+    
+    def __str__(self):
+        return self.name.title()
+    
+    def print(self):
+        print(DokanScene.RYOU_DOKAN_SCENE_GATHERING)        # 输出: DokanScene.Ryou_Daoguan_Scene_Gathering
+        print(DokanScene.RYOU_DOKAN_SCENE_CD.value)         # 输出: 2
+        print(str(DokanScene.RYOU_DOKAN_SCENE_FIGHTING))    # 输出: Ryou_Daoguan_Scene_Fighting
+
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DokanAssets):
+    medal_grid: ImageGrid = None
+    attack_priority_selected: bool = False
+    team_switched: bool = False
+    green_mark_done : bool = False
+
+    def run(self):
+        """ 道馆主函数
+
+        :return:
+        """
+        cfg: Dokan = self.config.dokan
+        current_scene: DokanScene = DokanScene.RYOU_DOKAN_SCENE_UNKNOWN
+        in_dokan: bool = False
+
+        # 攻击优先顺序
+        attack_priority: int = cfg.dokan_config.dokan_attack_priority
+
+        # 自动换御魂
+        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)
+
+        success = True
+        scene_err_count = 0
+
+        # 在阴阳竂界面点击并进入道馆
+        # 检测当前界面的场景(时间关系,暂时没有做庭院、町中等主界面的场景检测, 应考虑在GameUI.game_ui.ui_get_current_page()里实现)
+        in_dokan, current_scene = self.get_current_scene(True)
+
+        if not in_dokan:
+            self.ui_get_current_page()
+            self.ui_goto(page_guild)
+
+            self.goto_dokan()
+    
+        # 开始道馆流程
+        while 1:
+            self.screenshot()
+
+            # 检测当前界面的场景(时间关系,暂时没有做庭院、町中等主界面的场景检测, 应考虑在GameUI.game_ui.ui_get_current_page()里实现)
+            in_dokan, current_scene = self.get_current_scene(True)
+
+            logger.info(f"in_dokan={in_dokan}, current_scene={current_scene}")
+
+            # 如果当前不在道馆,或者被人工操作退出道馆了,重新尝试进入道馆
+            if not in_dokan:
+                scene_err_count += 1
+                logger.info(f"err count={scene_err_count}")
+                if scene_err_count >= 3:
+                    self.goto_dokan()
+                # 先点击一下,然后等5秒再重新截图
+                self.anti_detect(True, False, False)
+                time.sleep(5)
+                continue
+            else:
+                scene_err_count = 0
+
+            # 场景状态:道馆集结中
+            if current_scene == DokanScene.RYOU_DOKAN_SCENE_GATHERING:
+                logger.debug(f"Ryou DOKAN gathering, 集结中...")
+                # 如果还未选择优先攻击,选一下
+                if not self.attack_priority_selected:
+                    self.dokan_choose_attack_priority(attack_priority=attack_priority)
+            # 场景状态:等待馆主战开始
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_BOSS_WAITING:
+                logger.debug(f"Ryou DOKAN boss battle waiting...")
+            # 场景状态:检查右下角有没有挑战?通常是失败了,并退出来到集结界面,可重新开始点击右下角挑战进入战斗
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_START_CHALLENGE:
+                self.appear_then_click(self.I_RYOU_DOKAN_START_CHALLENGE)
+            # 场景状态:进入战斗,待开始
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_IN_FIELD:
+                # 战斗
+                success = self.dokan_battle(cfg)
+                # 战斗结束后,随便点三下,确保跳过各种结算画面
+                self.click(click=self.C_DOKAN_READY_FOR_BATLLE)
+                time.sleep(2)
+                self.click(click=self.C_DOKAN_RANDOM_CLICK_AREA2)
+                time.sleep(2)
+                self.click(click=self.C_DOKAN_RANDOM_CLICK_AREA3)
+                # 每次战斗结束都重置绿标
+                self.green_mark_done = False
+            # 场景状态:如果CD中,开始加油
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_CD:
+                logger.info(f"CD中,是否加油:{cfg.dokan_config.dokan_auto_cheering_while_cd}..")
+                if cfg.dokan_config.dokan_auto_cheering_while_cd:
+                    self.start_cheering()
+            # 场景状态:战斗中,左上角的加油图标
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_FIGHTING:
+                logger.info("战斗进行中")
+            # 场景状态:加油中
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_CHEERING:
+                self.appear_then_click(self.I_RYOU_DOKAN_CHEERING)
+            # 场景状态:道馆已经结束
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_FINISHED:
+                logger.info("道馆已经结束,退出")
+                break
+            elif current_scene == DokanScene.RYOU_DOKAN_SCENE_FAILED_VOTE_NO:
+                logger.info("道馆挑战失败:投票保留")
+            else:
+                logger.info(f"unknown scene, skipped")
+            
+            # 防封,随机移动,随机点击(安全点击),随机时延
+            if not self.anti_detect(True, True, True):
+                time.sleep(1)
+
+        # self.ui_current = page_ryou_dokan
+        # self.ui_goto(page_main)
+
+        ''' 保持好习惯,一个任务结束了就返回到庭院,方便下一个任务的开始
+         FIXME 退出道馆。注意:有的时候有退出确认框,有的时候没有。未找到规律。
+               先试试用确认框的,若是实在不行,就改成等道馆时间结束后,系统自动退出
+        '''
+        max_try = 3
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(GeneralBattle.I_EXIT, interval=1.5):
+                logger.info(f"Click {GeneralBattle.I_EXIT.name}")
+                continue
+            # 点了后EXIT后,可能无确认框
+            if self.appear_then_click(GeneralBattle.I_EXIT_ENSURE, interval=1.5):
+                logger.info(f"Click {GeneralBattle.I_EXIT_ENSURE.name}")
+                break
+            else:
+                max_try -= 1
+                time.sleep(1.2)
+
+            if max_try <= 0:
+                break
+        
+        # 退出道馆地图
+        while 1:
+            self.screenshot()
+            # 确认后会跳到竂地图,再点击左上角的蓝色的返回,但是不知道这个返回有没有确认
+            if self.appear_then_click(GameUi.I_BACK_BL, interval=2.5):
+                logger.info(f"Click {GameUi.I_BACK_BL.name}")
+                break
+        
+        # 设置下次运行时间
+        if success:
+            self.set_next_run(task='Dokan', finish=True, server=True, success=True)
+        else:
+            self.set_next_run(task='Dokan', finish=True, server=True, success=False)
+        raise TaskEnd
+    
+    def dokan_battle(self, cfg: Dokan):
+        """ 道馆战斗
+        道馆集结结束后会自动进入战斗,打完一个也会自动进入下一个,因此直接点击右下角的开始
+
+        :return: 战斗成功(True) or 战斗失败(False) or 区域不可用(False)
+        """
+        config: GeneralBattleConfig = cfg.general_battle_config
+
+        # 正式进攻会设定 2s - 10s 的随机延迟,避免攻击间隔及其相近被检测为脚本。
+        if cfg.dokan_config.random_delay:
+            self.anti_detect(False, False, True)
+
+        # 上面可能睡了一觉,重新截图
+        self.screenshot()
+
+        # 更换队伍
+        if not self.team_switched:
+            logger.info(f"更换队伍: config.preset_enable={config.preset_enable}, config.preset_group={config.preset_group}, config.preset_team={config.preset_team}")
+            self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
+            self.team_switched = True
+
+        # 等待准备按钮的出现
+        logger.debug("等待准备按钮的出现")
+        self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
+
+        # 点击准备
+        if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
+            logger.info("点击准备")
+
+            # 绿标式神, should we check there's a green marked role?
+            if not self.green_mark_done and self.is_in_battle(False):
+                logger.info(f"绿标式神:config.green_enable={config.green_enable}, config.green_mark={config.green_mark}")
+                self.green_mark(config.green_enable, config.green_mark)
+                self.green_mark_done = True
+
+        # 等待战斗结果
+        logger.info(f"等待战斗结果:config.random_click_swipt_enable={config.random_click_swipt_enable}")
+        logger.info("come on baby, let's go.")
+
+        while 1:
+            logger.info("take a nap")
+            time.sleep(1)
+
+            self.device.stuck_record_add('BATTLE_STATUS_S')
+            self.device.click_record_clear()
+
+            self.screenshot()
+
+            # 如果出现赢 就点击
+            if self.appear(GeneralBattle.I_WIN, threshold=0.8):
+                logger.info("道馆的小朋友们打完了,boss is on the way")
+                win = True
+                break
+
+            # 如果出现打败馆主的赢,就点击
+            if self.appear(self.I_RYOU_DOKAN_WIN, threshold=0.8):
+                logger.info("We've defeated the boss, and win the final game.")
+                win = True
+                break
+
+            # 如果出现失败 就点击,返回False。 TODO 不知道挑战馆主失败是不是同一个画面?
+            if self.appear(GeneralBattle.I_FALSE, threshold=0.8):
+                logger.info("Battle failed")
+                win = False
+                break
+
+            # 如果领奖励
+            if self.appear(self.I_RYOU_DOKAN_BATTLE_OVER, threshold=0.6):
+                logger.info("Battle over")
+                win = True
+                break
+
+            # 如果领奖励出现金币
+            if self.appear(GeneralBattle.I_REWARD_GOLD, threshold=0.8):
+                win = True
+                break
+
+            # 如果开启战斗过程随机滑动
+            if config.random_click_swipt_enable:
+                logger.info("random swipt ...")
+                self.random_click_swipt()
+
+            # 打完一个小朋友,自动进入下一个小朋友
+            if self.appear_then_click(self.I_RYOU_DOKAN_IN_FIELD):
+                logger.info("New battle starts")
+
+            continue
+
+        logger.info(f"输赢:{win}")
+        if win:
+            return True
+        else:
+            return False
+
+    def dokan_choose_attack_priority(self, attack_priority: int):
+        ''' 选择优先攻击
+        : return 
+        '''
+        logger.info("选择优先攻击")
+
+        max_try = 5
+
+        while 1:
+            if max_try <= 0:
+                logger.warn("give up priority selection!")
+                break
+
+            self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY, interval=2)
+
+            if not self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY, interval=2):
+                logger.info(f"start select attack priority: {attack_priority}, remain try: {max_try}")
+                max_try -= 1
+                self.screenshot()
+                if attack_priority == 0:
+                    if self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY_0, interval=1.8):
+                        logger.info(f"selected attack priority: {attack_priority}")
+                    else:
+                        continue
+                elif attack_priority == 1:
+                    if self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY_1, interval=1.8):
+                        logger.info(f"selected attack priority: {attack_priority}")
+                    else:
+                        continue
+                elif attack_priority == 2:
+                    if self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY_2):
+                        logger.info(f"selected attack priority: {attack_priority}")
+                    else:
+                        continue
+                elif attack_priority == 3:
+                    if self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY_3):
+                        logger.info(f"selected attack priority: {attack_priority}")
+                    else:
+                        continue
+                elif attack_priority == 4:
+                    if self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY_4):
+                        logger.info(f"selected attack priority: {attack_priority}")
+                    else:
+                        continue
+                else:
+                    self.appear_then_click(self.I_RYOU_DOKAN_PRIORITY_0)
+                    logger.error(f"invalid attack priority setting: {attack_priority}")
+
+                break
+
+
+        self.attack_priority_selected = True
+
+    def anti_detect(self, random_move: bool = True, random_click: bool = True, random_delay: bool = True):
+        '''额外的防封测试
+
+        准备找个号做做爬楼活动的每天300次试试
+        '''
+        res = False
+        # 三个行为中,任何一个生效了都返回True, 否则返回False
+        if random_move:
+            self.random_click_swipt()
+            res = True
+        if random_click:
+            # pos = self.C_DOKAN_RANDOM_CLICK_AREA.coord()
+            # self.click(pos)
+            res = True
+        if random_delay:
+            # 0到2秒之间的随机浮点数
+            sleep = random.uniform(0, 5)
+            # 只保留2位小数
+            sleep = round(sleep, 2)
+            time.sleep(sleep)
+            res = True
+        return res
+
+    def goto_dokan(self):
+        ''' 进入道馆
+        TODO 道馆相关场景
+        :return 
+        '''
+        self.ui_get_current_page()
+        try_count = 0
+        while try_count < 5:
+            # 点击进入道馆
+            logger.info("进入阴阳竂")
+            self.ui_goto(page_guild)
+            # 查找道馆
+            activity = "道馆"
+            pos = self.list_find(self.L_RYOU_ACTIVITY_LIST, activity)
+            if pos:
+                logger.info(f"Enter Dokan map: pos = {pos}")
+                self.device.click(x=pos[0], y=pos[1])
+
+                # 进了后的画面,我没有截图,盲猜应该是在画面正中间的
+                time.sleep(2)
+                image = self.screenshot()
+
+                # O_DOKAN_MAP = RuleOcr(roi=(270,130,740,460), area=(270,130,740,460), mode="Full", method="Default", keyword="万", name="dokan_map")
+                # image = cv2.imread("g:/yys/oas/tests/2.png")
+                pos = self.O_DOKAN_MAP.ocr_full(image)
+                if pos == (0, 0, 0, 0):
+                    logger.info("failed to find {self.O_DOKAN_MAP.keyword}")
+                else:
+                    # 取中间
+                    x = pos[0] + pos[2]/2
+                    # 往上偏移20
+                    y = pos[1] - 20
+
+                    logger.info("ocr detect result pos={pos}, try click pos, x={x}, y={y}")
+
+                    self.device.click(x=x, y=y)
+                    break
+            try_count += 1
+            time.sleep(1)
+
+        print(f"try_count: {try_count}")
+
+    def start_cheering(self):
+        logger.info("start cheering")
+
+    def get_current_scene(self, reuse_screenshot: bool = True):
+        ''' 检测当前场景
+        '''
+        if not reuse_screenshot:
+            self.screenshot()
+        logger.info(f"get_current_scene={reuse_screenshot}")
+        # 场景检测:阴阳竂
+        if self.appear(self.I_SCENE_RYOU, threshold=0.8):
+            return False, DokanScene.RYOU_DOKAN_RYOU
+
+        # 状态:判断是否集结中
+        # if self.ocr_appear(self.O_DOKAN_GATHERING):
+        if self.appear(self.I_RYOU_DOKAN_GATHERING, threshold=0.95):
+            return True, DokanScene.RYOU_DOKAN_SCENE_GATHERING
+        # 状态:是否在等待馆主战
+        # if self.ocr_appear(self.O_DOKAN_BOSS_WAITING):
+        if self.appear(self.I_DOKAN_BOSS_WAITING):
+            return True, DokanScene.RYOU_DOKAN_SCENE_BOSS_WAITING
+
+        # 状态:检查右下角有没有挑战?通常是失败了,并退出来到集结界面,可重新开始点击右下角挑战进入战斗
+        elif self.appear(self.I_RYOU_DOKAN_START_CHALLENGE, 0.95):
+            return True, DokanScene.RYOU_DOKAN_SCENE_START_CHALLENGE
+        
+        # 状态:进入战斗,待开始
+        elif self.appear(self.I_RYOU_DOKAN_IN_FIELD, threshold=0.85):
+            return True, DokanScene.RYOU_DOKAN_SCENE_IN_FIELD
+        # 状态:战斗结算,可能是打完小朋友了,也可能是失败了。
+        if self.appear(self.I_RYOU_DOKAN_BATTLE_OVER, threshold=0.85):
+            return True, DokanScene.RYOU_DOKAN_SCENE_BATTLE_OVER
+        
+        # 状态:达到失败次数,CD中
+        if self.appear(self.I_RYOU_DOKAN_CD, threshold=0.8):
+            return True, DokanScene.RYOU_DOKAN_SCENE_CD
+        # 状态:加油中,左下角有鼓
+        if self.appear_then_click(self.I_RYOU_DOKAN_CHEERING, threshold=0.8) or self.appear(self.I_RYOU_DOKAN_CHEERING_GRAY, threshold=0.8):
+            return True, DokanScene.RYOU_DOKAN_SCENE_CHEERING
+        # # 状态:战斗中,左上角的加油图标
+        # if self.appear(self.I_RYOU_DOKAN_FIGHTING, threshold=0.8):
+        #     return True, DokanScene.RYOU_DOKAN_SCENE_FIGHTING
+        # if self.appear(self.I_RYOU_DOKAN_FAILED_VOTE_NO):
+        #     return True, DokanScene.RYOU_DOKAN_SCENE_FAILED_VOTE_NO
+
+        # 状态:道馆已经结束
+        # if self.ocr_appear(self.O_DOKAN_SUCCEEDED):
+        if self.appear(self.I_RYOU_DOKAN_FINISHED, threshold=0.8):
+            return True, DokanScene.RYOU_DOKAN_SCENE_FINISHED
+        
+        return False, DokanScene.RYOU_DOKAN_SCENE_UNKNOWN
+
+if __name__ == "__main__":
+    # from module.config.config import Config
+    # from module.device.device import Device
+
+    # config = Config('oas1')
+    # device = Device(config)
+    # t = ScriptTask(config, device)
+    # t.run()
+
+    import cv2
+    from module.atom.ocr import RuleOcr
+
+    logger.info("========================================>>test 2")
+    O_DOKAN_MAP = RuleOcr(roi=(270,130,740,460), area=(270,130,740,460), mode="Full", method="Default", keyword="万", name="dokan_map")
+
+    image = cv2.imread("g:/yys/oas/tests/1.png")
+    pos = O_DOKAN_MAP.ocr_full(image)
+    print(f"image1: {pos}")
+
+    image = cv2.imread("g:/yys/oas/tests/2.png")
+    pos = O_DOKAN_MAP.ocr_full(image)
+    print(f"image2: {pos}")
+
+    image = cv2.imread("g:/yys/oas/tests/3.png")
+    pos = O_DOKAN_MAP.ocr_full(image)
+    print(f"image3: {pos}")
+
+    image = cv2.imread("g:/yys/oas/tests/4.png")
+    pos = O_DOKAN_MAP.ocr_full(image)
+    print(f"image4: {pos}")
+    if pos == (0, 0, 0, 0):
+        logger.info("failed to find {self.O_DOKAN_MAP.keyword}")
+    else:
+        # 取中间
+        x = pos[0] + pos[2]/2
+        # 往上偏移20
+        y = pos[1] - 20
+
+        logger.info(f"ocr detect result pos={pos}, try click pos, x={x}, y={y}")

+ 5 - 8
tasks/Restart/config.py

@@ -4,9 +4,7 @@
 from pydantic import BaseModel, Field
 
 from tasks.Restart.config_scheduler import RestartScheduler
-from tasks.Component.config_base import ConfigBase
-
-
+from tasks.Component.config_base import ConfigBase, DateTime
 
 class HarvestConfig(BaseModel):
     # 默认启用
@@ -24,13 +22,12 @@ class HarvestConfig(BaseModel):
     # 体力
     enable_ap: bool = Field(default=True)
 
-
-
-
-
-
+class TaskConfig(BaseModel):
+    reset_task_datetime_enable: bool = Field(default=False, description='reset_task_datetime_enable_help')
+    reset_task_datetime: DateTime = Field(default="2023-01-01 00:00:00", description='rest_task_datetime_help')
 
 class Restart(ConfigBase):
+    task_config: TaskConfig = Field(default_factory=TaskConfig)
     scheduler: RestartScheduler = Field(default_factory=RestartScheduler)
     harvest_config: HarvestConfig = Field(default_factory=HarvestConfig)