Skip to content

Commit fea697b

Browse files
authored
fix: 云游戏环境下任务流程稳定性优化(血清进度OCR/委托开始重试/复位传送) (#259)
* fix(autohedge): improve serum progress OCR parsing * fix: 修复进度百分比为0时任务状态未正确更新的问题 将条件判断从 `percentage > 0` 改为 `percentage >= 0`,确保当进度为0时任务状态也能被正确设置为“进行中”。 * refactor(AutoHedge): 移除血清进度解析方法并内联逻辑 将 `_parse_serum_pct` 方法的逻辑直接内联到 `get_serum_process` 方法中,简化代码结构并移除未使用的辅助函数。 * fix: 将重试按钮最大点击次数从3次增加到5次 增加重试按钮的最大点击次数以提高任务在遇到临时网络问题时的稳定性,避免过早放弃重试导致任务失败。 * fix(CommissionsTask): 增加重试按键次数以处理云游戏环境下的不稳定问题 将最大重试按键次数从3次增加到5次,以应对云游戏/浏览器环境下颜色采样不稳定导致的界面卡顿问题。同时调整按键间隔,提高重试机制的可靠性。 * fix: 降低云游戏菜单操作频率以避免卡顿 在云游戏环境中,打开菜单时会出现必然的卡顿。为避免频繁点击导致问题,在点击“其他设置”页签前增加固定延迟,并降低点击操作的频率。 * fix: 优化重试按钮处理逻辑,增加延迟避免过快触发 - 将最大重试次数提取为常量 `max_retry_press_count` 提高可读性 - 检测到重试按钮后增加 1 秒延迟,避免云游戏环境下操作过快 - 简化重试按键操作,合并两次按键为单次按键并延长按键后延迟 - 更新注释中的硬编码数字为常量引用,保持描述一致性 * fix(CommissionsTask): 将重试按键从发送R键改为点击重试按钮区域
1 parent 37637de commit fea697b

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/tasks/AutoHedge.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, *args, **kwargs):
4747
self.roulette_task = None
4848
self.maze_task = None
4949

50+
5051
@property
5152
def config(self):
5253
if self.external_movement == _default_movement or not self._external_config:
@@ -189,7 +190,7 @@ def update_mission_status(self):
189190
if percentage == 100:
190191
self.runtime_state["in_progress"] = False
191192
self.mission_complete = True
192-
elif percentage > 0:
193+
elif percentage >= 0:
193194
self.runtime_state["in_progress"] = True
194195
if not self.runtime_state["in_progress"] and not self.mission_complete:
195196
_track_point = self.find_top_right_track_pos()
@@ -205,18 +206,16 @@ def get_serum_process_info(self):
205206
if self.ocr_future and self.ocr_future.done():
206207
texts = self.ocr_future.result()
207208
self.ocr_future = None
208-
if texts and "%" in texts[0].name:
209-
name = texts[0].name.replace("%", "")
210-
if name.isdigit():
211-
pct = int(name)
209+
if texts and getattr(texts[0], "name", None):
210+
if (m := re.search(r"(\d{1,3})\s*[%%]", texts[0].name)):
211+
pct = int(m.group(1))
212212
if pct > self.last_ocr_result and pct <= 100:
213213
self.last_ocr_result = pct
214-
# self.info_set("进度", f"{pct}%")
215214
return self.last_ocr_result
216215
if self.ocr_future is None:
217-
box = self.box_of_screen_scaled(2560, 1440, 115, 490, 217, 550, name="process_info", hcenter=True)
216+
box = self.box_of_screen_scaled(3840, 2160, 12, 494, width_original=625, height_original=508, name="process_info", hcenter=True)
218217
frame = self.frame.copy()
219-
self.ocr_future = self.thread_pool_executor.submit(self.ocr, frame=frame, box=box, match=re.compile(r"\d+%"))
218+
self.ocr_future = self.thread_pool_executor.submit(self.ocr, frame=frame, box=box, match=re.compile(r"\d{1,3}\s*[%%]"))
220219
return self.last_ocr_result
221220

222221
def find_top_right_track_pos(self):

src/tasks/CommissionsTask.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,48 @@ def start_mission(self, timeout=0):
105105
box = self.box_of_screen_scaled(2560, 1440, 69, 969, 2498, 1331, name="reward_drag_area", hcenter=True)
106106
start_time = time.time()
107107
deadline = start_time + action_timeout
108+
max_retry_press_count = 5
109+
retry_click_box = self.box_of_screen_scaled(
110+
3840,
111+
2160,
112+
2555,
113+
1880,
114+
2555 + 430,
115+
1880 + 47,
116+
name="retry_click_area",
117+
hcenter=True,
118+
)
108119
retry_press_count = 0
109120
retry_seen = False
110121
retry_stall_deadline = None
111122

112123
while time.time() < deadline:
113124
if self.find_retry_btn():
125+
self.sleep(1)
114126
retry_seen = True
115-
if retry_press_count < 3:
127+
if retry_press_count < max_retry_press_count:
116128
retry_press_count += 1
117129
if retry_stall_deadline is None:
118130
retry_stall_deadline = time.time() + 15
119131
deadline = max(deadline, retry_stall_deadline)
120-
self.send_key("r", after_sleep=0.2)
132+
self.click_box_random(
133+
retry_click_box,
134+
down_time=0.02,
135+
after_sleep=0.5,
136+
use_safe_move=True,
137+
safe_move_box=box,
138+
)
121139
elif (btn := self.find_bottom_start_btn() or self.find_big_bottom_start_btn()):
122140
self.click_btn_random(btn, safe_move_box=box, after_sleep=0.2)
123141

124142
if self.wait_until(condition=lambda: self.find_drop_rate_btn() or self.find_letter_interface(), time_out=1):
125143
break
126144

127145
# 云游戏/浏览器环境下颜色采样不稳定:不再依赖按钮颜色判断“不可继续”。
128-
# 仅当检测到 retry_btn 但未进入后续界面时,最多按 3 次 R,并在首按后等待 15 秒仍无变化才判定为“任务无法继续”。
146+
# 仅当检测到 retry_btn 但未进入后续界面时,最多按 max_retry_press_count 次 R,并在首按后等待 15 秒仍无变化才判定为“任务无法继续”。
129147
if (
130148
retry_seen
131-
and retry_press_count >= 3
149+
and retry_press_count >= max_retry_press_count
132150
and retry_stall_deadline is not None
133151
and time.time() >= retry_stall_deadline
134152
):
@@ -525,10 +543,12 @@ def reset_and_transport(self):
525543
setting_box = self.box_of_screen_scaled(2560, 1440, 738, 4, 1123, 79, name="other_section", hcenter=True)
526544
setting_other = self.wait_until(lambda: self.find_one("setting_other", box=setting_box), time_out=10,
527545
raise_if_not_found=True)
546+
# 云游戏局内打开菜单必然卡一下
547+
self.sleep(0.5)
528548
self.wait_until(
529549
condition=lambda: self.calculate_color_percentage(setting_menu_selected_color, setting_other) > 0.24,
530-
# 3) 点击“其他设置”页签(setting_other), 直到该页签呈选中状态(通过颜色占比判断)
531-
post_action=lambda: self.click_box_random(setting_other),
550+
# 3) 点击“其他设置”页签(setting_other), 直到该页签呈选中状态(通过颜色占比判断),点击不要那么频繁
551+
post_action=lambda: self.click_box_random(setting_other, after_sleep=0.5),
532552
time_out=10,
533553
)
534554
self.sleep(0.5)

0 commit comments

Comments
 (0)