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

Merge pull request #1089 from runhey/dev

Automated PR 2025.09.25
huangrunheng 1 год назад
Родитель
Сommit
0db4275cb2
58 измененных файлов с 1012 добавлено и 547 удалено
  1. 5 1
      deploy/config.py
  2. 1 0
      module/base/decorator.py
  3. 5 0
      module/device/handle.py
  4. BIN
      tasks/ActivityShikigami/as/as_boss.png
  5. BIN
      tasks/ActivityShikigami/as/as_buff_box_1_empty.png
  6. BIN
      tasks/ActivityShikigami/as/as_buff_box_2_empty.png
  7. BIN
      tasks/ActivityShikigami/as/as_buff_change_button.png
  8. BIN
      tasks/ActivityShikigami/as/as_buff_down.png
  9. BIN
      tasks/ActivityShikigami/as/as_buff_switch.png
  10. BIN
      tasks/ActivityShikigami/as/as_buff_up.png
  11. BIN
      tasks/ActivityShikigami/as/as_check_battle_2.png
  12. BIN
      tasks/ActivityShikigami/as/as_check_boss.png
  13. BIN
      tasks/ActivityShikigami/as/as_check_buff.png
  14. BIN
      tasks/ActivityShikigami/as/as_red_exit_2.png
  15. BIN
      tasks/ActivityShikigami/as/as_skip_button.png
  16. 42 0
      tasks/ActivityShikigami/as/click.json
  17. 102 3
      tasks/ActivityShikigami/as/image.json
  18. 9 0
      tasks/ActivityShikigami/as/ocr.json
  19. 40 2
      tasks/ActivityShikigami/assets.py
  20. 49 12
      tasks/ActivityShikigami/config.py
  21. 345 339
      tasks/ActivityShikigami/script_task.py
  22. 25 32
      tasks/Component/BaseActivity/config_activity.py
  23. 1 1
      tasks/Component/Costume/assets.py
  24. 2 2
      tasks/Component/Costume/main12/image.json
  25. BIN
      tasks/Component/Costume/main12/main12_check_main_12.png
  26. 43 0
      tasks/Component/CostumeShikigami/assets.py
  27. 2 0
      tasks/Component/GeneralBattle/assets.py
  28. BIN
      tasks/Component/GeneralBattle/gb/gb_battle_info.png
  29. 9 0
      tasks/Component/GeneralBattle/gb/image.json
  30. 3 1
      tasks/Component/GeneralBattle/general_battle.py
  31. 1 1
      tasks/Component/SwitchSoul/switch_soul.py
  32. 20 0
      tasks/GameUi/additional/act.json
  33. BIN
      tasks/GameUi/additional/additional_act_list_expand.png
  34. BIN
      tasks/GameUi/additional/additional_paper_doll_close.png
  35. 25 2
      tasks/GameUi/assets.py
  36. 64 26
      tasks/GameUi/game_ui.py
  37. 43 4
      tasks/GameUi/page.py
  38. BIN
      tasks/GameUi/page/page_act_list_climb_act.png
  39. BIN
      tasks/GameUi/page/page_act_list_goto_act.png
  40. BIN
      tasks/GameUi/page/page_back_act_list.png
  41. BIN
      tasks/GameUi/page/page_check_act_list.png
  42. 5 5
      tasks/GameUi/page/page_img_3.json
  43. 18 0
      tasks/GameUi/page/page_img_supplement.json
  44. 13 0
      tasks/GameUi/page/page_list_act_img.json
  45. 13 0
      tasks/GameUi/page/page_list_act_ocr.json
  46. 1 1
      tasks/GlobalGame/assets.py
  47. 1 1
      tasks/GlobalGame/ui/image.json
  48. 0 1
      tasks/HeroTest/config.py
  49. 1 1
      tasks/Orochi/assets.py
  50. 4 0
      tasks/Orochi/config.py
  51. 4 0
      tasks/Orochi/res/list.json
  52. 2 0
      tasks/Orochi/script_task.py
  53. 2 1
      tasks/SoulsTidy/config.py
  54. 86 84
      tasks/SoulsTidy/script_task.py
  55. 1 1
      tasks/WantedQuests/assets.py
  56. 1 1
      tasks/WantedQuests/wq/image.json
  57. BIN
      tasks/WantedQuests/wq/wq_wq_seal.png
  58. 24 25
      tasks/base_task.py

+ 5 - 1
deploy/config.py

@@ -13,7 +13,7 @@ class ExecutionError(Exception):
 
 class ConfigModel:
     # Git
-    Repository: str = "https://e.coding.net/onmyojiautoscript/oas/OnmyojiAutoScript.git"
+    Repository: str = "https://gitcode.com/OnmyojiAutoScript/OnmyojiAutoScript.git"
     Branch: str = "master"
     GitExecutable: str = "./toolkit/Git/mingw64/bin/git.exe"
     GitProxy: Optional[str] = None
@@ -89,6 +89,10 @@ class DeployConfig(ConfigModel):
 
     def read(self):
         self.config = poor_yaml_read(DEPLOY_TEMPLATE)
+        # https://e.coding.net/onmyojiautoscript/oas/OnmyojiAutoScript.git
+        # 2025.09.01 腾讯coding跑路了
+        if self.config["Repository"].startswith("https://e.coding.net/"):
+            self.config["Repository"] = "https://gitcode.com/OnmyojiAutoScript/OnmyojiAutoScript.git"
         self.config_template = copy.deepcopy(self.config)
         self.config.update(poor_yaml_read(self.file))
 

+ 1 - 0
module/base/decorator.py

@@ -192,6 +192,7 @@ def run_once(f):
             action()
     """
 
+    @wraps(f)
     def wrapper(*args, **kwargs):
         if not wrapper.has_run:
             wrapper.has_run = True

+ 5 - 0
module/device/handle.py

@@ -257,6 +257,11 @@ class Handle:
         # 事实上 我们只需要最后一个 'MuMu模拟器12',其他的不重要
         if 'MuMu模拟器12' in emu_list and 'MuMuPlayer' in emu_list:
             emulator_title = 'MuMu模拟器12'
+        
+        # MuMu5.0更新,窗体标题改动: 'MuMu模拟器','MuMuNxDevice','MuMu安卓设备'
+        # 如果没有匹配上旧版本,尝试匹配MuMu5.0窗口名                                                                  
+        if emulator_title == '' and 'MuMu安卓设备' in emu_list:
+            emulator_title = 'MuMu安卓设备'
 
         if len(emu_list) > 1 and emulator_title == '':
             logger.warning(f'Find more than one emulator handle, oas will use the first one {emu_list[0]}')

BIN
tasks/ActivityShikigami/as/as_boss.png


BIN
tasks/ActivityShikigami/as/as_buff_box_1_empty.png


BIN
tasks/ActivityShikigami/as/as_buff_box_2_empty.png


BIN
tasks/ActivityShikigami/as/as_buff_change_button.png


BIN
tasks/ActivityShikigami/as/as_buff_down.png


BIN
tasks/ActivityShikigami/as/as_buff_switch.png


BIN
tasks/ActivityShikigami/as/as_buff_up.png


BIN
tasks/ActivityShikigami/as/as_check_battle_2.png


BIN
tasks/ActivityShikigami/as/as_check_boss.png


BIN
tasks/ActivityShikigami/as/as_check_buff.png


BIN
tasks/ActivityShikigami/as/as_red_exit_2.png


BIN
tasks/ActivityShikigami/as/as_skip_button.png


+ 42 - 0
tasks/ActivityShikigami/as/click.json

@@ -28,5 +28,47 @@
     "roiFront": "42,94,1207,543",
     "roiBack": "42,94,1207,543",
     "description": "description"
+  },
+  {
+    "itemName": "buff_1_up",
+    "roiFront": "204,626,134,39",
+    "roiBack": "204,626,134,39",
+    "description": "替换buff1"
+  },
+  {
+    "itemName": "buff_2_up",
+    "roiFront": "414,625,134,39",
+    "roiBack": "414,625,134,39",
+    "description": "替换buff2"
+  },
+  {
+    "itemName": "buff_3_up",
+    "roiFront": "619,625,134,39",
+    "roiBack": "619,625,134,39",
+    "description": "替换buff3"
+  },
+  {
+    "itemName": "buff_4_up",
+    "roiFront": "831,625,134,39",
+    "roiBack": "831,625,134,39",
+    "description": "替换buff4"
+  },
+  {
+    "itemName": "buff_5_up",
+    "roiFront": "1043,624,134,39",
+    "roiBack": "1043,624,134,39",
+    "description": "替换buff5"
+  },
+  {
+    "itemName": "buff_1_box",
+    "roiFront": "333,338,70,72",
+    "roiBack": "333,338,70,72",
+    "description": "上阵buff_1位置"
+  },
+  {
+    "itemName": "buff_2_box",
+    "roiFront": "877,220,59,62",
+    "roiBack": "877,220,59,62",
+    "description": "上阵buff_2位置"
   }
 ]

+ 102 - 3
tasks/ActivityShikigami/as/image.json

@@ -66,7 +66,7 @@
     "itemName": "fire",
     "imageName": "as_fire.png",
     "roiFront": "1131,598,103,54",
-    "roiBack": "1123,589,124,88",
+    "roiBack": "1113,564,136,111",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "点击战斗"
@@ -119,8 +119,8 @@
   {
     "itemName": "skip_button",
     "imageName": "as_skip_button.png",
-    "roiFront": "1154,34,64,30",
-    "roiBack": "1154,34,64,30",
+    "roiFront": "1159,37,51,22",
+    "roiBack": "1141,27,86,43",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "右上跳过按钮"
@@ -142,5 +142,104 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
+  },
+  {
+    "itemName": "boss",
+    "imageName": "as_boss.png",
+    "roiFront": "1054,265,33,132",
+    "roiBack": "966,131,211,355",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "爬塔进入首领战"
+  },
+  {
+    "itemName": "check_boss",
+    "imageName": "as_check_boss.png",
+    "roiFront": "87,18,126,37",
+    "roiBack": "63,0,172,81",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "爬塔boss战页面检查图像"
+  },
+  {
+    "itemName": "check_battle_2",
+    "imageName": "as_check_battle_2.png",
+    "roiFront": "93,12,128,46",
+    "roiBack": "82,0,148,86",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "爬塔活动副页检查标志"
+  },
+  {
+    "itemName": "red_exit_2",
+    "imageName": "as_red_exit_2.png",
+    "roiFront": "1097,177,46,45",
+    "roiBack": "1069,152,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "爬塔活动页面的红色退出"
+  },
+  {
+    "itemName": "buff_down",
+    "imageName": "as_buff_down.png",
+    "roiFront": "428,625,100,37",
+    "roiBack": "177,600,1040,98",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "卸载buff"
+  },
+  {
+    "itemName": "buff_change_button",
+    "imageName": "as_buff_change_button.png",
+    "roiFront": "491,604,48,46",
+    "roiBack": "439,574,197,108",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "切换buff按钮"
+  },
+  {
+    "itemName": "buff_box_1_empty",
+    "imageName": "as_buff_box_1_empty.png",
+    "roiFront": "342,345,50,59",
+    "roiBack": "317,322,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "buff容器1为空"
+  },
+  {
+    "itemName": "buff_box_2_empty",
+    "imageName": "as_buff_box_2_empty.png",
+    "roiFront": "883,224,49,54",
+    "roiBack": "854,195,107,105",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "buff容器2为空"
+  },
+  {
+    "itemName": "buff_up",
+    "imageName": "as_buff_up.png",
+    "roiFront": "419,624,120,41",
+    "roiBack": "176,576,1025,142",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "装配buff"
+  },
+  {
+    "itemName": "buff_switch",
+    "imageName": "as_buff_switch.png",
+    "roiFront": "640,624,100,39",
+    "roiBack": "180,601,1026,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "buff切换"
+  },
+  {
+    "itemName": "check_buff",
+    "imageName": "as_check_buff.png",
+    "roiFront": "91,12,130,47",
+    "roiBack": "77,0,156,83",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "爬塔活动buff页"
   }
 ]

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

@@ -43,5 +43,14 @@
     "method": "Default",
     "keyword": "驻守平安",
     "description": "从左侧进入战斗"
+  },
+  {
+    "itemName": "remain_boss",
+    "roiFront": "1113,669,131,31",
+    "roiBack": "0,0,100,100",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "boss剩余攻击次数"
   }
 ]

+ 40 - 2
tasks/ActivityShikigami/assets.py

@@ -41,6 +41,20 @@ class ActivityShikigamiAssets:
 	C_RANDOM_BOTTOM = RuleClick(roi_front=(182,539,1063,100), roi_back=(182,539,1063,100), name="random_bottom")
 	# description 
 	C_RANDOM_ALL = RuleClick(roi_front=(42,94,1207,543), roi_back=(42,94,1207,543), name="random_all")
+	# 替换buff1 
+	C_BUFF_1_UP = RuleClick(roi_front=(204,626,134,39), roi_back=(204,626,134,39), name="buff_1_up")
+	# 替换buff2 
+	C_BUFF_2_UP = RuleClick(roi_front=(414,625,134,39), roi_back=(414,625,134,39), name="buff_2_up")
+	# 替换buff3 
+	C_BUFF_3_UP = RuleClick(roi_front=(619,625,134,39), roi_back=(619,625,134,39), name="buff_3_up")
+	# 替换buff4 
+	C_BUFF_4_UP = RuleClick(roi_front=(831,625,134,39), roi_back=(831,625,134,39), name="buff_4_up")
+	# 替换buff5 
+	C_BUFF_5_UP = RuleClick(roi_front=(1043,624,134,39), roi_back=(1043,624,134,39), name="buff_5_up")
+	# 上阵buff_1位置 
+	C_BUFF_1_BOX = RuleClick(roi_front=(333,338,70,72), roi_back=(333,338,70,72), name="buff_1_box")
+	# 上阵buff_2位置 
+	C_BUFF_2_BOX = RuleClick(roi_front=(877,220,59,62), roi_back=(877,220,59,62), name="buff_2_box")
 
 
 	# Image Rule Assets
@@ -59,7 +73,7 @@ class ActivityShikigamiAssets:
 	# 还未上锁图片 
 	I_UNLOCK = RuleImage(roi_front=(884,648,28,25), roi_back=(758,607,242,85), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_unlock.png")
 	# 点击战斗 
-	I_FIRE = RuleImage(roi_front=(1131,598,103,54), roi_back=(1123,589,124,88), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_fire.png")
+	I_FIRE = RuleImage(roi_front=(1131,598,103,54), roi_back=(1113,564,136,111), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_fire.png")
 	# 寿司体力 
 	I_AP = RuleImage(roi_front=(1091,550,23,24), roi_back=(1081,532,103,71), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_ap.png")
 	# 活动体力 
@@ -71,11 +85,33 @@ class ActivityShikigamiAssets:
 	# 增加到最大 
 	I_ADD_MAX = RuleImage(roi_front=(17,24,33,37), roi_back=(974,524,57,54), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_add_max.png")
 	# 右上跳过按钮 
-	I_SKIP_BUTTON = RuleImage(roi_front=(1154,34,64,30), roi_back=(1154,34,64,30), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_skip_button.png")
+	I_SKIP_BUTTON = RuleImage(roi_front=(1159,37,51,22), roi_back=(1141,27,86,43), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_skip_button.png")
 	# 红色退出 
 	I_RED_EXIT = RuleImage(roi_front=(1162,96,39,38), roi_back=(1120,49,110,135), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_red_exit.png")
 	# description 
 	I_TOGGLE_BUTTON = RuleImage(roi_front=(1193,463,27,25), roi_back=(1169,146,73,403), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_toggle_button.png")
+	# 爬塔进入首领战 
+	I_BOSS = RuleImage(roi_front=(1054,265,33,132), roi_back=(966,131,211,355), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_boss.png")
+	# 爬塔boss战页面检查图像 
+	I_CHECK_BOSS = RuleImage(roi_front=(87,18,126,37), roi_back=(63,0,172,81), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_boss.png")
+	# 爬塔活动副页检查标志 
+	I_CHECK_BATTLE_2 = RuleImage(roi_front=(93,12,128,46), roi_back=(82,0,148,86), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_battle_2.png")
+	# 爬塔活动页面的红色退出 
+	I_RED_EXIT_2 = RuleImage(roi_front=(1097,177,46,45), roi_back=(1069,152,100,100), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_red_exit_2.png")
+	# 卸载buff 
+	I_BUFF_DOWN = RuleImage(roi_front=(428,625,100,37), roi_back=(177,600,1040,98), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_buff_down.png")
+	# 切换buff按钮 
+	I_BUFF_CHANGE_BUTTON = RuleImage(roi_front=(491,604,48,46), roi_back=(439,574,197,108), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_buff_change_button.png")
+	# buff容器1为空 
+	I_BUFF_BOX_1_EMPTY = RuleImage(roi_front=(342,345,50,59), roi_back=(317,322,100,100), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_buff_box_1_empty.png")
+	# buff容器2为空 
+	I_BUFF_BOX_2_EMPTY = RuleImage(roi_front=(883,224,49,54), roi_back=(854,195,107,105), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_buff_box_2_empty.png")
+	# 装配buff 
+	I_BUFF_UP = RuleImage(roi_front=(419,624,120,41), roi_back=(176,576,1025,142), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_buff_up.png")
+	# buff切换 
+	I_BUFF_SWITCH = RuleImage(roi_front=(640,624,100,39), roi_back=(180,601,1026,100), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_buff_switch.png")
+	# 爬塔活动buff页 
+	I_CHECK_BUFF = RuleImage(roi_front=(91,12,130,47), roi_back=(77,0,156,83), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_buff.png")
 
 
 	# Ocr Rule Assets
@@ -89,5 +125,7 @@ class ActivityShikigamiAssets:
 	O_REMAIN_AP_ACTIVITY2 = RuleOcr(roi=(558,18,47,29), area=(558,18,47,29), mode="Digit", method="Default", keyword="", name="remain_ap_activity2")
 	# 从左侧进入战斗 
 	O_ENTRY_ACTIVITY = RuleOcr(roi=(70,103,98,32), area=(70,103,98,32), mode="Single", method="Default", keyword="驻守平安", name="entry_activity")
+	# boss剩余攻击次数 
+	O_REMAIN_BOSS = RuleOcr(roi=(1113,669,131,31), area=(0,0,100,100), mode="DigitCounter", method="Default", keyword="", name="remain_boss")
 
 

+ 49 - 12
tasks/ActivityShikigami/config.py

@@ -5,8 +5,7 @@ from enum import Enum
 from datetime import time, timedelta
 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.GeneralBattle.config_general_battle import GreenMarkType
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase, TimeDelta
 from tasks.Component.BaseActivity.config_activity import GeneralClimb
@@ -18,18 +17,56 @@ class ShikigamiType(str, Enum):
     FOOD_TYPE_3 = 'shikigami_type_3'
     FOOD_TYPE_4 = 'shikigami_type_4'
 
-# class ShikigamiConfig(BaseModel):
-    # limit_time: TimeDelta = Field(default=TimeDelta(hours=0, minutes=30, seconds=0), description='limit_time_help')
-    # limit_count: int = Field(default=10, description='limit_count_help')
-    # food_type: ShikigamiType = Field(default=ShikigamiType.FOOD_TYPE_1, description='food_type_help')
 
-class ActivityShikigami(ConfigBase):
-    scheduler: Scheduler = Field(default_factory=Scheduler)
-    # shikigami: ShikigamiConfig = Field(default_factory=ShikigamiConfig)
-    general_climb: GeneralClimb = Field(default_factory=GeneralClimb)
-    general_battle: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
-    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
+class SwitchSoulConfig(BaseModel):
+    # 切换门票爬塔御魂
+    enable_switch_pass: bool = Field(default=False, description='是否切换门票爬塔御魂')
+    pass_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设使用该值')
+    enable_switch_pass_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
+    pass_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
+    # 切换体力爬塔御魂
+    enable_switch_ap: bool = Field(default=False, description='是否切换体力爬塔御魂')
+    ap_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设使用该值')
+    enable_switch_ap_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
+    ap_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
+    # 切换boss爬塔御魂
+    enable_switch_boss: bool = Field(default=False, description='是否切换boss爬塔御魂')
+    boss_group_team: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔。战斗内切换队伍预设使用该值')
+    enable_switch_boss_by_name: bool = Field(default=False, description='是否通过ocr切换御魂')
+    boss_group_team_name: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
+
 
+class GeneralBattleConfig(BaseModel):
+    # 是否切换门票爬塔预设
+    enable_pass_preset: bool = Field(default=False, description='是否切换门票爬塔预设')
+    # 是否开启门票爬塔绿标
+    enable_pass_green: bool = Field(default=False, description='是否开启门票爬塔绿标')
+    # 门票爬塔绿标位置
+    pass_green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='门票爬塔绿标位置')
+    # 门票爬塔战斗过程是否随机点击或滑动
+    enable_pass_anti_detect: bool = Field(default=False, description='门票爬塔战斗过程是否随机点击或滑动')
 
+    # 是否切换体力爬塔预设
+    enable_ap_preset: bool = Field(default=False, description='是否切换体力爬塔预设')
+    # 是否开启体力爬塔绿标
+    enable_ap_green: bool = Field(default=False, description='是否开启体力爬塔绿标')
+    # 体力爬塔绿标位置
+    ap_green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='体力爬塔绿标位置')
+    # 体力爬塔战斗过程是否随机点击或滑动
+    enable_ap_anti_detect: bool = Field(default=False, description='体力爬塔战斗过程是否随机点击或滑动')
 
+    # 是否切换boss爬塔预设
+    enable_boss_preset: bool = Field(default=False, description='是否切换boss爬塔预设')
+    # 是否开启boss爬塔绿标
+    enable_boss_green: bool = Field(default=False, description='是否开启boss爬塔绿标')
+    # boss爬塔绿标位置
+    boss_green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='boss爬塔绿标位置')
+    # boss爬塔战斗过程是否随机点击或滑动
+    enable_boss_anti_detect: bool = Field(default=False, description='boss爬塔战斗过程是否随机点击或滑动')
 
+
+class ActivityShikigami(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    general_climb: GeneralClimb = Field(default_factory=GeneralClimb)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
+    general_battle: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)

+ 345 - 339
tasks/ActivityShikigami/script_task.py

@@ -1,413 +1,419 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
+from time import sleep
+
+import cv2
+import numpy as np
 import random
+import tasks.Component.GeneralBattle.config_general_battle
 from datetime import datetime, timedelta, time
-from tasks.base_task import BaseTask
-from tasks.Component.GeneralBattle.general_battle import GeneralBattle
-from tasks.AreaBoss.assets import AreaBossAssets
-from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
-from tasks.Component.BaseActivity.base_activity import BaseActivity
-from tasks.Component.BaseActivity.config_activity import ApMode
+from module.atom.ocr import RuleOcr
+from module.base.protect import random_sleep
+from module.exception import TaskEnd
+from module.logger import logger
 from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
-from tasks.GameUi.page import page_main, page_shikigami_records
+from tasks.ActivityShikigami.config import SwitchSoulConfig, GeneralBattleConfig
+from tasks.Component.BaseActivity.base_activity import BaseActivity
+from tasks.Component.BaseActivity.config_activity import GeneralClimb
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_shikigami_records, page_climb_act, page_climb_act_pass, \
+    page_climb_act_boss, page_climb_act_ap, Page, page_climb_act_buff
 
-from module.logger import logger
-from module.exception import TaskEnd
-from module.base.protect import random_sleep
 
-import cv2
-import numpy as np
-from module.atom.ocr import RuleOcr
+def get_run_order_list(climb_conf: GeneralClimb) -> list[str]:
+    run_order_list = [climb_type.strip() for climb_type in climb_conf.run_sequence.split(',')]
+    return [climb_type for climb_type in run_order_list if getattr(climb_conf, f'enable_{climb_type}')]
 
-class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
 
-    def run(self) -> None:
+def _prepare_image_for_ocr(image: np.ndarray, asset: RuleOcr) -> np.ndarray:
 
-        config = self.config.activity_shikigami
-        self.limit_time: timedelta = config.general_climb.limit_time
-        if isinstance(self.limit_time, time):
-            self.limit_time = timedelta(hours=self.limit_time.hour, minutes=self.limit_time.minute,
-                                        seconds=self.limit_time.second)
-        self.limit_count = config.general_climb.limit_count
-
-        if config.switch_soul_config.enable:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul(config.switch_soul_config.switch_group_team)
-        if config.switch_soul_config.enable_switch_by_name:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul_by_name(
-                config.switch_soul_config.group_name,
-                config.switch_soul_config.team_name
-            )
+    image_copy = image.copy()
+    x, y, w, h = asset.roi
 
-        self.ui_get_current_page()
-        self.ui_goto(page_main)
+    roi_to_process = image_copy[y:y + h, x:x + w]
+    if len(roi_to_process.shape) == 3:
+        gray_image = cv2.cvtColor(roi_to_process, cv2.COLOR_BGR2GRAY)
+    else:
+        gray_image = roi_to_process
 
-        # 某些活动需要开启御魂加成
-        # self.open_buff()
-        # self.soul(is_open=True)
-        # self.close_buff()
+    # 自适应二值化
+    _, binary_norm = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
+    _, binary_inv = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
 
-        self.home_main()
+    if cv2.countNonZero(binary_norm) < cv2.countNonZero(binary_inv):
+        binary_correct = binary_norm
+    else:
+        binary_correct = binary_inv
 
-        # 选择是游戏的体力还是活动的体力
-        current_ap = config.general_climb.ap_mode
-        self.switch(current_ap)
+    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 1))
+    dilated_image = cv2.dilate(binary_correct, kernel, iterations=1)
 
-        # 设定是否锁定阵容
+    # 找轮廓
+    contours, _ = cv2.findContours(dilated_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
 
-        if config.general_battle.lock_team_enable:
-            logger.info("Lock team")
-            while 1:
-                self.screenshot()
-                if self.appear_then_click(self.I_UNLOCK, interval=1):
-                    continue
-                if self.appear(self.I_LOCK):
-                    break
+    processed_roi_content = None
+    if contours:
+        all_points = np.concatenate(contours, axis=0)
+        bx, by, bw, bh = cv2.boundingRect(all_points)
+
+        processed_roi_content = binary_correct[by:by + bh, bx:bx + bw]
+
+    centered_roi = np.full((h, w), 255, dtype=np.uint8)  # 255代表白色
+
+    if processed_roi_content is not None:
+        content_h, content_w = processed_roi_content.shape
+
+        if content_h <= h and content_w <= w:
+            # 计算居中粘贴的位置,放到中间
+            start_y = (h - content_h) // 2
+            start_x = (w - content_w) // 2
+
+            paste_area = centered_roi[start_y:start_y + content_h, start_x:start_x + content_w]
+
+            paste_area[processed_roi_content == 255] = 0
         else:
-            logger.info("Unlock team")
-            while 1:
-                self.screenshot()
-                if self.appear_then_click(self.I_LOCK, interval=1):
-                    continue
-                if self.appear(self.I_UNLOCK):
-                    break
+            logger.warning(f"Content for asset '{asset.name}' is larger than ROI. Skipping centering.")
+            # 内容过大,直接使用原始二值图的反转作为结果
+            centered_roi = cv2.bitwise_not(binary_correct)
+    else:
+        logger.warning(f"No content found in ROI for asset: {asset.name}. ROI will be blank.")
 
-        # 流程应该是 在页面处:
-        # 1. 判定计数是否超了,时间是否超了
-        # 2. 如果是消耗活动体力,判定活动体力是否足够 如果是消耗一般的体力,判定一般体力是否足够
-        # 3. 如果开启买体力,就买体力
-        # 4. 如果开启了切换到游戏体力,就切换
-        while 1:
-            # 1
-            if self.limit_time is not None and self.limit_time + self.start_time < datetime.now():
-                logger.info("Time out")
-                break
-            if self.current_count >= self.limit_count:
-                logger.info("Count out")
-                break
-            # 2
-            self.wait_until_appear(self.I_FIRE)
-            is_remain = self.check_ap_remain(current_ap)
-            # 如果没有剩余了且这个时候是体力,就退出活动
-            if not is_remain and current_ap == ApMode.AP_GAME:
-                logger.info("Game ap out")
-                break
-            # 如果不是那就切换到体力
-            elif not is_remain and current_ap == ApMode.AP_ACTIVITY:
-                if config.general_climb.activity_toggle:
-                    logger.info("Activity ap out and switch to game ap")
-                    current_ap = ApMode.AP_GAME
-                    self.switch(current_ap)
-                    continue
-                else:
-                    logger.info("Activity ap out")
-                    break
+    processed_roi_bgr = cv2.cvtColor(centered_roi, cv2.COLOR_GRAY2BGR)
+    image_copy[y:y + h, x:x + w] = processed_roi_bgr
 
-            # 随机休息
-            if config.general_climb.random_sleep:
-                random_sleep(probability=0.2)
-            # 点击战斗
-            logger.info("Click battle")
-            while 1:
-                self.screenshot()
-                if self.appear_then_click(self.I_FIRE, interval=2):
-                    continue
-                if not self.appear(self.I_FIRE):
-                    break
-                if self.appear_then_click(self.I_C_CONFIRM1, interval=0.6):
-                    continue
-                if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
-                    continue
-                if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
-                    continue
-                if self.appear_then_click(self.I_N_CONFIRM, interval=1):
-                    continue
+    return image_copy
 
-            if self.run_general_battle(config=config.general_battle):
-                logger.info("General battle success")
 
+class ScriptTask(GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets):
+    # key: climb type value: run count
+    count_map: dict[str, int] = {
+        'pass': 0,
+        'ap': 0,
+        'boss': 0
+    }
+    page_map: dict[str, Page] = {
+        'pass': page_climb_act_pass,
+        'ap': page_climb_act_ap,
+        'boss': page_climb_act_boss,
+    }
+
+    climb_type: str = 'pass'
+    run_idx: int = 0
+
+    def run(self) -> None:
+        config = self.config.activity_shikigami
+        self.limit_time: timedelta = config.general_climb.limit_time
+        if isinstance(self.limit_time, time):
+            self.limit_time = timedelta(hours=self.limit_time.hour, minutes=self.limit_time.minute,
+                                        seconds=self.limit_time.second)
+        # 初始化爬塔类型
+        self.climb_type = get_run_order_list(config.general_climb)[0]
+        while 1:
+            # 切换御魂
+            self.switch_soul(config.switch_soul_config)
+            # 进入爬塔活动主界面
+            self.home_main()
+            # 切换buff
+            self.switch_buff(config.general_climb)
+            # 锁定阵容
+            self.lock_team(config.general_battle)
+            while 1:
+                switch = False
+                # 超时退出
+                if self.limit_time is not None and datetime.now() - self.start_time >= self.limit_time:
+                    logger.info(f"{self.climb_type} time out")
+                    break
+                # 次数达到限制切换下一种爬塔
+                if self.get_count() >= self.get_limit(config.general_climb):
+                    logger.warn(f"{self.climb_type} count out, switch to next")
+                    switch = self.switch_next()
+                    break
+                # 判断是否可以运行
+                can_run = self.check_can_run()
+                if not can_run:
+                    logger.warn(f'{self.climb_type} tickets not enough, switch to next')
+                    switch = self.switch_next()
+                    break
+                # 开始战斗
+                self.start_battle()
+            if not switch:
+                break
+        # 返回庭院
         self.main_home()
-        # 某些活动需要开启御魂加成
-        # self.open_buff()
-        # self.soul(is_open=False)
-        # self.close_buff()
         if config.general_climb.active_souls_clean:
             self.set_next_run(task='SoulsTidy', success=False, finish=False, target=datetime.now())
         self.set_next_run(task="ActivityShikigami", success=True)
         raise TaskEnd
 
-    def home_main(self) -> bool:
+    def switch_soul(self, conf: SwitchSoulConfig):
         """
-        从庭院到活动的爬塔界面,统一入口
+        根据当前爬塔类型自动切换御魂
+        :param conf: 切换御魂配置
         :return:
         """
+        enabled = getattr(conf, f"enable_switch_{self.climb_type}")
+        if not enabled:
+            return
+        self.ui_get_current_page()
+        self.ui_goto(page_shikigami_records)
+        enable_by_name = getattr(conf, f"enable_switch_{self.climb_type}_by_name")
+        if enable_by_name:
+            group, team = getattr(conf, f"{self.climb_type}_group_team_name").split(",")
+            self.run_switch_soul_by_name(group, team)
+        else:
+            group_team = getattr(conf, f"{self.climb_type}_group_team")
+            self.run_switch_soul(group_team)
 
-        logger.hr("Enter Shikigami", 2)
+    def lock_team(self, battle_conf: GeneralBattleConfig):
+        """
+        根据配置判断当前爬塔类型是否锁定阵容, 并执行锁定或解锁
+        :param battle_conf: 战斗配置
+        :return:
+        """
+        self.ui_get_current_page()
+        self.ui_goto(self.page_map[self.climb_type])
+        enable_preset = getattr(battle_conf, f"enable_{self.climb_type}_preset")
+        if not enable_preset:
+            logger.info(f'Lock {self.climb_type} team')
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_UNLOCK, interval=1):
+                    continue
+                if self.appear(self.I_LOCK):
+                    return
+        logger.info(f'Unlock {self.climb_type} team')
         while 1:
             self.screenshot()
-            self.C_RANDOM_LEFT.name = "BATTLE_RANDOM"
-            self.C_RANDOM_RIGHT.name = "BATTLE_RANDOM"
-            self.C_RANDOM_TOP.name = "BATTLE_RANDOM"
-            self.C_RANDOM_BOTTOM.name = "BATTLE_RANDOM"
-            if self.appear(self.I_FIRE):
-                break
-            if self.appear(self.I_SHI):
-                # 有时会点到小纸人其他活动入口,等待稳定
-                self.wait_until_stable(self.I_SHI)
-                self.click(self.I_SHI, interval=1)
-                continue
-            if self.ocr_appear_click(self.O_ENTRY_ACTIVITY, interval=1):
-                continue
-            if self.appear_then_click(self.I_TOGGLE_BUTTON, interval=3):
-                continue
-            if self.appear_then_click(self.I_SKIP_BUTTON, interval=1.5):
-                continue
-            # 如果出现了 “获得奖励”
-            reward_click = random.choice([self.C_RANDOM_LEFT, self.C_RANDOM_RIGHT, self.C_RANDOM_TOP, self.C_RANDOM_BOTTOM])
-            if self.appear_then_click(self.I_UI_REWARD, action=reward_click, interval=1.3):
-                continue
-            if self.appear_then_click(self.I_RED_EXIT, interval=1.5):
-                continue
-            if self.appear_then_click(self.I_BATTLE, interval=2):
+            if self.appear_then_click(self.I_LOCK, interval=1):
                 continue
+            if self.appear(self.I_UNLOCK):
+                break
 
-    def main_home(self) -> bool:
+    def switch_buff(self, climb_conf: GeneralClimb):
+        buffs = getattr(climb_conf, f'{self.climb_type}_buff', None)
+        if not buffs:
+            logger.info('Not set buff, skip')
+            return
+        buff_list = [buff.strip() for buff in buffs.split(',')]
+        if not buff_list:
+            logger.info('Buff incorrect formatting, skip')
+            return
+        self.ui_get_current_page()
+        self.ui_goto(page_climb_act_buff)
+        buff_box_list = [self.C_BUFF_1_BOX, self.C_BUFF_2_BOX]
+        buff_box_empty_list = [self.I_BUFF_BOX_1_EMPTY, self.I_BUFF_BOX_2_EMPTY]
+        buff_up_map = {
+            'buff_1': self.C_BUFF_1_UP,
+            'buff_2': self.C_BUFF_2_UP,
+            'buff_3': self.C_BUFF_3_UP,
+            'buff_4': self.C_BUFF_4_UP,
+            'buff_5': self.C_BUFF_5_UP
+        }
+        logger.info(f'start switch {self.climb_type} {buff_list}')
+        for i, buff_box in enumerate(buff_box_list):
+            logger.info(f'Start down {buff_list[i]}')
+            ok = 0
+            while ok <= 3:
+                self.screenshot()
+                # 打开buff面板
+                self.click(buff_box, interval=1.5)
+                ok = (ok + 1) if self.appear(buff_box_empty_list[i]) else 0
+                # 卸下buff
+                self.appear_then_click(self.I_BUFF_DOWN, interval=0.5)
+            logger.info(f'Down {buff_list[i]} ok')
+        for i, buff_box in enumerate(buff_box_list):
+            logger.info(f'Start up {buff_list[i]}')
+            ok = 0
+            while ok <= 3:
+                self.screenshot()
+                # 打开buff面板
+                self.click(buff_box, interval=1.5)
+                ok = (ok + 1) if not self.appear(buff_box_empty_list[i]) else 0
+                # 装上buff
+                self.appear_then_click(self.I_BUFF_UP, buff_up_map[buff_list[i]], interval=0.5)
+            logger.info(f'Up {buff_list[i]} ok')
+
+    def get_count(self) -> int:
         """
-        从活动的爬塔界面到庭院
-        :return:
+        获取当前爬塔类型运行次数
+        :return: 运行次数
         """
-        logger.hr("Exit Shikigami", 2)
+        return self.count_map[self.climb_type]
+
+    def check_can_run(self) -> bool:
+        """
+        判断当前爬塔类型能否运行
+        pass: 剩余门票爬塔票数>0
+        ap: 剩余体力爬塔票数>0
+        boss: 剩余挑战次数>0
+        :return: True 可以运行 or False
+        """
+        self.ui_get_current_page()
+        self.ui_goto(self.page_map[self.climb_type])
+        logger.info(f'Check the {self.climb_type} can work')
+        self.wait_until_appear(self.I_FIRE)
+        self.screenshot()
+        remain_times = 0
+        if self.climb_type == 'pass':
+            remain_times = self.O_REMAIN_AP_ACTIVITY2.ocr_digit(
+                _prepare_image_for_ocr(self.device.image, asset=self.O_REMAIN_AP_ACTIVITY2))
+        if self.climb_type == 'ap':
+            remain_times = self.O_REMAIN_AP.ocr_digit(
+                _prepare_image_for_ocr(self.device.image, asset=self.O_REMAIN_AP))
+        if self.climb_type == 'boss':
+            _, remain_times, _ = self.O_REMAIN_BOSS.ocr_digit_counter(self.device.image)
+        return remain_times > 0
+
+    def get_limit(self, climb_conf: GeneralClimb) -> int:
+        """
+        获取配置中当前爬塔类型次数限制
+        :param climb_conf: 爬塔配置
+        :return: 限制次数
+        """
+        return getattr(climb_conf, f'{self.climb_type}_limit')
+
+    def switch_next(self) -> bool:
+        """
+        切换下一种爬塔类型
+        :return: True 切换成功 or False
+        """
+        self.run_idx += 1
+        climb_type_list = get_run_order_list(self.config.activity_shikigami.general_climb)
+        if self.run_idx >= len(climb_type_list):
+            logger.info('All tower climbing activities have been completed')
+            return False
+        self.climb_type = climb_type_list[self.run_idx]
+        self.current_count = 0
+        return True
+
+    def start_battle(self):
+        # 点击战斗前随机休息
+        if self.config.activity_shikigami.general_climb.random_sleep:
+            random_sleep(probability=0.2)
+        logger.info("Click battle")
         while 1:
             self.screenshot()
-            if self.appear(self.I_SHI):
+            # 点击挑战
+            if self.appear_then_click(self.I_FIRE, interval=2):
+                continue
+            if not self.appear(self.I_FIRE):
                 break
-            if self.appear_then_click(self.I_UI_BACK_RED, interval=2):
+            if self.appear_then_click(self.I_C_CONFIRM1, interval=0.6):
                 continue
-            if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=2):
+            if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
                 continue
-            if self.appear_then_click(self.I_BACK_GREEN, interval=2):
+            if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
                 continue
-            if self.appear_then_click(self.I_EXIT, interval=2.2, threshold=0.6):
+            if self.appear_then_click(self.I_N_CONFIRM, interval=1):
                 continue
+        # 运行战斗
+        if self.run_general_battle(config=self.get_general_battle_conf()):
+            self.count_map[self.climb_type] += 1
+            logger.info("General battle success")
+
+    def get_general_battle_conf(self) -> tasks.Component.GeneralBattle.config_general_battle.GeneralBattleConfig:
+        from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig as gbc
+        conf = self.config.activity_shikigami
+        enable_preset = getattr(conf.general_battle, f'enable_{self.climb_type}_preset')
+        group, team = (getattr(conf.switch_soul_config, f'{self.climb_type}_group_team').split(','))
+        return gbc(lock_team_enable=not enable_preset,
+                   preset_enable=enable_preset,
+                   preset_group=group if enable_preset else 1,
+                   preset_team=team if enable_preset else 1,
+                   green_enable=getattr(conf.general_battle, f'enable_{self.climb_type}_green'),
+                   green_mark=getattr(conf.general_battle, f'{self.climb_type}_green_mark'),
+                   random_click_swipt_enable=getattr(conf.general_battle, f'enable_{self.climb_type}_anti_detect'), )
 
-    def check_ap_remain(self, current_ap: ApMode) -> bool:
+    def home_main(self) -> bool:
         """
-        检查体力是否足够
-        :return: 如何还有体力,返回True,否则返回False
+        从庭院到活动的爬塔界面,(只到爬塔活动主界面)
+        :return:
         """
-        self.screenshot()
-        if current_ap == ApMode.AP_ACTIVITY:
-            res: int = self.O_REMAIN_AP_ACTIVITY2.ocr_digit(
-                self._prepare_image_for_ocr(self.device.image, asset=self.O_REMAIN_AP_ACTIVITY2))
-            if res <= 0:
-                logger.warning(f'Activity ap {res} not enough')
-                return False
-            return True
-            # cu, res, total = self.O_REMAIN_AP_ACTIVITY.ocr(image=self.device.image)
-            # if cu == 0 and cu + res == total:
-            #     logger.warning("Activity ap not enough")
-            #     return False
-            # return True
-
-        elif current_ap == ApMode.AP_GAME:
-            cu: int = self.O_REMAIN_AP.ocr_digit(self._prepare_image_for_ocr(self.device.image,asset=self.O_REMAIN_AP))
-            if cu > 0:
-                logger.warning(f'Game ap {cu} more than 0')
-                return True
-            logger.warning(f'Game ap not enough: {cu}')
-            return False
+        logger.hr("Enter Shikigami", 2)
+        self.ui_get_current_page()
+        self.main_goto_act_by_list(page_climb_act)
 
-            # cu, res, total = self.O_REMAIN_AP.ocr(image=self.device.image)
-            # if cu == total and cu + res == total:
-            #     if cu > total:
-            #         logger.warning(f'Game ap {cu} more than total {total}')
-            #         return True
-            #     logger.warning(f'Game ap not enough: {cu}')
-            #     return False
-            #
-            # return True
-
-    def switch(self, current_ap: ApMode) -> None:
+    def main_home(self) -> bool:
         """
-        切换体力
-        :param current_ap:
+        从活动的爬塔界面到庭院
         :return:
         """
-        if current_ap == ApMode.AP_ACTIVITY:
-            logger.info("Select activity ap")
-            while 1:
-                self.screenshot()
-                if self.appear(self.I_AP_ACTIVITY):
-                    break
-                if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1):
-                    continue
-                if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
-                    continue
-                if self.appear(self.I_AP, interval=1):
-                    self.appear_then_click(self.I_SWITCH, interval=2)  # 点击切换
-        else:
-            logger.info("Select game ap")
-            while 1:
-                self.screenshot()
-                if self.appear(self.I_AP):
-                    break
-                if self.appear(self.I_AP_ACTIVITY, interval=1):
-                    self.appear_then_click(self.I_SWITCH, interval=2)
-
-    def battle_wait(self, random_click_swipt_enable: bool) -> bool:
-        # 重写,不出现达摩版本999专用
-        self.device.stuck_record_add('BATTLE_STATUS_S')
-        self.device.click_record_clear()
-        logger.info("Start battle process")
-        self.C_RANDOM_LEFT.name = "BATTLE_RANDOM"
-        self.C_RANDOM_RIGHT.name = "BATTLE_RANDOM"
-        self.C_RANDOM_TOP.name = "BATTLE_RANDOM"
-        self.C_RANDOM_BOTTOM.name = "BATTLE_RANDOM"
-        click_count = 0
-        while 1:
-            self.screenshot()
-            # 如果出现了 “获得奖励”
-            reward_click = random.choice([self.C_RANDOM_LEFT, self.C_RANDOM_RIGHT, self.C_RANDOM_TOP, self.C_RANDOM_BOTTOM])
-            if self.appear_then_click(self.I_UI_REWARD, action=reward_click, interval=1.3):
-                click_count += 1
-                continue
-            # 如果出现了 “鼓”
-            if self.appear(self.I_WIN) or click_count >= 1:
-                logger.info("Win")
-                while 1:
-                    self.screenshot()
-                    if not self.appear(self.I_WIN):
-                        break
-                    if self.appear_then_click(self.I_WIN, action=self.C_RANDOM_ALL, interval=1.1):
-                        continue
-                if self.appear(self.I_FIRE):
-                    return True
-            # 失败 -> 正常人不会失败
-            if self.appear(self.I_FALSE):
-                logger.warning('False battle')
-                self.ui_click_until_disappear(self.I_FALSE)
-                return False
-            # 如果开启战斗过程随机滑动
-            if random_click_swipt_enable:
-                self.random_click_swipt()
-
-    def _prepare_image_for_ocr(self, image: np.ndarray, asset: RuleOcr) -> np.ndarray:
-
-        image_copy = image.copy()
-        x, y, w, h = asset.roi
-
-        roi_to_process = image_copy[y:y + h, x:x + w]
-        if len(roi_to_process.shape) == 3:
-            gray_image = cv2.cvtColor(roi_to_process, cv2.COLOR_BGR2GRAY)
-        else:
-            gray_image = roi_to_process
-
-        # 自适应二值化
-        _, binary_norm = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
-        _, binary_inv = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
-
-        if cv2.countNonZero(binary_norm) < cv2.countNonZero(binary_inv):
-            binary_correct = binary_norm
-        else:
-            binary_correct = binary_inv
-
-        kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 1))
-        dilated_image = cv2.dilate(binary_correct, kernel, iterations=1)
-
-        # 找轮廓
-        contours, _ = cv2.findContours(dilated_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
-
-        processed_roi_content = None
-        if contours:
-            all_points = np.concatenate(contours, axis=0)
-            bx, by, bw, bh = cv2.boundingRect(all_points)
-
-            processed_roi_content = binary_correct[by:by + bh, bx:bx + bw]
-
-        centered_roi = np.full((h, w), 255, dtype=np.uint8)  # 255代表白色
-
-        if processed_roi_content is not None:
-            content_h, content_w = processed_roi_content.shape
-
-            if content_h <= h and content_w <= w:
-                # 计算居中粘贴的位置,放到中间
-                start_y = (h - content_h) // 2
-                start_x = (w - content_w) // 2
-
-                paste_area = centered_roi[start_y:start_y + content_h, start_x:start_x + content_w]
-
-                paste_area[processed_roi_content == 255] = 0
-            else:
-                logger.warning(f"Content for asset '{asset.name}' is larger than ROI. Skipping centering.")
-                # 内容过大,直接使用原始二值图的反转作为结果
-                centered_roi = cv2.bitwise_not(binary_correct)
-        else:
-            logger.warning(f"No content found in ROI for asset: {asset.name}. ROI will be blank.")
-
-        processed_roi_bgr = cv2.cvtColor(centered_roi, cv2.COLOR_GRAY2BGR)
-        image_copy[y:y + h, x:x + w] = processed_roi_bgr
-
-        return image_copy
-
+        logger.hr("Exit Shikigami", 2)
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
 
+    def random_reward_click(self, exclude_bottom=False):
+        options = [self.C_RANDOM_LEFT, self.C_RANDOM_RIGHT, self.C_RANDOM_TOP]
+        if not exclude_bottom:
+            options.append(self.C_RANDOM_BOTTOM)
+        target = random.choice(options)
+        self.click(target, interval=1.8)
+        return 1
 
-    """
     def battle_wait(self, random_click_swipt_enable: bool) -> bool:
-        # 重写,出现达摩版本月度常用
-        self.device.stuck_record_add('BATTLE_STATUS_S')
+        # 通用战斗结束判断
+        self.device.stuck_record_add("BATTLE_STATUS_S")
         self.device.click_record_clear()
         logger.info("Start battle process")
-        self.C_RANDOM_LEFT.name = "BATTLE_RANDOM"
-        self.C_RANDOM_RIGHT.name = "BATTLE_RANDOM"
-        self.C_RANDOM_TOP.name = "BATTLE_RANDOM"
-        self.C_RANDOM_BOTTOM.name = "BATTLE_RANDOM"
-        click_count = 0
+
+        for btn in (self.C_RANDOM_LEFT, self.C_RANDOM_RIGHT, self.C_RANDOM_TOP, self.C_RANDOM_BOTTOM):
+            btn.name = "BATTLE_RANDOM"
+        ok_cnt, max_retry = 0, 5
         while 1:
             self.screenshot()
-            # 如果出现了 “鼓”
-            if self.appear_then_click(self.I_WIN, interval=2.3):
-                logger.info("Win")
+            sleep(0.5)
+            # 已经回到对应挑战界面
+            if self.ui_page_appear(self.page_map[self.climb_type]):
+                break
+            # 达到最大重试次数且没有回到活动界面
+            if ok_cnt > max_retry:
+                self.click(self.random_reward_click(exclude_bottom=True), interval=1)
+                break
+            # 已经胜利但是后续识别失败则重新识别并点击
+            if 0 < ok_cnt <= max_retry:
+                # 紫蛇皮消失
+                self.ui_click_until_smt_disappear(self.random_reward_click(exclude_bottom=True),
+                                                  self.I_REWARD_PURPLE_SNAKE_SKIN, interval=1.6)
+                self.ui_get_current_page()
+                self.ui_goto(self.page_map[self.climb_type])
+                ok_cnt += 1
+                continue
+            # 胜利(鼓 | 魂 | 获得奖励)
+            if self.appear(self.I_WIN) or self.appear(self.I_REWARD) or self.appear(self.I_UI_REWARD):
+                if ok_cnt == 0:
+                    logger.info("Win battle")
+                # 鼓消失
+                self.ui_click_until_smt_disappear(self.random_reward_click(), self.I_WIN, interval=1.1)
+                # 魂消失
+                self.ui_click_until_smt_disappear(self.random_reward_click(exclude_bottom=True), self.I_REWARD,
+                                                  interval=1.3)
+                # 紫蛇皮消失
+                self.ui_click_until_smt_disappear(self.random_reward_click(exclude_bottom=True),
+                                                  self.I_REWARD_PURPLE_SNAKE_SKIN, interval=1.6)
+                # 获得奖励消失
+                self.ui_click_until_smt_disappear(self.random_reward_click(),
+                                                  self.I_UI_REWARD, interval=1.6)
+                ok_cnt += 1
                 continue
-            #  出现 “魂” 和 紫蛇皮
-            if self.appear(self.I_REWARD):
-                logger.info('Win battle')
-                self.wait_until_appear(self.I_REWARD_PURPLE_SNAKE_SKIN, wait_time=5)
-                while 1:
-                    self.screenshot()
-                    appear_reward = self.appear(self.I_REWARD)
-                    appear_reward_purple_snake_skin = self.appear(self.I_REWARD_PURPLE_SNAKE_SKIN)
-                    if not appear_reward and not appear_reward_purple_snake_skin and click_count >= 1:
-                        break
-                    if appear_reward or appear_reward_purple_snake_skin:
-                        reward_click = random.choice(
-                            [self.C_RANDOM_LEFT, self.C_RANDOM_RIGHT, self.C_RANDOM_TOP])
-                        self.click(reward_click, interval=1.8)
-                        click_count += 1
-                        continue
-                return True
-
-            # 失败 -> 正常人不会失败
+            # 失败
             if self.appear(self.I_FALSE):
-                logger.warning('False battle')
-                self.ui_click_until_disappear(self.I_FALSE)
+                logger.warning("False battle")
+                self.ui_click_until_smt_disappear(self.random_reward_click(), self.I_FALSE, interval=1.5)
                 return False
-            # 如果开启战斗过程随机滑动
+            # 战斗中随机滑动
             if random_click_swipt_enable:
                 self.random_click_swipt()
-    """
+        return True
 
 
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
 
-    c = Config('oas1')
+    c = Config('oas3')
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.run()
+    t.switch_buff(c.activity_shikigami.general_climb)

+ 25 - 32
tasks/Component/BaseActivity/config_activity.py

@@ -9,6 +9,7 @@ from module.logger import logger
 
 from tasks.Component.config_base import ConfigBase, TimeDelta, Time
 
+
 class ApMode(str, Enum):
     AP_ACTIVITY = 'ap_activity'
     AP_GAME = 'ap_game'
@@ -16,22 +17,32 @@ class ApMode(str, Enum):
 
 class GeneralClimb(ConfigBase):
     # 限制执行的时间
-    limit_time: Time = Field(default=Time(minute=30), description='limit_time_help')
-    # 限制执行的次数
-    limit_count: int = Field(default=50, description='limit_count_help')
-    # 每日使用体力挑战的最大次数,默认是300
-    ap_game_max: int = Field(default=1800, description='ap_game_max_help')
-    # 爬塔活动挂活动的体力还是游戏的体力
-    ap_mode: ApMode = Field(default=ApMode.AP_ACTIVITY, description='ap_mode_help')
-    # 游戏体力不足是否需要话勾玉购买
-    # buy_ap_activity: bool = Field(default=False, description='buy_ap_activity_help')  # 该功能已经废弃
-    # 如果挂完的活动的体力,是不是需要挂游戏的体力
-    # 在我的设计理念中:活动体力>游戏体力。所以不提供从300挂满然后才到挂活动币
-    activity_toggle: bool = Field(default=False, description='activity_toggle_help')
+    limit_time: Time = Field(default=Time(minute=30), description='限制爬塔运行时间')
+    # 限制门票爬塔的次数
+    pass_limit: int = Field(default=50, description='门票爬塔的最大次数')
+    # 限制体力爬塔的次数
+    ap_limit: int = Field(default=300, description='体力爬塔的最大次数')
+    # 限制boss战爬塔的次数
+    boss_limit: int = Field(default=20, description='boss战爬塔的最大次数')
+    # 启用门票爬塔
+    enable_pass: bool = Field(default=True, description='是否启用门票爬塔')
+    # 启用体力爬塔
+    enable_ap: bool = Field(default=True, description='是否启用体力爬塔')
+    # 启用boss战爬塔
+    enable_boss: bool = Field(default=True, description='是否启用boss战爬塔')
+    # 爬塔运行顺序
+    run_sequence: str = Field(default='pass,boss,ap',
+                              description='爬塔运行顺序,英文逗号分隔,从左到右运行,若没启用自动跳过对应类型(pass:门票,boss:boss战,ap:体力)')
+    # 门票爬塔buff
+    pass_buff: str = Field(default='buff_4,buff_5', description='门票爬塔加成,buff1-5,加成页从左往右顺序,清空则不切换加成')
+    # 体力爬塔buff
+    ap_buff: str = Field(default='buff_4,buff_5', description='体力爬塔加成,buff1-5,加成页从左往右顺序,清空则不切换加成')
+    # boss爬塔buff
+    boss_buff: str = Field(default='buff_1,buff_3', description='boss战爬塔加成,buff1-5,加成页从左往右顺序,清空则不切换加成')
     # 结束后激活 御魂清理
-    active_souls_clean: bool = Field(default=False, description='active_souls_clean_help')
+    active_souls_clean: bool = Field(default=False, description='是否运行结束后清理御魂')
     # 点击战斗随机休息
-    random_sleep: bool = Field(default=False, description='random_delay_help')
+    random_sleep: bool = Field(default=False, description='是否启用在点击战斗前随机休息')
 
     @validator('limit_time', pre=True, always=True)
     def parse_limit_time(cls, value):
@@ -51,21 +62,3 @@ class GeneralClimb(ConfigBase):
                     logger.warning('Invalid limit_time value. Expected format: HH:MM:SS')
                     return time(hour=0, minute=30, second=0)
         return value
-
-    @validator('ap_game_max', pre=True, always=True)
-    def reset_game_max(cls, value):
-        def_value = int(300)
-        if isinstance(value, str):
-            try:
-                return int(value)
-            except ValueError:
-                logger.warning('Invalid ap_game_max value. Expected format: int')
-                return def_value
-        elif isinstance(value, int):
-            return def_value
-        return def_value
-
-    # 适用于活动爬塔仅有游戏体力的情况
-    # @field_validator('ap_mode', mode='after')
-    # def check_mode(cls, value):
-    #     return ApMode.AP_GAME

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

@@ -51,7 +51,7 @@ class CostumeAssets:
 
 	# Image Rule Assets
 	# description 
-	I_CHECK_MAIN_12 = RuleImage(roi_front=(937,487,49,31), roi_back=(78,474,1099,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main12/main12_check_main_12.png")
+	I_CHECK_MAIN_12 = RuleImage(roi_front=(829,278,39,26), roi_back=(61,241,1099,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main12/main12_check_main_12.png")
 	# 探索 
 	I_MAIN_GOTO_EXPLORATION_12 = RuleImage(roi_front=(557,142,20,34), roi_back=(192,123,904,66), threshold=0.6, method="Template matching", file="./tasks/Component/Costume/main12/main12_main_goto_exploration_12.png")
 	# 召唤屋 

+ 2 - 2
tasks/Component/Costume/main12/image.json

@@ -2,8 +2,8 @@
   {
     "itemName": "check_main_12",
     "imageName": "main12_check_main_12.png",
-    "roiFront": "937,487,49,31",
-    "roiBack": "78,474,1099,100",
+    "roiFront": "829,278,39,26",
+    "roiBack": "61,241,1099,100",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

BIN
tasks/Component/Costume/main12/main12_check_main_12.png


+ 43 - 0
tasks/Component/CostumeShikigami/assets.py

@@ -182,3 +182,46 @@ class CostumeShikigamiAssets:
 	I_ST_REPLACE_4 = RuleImage(roi_front=(860,168,100,100), roi_back=(872,186,78,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk4/sk4_st_replace_4.png")
 
 
+	# Image Rule Assets
+	# 用于判断在式神录 
+	I_CHECK_RECORDS_5 = RuleImage(roi_front=(267,76,51,46), roi_back=(265,74,55,50), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_check_records_5.png")
+	# 退出式神录 
+	I_RECORD_SOUL_BACK_5 = RuleImage(roi_front=(19,9,51,44), roi_back=(19,9,51,44), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_record_soul_back_5.png")
+	# 预设 
+	I_SOUL_PRESET_5 = RuleImage(roi_front=(335,73,90,51), roi_back=(310,57,169,72), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_soul_preset_5.png")
+	# 第一组切换 
+	I_SOU_SWITCH_1_5 = RuleImage(roi_front=(973,140,34,32), roi_back=(967,131,51,48), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_switch_1_5.png")
+	# 第二组切换 
+	I_SOU_SWITCH_2_5 = RuleImage(roi_front=(973,293,33,33), roi_back=(960,284,58,49), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_switch_2_5.png")
+	# description 
+	I_SOU_SWITCH_3_5 = RuleImage(roi_front=(968,448,41,38), roi_back=(962,442,52,48), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_switch_3_5.png")
+	# description 
+	I_SOU_SWITCH_4_5 = RuleImage(roi_front=(967,597,42,25), roi_back=(962,592,53,34), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_switch_4_5.png")
+	# description 
+	I_SOU_SWITCH_SURE_5 = RuleImage(roi_front=(668,401,180,61), roi_back=(668,401,180,61), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_switch_sure_5.png")
+	# 用于判断是否在式神录里面 
+	I_SOU_CHECK_IN_5 = RuleImage(roi_front=(268,74,50,49), roi_back=(268,74,50,49), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_in_5.png")
+	# 检查是否为第一组 
+	I_SOU_CHECK_GROUP_1_5 = RuleImage(roi_front=(1086,91,22,57), roi_back=(1086,91,22,57), threshold=0.9, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_1_5.png")
+	# description 
+	I_SOU_CHECK_GROUP_2_5 = RuleImage(roi_front=(1086,163,25,57), roi_back=(1086,163,25,57), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_2_5.png")
+	# description 
+	I_SOU_CHECK_GROUP_3_5 = RuleImage(roi_front=(1085,234,22,49), roi_back=(1085,234,22,49), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_3_5.png")
+	# description 
+	I_SOU_CHECK_GROUP_4_5 = RuleImage(roi_front=(1086,303,21,56), roi_back=(1086,303,21,56), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_4_5.png")
+	# description 
+	I_SOU_CHECK_GROUP_5_5 = RuleImage(roi_front=(1088,370,21,53), roi_back=(1088,370,21,53), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_5_5.png")
+	# description 
+	I_SOU_CHECK_GROUP_6_5 = RuleImage(roi_front=(1085,443,23,54), roi_back=(1085,443,23,54), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_6_5.png")
+	# description 
+	I_SOU_CHECK_GROUP_7_5 = RuleImage(roi_front=(1088,512,21,54), roi_back=(1088,512,21,54), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_check_group_7_5.png")
+	# 匹配队伍预设 
+	I_SOU_TEAM_PRESENT_5 = RuleImage(roi_front=(720,76,136,43), roi_back=(706,68,175,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_team_present_5.png")
+	# 需要切换的预设按钮(颜色深一点) 
+	I_SOU_CLICK_PRESENT_5 = RuleImage(roi_front=(967,305,43,22), roi_back=(965,142,48,480), threshold=0.9, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_sou_click_present_5.png")
+	# 点击御魂 
+	I_ST_SOULS_5 = RuleImage(roi_front=(1176,227,70,80), roi_back=(1181,234,58,69), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_st_souls_5.png")
+	# 更换 
+	I_ST_REPLACE_5 = RuleImage(roi_front=(860,168,100,100), roi_back=(872,186,78,63), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeShikigami/sk5/sk5_st_replace_5.png")
+
+

+ 2 - 0
tasks/Component/GeneralBattle/assets.py

@@ -133,6 +133,8 @@ class GeneralBattleAssets:
 	I_GREEN_MARKER_BOTTOM = RuleImage(roi_front=(0,0,1280,720), roi_back=(0,0,1280,720), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_green_marker_bottom.png")
 	# 新版本的预设图案带数字 
 	I_PRESET_WIT_NUMBER = RuleImage(roi_front=(40,655,37,37), roi_back=(9,636,100,74), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_preset_wit_number.png")
+	# 战斗信息标识 
+	I_BATTLE_INFO = RuleImage(roi_front=(230,12,37,39), roi_back=(210,1,147,72), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_battle_info.png")
 
 
 	# Image Rule Assets

BIN
tasks/Component/GeneralBattle/gb/gb_battle_info.png


+ 9 - 0
tasks/Component/GeneralBattle/gb/image.json

@@ -295,5 +295,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "新版本的预设图案带数字"
+  },
+  {
+    "itemName": "battle_info",
+    "imageName": "gb_battle_info.png",
+    "roiFront": "230,12,37,39",
+    "roiBack": "210,1,147,72",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战斗信息标识"
   }
 ]

+ 3 - 1
tasks/Component/GeneralBattle/general_battle.py

@@ -11,6 +11,7 @@ from module.base.utils import get_color, color_similar
 from tasks.base_task import BaseTask
 from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType, GeneralBattleConfig
 from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
+from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType, GeneralBattleConfig
 from tasks.Component.GeneralBuff.config_buff import BuffClass
 from tasks.Component.GeneralBuff.general_buff import GeneralBuff
 
@@ -416,7 +417,8 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         """
         if is_screenshot:
             self.screenshot()
-        if self.appear(self.I_FRIENDS) or \
+        if self.appear(self.I_BATTLE_INFO) or \
+                self.appear(self.I_FRIENDS) or \
                 self.appear(self.I_WIN) or \
                 self.appear(self.I_FALSE) or \
                 self.appear(self.I_REWARD):

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

@@ -24,7 +24,7 @@ def switch_parser(switch_str: str) -> tuple:
 
 class SwitchSoul(BaseTask, SwitchSoulAssets):
 
-    def run_switch_soul(self, target: tuple or list[tuple]):
+    def run_switch_soul(self, target: tuple | list[tuple] | str):
         """
         保证在式神录的界面
         :return:

+ 20 - 0
tasks/GameUi/additional/act.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "paper_doll_close",
+    "imageName": "additional_paper_doll_close.png",
+    "roiFront": "1253,102,25,62",
+    "roiBack": "1238,58,40,153",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "act_list_expand",
+    "imageName": "additional_act_list_expand.png",
+    "roiFront": "1191,508,30,25",
+    "roiBack": "1160,456,92,103",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

BIN
tasks/GameUi/additional/additional_act_list_expand.png


BIN
tasks/GameUi/additional/additional_paper_doll_close.png


+ 25 - 2
tasks/GameUi/assets.py

@@ -10,6 +10,13 @@ from module.atom.list import RuleList
 class GameUiAssets: 
 
 
+	# Image Rule Assets
+	# description 
+	I_PAPER_DOLL_CLOSE = RuleImage(roi_front=(1253,102,25,62), roi_back=(1238,58,40,153), threshold=0.8, method="Template matching", file="./tasks/GameUi/additional/additional_paper_doll_close.png")
+	# description 
+	I_ACT_LIST_EXPAND = RuleImage(roi_front=(1191,508,30,25), roi_back=(1160,456,92,103), threshold=0.8, method="Template matching", file="./tasks/GameUi/additional/additional_act_list_expand.png")
+
+
 	# Ocr Rule Assets
 	# 点击空白处关闭此界面 
 	O_CLICK_CLOSE_1 = RuleOcr(roi=(521,659,232,32), area=(521,659,232,32), mode="Single", method="Default", keyword="点击空白处关闭此界面", name="click_close_1")
@@ -170,8 +177,8 @@ class GameUiAssets:
 	I_BACK_FRIENDS = RuleImage(roi_front=(1152,87,53,52), roi_back=(1152,87,53,52), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_back_friends.png")
 	# description 
 	I_BACK_DAILY = RuleImage(roi_front=(33,13,39,50), roi_back=(33,13,39,50), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_back_daily.png")
-	# description 
-	I_NEW = RuleImage(roi_front=(0,0,100,100), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/image_name.png")
+	# 活动列表页返回庭院 
+	I_BACK_ACT_LIST = RuleImage(roi_front=(1165,65,51,47), roi_back=(1124,23,131,133), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_back_act_list.png")
 	# 下载拓展包弹窗 
 	I_DLC_CLOSE = RuleImage(roi_front=(916,147,24,25), roi_back=(916,147,24,25), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/store_dlc_close.png")
 
@@ -194,6 +201,10 @@ class GameUiAssets:
 	I_MAIN_GOTO_TRAVEL = RuleImage(roi_front=(202,619,64,61), roi_back=(202,619,64,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_travel.png")
 	# 珍旅居 
 	I_CHECK_TRAVEL = RuleImage(roi_front=(1134,583,78,77), roi_back=(1134,583,78,77), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_travel.png")
+	# 活动列表页前往活动 
+	I_ACT_LIST_GOTO_ACT = RuleImage(roi_front=(971,506,156,60), roi_back=(925,458,272,166), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_act_list_goto_act.png")
+	# 活动列表页标志 
+	I_CHECK_ACT_LIST = RuleImage(roi_front=(60,617,79,66), roi_back=(19,555,163,164), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_act_list.png")
 
 
 	# Image Rule Assets
@@ -201,6 +212,18 @@ class GameUiAssets:
 	I_KEKKAI_TOPPA = RuleImage(roi_front=(1065,3,203,61), roi_back=(1065,3,203,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_kekkai_toppa.png")
 
 
+	# List Rule Assets
+	# 活动列表页图像列表 
+	L_ACT_LIST_IMG = RuleList(folder="./tasks/GameUi/page", direction="vertical", mode="image", roi_back=(140,105,53,479), size=(46, 78), 
+					 array=["climb_act"])
+
+
+	# List Rule Assets
+	# 活动列表页文字列表 
+	L_ACT_LIST_OCR = RuleList(folder="./tasks/GameUi/page", direction="vertical", mode="ocr", roi_back=(192,90,190,513), size=(186, 78), 
+					 array=["冰火永烬"])
+
+
 	# Image Rule Assets
 	# 左上角蓝色的返回 
 	I_BACK_BL = RuleImage(roi_front=(32,31,50,53), roi_back=(1,2,139,120), threshold=0.8, method="Template matching", file="./tasks/GameUi/res/res_back_blue.png")

+ 64 - 26
tasks/GameUi/game_ui.py

@@ -4,18 +4,19 @@
 import time
 from time import sleep
 
-from module.base.decorator import run_once
-from module.base.timer import Timer
+import random
 from module.atom.image import RuleImage
 from module.atom.ocr import RuleOcr
-
+from module.base.decorator import run_once
+from module.base.timer import Timer
+from module.exception import (GameNotRunningError, GamePageUnknownError)
+from module.logger import logger
 from tasks.GameUi.assets import GameUiAssets
 from tasks.GameUi.page import *
 from tasks.Restart.assets import RestartAssets
-from tasks.base_task import BaseTask
 from tasks.SixRealms.assets import SixRealmsAssets
-from module.logger import logger
-from module.exception import (GameNotRunningError, GamePageUnknownError, RequestHumanTakeover)
+from tasks.base_task import BaseTask
+from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
 
 
 class GameUi(BaseTask, GameUiAssets):
@@ -33,13 +34,16 @@ class GameUi(BaseTask, GameUiAssets):
         page_duel, page_demon_encounter, page_hunt, page_hunt_kirin, page_draft_duel, page_hyakkisen,
         # 庭院里面的
         page_shikigami_records, page_onmyodo, page_friends, page_daily, page_mall, page_guild, page_team,
-        page_collection,
+        page_collection, page_act_list,
+        # 爬塔活动
+        page_climb_act, page_climb_act_2, page_climb_act_pass, page_climb_act_ap, page_climb_act_boss, page_climb_act_buff
     ]
     ui_close = [GameUiAssets.I_BACK_MALL,
                 BaseTask.I_UI_BACK_RED, BaseTask.I_UI_BACK_YELLOW, BaseTask.I_UI_BACK_BLUE,
                 GameUiAssets.I_BACK_FRIENDS, GameUiAssets.I_BACK_DAILY,
                 GameUiAssets.I_REALM_RAID_GOTO_EXPLORATION,
-                GameUiAssets.I_SIX_GATES_GOTO_EXPLORATION, SixRealmsAssets.I_EXIT_SIXREALMS]
+                GameUiAssets.I_SIX_GATES_GOTO_EXPLORATION, SixRealmsAssets.I_EXIT_SIXREALMS,
+                ActivityShikigamiAssets.I_SKIP_BUTTON, ActivityShikigamiAssets.I_RED_EXIT, ActivityShikigamiAssets.I_RED_EXIT_2]
 
     def home_explore(self) -> bool:
         """
@@ -214,7 +218,8 @@ class GameUi(BaseTask, GameUiAssets):
             if destination.additional and isinstance(destination.additional, list):
                 appear = False
                 for button in destination.additional:
-                    if self.appear_then_click(button, interval=0.6):
+                    if self.appear_then_click(button, interval=0.6) or (
+                            isinstance(button, RuleOcr) and self.ocr_appear_click(button, interval=2)):
                         appear = True
                         logger.info(f'Page {destination} AB {button} clicked')
                 if appear:
@@ -233,22 +238,12 @@ class GameUi(BaseTask, GameUiAssets):
             for page in visited:
                 if page.parent is None or page.check_button is None:
                     continue
-                # 如果当前页面不出现可以检测当前按键的按钮,那可能是有一些弹窗,广告,这个时候额外处理
-                # if page.additional:
-                #     if not isinstance(page.additional, list):
-                #         page.additional = [page.additional]
-                #     for button in page.additional:
-                #         logger.info(f'Page {page} AB {button} checking')
-                #         if self.appear_then_click(button, interval=1):
-                #             sleep(0.2)
-                #             logger.info(f'Page {page} AB {button} clicked')
-
-
                 # 获取当前页面的要点击的按钮
                 if self.appear(page.check_button, interval=4):
                     logger.info(f'Page switch: {page} -> {page.parent}')
                     button = page.links[page.parent]
-                    if self.appear_then_click(button, interval=2):
+                    if self.appear_then_click(button, interval=2) or (
+                            isinstance(button, RuleOcr) and self.ocr_appear_click(button, interval=2)):
                         self.ui_button_interval_reset(button)
                         confirm_timer.reset()
                         clicked = True
@@ -256,6 +251,7 @@ class GameUi(BaseTask, GameUiAssets):
 
             if clicked:
                 continue
+            sleep(0.5)
 
         # Reset connection
         for page in self.ui_pages:
@@ -284,15 +280,57 @@ class GameUi(BaseTask, GameUiAssets):
         time.sleep(1)
         return
 
+    def main_goto_act_by_list(self, dest_act: Page):
+        """
+        庭院通过活动列表页跳转到对应活动页面
+        :param dest_act: 活动页面
+        :return:
+        """
+        # key: page名称, value: (活动列表中文字, 活动列表中png图像名称)
+        # png图像必须存放在page文件夹下
+        # 添加其他活动列表页的活动时需同时添加下方map内容
+        act_map = {
+            'page_climb_act': ('冰火永烬', 'page_act_list_climb_act')
+        }
+        self.ui_get_current_page()
+        self.ui_goto(page_act_list)
+        # 获取活动页面在活动列表中的文字和图标
+        text, png = act_map[dest_act.name]
+        ok_cnt, max_retry = 0, 3
+        while True:
+            # 多次成功才算成功
+            if ok_cnt >= max_retry:
+                break
+            self.screenshot()
+            # 先尝试文字识别,失败则尝试图像识别,都失败则向下滑动
+            result = self.L_ACT_LIST_OCR.ocr_appear(self.device.image, name=text)
+            if not isinstance(result, tuple):
+                result = self.L_ACT_LIST_IMG.image_appear(self.device.image, name=png)
+            if isinstance(result, tuple):
+                pos = result
+                ok_cnt += 1
+            else:
+                ok_cnt = 0
+            # 一次都未成功则向下滑动
+            if ok_cnt == 0:
+                x1, y1, x2, y2 = self.L_ACT_LIST_OCR.swipe_pos(number=1)
+                self.device.swipe(p1=(x1, y1), p2=(x2, y2))
+            sleep(0.5)
+        if isinstance(pos, tuple):
+            x, y = pos
+            self.device.click(x, y)
+        self.ui_goto(dest_act, confirm_wait=2)
+
 
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
 
-    c = Config('oas1')
+    c = Config('oas2')
     d = Device(c)
     game = GameUi(config=c, device=d)
-
-    game.screenshot()
-    print(game.appear(game.I_CHECK_AREA_BOSS))
-    print(game.appear(game.I_RECORDS_CLOSE))
+    game.ui_get_current_page()
+    game.ui_goto(page_main)
+    game.main_goto_act_by_list(page_climb_act)
+    game.ui_get_current_page()
+    game.ui_goto(page_climb_act_pass)

+ 43 - 4
tasks/GameUi/page.py

@@ -1,6 +1,7 @@
 import traceback
 
 from tasks.GameUi.assets import GameUiAssets as G
+from tasks.base_task import BaseTask as BT
 from tasks.RyouToppa.assets import RyouToppaAssets
 
 class Page:
@@ -31,6 +32,7 @@ class Page:
 page_login=Page(G.I_CHECK_LOGIN_FORM)
 # Main Home 主页
 page_main = Page(G.I_CHECK_MAIN)
+page_main.additional = [G.I_BACK_Y, G.I_BACK_MALL, G.I_AD_CLOSE_RED, G.I_BACK_YOLLOW, G.I_BACK_FRIENDS, G.I_BACK_DAILY, G.I_BACK_BLUE, G.I_BACK_ACT_LIST]
 # 召唤summon
 page_summon = Page(G.I_CHECK_SUMMON)
 page_summon.link(button=G.I_SUMMON_GOTO_MAIN, destination=page_main)
@@ -166,6 +168,11 @@ page_main.link(button=G.I_MAIN_GOTO_COLLECTION, destination=page_collection)
 page_travel = Page(G.I_CHECK_TRAVEL)
 page_travel.link(button=G.I_BACK_Y, destination=page_main)
 page_main.link(button=G.I_MAIN_GOTO_TRAVEL, destination=page_travel)
+# 活动列表页 act_list
+page_act_list = Page(G.I_CHECK_ACT_LIST)
+page_act_list.additional = [G.I_PAPER_DOLL_CLOSE]
+page_act_list.link(button=G.I_BACK_ACT_LIST, destination=page_main)
+page_main.link(button=G.I_ACT_LIST_EXPAND, destination=page_act_list)
 
 
 # 道馆
@@ -175,7 +182,39 @@ page_dokan = Page(DokanAssets.I_RYOU_DOKAN_CHECK)
 page_dokan.additional = [GeneralBattleAssets.I_EXIT, DokanAssets.I_RYOU_DOKAN_EXIT_ENSURE, G.I_BACK_BLUE]
 page_dokan.link(button=G.I_BACK_Y, destination=page_main)
 
-
-
-
-
+# ************************************* 活动部分 *****************************************#
+from tasks.ActivityShikigami.assets import ActivityShikigamiAssets as asa
+from tasks.GlobalGame.assets import GlobalGameAssets as gga
+# 爬塔活动界面
+page_climb_act = Page(asa.I_BATTLE)
+page_climb_act.additional = [gga.I_UI_REWARD, asa.I_SKIP_BUTTON, asa.I_TOGGLE_BUTTON, asa.I_RED_EXIT_2]
+page_climb_act.link(button=G.I_BACK_Y, destination=page_main)
+page_act_list.link(button=G.I_ACT_LIST_GOTO_ACT, destination=page_climb_act)
+# 爬塔活动副界面
+page_climb_act_2 = Page(asa.I_CHECK_BATTLE_2)
+page_climb_act_2.additional = [asa.I_SKIP_BUTTON, asa.I_TOGGLE_BUTTON, gga.I_UI_REWARD, asa.I_RED_EXIT]
+page_climb_act_2.link(button=G.I_BACK_Y, destination=page_climb_act)
+page_climb_act.link(button=asa.I_BATTLE, destination=page_climb_act_2)
+# 门票爬塔活动界面
+page_climb_act_pass = Page(asa.I_AP_ACTIVITY)
+page_climb_act_pass.additional = [asa.I_SKIP_BUTTON, asa.I_TOGGLE_BUTTON, gga.I_UI_REWARD, asa.I_RED_EXIT]
+page_climb_act_pass.link(button=G.I_BACK_Y, destination=page_climb_act_2)
+page_climb_act_2.link(button=asa.O_ENTRY_ACTIVITY, destination=page_climb_act_pass)
+# 体力爬塔活动界面
+page_climb_act_ap = Page(asa.I_AP)
+page_climb_act_ap.additional = [asa.O_ENTRY_ACTIVITY, asa.I_SKIP_BUTTON, asa.I_TOGGLE_BUTTON, gga.I_UI_REWARD, asa.I_RED_EXIT]
+page_climb_act_ap.link(button=G.I_BACK_Y, destination=page_climb_act_2)
+page_climb_act_2.link(button=asa.O_ENTRY_ACTIVITY, destination=page_climb_act_ap)
+# 体力, 门票互相跳转
+page_climb_act_ap.link(button=asa.I_SWITCH, destination=page_climb_act_pass)
+page_climb_act_pass.link(button=asa.I_SWITCH, destination=page_climb_act_ap)
+# 爬塔活动boss战界面
+page_climb_act_boss = Page(asa.I_CHECK_BOSS)
+page_climb_act_boss.additional = [BT.I_UI_BACK_RED, asa.I_SKIP_BUTTON]
+page_climb_act_boss.link(button=G.I_BACK_Y, destination=page_climb_act)
+page_climb_act.link(button=asa.I_BOSS, destination=page_climb_act_boss)
+# 爬塔活动加成界面
+page_climb_act_buff = Page(asa.I_CHECK_BUFF)
+page_climb_act_buff.additional = [BT.I_UI_BACK_RED, asa.I_SKIP_BUTTON]
+page_climb_act_buff.link(button=G.I_BACK_Y, destination=page_climb_act)
+page_climb_act.link(button=asa.I_BUFF_CHANGE_BUTTON, destination=page_climb_act_buff)

BIN
tasks/GameUi/page/page_act_list_climb_act.png


BIN
tasks/GameUi/page/page_act_list_goto_act.png


BIN
tasks/GameUi/page/page_back_act_list.png


BIN
tasks/GameUi/page/page_check_act_list.png


+ 5 - 5
tasks/GameUi/page/page_img_3.json

@@ -180,13 +180,13 @@
     "description": "description"
   },
   {
-    "itemName": "new",
-    "imageName": "image_name.png",
-    "roiFront": "0,0,100,100",
-    "roiBack": "0,0,100,100",
+    "itemName": "back_act_list",
+    "imageName": "page_back_act_list.png",
+    "roiFront": "1165,65,51,47",
+    "roiBack": "1124,23,131,133",
     "method": "Template matching",
     "threshold": 0.8,
-    "description": "description"
+    "description": "活动列表页返回庭院"
   },
   {
     "itemName": "dlc_close",

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

@@ -52,5 +52,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "珍旅居"
+  },
+  {
+    "itemName": "act_list_goto_act",
+    "imageName": "page_act_list_goto_act.png",
+    "roiFront": "971,506,156,60",
+    "roiBack": "925,458,272,166",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "活动列表页前往活动"
+  },
+  {
+    "itemName": "check_act_list",
+    "imageName": "page_check_act_list.png",
+    "roiFront": "60,617,79,66",
+    "roiBack": "19,555,163,164",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "活动列表页标志"
   }
 ]

+ 13 - 0
tasks/GameUi/page/page_list_act_img.json

@@ -0,0 +1,13 @@
+{
+  "name": "act_list_img",
+  "direction": "vertical",
+  "type": "image",
+  "roiBack": "140,105,53,479",
+  "description": "活动列表页图像列表",
+  "list": [
+    {
+      "itemName": "climb_act",
+      "roiFront": "143,266,46,78"
+    }
+  ]
+}

+ 13 - 0
tasks/GameUi/page/page_list_act_ocr.json

@@ -0,0 +1,13 @@
+{
+  "name": "act_list_ocr",
+  "direction": "vertical",
+  "type": "ocr",
+  "roiBack": "192,90,190,513",
+  "description": "活动列表页文字列表",
+  "list": [
+    {
+      "itemName": "冰火永烬",
+      "roiFront": "194,361,186,78"
+    }
+  ]
+}

+ 1 - 1
tasks/GlobalGame/assets.py

@@ -46,7 +46,7 @@ class GlobalGameAssets:
 	# '获得奖励' 四个大字 
 	I_UI_REWARD = RuleImage(roi_front=(481,185,317,42), roi_back=(464,142,350,145), threshold=0.73, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_reward.png")
 	# description 
-	I_UI_BACK_RED = RuleImage(roi_front=(1041,111,34,38), roi_back=(834,15,427,200), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_back_red.png")
+	I_UI_BACK_RED = RuleImage(roi_front=(1041,111,34,38), roi_back=(877,15,383,254), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_back_red.png")
 	# description 
 	I_UI_BACK_YELLOW = RuleImage(roi_front=(26,17,47,46), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/GlobalGame/ui/ui_ui_back_yellow.png")
 	# description 

+ 1 - 1
tasks/GlobalGame/ui/image.json

@@ -30,7 +30,7 @@
     "itemName": "ui_back_red",
     "imageName": "ui_ui_back_red.png",
     "roiFront": "1041,111,34,38",
-    "roiBack": "834,15,427,200",
+    "roiBack": "877,15,383,254",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

+ 0 - 1
tasks/HeroTest/config.py

@@ -8,7 +8,6 @@ from pydantic import BaseModel, Field
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase, Time, TimeDelta
-from tasks.Component.BaseActivity.config_activity import GeneralClimb
 from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 
 class Layer(str, Enum):

+ 1 - 1
tasks/Orochi/assets.py

@@ -30,7 +30,7 @@ class OrochiAssets:
 	# List Rule Assets
 	# 这个是御魂界面选择不同层数的 
 	L_LAYER_LIST = RuleList(folder="./tasks/Orochi/res", direction="vertical", mode="ocr", roi_back=(138,130,359,500), size=(45, 88), 
-					 array=["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "悲", "神"])
+					 array=["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "悲", "神", "虚"])
 
 
 	# Ocr Rule Assets

+ 4 - 0
tasks/Orochi/config.py

@@ -31,6 +31,8 @@ class Layer(str, Enum):
     TEN = '拾层'
     ELEVEN = '悲鸣'
     TWELVE = '神罚'
+    THIRTEEN = '虚无'
+
 
 class OrochiConfig(ConfigBase):
     # 身份
@@ -57,6 +59,8 @@ class SwitchSoulConfig(BaseSwitchSoulConfig):
     eleven_switch: str = Field(default='-1,-1', description='eleven_switch_help')
     # 神罚 config
     twelve_switch: str = Field(default='-1,-1', description='twelve_switch_help')
+    # 虚无 config
+    thirteen_switch: str = Field(default='-1,-1', description='thirteen_switch_help')
 
 
 class Orochi(ConfigBase):

+ 4 - 0
tasks/Orochi/res/list.json

@@ -52,6 +52,10 @@
     {
       "itemName": "神",
       "roiFront": "277,534,46,86"
+    },
+    {
+      "itemName": "虚",
+      "roiFront": "277,534,46,86"
     }
   ]
 }

+ 2 - 0
tasks/Orochi/script_task.py

@@ -489,6 +489,8 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
                 group_team = orochi_switch_soul.eleven_switch
             case Layer.TWELVE:
                 group_team = orochi_switch_soul.twelve_switch
+            case Layer.THIRTEEN:
+                group_team = orochi_switch_soul.thirteen_switch
 
         if orochi_switch_soul.auto_switch_soul:
             self.ui_get_current_page()

+ 2 - 1
tasks/SoulsTidy/config.py

@@ -9,7 +9,8 @@ from tasks.Component.config_base import ConfigBase
 
 class SimpleTidy(BaseModel):
     # 贪吃鬼和招财猫
-    greed_maneki: bool = Field(default=False, description="greed_maneki_help")
+    enable_greed: bool = Field(default=False, description="是否启用贪吃鬼")
+    enable_maneki: bool = Field(default=False, description="是否启用奉纳")
 
 
 class SoulsTidy(ConfigBase):

+ 86 - 84
tasks/SoulsTidy/script_task.py

@@ -20,7 +20,7 @@ class ScriptTask(GameUi, SoulsTidyAssets):
         self.ui_get_current_page()
         self.ui_goto(page_shikigami_records)
         con = self.config.souls_tidy
-        if con.simple_tidy.greed_maneki:
+        if con.simple_tidy.enable_greed or con.simple_tidy.enable_maneki:
             self.goto_souls()
             self.greed_maneki()
             self.back_records()
@@ -61,31 +61,32 @@ class ScriptTask(GameUi, SoulsTidyAssets):
         :return:
         """
         # 先是贪吃鬼
-        logger.hr('Greed Ghost')
-        self.ui_click(self.I_ST_GREED, self.I_ST_GREED_HABIT)
-        self.ui_click(self.I_ST_GREED_HABIT, self.I_ST_FEED_NOW)
-        logger.info('Feed greed ghost')
-        feed_count = 0
-        while 1:
-            self.screenshot()
-            if self.appear(self.I_ST_UNSELECTED):
-                self.ui_click_until_disappear(self.I_ST_UNSELECTED)
-                continue
-            if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
-                continue
-            if feed_count >= 3:
-                break
-            if self.appear_then_click(self.I_ST_FEED_NOW, interval=3.5):
-                feed_count += 1
-                continue
-        logger.info('Feed greed ghost done')
+        if self.config.souls_tidy.simple_tidy.enable_greed:
+            logger.hr('Greed Ghost')
+            self.ui_click(self.I_ST_GREED, self.I_ST_GREED_HABIT)
+            self.ui_click(self.I_ST_GREED_HABIT, self.I_ST_FEED_NOW)
+            logger.info('Feed greed ghost')
+            feed_count = 0
+            while 1:
+                self.screenshot()
+                if self.appear(self.I_ST_UNSELECTED):
+                    self.ui_click_until_disappear(self.I_ST_UNSELECTED)
+                    continue
+                if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
+                    continue
+                if feed_count >= 3:
+                    break
+                if self.appear_then_click(self.I_ST_FEED_NOW, interval=3.5):
+                    feed_count += 1
+                    continue
+            logger.info('Feed greed ghost done')
         # 关闭贪吃鬼, 进入奉纳
         while 1:
             self.screenshot()
             if self.appear(self.I_ST_CAT):
                 # 出现招财猫
                 break
-            
+
             # https://github.com/runhey/OnmyojiAutoScript/issues/662
             if self.appear(self.I_ST_UNSELECTED):
                 self.ui_click_until_disappear(self.I_ST_UNSELECTED)
@@ -97,76 +98,77 @@ class ScriptTask(GameUi, SoulsTidyAssets):
                 continue
             if self.appear_then_click(self.I_ST_BONGNA, interval=1, threshold=0.6):
                 continue
-        logger.hr('Enter bongna')
-        # 进入已弃置界面
-        """
-        现在默认进入就是已弃置界面,所以不需要点击
-        """
-        # 确保是按照等级来排序的
-        while 1:
-            self.screenshot()
-            if self.ocr_appear(self.O_ST_SORT_LEVEL_1):
-                break
-            if self.ocr_appear_click(self.O_ST_SORT_LEVEL_2, interval=0.6):
-                continue
-            if self.ocr_appear_click(self.O_ST_SORT_TIME, interval=2):
-                continue
-            if self.ocr_appear_click(self.O_ST_SORT_TYPE, interval=2):
-                continue
-            if self.ocr_appear_click(self.O_ST_SORT_LOCATION, interval=2):
-                continue
-        logger.info('Sort by level')
-        # 开始奉纳
-        while 1:
-            self.wait_until_appear(self.I_ST_LEVEL_0, wait_time=2)
-            self.screenshot()
-            # 非+0的不弃置 双保险
-            if not self.appear(self.I_ST_LEVEL_0):
-                logger.info("First Orichi isn't Level 0,quit")
-                break
-            firvel = self.O_ST_FIRSET_LEVEL.ocr(self.device.image)
-            if firvel is None or firvel == '':
-                logger.info('ocr result is Null')
-                continue
-            if firvel != '古':
-                # 问就是 把 +0 识别成了 古
-                logger.info('No zero level, bongna done')
-                break
-
-            # !!!!!!  这里没有检查金币是否足够
-            # 长按
-            self.click(self.L_ONE, interval=2.5)
-            self.screenshot()
-            gold_amount = self.O_ST_GOLD.ocr(self.device.image)
-            if not isinstance(gold_amount, int):
-                logger.warning('Gold amount not int, skip')
-                continue
-            if gold_amount == 0:
-                continue
-
-            # 点击奉纳收取奖励
-            if not self.appear(self.I_ST_DONATE):
-                logger.warning('Donate button not appear, skip')
-                continue
-            # 点击奉纳 及收取奖励
+        if self.config.souls_tidy.simple_tidy.enable_maneki:
+            logger.hr('Enter bongna')
+            # 进入已弃置界面
+            """
+            现在默认进入就是已弃置界面,所以不需要点击
+            """
+            # 确保是按照等级来排序的
             while 1:
                 self.screenshot()
-                if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
+                if self.ocr_appear(self.O_ST_SORT_LEVEL_1):
+                    break
+                if self.ocr_appear_click(self.O_ST_SORT_LEVEL_2, interval=0.6):
+                    continue
+                if self.ocr_appear_click(self.O_ST_SORT_TIME, interval=2):
                     continue
-                # 如果奉纳少就不是神赐而是获得奖励
-                if self.ui_reward_appear_click():
+                if self.ocr_appear_click(self.O_ST_SORT_TYPE, interval=2):
                     continue
-                # 出现神赐, 就点击然后消失,
-                if self.appear(self.I_ST_GOD_PRESENT):
-                    logger.info('God present appear')
-                    self.click(self.C_ST_GOD_PRSENT, interval=2)
+                if self.ocr_appear_click(self.O_ST_SORT_LOCATION, interval=2):
                     continue
-                if self.appear_then_click(self.I_ST_DONATE, interval=5.5):
-                    self.wait_until_appear(self.I_ST_GOLD, True, wait_time=5)
+            logger.info('Sort by level')
+            # 开始奉纳
+            while 1:
+                self.wait_until_appear(self.I_ST_LEVEL_0, wait_time=2)
+                self.screenshot()
+                # 非+0的不弃置 双保险
+                if not self.appear(self.I_ST_LEVEL_0):
+                    logger.info("First Orichi isn't Level 0,quit")
+                    break
+                firvel = self.O_ST_FIRSET_LEVEL.ocr(self.device.image)
+                if firvel is None or firvel == '':
+                    logger.info('ocr result is Null')
                     continue
-                if not self.appear(self.I_ST_GOLD):
+                if firvel != '古':
+                    # 问就是 把 +0 识别成了 古
+                    logger.info('No zero level, bongna done')
                     break
-            logger.info('Donate one')
+
+                # !!!!!!  这里没有检查金币是否足够
+                # 长按
+                self.click(self.L_ONE, interval=2.5)
+                self.screenshot()
+                gold_amount = self.O_ST_GOLD.ocr(self.device.image)
+                if not isinstance(gold_amount, int):
+                    logger.warning('Gold amount not int, skip')
+                    continue
+                if gold_amount == 0:
+                    continue
+
+                # 点击奉纳收取奖励
+                if not self.appear(self.I_ST_DONATE):
+                    logger.warning('Donate button not appear, skip')
+                    continue
+                # 点击奉纳 及收取奖励
+                while 1:
+                    self.screenshot()
+                    if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
+                        continue
+                    # 如果奉纳少就不是神赐而是获得奖励
+                    if self.ui_reward_appear_click():
+                        continue
+                    # 出现神赐, 就点击然后消失,
+                    if self.appear(self.I_ST_GOD_PRESENT):
+                        logger.info('God present appear')
+                        self.click(self.C_ST_GOD_PRSENT, interval=2)
+                        continue
+                    if self.appear_then_click(self.I_ST_DONATE, interval=5.5):
+                        self.wait_until_appear(self.I_ST_GOLD, True, wait_time=5)
+                        continue
+                    if not self.appear(self.I_ST_GOLD):
+                        break
+                logger.info('Donate one')
 
         logger.info('Bongna done')
 
@@ -175,7 +177,7 @@ if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
 
-    c = Config('oas1')
+    c = Config('oas3')
     d = Device(c)
     t = ScriptTask(c, d)
 

+ 1 - 1
tasks/WantedQuests/assets.py

@@ -139,7 +139,7 @@ class WantedQuestsAssets:
 
 	# Image Rule Assets
 	# 封印 
-	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_SEAL = RuleImage(roi_front=(174,184,20,29), 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")
 	# 一键追踪 

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

@@ -2,7 +2,7 @@
   {
     "itemName": "wq_seal",
     "imageName": "wq_wq_seal.png",
-    "roiFront": "244,181,40,40",
+    "roiFront": "174,184,20,29",
     "roiBack": "56,93,664,455",
     "method": "Template matching",
     "threshold": 0.8,

BIN
tasks/WantedQuests/wq/wq_wq_seal.png


+ 24 - 25
tasks/base_task.py

@@ -1,35 +1,29 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-import numpy as np
 
 from time import sleep
-from datetime import datetime, timedelta, time
-from typing import Union
-
-from dev_tools.decorator import usage_time
 
-from module.config.utils import convert_to_underscore
-from module.atom.image import RuleImage
+from datetime import datetime, timedelta
+from module.atom.animate import RuleAnimate
 from module.atom.click import RuleClick
+from module.atom.gif import RuleGif
+from module.atom.image import RuleImage
+from module.atom.list import RuleList
 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
-from module.atom.gif import RuleGif
-from module.ocr.base_ocr import OcrMode, OcrMethod
-from module.atom.animate import RuleAnimate
-from module.logger import logger
+from module.atom.swipe import RuleSwipe
 from module.base.timer import Timer
 from module.config.config import Config
-from module.config.utils import get_server_next_update, nearest_future, dict_to_kv, parse_tomorrow_server
 from module.device.device import Device
-from tasks.GlobalGame.assets import GlobalGameAssets
-from tasks.GlobalGame.config_emergency import FriendInvitation, WhenNetworkAbnormal, WhenNetworkError
+from module.exception import ScriptError
+from module.logger import logger
+from module.ocr.base_ocr import OcrMode
 from tasks.Component.Costume.costume_base import CostumeBase
-from tasks.Component.config_base import ConfigBase, Time
-
-from module.exception import GameStuckError, ScriptError
+from tasks.Component.config_base import Time
+from tasks.GlobalGame.assets import GlobalGameAssets
+from tasks.GlobalGame.config_emergency import FriendInvitation
+from typing import Union
 
 
 class BaseTask(GlobalGameAssets, CostumeBase):
@@ -234,20 +228,25 @@ class BaseTask(GlobalGameAssets, CostumeBase):
 
     def wait_until_appear_then_click(self,
                                      target: RuleImage,
-                                     action: Union[RuleClick, RuleLongClick] = None) -> None:
+                                     action: Union[RuleClick, RuleLongClick] = None,
+                                     wait_time: int = None) -> bool:
         """
         等待直到出现目标,然后点击
+        :param wait_time:
         :param action:
         :param target:
         :return:
         """
-        self.wait_until_appear(target)
+        if not self.wait_until_appear(target, wait_time):
+            return False
+        click_x, click_y = target.coord()
         if action is None:
-            self.device.click(target.coord(), control_name=target.name)
+            self.device.click(click_x, click_y, control_name=target.name)
         elif isinstance(action, RuleLongClick):
-            self.device.long_click(target.coord(), duration=action.duration / 1000, control_name=target.name)
+            self.device.long_click(click_x, click_y, duration=action.duration / 1000, control_name=target.name)
         elif isinstance(action, RuleClick):
-            self.device.click(target.coord(), control_name=target.name)
+            self.device.click(click_x, click_y, control_name=target.name)
+        return True
 
     def wait_until_disappear(self, target: RuleImage) -> None:
         while 1:
@@ -459,7 +458,7 @@ class BaseTask(GlobalGameAssets, CostumeBase):
             self.device.click(x=x, y=y, control_name=target.name)
         return True
 
-    def list_find(self, target: RuleList, name: str | list[str]) -> bool:
+    def list_find(self, target: RuleList, name: str | list[str]) -> bool | tuple:
         """
         会一致在列表寻找目标,找到了就退出。
         如果是图片列表会一直往下找