Skip to content

Commit 5be51ad

Browse files
syokounyapre-commit-ci[bot]kuainx
authored
fix(decisive): 扩展决战1-3章支持并修复Ex-1状态机误判 (#414)
* fix(decisive): extend recognize_stage to chapters 1-3 with manual calibration points * fix(decisive): use ship-icon detection to skip node recognition when no overlay * fix(decisive): use ship-icon absence to correct PREPARE_COMBAT to CHOOSE_FLEET in waiting_for_map * fix(decisive): return to WAITING_FOR_MAP after skill use when fleet not yet chosen * fix(decisive): fix stage clear reward popup acknowledgment position and add extra confirm * fix(decisive): add fallback to return to entry page after stage clear * chore: ignore debug screenshots and temporary debug scripts * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update .gitignore * Update handlers.py 中途进入决战时,舰标也在地图上,不需要智能判定 * Update handlers.py 中途进入节点会卡在这里 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: KUAI <ekuai@foxmail.com>
1 parent c72ed6a commit 5be51ad

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

autowsgr/ops/decisive/handlers.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import time
1818
from typing import TYPE_CHECKING
1919

20+
import cv2
21+
2022
from autowsgr.combat.engine import run_combat
2123
from autowsgr.combat.plan import CombatMode, CombatPlan, NodeDecision
2224
from autowsgr.infra.logger import get_logger
@@ -153,11 +155,20 @@ def _handle_waiting_for_map(self) -> None:
153155
phase == DecisivePhase.PREPARE_COMBAT
154156
and self._state.stage == 1
155157
and not self._has_chosen_fleet
156-
and self._state.node != 'U' # 排除暂离后重进的情况
157158
):
158-
_log.warning('[决战] 首进第 1 小节将 PREPARE_COMBAT 修正为 CHOOSE_FLEET')
159-
self._state.phase = DecisivePhase.CHOOSE_FLEET
160-
return
159+
if self._state.node != 'U':
160+
_log.warning('[决战] 首进第 1 小节将 PREPARE_COMBAT 修正为 CHOOSE_FLEET')
161+
self._state.phase = DecisivePhase.CHOOSE_FLEET
162+
return
163+
# node == 'U' 时,通过舰标检测区分暂离重进与 overlay 延迟加载
164+
bgr = cv2.cvtColor(screen, cv2.COLOR_RGB2BGR)
165+
icon_x = self._map._locate_ship_icon(bgr)
166+
if icon_x is None:
167+
_log.warning(
168+
'[决战] 首进第 1 小节未检测到舰标,将 PREPARE_COMBAT 修正为 CHOOSE_FLEET'
169+
)
170+
self._state.phase = DecisivePhase.CHOOSE_FLEET
171+
return
161172

162173
if phase is not None:
163174
self._state.phase = phase
@@ -280,6 +291,7 @@ def _handle_prepare_combat(self) -> None:
280291

281292
# 先使用技能,再注册舰船,如果是未知节点,也判定一下技能是否使用
282293
current_node = self._state.node
294+
time.sleep(0.5) # 等待动画稳定后截图判定
283295
skill_used = self._map.is_skill_used()
284296
_log.debug('[决战] 节点: {}, 技能已使用检测: {}', current_node, skill_used)
285297

@@ -300,6 +312,14 @@ def _handle_prepare_combat(self) -> None:
300312
else:
301313
_log.debug('[决战] 跳过技能使用: 节点={}, 技能已使用={}', current_node, skill_used)
302314

315+
# 首次进入且尚未选择过舰队时,使用技能后可能出现战备舰队获取 overlay,
316+
# 先切回 WAITING_FOR_MAP 等待 overlay 稳定,避免直接点击编队超时。
317+
if not skill_used not self._has_chosen_fleet:
318+
_log.info('[决战] 首次进入,使用技能后等待 overlay 稳定')
319+
self._wait_deadline = time.monotonic() + 10.0
320+
self._state.phase = DecisivePhase.WAITING_FOR_MAP
321+
return
322+
303323
# ── 恢复模式: 扫描当前舰队与可用舰船 ─────────────────────────
304324
# 对齐 legacy: if fleet.empty() and not is_begin(): _check_fleet()
305325
if self._resume_mode:

autowsgr/ui/decisive/battle_page.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@
107107
"""章节导航最大尝试次数。"""
108108

109109
MAX_CHAPTER: int = 6
110-
MIN_CHAPTER: int = 4
110+
MIN_CHAPTER: int = 1
111111

112112
# ── recognize_stage 检测点 ──
113113

114114
_STAGE_CHECK_POINTS: dict[int, list[tuple[float, float]]] = {
115+
1: [(0.4115, 0.4019), (0.6604, 0.4630), (0.8396, 0.7093)],
116+
2: [(0.4354, 0.3852), (0.5792, 0.6648), (0.8187, 0.5889)],
117+
3: [(0.4219, 0.6648), (0.6531, 0.3944), (0.8042, 0.7444)],
115118
4: [(0.381, 0.436), (0.596, 0.636), (0.778, 0.521)],
116119
5: [(0.418, 0.378), (0.760, 0.477), (0.550, 0.750)],
117120
6: [(0.606, 0.375), (0.532, 0.703), (0.862, 0.644)],

autowsgr/ui/decisive/map_controller.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def confirm_stage_clear(self) -> list[str]:
626626

627627
# 掉落处理结束后,继续等待回到决战入口页,避免奖励弹窗残留导致后续状态识别超时
628628
settle_deadline = time.monotonic() + 12.0
629-
reward_ack_pos = (0.5, 0.5)
629+
reward_ack_pos = (0.953, 0.954)
630630
while time.monotonic() < settle_deadline:
631631
screen = self._ctrl.screenshot()
632632
if ImageChecker.find_any(screen, entry_templates, confidence=0.8) is not None:
@@ -639,6 +639,7 @@ def confirm_stage_clear(self) -> list[str]:
639639
self._ctrl.click(*reward_ack_pos)
640640
time.sleep(0.35)
641641
confirm_operation(self._ctrl, timeout=0.8)
642+
confirm_operation(self._ctrl, timeout=0.8)
642643
continue
643644

644645
if confirm_operation(self._ctrl, timeout=0.8):
@@ -648,6 +649,18 @@ def confirm_stage_clear(self) -> list[str]:
648649
else:
649650
_log.warning('[地图控制器] 小关通关后未能确认已回到决战入口页')
650651

652+
# settle 循环结束后,如果仍未回到入口页,尝试从地图页返回
653+
for _ in range(5):
654+
screen = self._ctrl.screenshot()
655+
if ImageChecker.find_any(screen, entry_templates, confidence=0.8) is not None:
656+
_log.info('[地图控制器] 通过返回按钮回到决战入口页')
657+
break
658+
_log.debug('[地图控制器] 尝试点击返回按钮回到决战入口页')
659+
self._ctrl.click(0.03, 0.06)
660+
time.sleep(1.0)
661+
else:
662+
_log.warning('[地图控制器] 多次尝试后仍未能回到决战入口页')
663+
651664
if collected:
652665
_log.info('[地图控制器] 小关通关共收集 {} 个掉落', len(collected))
653666
return collected

0 commit comments

Comments
 (0)