Browse Source

Merge pull request #1729 from runhey/dev

Automated PR 2026.08.13
huangrunheng 3 tháng trước cách đây
mục cha
commit
2e54190bc7

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

@@ -47,5 +47,13 @@
   "enable_book_auto": "自动选择",
   "enable_book_auto_help": "游戏内是否开启自动选择御魂",
   "earn_money": "获取樱灯饰",
-  "earn_money_help": "通过放置借处式神获取500樱灯饰\n开启前确保已放置借出式神"
+  "BudokaiTournament": "武道大会",
+  "earn_money_help": "通过放置借处式神获取500樱灯饰\n开启前确保已放置借出式神",
+  "daily_training": "配置",
+  "limit_daily_training": "日常训练限制次数",
+  "limit_daily_training_help": "",
+  "limit_cultivation_drills": "修行合训挑战鬼王数量",
+  "limit_cultivation_drills_help": "搜寻到一只后会一直打,直到打完算一次",
+  "enable_switch_daily_training": "日常训练开启切换御魂",
+  "enable_switch_cultivation_drills": "修行合训开启切换御魂"
 }

+ 1 - 1
module/config/config_manual.py

@@ -13,7 +13,7 @@ class ConfigManual:
         > AreaBoss > GoldYoukai > ExperienceYoukai > Nian > Tako > AutoCheckinBigGod > RealmRaid > RyouToppa > DailyTrifles > Exploration
         > Dokan > AbyssShadows > Hunt > GuildBanquet > DemonRetreat > GuildActivityMonitor
         > Orochi > OrochiMoans > OrochiJudgement > Sougenbi > FallenSun > EternitySea > SixRealms
-        > ActivityShikigami > WantedQuests
+        > ActivityShikigami > BudokaiTournament > WantedQuests
         > BondlingFairyland > EvoZone > GoryouRealm > HeroTest
         > CollectiveMissions
         > Pets > TalismanPass > Delegation > Hyakkiyakou

+ 1 - 1
module/config/config_menu.py

@@ -41,7 +41,7 @@ class ConfigMenu:
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         # 活动的任务
-        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop', 'DyeTrials']
+        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop', 'DyeTrials', 'BudokaiTournament']
         # 开发工具
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
 

+ 2 - 0
module/config/config_model.py

@@ -60,6 +60,7 @@ from tasks.FloatParade.config import FloatParade
 from tasks.Quiz.config import Quiz
 from tasks.KittyShop.config import KittyShop
 from tasks.DyeTrials.config import DyeTrials
+from tasks.BudokaiTournament.config import BudokaiTournament
 # ----------------------------------------------------------------------------------------------------------------------
 
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
@@ -150,6 +151,7 @@ class ConfigModel(ConfigBase):
     guild_banquet: GuildBanquet = Field(default_factory=GuildBanquet)
     demon_retreat: DemonRetreat = Field(default_factory=DemonRetreat)
     guild_activity_monitor: GuildActivityMonitor = Field(default_factory=GuildActivityMonitor)
+    budokai_tournament: BudokaiTournament = Field(default_factory=BudokaiTournament)
 
     def __init__(self, config_name: str=None) -> None:
         """

BIN
tasks/ActivityShikigami/as/as_battle_main_to_records.png


BIN
tasks/ActivityShikigami/as/as_check_battle_boss.png


BIN
tasks/ActivityShikigami/as/as_shi.png


BIN
tasks/ActivityShikigami/as/as_to_battle_boss.png


BIN
tasks/ActivityShikigami/as/as_to_battle_main.png


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

@@ -3,7 +3,7 @@
     "itemName": "lock",
     "imageName": "as_lock.png",
     "roiFront": "825,657,28,25",
-    "roiBack": "739,613,276,85",
+    "roiBack": "739,432,440,266",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "上锁图标"
@@ -12,7 +12,7 @@
     "itemName": "unlock",
     "imageName": "as_unlock.png",
     "roiFront": "884,648,28,25",
-    "roiBack": "733,607,266,95",
+    "roiBack": "733,426,444,276",
     "method": "Template matching",
     "threshold": 0.5,
     "description": "还未上锁图片"

+ 10 - 10
tasks/ActivityShikigami/as/pages.json

@@ -2,8 +2,8 @@
   {
     "itemName": "shi",
     "imageName": "as_shi.png",
-    "roiFront": "1189,467,39,28",
-    "roiBack": "1164,134,83,393",
+    "roiFront": "1186,220,39,28",
+    "roiBack": "1165,128,83,393",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "进入活动"
@@ -38,8 +38,8 @@
   {
     "itemName": "to_battle_main",
     "imageName": "as_to_battle_main.png",
-    "roiFront": "1040,173,38,152",
-    "roiBack": "951,101,238,269",
+    "roiFront": "180,207,38,152",
+    "roiBack": "118,145,238,269",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "进入主要的战斗界面"
@@ -47,8 +47,8 @@
   {
     "itemName": "to_battle_boss",
     "imageName": "as_to_battle_boss.png",
-    "roiFront": "1076,241,37,136",
-    "roiBack": "934,209,234,327",
+    "roiFront": "1111,248,37,136",
+    "roiBack": "973,174,234,327",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "点击进入boss战斗页面"
@@ -59,14 +59,14 @@
     "roiFront": "50,642,62,58",
     "roiBack": "1,510,415,203",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.65,
     "description": "description"
   },
   {
     "itemName": "check_battle_boss",
     "imageName": "as_check_battle_boss.png",
-    "roiFront": "34,365,45,35",
-    "roiBack": "20,328,100,100",
+    "roiFront": "978,636,43,31",
+    "roiBack": "899,537,167,154",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -74,7 +74,7 @@
   {
     "itemName": "battle_main_to_records",
     "imageName": "as_battle_main_to_records.png",
-    "roiFront": "1018,562,39,42",
+    "roiFront": "1001,558,39,42",
     "roiBack": "966,534,140,100",
     "method": "Template matching",
     "threshold": 0.7,

+ 10 - 10
tasks/ActivityShikigami/assets.py

@@ -25,9 +25,9 @@ class ActivityShikigamiAssets:
 
 	# Image Rule Assets
 	# 上锁图标 
-	I_LOCK = RuleImage(roi_front=(825,657,28,25), roi_back=(739,613,276,85), threshold=0.5, method="Template matching", file="./tasks/ActivityShikigami/as/as_lock.png")
+	I_LOCK = RuleImage(roi_front=(825,657,28,25), roi_back=(739,432,440,266), threshold=0.5, method="Template matching", file="./tasks/ActivityShikigami/as/as_lock.png")
 	# 还未上锁图片 
-	I_UNLOCK = RuleImage(roi_front=(884,648,28,25), roi_back=(733,607,266,95), threshold=0.5, method="Template matching", file="./tasks/ActivityShikigami/as/as_unlock.png")
+	I_UNLOCK = RuleImage(roi_front=(884,648,28,25), roi_back=(733,426,444,276), threshold=0.5, method="Template matching", file="./tasks/ActivityShikigami/as/as_unlock.png")
 	# 活动爬塔标志 
 	I_CLIMB_MODE_PASS = RuleImage(roi_front=(1142,547,21,21), roi_back=(1096,516,78,83), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_climb_mode_pass.png")
 	# 体力爬塔标志 
@@ -38,7 +38,7 @@ class ActivityShikigamiAssets:
 
 	# Image Rule Assets
 	# 进入活动 
-	I_SHI = RuleImage(roi_front=(1189,467,39,28), roi_back=(1164,134,83,393), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_shi.png")
+	I_SHI = RuleImage(roi_front=(1186,220,39,28), roi_back=(1165,128,83,393), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_shi.png")
 	# 左上角返回 
 	I_BACK_GREEN = RuleImage(roi_front=(27,19,34,38), roi_back=(2,1,170,75), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_back_green.png")
 	# 右上跳过按钮 
@@ -46,15 +46,15 @@ class ActivityShikigamiAssets:
 	# 红色退出 
 	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")
 	# 进入主要的战斗界面 
-	I_TO_BATTLE_MAIN = RuleImage(roi_front=(1040,173,38,152), roi_back=(951,101,238,269), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_to_battle_main.png")
+	I_TO_BATTLE_MAIN = RuleImage(roi_front=(180,207,38,152), roi_back=(118,145,238,269), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_to_battle_main.png")
 	# 点击进入boss战斗页面 
-	I_TO_BATTLE_BOSS = RuleImage(roi_front=(1076,241,37,136), roi_back=(934,209,234,327), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_to_battle_boss.png")
+	I_TO_BATTLE_BOSS = RuleImage(roi_front=(1111,248,37,136), roi_back=(973,174,234,327), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_to_battle_boss.png")
 	# description 
-	I_CHECK_BATTLE_MAIN = RuleImage(roi_front=(50,642,62,58), roi_back=(1,510,415,203), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_battle_main.png")
+	I_CHECK_BATTLE_MAIN = RuleImage(roi_front=(50,642,62,58), roi_back=(1,510,415,203), threshold=0.65, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_battle_main.png")
 	# description 
-	I_CHECK_BATTLE_BOSS = RuleImage(roi_front=(34,365,45,35), roi_back=(20,328,100,100), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_battle_boss.png")
+	I_CHECK_BATTLE_BOSS = RuleImage(roi_front=(978,636,43,31), roi_back=(899,537,167,154), threshold=0.8, method="Template matching", file="./tasks/ActivityShikigami/as/as_check_battle_boss.png")
 	# 从main进入到式神录 
-	I_BATTLE_MAIN_TO_RECORDS = RuleImage(roi_front=(1018,562,39,42), roi_back=(966,534,140,100), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_battle_main_to_records.png")
+	I_BATTLE_MAIN_TO_RECORDS = RuleImage(roi_front=(1001,558,39,42), roi_back=(966,534,140,100), threshold=0.7, method="Template matching", file="./tasks/ActivityShikigami/as/as_battle_main_to_records.png")
 	# description 
 	I_TO_BATTLE_MAIN_2 = RuleImage(roi_front=(15,94,247,38), roi_back=(2,68,311,100), threshold=0.65, method="Template matching", file="./tasks/ActivityShikigami/as/as_to_battle_main_2.png")
 	# 确认跳过 
@@ -94,7 +94,7 @@ class ActivityShikigamiAssets:
 	# 挑战 
 	O_FIRE = RuleOcr(roi=(1124,599,96,50), area=(1123,570,106,100), mode="Single", method="Default", keyword="挑战", name="fire")
 	# 体力的数量检测 
-	O_REMAIN_AP = RuleOcr(roi=(777,17,63,30), area=(776,16,63,30), mode="DigitCounter", method="Default", keyword="", name="remain_ap")
+	O_REMAIN_AP = RuleOcr(roi=(1153,16,63,27), area=(1151,15,63,30), mode="DigitCounter", method="Default", keyword="", name="remain_ap")
 	# 活动体力的剩余检测 
 	O_REMAIN_PASS = RuleOcr(roi=(599,15,50,29), area=(600,16,49,28), mode="DigitCounter", method="Default", keyword="", name="remain_pass")
 	# 还有多少次购买体力的机会 
@@ -102,7 +102,7 @@ class ActivityShikigamiAssets:
 	# 活动票数(没有百分比) 
 	O_REMAIN_PASS2 = RuleOcr(roi=(750,17,88,29), area=(750,17,88,29), mode="Digit", method="Default", keyword="", name="remain_pass2")
 	# boss剩余攻击次数 
-	O_REMAIN_BOSS = RuleOcr(roi=(1113,669,131,31), area=(1099,659,162,52), mode="DigitCounter", method="Default", keyword="", name="remain_boss")
+	O_REMAIN_BOSS = RuleOcr(roi=(970,16,42,29), area=(970,16,42,29), mode="DigitCounter", method="Default", keyword="", name="remain_boss")
 	# 100体活动门票检测 
 	O_REMAIN_AP100 = RuleOcr(roi=(922,21,112,39), area=(913,8,131,62), mode="Digit", method="Default", keyword="", name="remain_ap100")
 	# 进入100体活动标识 

+ 4 - 4
tasks/ActivityShikigami/fire/ocr.json

@@ -10,8 +10,8 @@
   },
   {
     "itemName": "remain_ap",
-    "roiFront": "777,17,63,30",
-    "roiBack": "776,16,63,30",
+    "roiFront": "1153,16,63,27",
+    "roiBack": "1151,15,63,30",
     "mode": "DigitCounter",
     "method": "Default",
     "keyword": "",
@@ -46,8 +46,8 @@
   },
   {
     "itemName": "remain_boss",
-    "roiFront": "1113,669,131,31",
-    "roiBack": "1099,659,162,52",
+    "roiFront": "970,16,42,29",
+    "roiBack": "970,16,42,29",
     "mode": "DigitCounter",
     "method": "Default",
     "keyword": "",

+ 34 - 0
tasks/BudokaiTournament/assets.py

@@ -0,0 +1,34 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.atom.list import RuleList
+
+# This file was automatically generated by ./dev_tools/assets_extract.py.
+# Don't modify it manually.
+class BudokaiTournamentAssets: 
+
+
+	# Click Rule Assets
+	# Close cultivation drills boss detail
+	C_BOSS_DETAIL_CLOSE = RuleClick(roi_front=(1182,73,47,43), roi_back=(1182,73,47,43), name="boss_detail_close")
+
+
+	# Image Rule Assets
+	# 自己发现 
+	I_IMG2 = RuleImage(roi_front=(225,70,60,54), roi_back=(187,48,152,432), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_img2.png")
+	# 开启挑战 
+	I_IMG3 = RuleImage(roi_front=(1108,530,70,82), roi_back=(1068,500,161,139), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_img3.png")
+	# 继续挑战 
+	I_IMG4 = RuleImage(roi_front=(1106,541,72,72), roi_back=(1076,414,170,234), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_img4.png")
+	#  
+	I_ITEM_5 = RuleImage(roi_front=(1186,215,42,37), roi_back=(1164,122,80,434), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_item_5.png")
+	#  
+	I_ITEM_6 = RuleImage(roi_front=(1186,215,42,37), roi_back=(1164,122,80,434), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_item_6.png")
+	#  
+	I_ITEM_7 = RuleImage(roi_front=(1186,215,42,37), roi_back=(1164,122,80,434), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_item_7.png")
+	# 搜寻 
+	I_IMG1 = RuleImage(roi_front=(1102,590,86,73), roi_back=(1059,547,161,139), threshold=0.8, method="Template matching", file="./tasks/BudokaiTournament/bt/bt_img1.png")
+
+

BIN
tasks/BudokaiTournament/bt/bt_img1.png


BIN
tasks/BudokaiTournament/bt/bt_img2.png


BIN
tasks/BudokaiTournament/bt/bt_img3.png


BIN
tasks/BudokaiTournament/bt/bt_img4.png


+ 8 - 0
tasks/BudokaiTournament/bt/click.json

@@ -0,0 +1,8 @@
+[
+  {
+    "itemName": "boss_detail_close",
+    "roiFront": "1182,73,47,43",
+    "roiBack": "1182,73,47,43",
+    "description": "Close cultivation drills boss detail"
+  }
+]

+ 65 - 0
tasks/BudokaiTournament/bt/page.json

@@ -0,0 +1,65 @@
+[
+  {
+    "itemName": "img2",
+    "imageName": "bt_img2.png",
+    "roiFront": "225,70,60,54",
+    "roiBack": "187,48,152,432",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "自己发现"
+  },
+  {
+    "itemName": "img3",
+    "imageName": "bt_img3.png",
+    "roiFront": "1108,530,70,82",
+    "roiBack": "1068,500,161,139",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "开启挑战"
+  },
+  {
+    "itemName": "img4",
+    "imageName": "bt_img4.png",
+    "roiFront": "1106,541,72,72",
+    "roiBack": "1076,414,170,234",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "继续挑战"
+  },
+  {
+    "itemName": "item_5",
+    "imageName": "bt_item_5.png",
+    "roiFront": "1186,215,42,37",
+    "roiBack": "1164,122,80,434",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": ""
+  },
+  {
+    "itemName": "item_6",
+    "imageName": "bt_item_6.png",
+    "roiFront": "1186,215,42,37",
+    "roiBack": "1164,122,80,434",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": ""
+  },
+  {
+    "itemName": "item_7",
+    "imageName": "bt_item_7.png",
+    "roiFront": "1186,215,42,37",
+    "roiBack": "1164,122,80,434",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": ""
+  },
+  {
+    "itemName": "img1",
+    "imageName": "bt_img1.png",
+    "roiFront": "1102,590,86,73",
+    "roiBack": "1059,547,161,139",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "搜寻"
+  }
+]

+ 74 - 0
tasks/BudokaiTournament/config.py

@@ -0,0 +1,74 @@
+from pydantic import BaseModel, Field, model_validator
+
+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
+
+class DailyTraining(ConfigBase):
+    limit_daily_training: int = Field(default=200, description='limit_daily_training_help')
+    limit_cultivation_drills: int = Field(default=30, description='limit_cultivation_drills_help')
+    active_souls_clean: bool = Field(default=False, description='是否运行结束后清理御魂')  # 结束后激活 御魂清理
+    random_sleep: bool = Field(default=False, description='是否启用在点击战斗前随机休息')  # 点击战斗随机休息
+
+class SwitchSoulConfig(BaseModel):
+    enable_switch_daily_training: bool = Field(default=False, description='是否切换门票爬塔御魂')
+    group_team_daily_training: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔')
+    enable_switch_by_name_daily_training: bool = Field(default=False, description='是否通过ocr切换御魂')
+    group_team_name_daily_training: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
+
+    enable_switch_cultivation_drills: bool = Field(default=False, description='是否切换门票爬塔御魂')
+    group_team_cultivation_drills: str = Field(default='-1,-1', description='组1-7,队伍1-4 中间用英文,分隔')
+    enable_switch_by_name_cultivation_drills: bool = Field(default=False, description='是否通过ocr切换御魂')
+    group_team_name_cultivation_drills: str = Field(default='', description='组名,队伍名 中间用英文,分隔')
+
+    def get_label_set(self):
+        return {field.replace("enable_switch_", "") for field in self.model_fields if
+                     field.startswith("enable_switch_") and not field.endswith("by_name")}
+
+    def validate_switch_soul(self):
+        from tasks.ActivityShikigami.config import check_soul_by_number, check_soul_by_ocr
+        label_set = self.get_label_set()
+        for label in label_set:
+            enable_num = getattr(self, f"enable_switch_{label}", False)
+            team = getattr(self, f"group_team_{label}", None)
+            check_soul_by_number(enable_num, team, label=label.upper())
+
+            enable_ocr = getattr(self, f"enable_switch_by_name_{label}", False)
+            team_name = getattr(self, f"group_team_name_{label}", None)
+            check_soul_by_ocr(enable_ocr, team_name, label=label.upper())
+        return self
+
+
+
+class GeneralBattleConfig(BaseModel):
+    enable_preset_daily_training: bool = Field(default=False, description='是否切换门票爬塔预设, 仅数字切换御魂可用')
+    enable_green_daily_training: bool = Field(default=False, description='是否开启门票爬塔绿标')
+    green_mark_daily_training: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='门票爬塔绿标位置')
+    enable_anti_detect_daily_training: bool = Field(default=False, description='门票爬塔战斗过程是否随机点击或滑动')
+
+    enable_preset_cultivation_drills: bool = Field(default=False, description='是否切换门票爬塔预设, 仅数字切换御魂可用')
+    enable_green_cultivation_drills: bool = Field(default=False, description='是否开启门票爬塔绿标')
+    green_mark_cultivation_drills: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1, description='门票爬塔绿标位置')
+    enable_anti_detect_cultivation_drills: bool = Field(default=False, description='门票爬塔战斗过程是否随机点击或滑动')
+
+class BudokaiTournament(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    daily_training: DailyTraining = Field(default_factory=DailyTraining)
+    # cultivation_drills: CultivationDrills = Field(default_factory=CultivationDrills)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
+    general_battle: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+
+    @classmethod
+    def run_sequence(cls) -> list[str]:
+        return ['daily_training', 'cultivation_drills']
+
+
+
+
+
+
+
+
+
+

+ 389 - 0
tasks/BudokaiTournament/script_task.py

@@ -0,0 +1,389 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from enum import Enum, auto
+from time import sleep
+from datetime import datetime, timedelta
+import cv2
+import numpy as np
+import random
+from typing import Any
+from cached_property import cached_property
+
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.ocr import RuleOcr
+from module.base.protect import random_sleep
+from module.base.timer import Timer
+from module.exception import TaskEnd, GameStuckError
+from module.logger import logger
+
+from tasks.base_task import BaseTask
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
+from tasks.ActivityShikigami.config import SwitchSoulConfig, GeneralBattleConfig, ActivityShikigami
+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
+import tasks.Component.GeneralBattle.config_general_battle
+import tasks.ActivityShikigami.page as game
+from tasks.BudokaiTournament.config import BudokaiTournament
+from tasks.BudokaiTournament.assets import BudokaiTournamentAssets
+
+
+
+
+class LimitTimeOut(Exception):
+    pass
+
+
+class LimitCountOut(Exception):
+    pass
+
+
+class StateMachine(BaseTask):
+    run_idx: int = 0  # 当前爬塔类型
+    _count_map = None
+
+    @cached_property
+    def conf(self) -> BudokaiTournament:
+        return self.config.model.budokai_tournament
+
+    @property
+    def climb_type(self) -> str:
+        if self.run_idx >= len(self.conf.run_sequence()):
+            return self.conf.run_sequence()[-1]
+        return self.conf.run_sequence()[self.run_idx]
+
+    @property
+    def count_map(self) -> dict[str, int]:
+        """
+        :return: key: climb type, value: run count
+        """
+        if not getattr(self, "_count_map", None):
+            self._count_map = {climb_type: 0 for climb_type in self.conf.run_sequence()}
+        return self._count_map
+
+    # ----------------------------------------------------
+    def put_status(self):
+        """
+        更新全局状态
+        """
+        def get_count(self) -> int:
+            return self.count_map[self.climb_type]
+
+        def get_limit(self) -> int:
+            limit = getattr(self.conf.daily_training, f'limit_{self.climb_type}', 0)
+            return 0 if not limit else limit
+
+        # # 超过运行时间
+        # if self.limit_time is not None and datetime.now() - self.start_time >= self.limit_time:
+        #     logger.info(f"Climb type {self.climb_type} time out")
+        #     raise LimitTimeOut
+        # 次数达到限制
+        if get_count(self) >= get_limit(self):
+            logger.info(f"Climb type {self.climb_type} count limit reached")
+            raise LimitCountOut
+
+    def switch_next(self):
+        """
+        切换下一种爬塔类型
+        :return: True 切换成功 or False
+        """
+        self.run_idx += 1
+        if self.run_idx >= len(self.conf.run_sequence()):
+            logger.info('All climbing activities have been completed')
+            return False
+        # 切换爬塔类型了, 恢复所有状态
+        self.current_count = 0
+        logger.hr(f'Climb switch to {self.climb_type}', 2)
+        return True
+
+
+class Foot(StateMachine, GameUi, BaseActivity, SwitchSoul, ActivityShikigamiAssets, BudokaiTournamentAssets):
+
+    def lock_team(self, battle_conf: GeneralBattleConfig):
+        """
+        根据配置判断当前爬塔类型是否锁定阵容, 并执行锁定或解锁
+        """
+        enable_preset = getattr(battle_conf, f"enable_preset_{self.climb_type}", False)
+        if not enable_preset:
+            logger.info(f'Lock {self.climb_type} team')
+            self.ui_click(self.I_UNLOCK, stop=self.I_LOCK, interval=1.5)
+            return
+        logger.info(f'Unlock {self.climb_type} team')
+        self.ui_click(self.I_LOCK, stop=self.I_UNLOCK, interval=1.5)
+
+    def start_battle(self):
+        click_times, max_times = 0, random.randint(4, 8)
+        while 1:
+            self.screenshot()
+            if self.is_in_battle(False):
+                break
+            if click_times >= max_times:
+                logger.warning(f'Climb {self.climb_type} cannot enter, maybe already end, try next')
+                return False
+            if (self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1) or
+                    self.appear_then_click(self.I_UI_CONFIRM, interval=1) ):
+                continue
+            if self.ocr_appear_click(self.O_FIRE, interval=2) or self.appear_then_click(self.I_IMG3, interval=2)or self.appear_then_click(self.I_IMG4, interval=2):
+                click_times += 1
+                logger.info(f'Try click fire, remain times[{max_times - click_times}]')
+                continue
+        # 运行战斗
+        return self.run_general_battle(config=self.get_general_battle_conf())
+
+    def battle_wait(self, random_click_swipt_enable: bool) -> bool:
+        func = getattr(self, f'battle_wait_daily_training', self.battle_wait_daily_training)
+        return func(random_click_swipt_enable)
+
+    def battle_wait_daily_training(self, random_click_swipt_enable: bool):
+        self.C_REWARD_1.name, self.C_REWARD_2.name, self.C_REWARD_3.name = 'C_REWARD', 'C_REWARD', 'C_REWARD'
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        self.device.click_record_clear()
+        logger.info(f"Start {self.climb_type} battle process")
+        if self.climb_type ==  'daily_training':
+            self.count_map[self.climb_type] = self.current_count
+            super_long_timer = None
+        else:
+            super_long_timer = Timer(270).start()
+            super_long_cnt = 0
+
+        while 1:
+            self.screenshot()
+
+            # 出现赢的鼓,点击直到消失
+            if self.appear_then_click(self.I_WIN, interval=1.8):
+                self.ui_click_until_disappear(self.I_DE_WIN, interval=1.5)
+                return True
+            if self.appear(self.I_FALSE, threshold=0.8):
+                logger.warning('False battle')
+                self.ui_click_until_disappear(self.I_FALSE)
+                return False
+            if self.ui_reward_appear_click():
+                continue
+            if super_long_timer and super_long_timer.reached_and_reset():
+                if super_long_cnt >= 3:
+                    raise GameStuckError
+                self.click(self.C_RANDOM_CLICK, interval=10)
+                self.device.stuck_record_add('BATTLE_STATUS_S')
+                logger.info(f"Start click in battle process for 270s")
+                super_long_cnt += 1
+            # 随机滑动
+            if random_click_swipt_enable:
+                self.random_click_swipt()
+        return False
+
+    def battle_wait_cultivation_drills(self, random_click_swipt_enable: bool):
+        self.C_REWARD_1.name, self.C_REWARD_2.name, self.C_REWARD_3.name = 'C_REWARD', 'C_REWARD', 'C_REWARD'
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        self.device.click_record_clear()
+        logger.info(f"Start {self.climb_type} battle process")
+        while 1:
+            self.screenshot()
+
+
+    def get_general_battle_conf(self) -> tasks.Component.GeneralBattle.config_general_battle.GeneralBattleConfig:
+        from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig as gbc
+        # self.conf.validate_switch_preset()
+        enable_preset = getattr(self.conf.general_battle, f'enable_preset_{self.climb_type}', False)
+        group, team = getattr(self.conf.switch_soul_config, f'group_team_{self.climb_type}').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(self.conf.general_battle, f'enable_green_{self.climb_type}', False),
+                   green_mark=getattr(self.conf.general_battle, f'green_mark_{self.climb_type}'),
+                   random_click_swipt_enable=getattr(self.conf.general_battle,
+                                                     f'enable_anti_detect_{self.climb_type}',
+                                                     False), )
+
+    def random_reward_click(self, exclude_click: list = None, click_now: bool = True) -> RuleClick:
+        """
+        随机点击
+        :param exclude_click: 排除的点击位置
+        :param click_now: 是否立即点击
+        :return: 随机的点击位置
+        """
+        options = [self.C_RANDOM_LEFT, self.C_RANDOM_RIGHT, self.C_RANDOM_TOP, self.C_RANDOM_BOTTOM]
+        if exclude_click:
+            options = [option for option in options if option not in exclude_click]
+        target = random.choice(options)
+        if click_now:
+            self.click(target, interval=1.8)
+        return target
+
+    def switch_soul(self, enter_button: RuleImage, cur_img: RuleImage):
+        conf = self.conf.switch_soul_config
+        enable_switch = getattr(conf, f"enable_switch_{self.climb_type}", False)
+        enable_by_name = getattr(conf, f"enable_switch_by_name_{self.climb_type}", False)
+        if not enable_switch and not enable_by_name:
+            return
+        logger.hr('Start switch soul', 2)
+        # conf.validate_switch_soul()
+        self.ui_click(enter_button, stop=self.I_CHECK_RECORDS, interval=1)
+        if enable_by_name:
+            group, team = getattr(conf, f"group_team_name_{self.climb_type}").split(",")
+            self.run_switch_soul_by_name(group, team)
+        elif enable_switch:
+            group_team = getattr(conf, f"group_team_{self.climb_type}")
+            self.run_switch_soul(group_team)
+        self.ui_click(self.I_UI_BACK_YELLOW, stop=cur_img, interval=1)
+
+class ScriptTask(Foot):
+
+    def run(self) -> None:
+        # self.limit_time: timedelta = self.conf.general_climb.limit_time_v
+        #
+        for climb_type in self.conf.run_sequence():
+            # 进入到活动的主页面,不是具体的战斗页面
+            self.ui_get_current_page()
+            self.ui_goto(game.page_climb_act)
+            try:
+                if getattr(self.conf.daily_training, f'limit_{self.climb_type}') > 0:
+                    method_func = getattr(self, f'_run_{climb_type}')
+                    method_func()
+            except LimitCountOut as e:
+                self.ui_click(self.I_UI_BACK_YELLOW, stop=self.I_TO_BATTLE_MAIN, interval=1)
+            except LimitTimeOut as e:
+                break
+            finally:
+                # 切换下一个爬塔类型
+                self.switch_next()
+
+        # 返回庭院
+        logger.hr("Exit BudokaiTournament", 2)
+        self.ui_get_current_page(False)
+        self.ui_goto(game.page_main)
+        if self.conf.daily_training.active_souls_clean:
+            self.set_next_run(task='SoulsTidy', success=False, finish=False, target=datetime.now())
+        self.set_next_run(task="BudokaiTournament", success=True)
+        raise TaskEnd
+
+    def _run_daily_training(self):
+        """
+            更新前请先看 ./README.md
+        """
+        logger.hr(f'Start run climb type PASS', 1)
+        self.ui_clicks([self.I_TO_BATTLE_MAIN, self.I_TO_BATTLE_MAIN_2],
+                       stop=self.I_CHECK_BATTLE_MAIN, interval=1)
+        self.switch_soul(self.I_BATTLE_MAIN_TO_RECORDS, self.I_CHECK_BATTLE_MAIN)
+
+        ocr_limit_timer = Timer(1).start()
+        click_limit_timer = Timer(4).start()
+        while 1:
+            self.screenshot()
+            self.put_status()
+            # --------------------------------------------------------------
+            if (self.appear_then_click(self.I_UI_CONFIRM, interval=0.5)
+                    or self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=0.5)):
+                continue
+            if self.ui_reward_appear_click():
+                continue
+            if not ocr_limit_timer.reached():
+                continue
+            ocr_limit_timer.reset()
+            if not self.ocr_appear(self.O_FIRE):
+                continue
+            #  --------------------------------------------------------------
+            self.lock_team(self.conf.general_battle)
+            if not self.check_tickets_enough():
+                logger.warning(f'No tickets left, wait for next time')
+                break
+            if self.conf.daily_training.random_sleep:
+                random_sleep(probability=0.2)
+            if self.start_battle():
+                continue
+
+        self.ui_click(self.I_UI_BACK_YELLOW, stop=self.I_TO_BATTLE_MAIN, interval=1)
+
+    def _run_cultivation_drills(self):
+        """
+        更新前请先看 ./README.md
+        """
+        logger.hr(f'Start run climb type BOSS')
+
+        self.ui_clicks([self.I_TO_BATTLE_BOSS],
+                       stop=self.I_CHECK_BATTLE_BOSS, interval=1)
+
+        cnt_scout = 0  # 保留
+        switch_soul_done = False
+        while 1:
+            self.screenshot()
+            # --------------------------------------------------------------
+            if (self.appear_then_click(self.I_UI_CONFIRM, interval=0.5)
+                    or self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=0.5)):
+                continue
+            if self.ui_reward_appear_click():
+                continue
+            if self.appear_then_click(self.I_IMG2, interval=0.8):
+                continue
+
+            # 搜寻
+            if self.appear(self.I_IMG1):
+                # self.put_status()
+                if cnt_scout >= self.conf.daily_training.limit_cultivation_drills:
+                    raise LimitCountOut
+                if self.ui_click(self.I_IMG1, stop=self.I_IMG3, interval=1.5, timeout=10):
+                    logger.info(f'Cultivation drill done, for next time {cnt_scout}')
+                    cnt_scout += 1
+                    pass
+                continue
+            if not (self.appear(self.I_IMG3) or self.appear(self.I_IMG4)):
+                continue
+            if not switch_soul_done:
+                self.switch_soul(self.I_BATTLE_MAIN_TO_RECORDS, self.I_BATTLE_MAIN_TO_RECORDS)
+                switch_soul_done = True
+                continue
+
+            self.lock_team(self.conf.general_battle)
+            if not self.check_tickets_enough():
+                logger.warning(f'No tickets left, wait for next time')
+                if not self.ui_click(self.C_BOSS_DETAIL_CLOSE, stop=self.I_CHECK_BATTLE_BOSS,
+                                     interval=1, timeout=10):
+                    raise GameStuckError('Unable to close cultivation drills boss detail')
+                break
+            if self.conf.daily_training.random_sleep:
+                random_sleep(probability=0.2)
+            if self.start_battle():
+                continue
+
+        self.ui_click(self.I_UI_BACK_YELLOW, stop=self.I_TO_BATTLE_BOSS, interval=1)
+
+
+
+
+
+
+    def check_tickets_enough(self) -> bool:
+        """
+        判断当前爬塔门票是否足够
+        :return: True 可以运行 or False
+        """
+        logger.hr(f'Check {self.climb_type} tickets')
+        # apper_button = self.O_FIRE if self.climb_type == 'daily_training' else self.I_IMG3
+        if self.climb_type == 'daily_training' and not self.wait_until_appear(self.O_FIRE, wait_time=3):
+            logger.warning(f'Detect fire fail, try reidentify')
+            return False
+        self.screenshot()
+        remain_times = 0
+        if self.climb_type == 'daily_training':
+            remain_times = self.O_REMAIN_AP.ocr_digit(self.device.image)
+        if self.climb_type == 'cultivation_drills':
+            remain_times= self.O_REMAIN_BOSS.ocr_digit(self.device.image)
+        return remain_times > 0
+
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    t = ScriptTask(c, d)
+
+    t.run()
+
+

+ 3 - 0
tasks/RealmRaid/script_task.py

@@ -557,6 +557,9 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RealmRaidAssets):
                          method="Template matching",
                          file="./tasks/RyouToppa/dev/loser_sign_1.png")
 
+    def battle_wait(self, random_click_swipt_enable: bool) -> bool:
+        return self.battle_wait_v2(random_click_swipt_enable=random_click_swipt_enable)
+
 
 if __name__ == "__main__":
     from module.config.config import Config