Răsfoiți Sursa

Merge pull request #966 from runhey/dev

Automated PR 2025.07.24
huangrunheng 1 an în urmă
părinte
comite
9d34111574

+ 24 - 0
server.py

@@ -1,5 +1,29 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 # Copy from https://github.com/LmeSzinc/AzurLaneAutoScript/gui.py
 # Copy from https://github.com/LmeSzinc/AzurLaneAutoScript/gui.py
+
+
+"""
+在任何平台把当前 Python 进程(含子线程、子进程)切到北京时间。
+• Linux/macOS/WSL 及 Win-Py 3.11+ → TZ='Asia/Shanghai' + time.tzset()
+• Win-Py ≤ 3.10            → TZ='CST-8'       + _tzset()(POSIX 语法)
+"""
+import os, sys, time
+
+if hasattr(time, "tzset"):
+    # Unix 全系  /  Windows 3.11+ 走这条
+    os.environ["TZ"] = "Asia/Shanghai"     # IANA 名称,glibc/Apple libc 都认识
+    time.tzset()
+else:
+    # 只有旧 Windows 才会落到这里
+    import ctypes
+    os.environ["TZ"] = "CST-8"             # POSIX 字符串:UTC+8 且无 DST
+    for dll in ("ucrtbase", "msvcrt"):     # 新旧 CRT 都试一遍
+        try:
+            ctypes.CDLL(dll)._tzset()
+            break
+        except (OSError, AttributeError):
+            continue
+        
 import threading
 import threading
 
 
 from module.logger import logger
 from module.logger import logger

+ 7 - 5
tasks/BondlingFairyland/script_task.py

@@ -41,6 +41,7 @@ class BondlingNumberMax(Exception):
 class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul, BondlingFairylandAssets):
 class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul, BondlingFairylandAssets):
     ball_pos_list = [None, None, None, None, None]  # 用于记录每一个位置的球是否出现
     ball_pos_list = [None, None, None, None, None]  # 用于记录每一个位置的球是否出现
     first_catch = True  # 用于记录是否是第一次捕捉
     first_catch = True  # 用于记录是否是第一次捕捉
+    first_win = False  # 用于记录是不是第一次捕获成功
     current_ball_index = 5
     current_ball_index = 5
     def run(self):
     def run(self):
         # 引用配置
         # 引用配置
@@ -273,11 +274,11 @@ class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul,
 
 
         success = True
         success = True
         while 1:
         while 1:
-
-            if not self.in_search_ui(screenshot=True):
-                self.ui_get_current_page()
-                self.ui_goto(page_bondling_fairyland)
-                continue
+            if not self.first_win:
+                if not self.in_search_ui(screenshot=True):
+                    self.ui_get_current_page()
+                    self.ui_goto(page_bondling_fairyland)
+                    continue
 
 
             if bondling_config.bondling_mode != BondlingMode.MODE1:
             if bondling_config.bondling_mode != BondlingMode.MODE1:
                 if self.ball_click(self.current_ball_index):
                 if self.ball_click(self.current_ball_index):
@@ -299,6 +300,7 @@ class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul,
                     # 执行捕捉
                     # 执行捕捉
                     if self.run_catch(bondling_config, bondling_switch_soul, battle_config):
                     if self.run_catch(bondling_config, bondling_switch_soul, battle_config):
                         logger.info(f'Catch successful and current ball number: {self.current_ball_index} ')
                         logger.info(f'Catch successful and current ball number: {self.current_ball_index} ')
+                        self.first_win = True
                     else:
                     else:
                         break
                         break
                 except BondlingNumberMax:
                 except BondlingNumberMax:

+ 9 - 2
tasks/Component/ReplaceShikigami/replace_shikigami.py

@@ -8,8 +8,8 @@ from module.logger import logger
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.Component.ReplaceShikigami.assets import ReplaceShikigamiAssets
 from tasks.Component.ReplaceShikigami.assets import ReplaceShikigamiAssets
-
-
+import time
+from module.exception import GameStuckError
 class ReplaceShikigami(BaseTask, ReplaceShikigamiAssets):
 class ReplaceShikigami(BaseTask, ReplaceShikigamiAssets):
 
 
 
 
@@ -85,7 +85,14 @@ class ReplaceShikigami(BaseTask, ReplaceShikigamiAssets):
                         6: self.C_SHIKIGAMI_LEFT_6,
                         6: self.C_SHIKIGAMI_LEFT_6,
                         7: self.C_SHIKIGAMI_LEFT_7}
                         7: self.C_SHIKIGAMI_LEFT_7}
         click_match = _click_match[shikigami_order]
         click_match = _click_match[shikigami_order]
+        TIMEOUT_SEC = 120          # 超时时长(秒)
+        start_time = time.time()   # 记录起始时间
         while 1:
         while 1:
+            # ——1. 先做超时检查——
+            if time.time() - start_time > TIMEOUT_SEC:
+                logger.error('寄养等待超过 2 分钟,自动退出')
+                raise GameStuckError('寄养超时(>120 s)')
+            
             self.screenshot()
             self.screenshot()
 
 
             if not self.appear(stop_image):
             if not self.appear(stop_image):

+ 1 - 1
tasks/DailyTrifles/assets.py

@@ -37,7 +37,7 @@ class DailyTriflesAssets:
 	# 免费一抽领黑蛋 
 	# 免费一抽领黑蛋 
 	I_GIFT_SIGN = RuleImage(roi_front=(629,192,129,149), roi_back=(130,129,891,473), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_gift_sign.png")
 	I_GIFT_SIGN = RuleImage(roi_front=(629,192,129,149), roi_back=(130,129,891,473), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_gift_sign.png")
 	# 体力 
 	# 体力 
-	I_SPECIAL_SUSHI = RuleImage(roi_front=(180,130,800,460), roi_back=(180,130,800,460), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_special_sushi.png")
+	I_SPECIAL_SUSHI = RuleImage(roi_front=(180,130,800,460), roi_back=(180,130,800,460), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_sushi.png")
 	# 购买时货币类型为勾玉 
 	# 购买时货币类型为勾玉 
 	I_STORE_COST_TYPE_JADE = RuleImage(roi_front=(600,490,50,60), roi_back=(600,490,50,60), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_cost_type_jade.png")
 	I_STORE_COST_TYPE_JADE = RuleImage(roi_front=(600,490,50,60), roi_back=(600,490,50,60), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_cost_type_jade.png")
 
 

+ 1 - 1
tasks/DailyTrifles/store/image.json

@@ -28,7 +28,7 @@
   },
   },
   {
   {
     "itemName": "special_sushi",
     "itemName": "special_sushi",
-    "imageName": "store_special_sushi.png",
+    "imageName": "store_sushi.png",
     "roiFront": "180,130,800,460",
     "roiFront": "180,130,800,460",
     "roiBack": "180,130,800,460",
     "roiBack": "180,130,800,460",
     "method": "Template matching",
     "method": "Template matching",

+ 1 - 2
tasks/Duel/script_task.py

@@ -155,8 +155,7 @@ class ScriptTask(GameUi, GeneralBattle, DuelAssets):
                 break
                 break
             if current_score <= 1800 and self.appear(self.I_D_PREPARE):
             if current_score <= 1800 and self.appear(self.I_D_PREPARE):
                 # 低段位有的准备
                 # 低段位有的准备
-                self.ui_click(self.I_D_PREPARE, self.I_D_PREPARE_DONE)
-                self.wait_until_disappear(self.I_D_PREPARE_DONE)
+                self.ui_click_until_disappear(self.I_D_PREPARE)
                 logger.info('Duel prepare')
                 logger.info('Duel prepare')
                 break
                 break
         # 正式进入战斗
         # 正式进入战斗

+ 7 - 1
tasks/Exploration/base.py

@@ -22,7 +22,7 @@ from tasks.Utils.config_enum import ShikigamiClass
 
 
 from module.logger import logger
 from module.logger import logger
 from module.base.timer import Timer
 from module.base.timer import Timer
-from module.exception import RequestHumanTakeover, TaskEnd
+from module.exception import RequestHumanTakeover, TaskEnd, GameStuckError
 from module.atom.image_grid import ImageGrid
 from module.atom.image_grid import ImageGrid
 from module.atom.animate import RuleAnimate
 from module.atom.animate import RuleAnimate
 from module.base.utils import load_image
 from module.base.utils import load_image
@@ -151,8 +151,14 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
             self.device.click_record_clear()
             self.device.click_record_clear()
             self.swipe(self.S_SWIPE_LEVEL_UP)
             self.swipe(self.S_SWIPE_LEVEL_UP)
             swipeCount += 1
             swipeCount += 1
+            debug_info = f"Swiped {swipeCount} times, current exploration level: {text1}"
+            logger.info(debug_info)
             if swipeCount >= 25:
             if swipeCount >= 25:
+                raise GameStuckError(
+                    f"Swiped too many times ({swipeCount}), seems stuck in exploration level selection"
+                )
                 return False
                 return False
+            time.sleep(1)
 
 
         # 选中对应章节
         # 选中对应章节
         while 1:
         while 1:

+ 4 - 1
tasks/Hyakkiyakou/utils/exp_test.py

@@ -23,7 +23,7 @@ from tasks.Exploration.config import ExplorationLevel
 
 
 from utils import usage_time
 from utils import usage_time
 from fast_device import FastDevice
 from fast_device import FastDevice
-
+from module.exception import GameStuckError
 
 
 class Step:
 class Step:
     def __init__(self,
     def __init__(self,
@@ -342,6 +342,9 @@ class ExpTest(RightActivity, FastDevice, RestartAssets, ExplorationAssets):
             self.swipe(self.S_SWIPE_LEVEL_UP)
             self.swipe(self.S_SWIPE_LEVEL_UP)
             swipeCount += 1
             swipeCount += 1
             if swipeCount >= 25:
             if swipeCount >= 25:
+                raise GameStuckError(
+                    f"Swiped too many times ({swipeCount}), seems stuck in exploration level selection"
+                )
                 return False
                 return False
         self.config.model.script.device.control_method = ControlMethod.WINDOW_MESSAGE
         self.config.model.script.device.control_method = ControlMethod.WINDOW_MESSAGE
 
 

+ 7 - 1
tasks/KekkaiUtilize/script_task.py

@@ -8,7 +8,7 @@ from datetime import timedelta, datetime
 from module.base.timer import Timer
 from module.base.timer import Timer
 from module.atom.image_grid import ImageGrid
 from module.atom.image_grid import ImageGrid
 from module.logger import logger
 from module.logger import logger
-from module.exception import TaskEnd
+from module.exception import TaskEnd,GameStuckError
 
 
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.Utils.config_enum import ShikigamiClass
@@ -461,7 +461,13 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             # 可能是滑动的时候出错
             # 可能是滑动的时候出错
             logger.warning('The best reason is that the swipe is wrong')
             logger.warning('The best reason is that the swipe is wrong')
             return False
             return False
+        TIMEOUT_SEC = 120          # 超时时长(秒)
+        start_time = time.time()   # 记录起始时间
         while 1:
         while 1:
+            # ——1. 先做超时检查——
+            if time.time() - start_time > TIMEOUT_SEC:
+                logger.error('寄养等待超过 2 分钟,自动退出')
+                raise GameStuckError('寄养超时(>120 s)')
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_CHECK_FRIEND_REALM_1):
             if self.appear(self.I_CHECK_FRIEND_REALM_1):
                 self.wait_until_stable(self.I_CHECK_FRIEND_REALM_1)
                 self.wait_until_stable(self.I_CHECK_FRIEND_REALM_1)

+ 12 - 5
tasks/Restart/login.py

@@ -7,7 +7,7 @@ from module.exception import RequestHumanTakeover, GameTooManyClickError, GameSt
 from module.logger import logger
 from module.logger import logger
 from tasks.Restart.assets import RestartAssets
 from tasks.Restart.assets import RestartAssets
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
-
+import time
 
 
 class LoginHandler(BaseTask, RestartAssets):
 class LoginHandler(BaseTask, RestartAssets):
     character: str
     character: str
@@ -111,12 +111,18 @@ class LoginHandler(BaseTask, RestartAssets):
             if self.appear(self.I_CREATE_ACCOUNT):
             if self.appear(self.I_CREATE_ACCOUNT):
                 logger.warning('Appear create account')
                 logger.warning('Appear create account')
                 raise GameStuckError('Appear create account')
                 raise GameStuckError('Appear create account')
+
+            # 点击“进入游戏”速度过快会进入区服设置,同时需在检测I_LOGIN_8之前检测,因为新服图标会让I_LOGIN_8向右偏移导致永远无法检测成功
+            # 同时修复了点击位置(之前是点击I_CHARACTARS而不是左边的区域)
+            if self.appear(self.I_CHARACTARS, interval=1):
+                logger.info('误入区服设置')
+                # https://github.com/runhey/OnmyojiAutoScript/issues/585
+                self.device.click(x=106, y=535)
+                
             # 点击’进入游戏‘
             # 点击’进入游戏‘
             if not self.appear(self.I_LOGIN_8):
             if not self.appear(self.I_LOGIN_8):
                 continue
                 continue
-            if self.appear(self.I_CHARACTARS, interval=1):
-                # https://github.com/runhey/OnmyojiAutoScript/issues/585
-                self.device.click(x=246, y=535)
+            
             # 登录体验服时,点击“进入游戏”速度过快,可能会出现体验服的弹窗
             # 登录体验服时,点击“进入游戏”速度过快,可能会出现体验服的弹窗
             if self.appear(self.I_EARLY_SERVER):
             if self.appear(self.I_EARLY_SERVER):
                 if self.appear_then_click(self.I_EARLY_SERVER_CANCEL):
                 if self.appear_then_click(self.I_EARLY_SERVER_CANCEL):
@@ -254,7 +260,8 @@ class LoginHandler(BaseTask, RestartAssets):
                     self.wait_until_appear(self.I_HARVEST_MAIL_CONFIRM, wait_time=1)
                     self.wait_until_appear(self.I_HARVEST_MAIL_CONFIRM, wait_time=1)
                     timer_harvest.reset()
                     timer_harvest.reset()
                     continue
                     continue
-                if self.appear(self.I_HARVEST_MAIL_OPEN, threshold=0.9):
+                #threshold如果是0.9,可能会导致有邮件但无法识别永久卡住
+                if self.appear(self.I_HARVEST_MAIL_OPEN, threshold=0.8):
                     self.click(self.I_HARVEST_MAIL_OPEN, interval=0.8)
                     self.click(self.I_HARVEST_MAIL_OPEN, interval=0.8)
                     timer_harvest.reset()
                     timer_harvest.reset()
                     continue
                     continue

+ 1 - 1
tasks/RichMan/mall/special.py

@@ -161,7 +161,7 @@ class Special(Buy, MallNavbar):
         result = result.replace('?', '2').replace('?', '2').replace(':', ';').replace('火', '次').replace('教', '数')
         result = result.replace('?', '2').replace('?', '2').replace(':', ';').replace('火', '次').replace('教', '数')
         try:
         try:
             if ':' in result:
             if ':' in result:
-                result = re.findall(r'余购买次数:(\d+)', result)[0]
+                result = re.findall(r'(?:剩余)?购买次数:(\d+)', result)[0]
                 result = int(result)
                 result = int(result)
             else:
             else:
                 result = re.findall(r'本周剩余数量(\d+)', result)[0]
                 result = re.findall(r'本周剩余数量(\d+)', result)[0]