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

feat(theme):新增支持底部卷轴任意主题的功能,通过识别"闲庭"按钮来点击展开卷轴。同时修改探索候补添加逻辑和封魔返回按钮这2个小问题。

lhye 9 месяцев назад
Родитель
Сommit
71fb8efd1a

+ 3 - 2
tasks/Duel/script_task.py

@@ -15,11 +15,10 @@ from module.base.timer import Timer
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_main, page_duel
 from tasks.Duel.config import Duel, Onmyoji
 from tasks.Duel.assets import DuelAssets
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
-from tasks.GameUi.page import page_main, page_team, page_shikigami_records
+from tasks.GameUi.page import page_main, page_duel, page_onmyodo, page_shikigami_records
 import os
 from module.atom.image import RuleImage
 from tasks.GlobalGame.assets import GlobalGameAssets as GGA
@@ -63,6 +62,8 @@ class ScriptTask(GameUi, GeneralBattle, SwitchSoul, DuelAssets):
         self.ui_goto(page_main)
         # 切换阴阳师
         if con.switch_enabled:
+            self.ui_get_current_page()
+            self.ui_goto(page_onmyodo)
             # 清明
             if con.switch_onmyoji == Onmyoji.Qm:
                 self.switch_kagura(con, self.C_QM_ZHAN, self.I_QM_ZHAN)

+ 4 - 1
tasks/Exploration/base.py

@@ -211,11 +211,14 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
             if not self.appear(self.I_E_OPEN_SETTINGS):
                 logger.warning('Opening settings failed due to now in battle')
                 return
+
+        # 先点候补式神区域,再切换稀有度,避免点击失败
+        self.click(self.C_CLICK_STANDBY_TEAM)
+
         choose_rarity = self._config.exploration_config.choose_rarity
         rarity = ShikigamiClass.N if choose_rarity == ChooseRarity.N else ShikigamiClass.MATERIAL
         self.switch_shikigami_class(rarity)
 
-        self.click(self.C_CLICK_STANDBY_TEAM)
         # 移动至未候补的狗粮
         while 1:
             # 慢一点

+ 10 - 10
tasks/GameUi/assets.py

@@ -113,7 +113,7 @@ class GameUiAssets:
 	# 百鬼奕 
 	I_TOWN_GOTO_HYAKKISEN = RuleImage(roi_front=(192,145,48,67), roi_back=(86,130,447,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_town_goto_hyakkisen.png")
 	# description 
-	I_CHECK_DUEL = RuleImage(roi_front=(110,10,64,38), roi_back=(79,1,110,74), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_duel.png")
+	I_CHECK_DUEL = RuleImage(roi_front=(155,20,64,38), roi_back=(140,10,110,74), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_duel.png")
 	# description 
 	I_CHECK_DEMON_ENCOUNTER = RuleImage(roi_front=(26,658,42,43), roi_back=(2,619,100,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_demon_encounter.png")
 	# 检查狩猎战界面 
@@ -138,21 +138,21 @@ class GameUiAssets:
 
 	# Image Rule Assets
 	# 式神录 
-	I_MAIN_GOTO_SHIKIGAMI_RECORDS = RuleImage(roi_front=(1098,611,56,64), roi_back=(1084,589,93,106), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_shikigami_records.png")
+	I_MAIN_GOTO_SHIKIGAMI_RECORDS = RuleImage(roi_front=(1080,590,56,64), roi_back=(1080,590,120,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_shikigami_records.png")
 	# description 
-	I_MAIN_GOTO_ONMYODO = RuleImage(roi_front=(992,614,51,60), roi_back=(992,614,51,60), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_onmyodo.png")
+	I_MAIN_GOTO_ONMYODO = RuleImage(roi_front=(960,590,39,36), roi_back=(960,590,120,100), threshold=0.5, method="Template matching", file="./tasks/GameUi/page/page_main_goto_onmyodo.png")
 	# description 
-	I_MAIN_GOTO_FRIENDS = RuleImage(roi_front=(879,623,55,55), roi_back=(867,606,79,77), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_friends.png")
+	I_MAIN_GOTO_FRIENDS = RuleImage(roi_front=(845,590,55,55), roi_back=(845,590,120,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_friends.png")
 	# 进入花合战 
-	I_MAIN_GOTO_DAILY = RuleImage(roi_front=(779,612,51,67), roi_back=(754,595,89,97), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_daily.png")
+	I_MAIN_GOTO_DAILY = RuleImage(roi_front=(735,590,35,31), roi_back=(735,590,120,100), threshold=0.5, method="Template matching", file="./tasks/GameUi/page/page_main_goto_daily.png")
 	# description 
-	I_MAIN_GOTO_MALL = RuleImage(roi_front=(663,661,41,22), roi_back=(644,613,81,78), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_mall.png")
+	I_MAIN_GOTO_MALL = RuleImage(roi_front=(620,590,33,35), roi_back=(620,590,120,100), threshold=0.5, method="Template matching", file="./tasks/GameUi/page/page_main_goto_mall.png")
 	# description 
-	I_MAIN_GOTO_GUILD = RuleImage(roi_front=(544,611,50,47), roi_back=(520,583,99,105), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_guild.png")
+	I_MAIN_GOTO_GUILD = RuleImage(roi_front=(495,590,50,22), roi_back=(495,590,120,100), threshold=0.5, method="Template matching", file="./tasks/GameUi/page/page_main_goto_guild.png")
 	# description 
-	I_MAIN_GOTO_TEAM = RuleImage(roi_front=(437,625,38,48), roi_back=(366,606,192,83), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_team.png")
+	I_MAIN_GOTO_TEAM = RuleImage(roi_front=(395,590,38,48), roi_back=(395,590,120,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_team.png")
 	# description 
-	I_MAIN_GOTO_COLLECTION = RuleImage(roi_front=(92,621,36,41), roi_back=(51,596,159,85), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_collection.png")
+	I_MAIN_GOTO_COLLECTION = RuleImage(roi_front=(70,590,36,41), roi_back=(70,590,120,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_collection.png")
 	# description 
 	I_CHECK_RECORDS = RuleImage(roi_front=(269,71,55,50), roi_back=(269,71,55,50), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_records.png")
 	# description 
@@ -200,7 +200,7 @@ class GameUiAssets:
 	# 就是一个红叉 
 	I_REALM_RAID_GOTO_EXPLORATION = RuleImage(roi_front=(1192,107,36,43), roi_back=(1192,107,36,43), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_realm_raid_goto_exploration.png")
 	# description 
-	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_MAIN_GOTO_TRAVEL = RuleImage(roi_front=(170,590,64,61), roi_back=(170,590,120,100), 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")
 	# 活动列表页前往活动 

+ 9 - 1
tasks/GameUi/game_ui.py

@@ -316,7 +316,15 @@ class GameUi(BaseTask, GameUiAssets):
         if not page.additional:
             return
         for btn in page.additional:
-            if self.appear_then_operate(btn, interval=interval, skip_first_screenshot=skip_first_screenshot):
+            # 支持复合条件操作: [条件元素, 操作元素]。出现条件图片时点击另一个区域。
+            if isinstance(btn, list) and len(btn) == 2:
+                condition, action = btn
+                self.maybe_screenshot(skip_first_screenshot)
+                if self.appear(condition):
+                    if self.appear_then_operate(action, interval=interval, skip_first_screenshot=False):
+                        logger.info(f'Page {page} additional conditional {condition} -> {action} executed')
+                        skip_first_screenshot = False
+            elif self.appear_then_operate(btn, interval=interval, skip_first_screenshot=skip_first_screenshot):
                 logger.info(f'Page {page} additional {btn} clicked')
                 skip_first_screenshot = False
 

+ 2 - 2
tasks/GameUi/page.py

@@ -53,7 +53,7 @@ page_login = Page(G.I_CHECK_LOGIN_FORM)
 # Main Home 主页
 page_main = Page(G.I_CHECK_MAIN)
 page_main.additional = [G.I_AD_CLOSE_RED, G.I_BACK_FRIENDS, RestartAssets.I_CANCEL_BATTLE,
-                        RestartAssets.I_LOGIN_SCROOLL_CLOSE]
+                        [RestartAssets.I_LOGIN_COURTYARD, RestartAssets.C_LOGIN_SCROOLL_CLOSE_AREA]]
 # 召唤summon
 page_summon = Page(G.I_CHECK_SUMMON)
 page_summon.link(button=G.I_SUMMON_GOTO_MAIN, destination=page_main)
@@ -125,7 +125,7 @@ page_duel.link(button=G.I_BACK_YOLLOW, destination=page_town)
 page_town.link(button=G.I_TOWN_GOTO_DUEL, destination=page_duel)
 # 逢魔之时 demon_encounter
 page_demon_encounter = Page(G.I_CHECK_DEMON_ENCOUNTER)
-page_demon_encounter.link(button=G.I_DEMON_ENCOUNTER_GOTO_TOWN, destination=page_town)
+page_demon_encounter.link(button=G.I_BACK_YOLLOW, destination=page_town)
 page_town.link(button=G.I_TOWN_GOTO_DEMON_ENCOUNTER, destination=page_demon_encounter)
 # 狩猎战 hunt
 page_hunt = Page(G.I_CHECK_HUNT)

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

@@ -2,8 +2,8 @@
   {
     "itemName": "main_goto_shikigami_records",
     "imageName": "page_main_goto_shikigami_records.png",
-    "roiFront": "1098,611,56,64",
-    "roiBack": "1084,589,93,106",
+    "roiFront": "1080,590,56,64",
+    "roiBack": "1080,590,120,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "式神录"
@@ -11,17 +11,17 @@
   {
     "itemName": "main_goto_onmyodo",
     "imageName": "page_main_goto_onmyodo.png",
-    "roiFront": "992,614,51,60",
-    "roiBack": "992,614,51,60",
+    "roiFront": "960,590,39,36",
+    "roiBack": "960,590,120,100",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.5,
     "description": "description"
   },
   {
     "itemName": "main_goto_friends",
     "imageName": "page_main_goto_friends.png",
-    "roiFront": "879,623,55,55",
-    "roiBack": "867,606,79,77",
+    "roiFront": "845,590,55,55",
+    "roiBack": "845,590,120,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"
@@ -29,8 +29,8 @@
   {
     "itemName": "main_goto_daily",
     "imageName": "page_main_goto_daily.png",
-    "roiFront": "779,612,51,67",
-    "roiBack": "754,595,89,97",
+    "roiFront": "735,590,50,32",
+    "roiBack": "735,590,120,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "进入花合战"
@@ -38,17 +38,17 @@
   {
     "itemName": "main_goto_mall",
     "imageName": "page_main_goto_mall.png",
-    "roiFront": "663,661,41,22",
-    "roiBack": "644,613,81,78",
+    "roiFront": "620,590,33,35",
+    "roiBack": "620,590,120,100",
     "method": "Template matching",
-    "threshold": 0.7,
+    "threshold": 0.5,
     "description": "description"
   },
   {
     "itemName": "main_goto_guild",
     "imageName": "page_main_goto_guild.png",
-    "roiFront": "544,611,50,47",
-    "roiBack": "520,583,99,105",
+    "roiFront": "495,590,50,22",
+    "roiBack": "495,590,120,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"
@@ -56,8 +56,8 @@
   {
     "itemName": "main_goto_team",
     "imageName": "page_main_goto_team.png",
-    "roiFront": "437,625,38,48",
-    "roiBack": "366,606,192,83",
+    "roiFront": "395,590,38,48",
+    "roiBack": "395,590,120,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"
@@ -65,8 +65,8 @@
   {
     "itemName": "main_goto_collection",
     "imageName": "page_main_goto_collection.png",
-    "roiFront": "92,621,36,41",
-    "roiBack": "51,596,159,85",
+    "roiFront": "70,590,36,41",
+    "roiBack": "70,590,120,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "description"

+ 2 - 2
tasks/GameUi/page/page_img_supplement.json

@@ -38,8 +38,8 @@
   {
     "itemName": "main_goto_travel",
     "imageName": "page_main_goto_travel.png",
-    "roiFront": "202,619,64,61",
-    "roiBack": "202,619,64,61",
+    "roiFront": "170,590,64,61",
+    "roiBack": "170,590,120,100",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

BIN
tasks/GameUi/page/page_main_goto_daily.png


BIN
tasks/GameUi/page/page_main_goto_guild.png


BIN
tasks/GameUi/page/page_main_goto_mall.png


BIN
tasks/GameUi/page/page_main_goto_onmyodo.png


+ 4 - 0
tasks/Restart/assets.py

@@ -79,6 +79,10 @@ class RestartAssets:
 	I_LOGIN_SCROOLL_OPEN = RuleImage(roi_front=(1208,609,33,83), roi_back=(1208,609,33,83), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_scrooll_open.png")
 	# 庭院卷轴关闭 
 	I_LOGIN_SCROOLL_CLOSE = RuleImage(roi_front=(1181,634,28,39), roi_back=(1162,595,77,112), threshold=0.7, method="Template matching", file="./tasks/Restart/login/login_login_scrooll_close.png")
+	# 闲庭图片(用户新增,用于判断是否需要点击卷轴关闭区域)
+	I_LOGIN_COURTYARD = RuleImage(roi_front=(40,640,100,50), roi_back=(40,640,100,50), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_courtyard.png")
+	# 卷轴关闭区域点击(用户新增,用于点击I_LOGIN_SCROOLL_CLOSE的区域而不依赖图片识别)
+	C_LOGIN_SCROOLL_CLOSE_AREA = RuleClick(roi_front=(1181,634,28,39), roi_back=(1162,595,77,112), name="login_scroll_close_area")
 	# description 
 	I_LOGIN_RED_CLOSE = RuleImage(roi_front=(800,0,480,290), roi_back=(800,0,480,290), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_red_close.png")
 	# description 

+ 19 - 9
tasks/Restart/login.py

@@ -6,10 +6,11 @@ from module.base.timer import Timer
 from module.exception import RequestHumanTakeover, GameTooManyClickError, GameStuckError
 from module.logger import logger
 from tasks.Restart.assets import RestartAssets
+from tasks.GameUi.assets import GameUiAssets
 from tasks.base_task import BaseTask
 import time
 
-class LoginHandler(BaseTask, RestartAssets):
+class LoginHandler(BaseTask, RestartAssets, GameUiAssets):
     character: str
 
     def __init__(self, *wargs, **kwargs):
@@ -42,19 +43,28 @@ class LoginHandler(BaseTask, RestartAssets):
             if self.appear_then_click(self.I_CANCEL_BATTLE, interval=0.8):
                 logger.info('Cancel continue battle')
                 continue
-            # 确认进入庭院
-            if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2, threshold=0.9):
-                logger.info('Open scroll')
-                continue
-            if self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.2):
+            # 确认进入庭院(优化:当出现闲庭图片时,点击卷轴关闭区域,然后判断式神录按钮出现就代表登录成功)
+            if self.appear(self.I_LOGIN_COURTYARD, interval=0.2):
+                if self.click(self.C_LOGIN_SCROOLL_CLOSE_AREA, interval=2):
+                    logger.info('Click scroll close area because courtyard appears')
+                    self.screenshot()  # 点击后立即获取最新截图,确保后续状态检查准确
+                    continue
+            if self.appear(self.I_MAIN_GOTO_SHIKIGAMI_RECORDS, interval=0.2):
                 if confirm_timer.reached():
-                    logger.info('Login to main confirm')
+                    logger.info('Login to main confirm (shikigami records button appears)')
+                    break
+            elif self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.2):
+                if confirm_timer.reached():
+                    logger.info('Login to main confirm (scroll open)')
                     break
             else:
                 confirm_timer.reset()
             # 登录成功
-            if self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.5):
-                logger.info('Login success')
+            if self.appear(self.I_MAIN_GOTO_SHIKIGAMI_RECORDS, interval=0.5):
+                logger.info('Login success: shikigami records button appears')
+                login_success = True
+            elif self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.5):
+                logger.info('Login success: scroll open')
                 login_success = True
 
             # 网络异常

BIN
tasks/Restart/login/login_courtyard.png


+ 2 - 2
tasks/RichMan/mall/navbar/image_bottom.json

@@ -83,8 +83,8 @@
   {
     "itemName": "mall_sundry_check",
     "imageName": "navbar_mall_sundry_check.png",
-    "roiFront": "1093,10,31,44",
-    "roiBack": "1093,10,31,44",
+    "roiFront": "1050,0,31,44",
+    "roiBack": "1050,0,150,100",
     "method": "Template matching",
     "threshold": 0.7,
     "description": "杂货铺"