Skip to content

Commit de5800a

Browse files
authored
fix: map page recognition with loot badge & add acquisition API (#352)
- Move TAB_PROBES[0] y from 0.0417 to 0.0650 to avoid loot badge overlay - Add GET /api/game/acquisition - OCR recognition of ship/loot counts - Add GET /api/game/context - game context runtime counters - Bump version to 2.0.4
1 parent a30d7a5 commit de5800a

3 files changed

Lines changed: 66 additions & 2 deletions

File tree

autowsgr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""AutoWSGR — 战舰少女R 自动化框架 (v2)"""
22

3-
__version__ = '2.0.4.dev1'
3+
__version__ = '2.0.4'

autowsgr/server/main.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- POST /api/task/stop — 停止任务
66
- GET /api/task/status — 查询状态
77
- POST /api/expedition/check — 检查并收取远征
8+
- GET /api/game/acquisition — OCR 识别今日舰船/战利品获取数量
9+
- GET /api/game/context — 查询游戏运行时计数器
810
- WS /ws/logs — 实时日志流
911
- WS /ws/task — 任务状态更新
1012
@@ -471,6 +473,67 @@ async def expedition_check():
471473
return ApiResponse(success=False, error=str(e))
472474

473475

476+
# ═══════════════════════════════════════════════════════════════════════════════
477+
# 游戏状态查询接口
478+
# ═══════════════════════════════════════════════════════════════════════════════
479+
480+
481+
@app.get('/api/game/acquisition', response_model=ApiResponse)
482+
async def game_acquisition():
483+
"""从出征面板截图 OCR 识别今日舰船 (X/500) 与战利品 (X/50) 获取数量。
484+
485+
仅在空闲时可用 (需要控制画面导航到出征面板)。
486+
"""
487+
try:
488+
ctx = get_context()
489+
except RuntimeError as e:
490+
raise HTTPException(status_code=503, detail=str(e)) from e
491+
492+
if task_manager.is_running:
493+
raise HTTPException(status_code=409, detail='任务执行中,无法查询获取数量')
494+
495+
from autowsgr.ui.map.page import MapPage
496+
497+
def _recognize() -> dict[str, int | None]:
498+
map_page = MapPage(ctx)
499+
counts = map_page.get_acquisition_counts()
500+
return {
501+
'ship_count': counts.ship_count,
502+
'ship_max': counts.ship_max,
503+
'loot_count': counts.loot_count,
504+
'loot_max': counts.loot_max,
505+
}
506+
507+
try:
508+
data = await asyncio.to_thread(_recognize)
509+
return ApiResponse(success=True, data=data, message='获取数量识别完成')
510+
except Exception as e:
511+
_log.opt(exception=True).warning('[API] 获取数量识别失败: {}', e)
512+
return ApiResponse(success=False, error=str(e))
513+
514+
515+
@app.get('/api/game/context', response_model=ApiResponse)
516+
async def game_context_info():
517+
"""返回当前游戏上下文中的运行时计数器和状态。
518+
519+
不需要截图或画面操作,直接读取内存中的计数器。
520+
"""
521+
try:
522+
ctx = get_context()
523+
except RuntimeError as e:
524+
raise HTTPException(status_code=503, detail=str(e)) from e
525+
526+
return ApiResponse(
527+
success=True,
528+
data={
529+
'dropped_ship_count': ctx.dropped_ship_count,
530+
'dropped_loot_count': ctx.dropped_loot_count,
531+
'quick_repair_used': ctx.quick_repair_used,
532+
'current_page': ctx.current_page,
533+
},
534+
)
535+
536+
474537
# ═══════════════════════════════════════════════════════════════════════════════
475538
# WebSocket 接口
476539
# ═══════════════════════════════════════════════════════════════════════════════

autowsgr/ui/tabbed_page.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class TabbedPageType(enum.Enum):
9898
# ═══════════════════════════════════════════════════════════════════════════════
9999

100100
TAB_PROBES: list[tuple[float, float]] = [
101-
(0.1415, 0.0417),
101+
(0.1415, 0.0650),
102102
(0.2727, 0.0486),
103103
(0.4031, 0.0486),
104104
(0.5352, 0.0486),
@@ -107,6 +107,7 @@ class TabbedPageType(enum.Enum):
107107
"""5 个固定标签栏探测点 (相对坐标)。
108108
109109
激活标签处显示蓝色 ≈ (15, 132, 228),其余为深色 (max < 80)。
110+
第 0 号探测点 y 下移至 0.065 以避开 "战利品▲" 徽标遮挡区域。
110111
"""
111112

112113
TAB_BLUE = Color.of(15, 132, 228)

0 commit comments

Comments
 (0)