持续化刷取: 修复 TEAMS 界面判定与狂气读取重试

Browse Source
为"反复刷镜牢+经验、不消费狂气"的持续运行做的两处加固:

1. on_teams_screen() 判定漏判 (scripts/auto_cycle.py)
   实测 OCR 把 "SIN COST" 输出成 "SINICOST"(无空格), 而判定写死了带空格的
   'SIN COST', 于是 ensure_team1() 以为不在 TEAMS 页, 去点 Sinners 按钮空转,
   每轮都报 "未能确认选中 TEAMS #1"。改为去空格后再比, 并同时接受
   ALLIDENTITIES / ALLE.G.O 等 OCR 变体。

2. read_lunacy() 增加重试 (scripts/auto_cycle.py)
   狂气校验是"不许消费"的唯一防线, 但 OCR 偶尔漏掉 LUNACY 标签, 旧代码直接
   返回 None 并静默放行("读不到狂气余额, 跳过校验") —— 等于没校验。
   改为重试 2 次(每次间隔 2 秒)。

3. 计划任务支持持续刷取 (scripts/install_unattended.ps1)
   新增 -EveryHours N: 每 N 小时重复一轮, 而不是每天一次。
   顺带修掉两处过时注释("每 5 分钟" -> 1 分钟, 实际早已是 1 分钟)。

4. 补 BOM (scripts/install_unattended.ps1, install_logon_task.ps1)
   Windows PowerShell 5.1 对无 BOM 的 UTF-8 按 GBK 解析, 中文串会乱码报错
   (10-04 坑 6)。keep_display.ps1 本来就有, 这两个安装脚本漏了。
   注意: 改动 install_unattended.ps1 会让文件 LF 变 CRLF, 属正常。

新增测试 6 个(on_teams_screen 4 个 + read_lunacy 2 个), 全套 213/213 通过。
This commit is contained in:
Codex Agent
2026-10-13 15:40:46 +08:00
parent 1031aca7de
commit 27a2eb9a1b
4 changed files with 108 additions and 25 deletions
+34 -18
View File
@@ -75,7 +75,15 @@ def goto_identities():
def on_teams_screen(txt): def on_teams_screen(txt):
return ('SIN COST' in txt) or ('All Idensities' in txt) or ('All E.6.0' in txt) """TEAMS 界面的判定。
实测 OCR 会把 "SIN COST" 输出成 "SINICOST"(无空格), 直接匹配 'SIN COST'
会漏判 —— 于是 ensure_team1() 以为不在 TEAMS 页, 去点 Sinners 按钮空转,
最后报 "未能确认选中 TEAMS #1"。所以先去空格再比。
"""
t = txt.replace(' ', '').upper()
return ('SINCOST' in t or 'SINICOST' in t
or 'ALLIDENTITIES' in t or 'ALLE.G.0' in t or 'ALLE.G.O' in t)
def on_grid(txt): def on_grid(txt):
@@ -164,24 +172,32 @@ def report_grid():
return out.strip() return out.strip()
def read_lunacy(): def read_lunacy(retries=2, pause=2.0):
"""从主界面读狂气余额(LUNACY 标签右下方的数字)。读不到返回 None。""" """从当前画面读狂气余额(LUNACY 标签右下方的数字)。读不到返回 None。
its = items()
lab = None OCR 偶尔会漏掉 LUNACY 这个标签(实测同一画面一次抓到、一次没抓到), 而狂气
for it in its: 校验是"不许消费"的唯一防线 —— 静默跳过等于没校验, 所以这里重试几次。
if 'LUNACY' in it.get('text', '').upper(): """
lab = it
break
if not lab:
return None
best = None best = None
for it in its: for attempt in range(retries + 1):
t = it.get('text', '').strip() its = items()
if t.isdigit() and len(t) >= 3: lab = None
dy = it.get('y', 0) - lab.get('y', 0) for it in its:
dx = abs(it.get('x', 0) - lab.get('x', 0)) if 'LUNACY' in it.get('text', '').upper():
if 0 < dy < 70 and dx < 130: lab = it
best = int(t) break
if lab:
for it in its:
t = it.get('text', '').strip()
if t.isdigit() and len(t) >= 3:
dy = it.get('y', 0) - lab.get('y', 0)
dx = abs(it.get('x', 0) - lab.get('x', 0))
if 0 < dy < 70 and dx < 130:
best = int(t)
if best is not None:
return best
if attempt < retries:
time.sleep(pause)
return best return best
+1 -1
View File
@@ -1,4 +1,4 @@
# 注册登录时启动的 lc-mcp 常驻服务 (交互会话, 能看到游戏窗口)。 # 注册登录时启动的 lc-mcp 常驻服务 (交互会话, 能看到游戏窗口)。
# 用法 (在要跑游戏的那个账号下, 普通 PowerShell 即可): # 用法 (在要跑游戏的那个账号下, 普通 PowerShell 即可):
# powershell -ExecutionPolicy Bypass -File scripts\install_logon_task.ps1 # powershell -ExecutionPolicy Bypass -File scripts\install_logon_task.ps1
# 可选: -Python <python.exe 路径> 默认用 vendor\aalc\.venv (uv sync 生成) # 可选: -Python <python.exe 路径> 默认用 vendor\aalc\.venv (uv sync 生成)
+21 -6
View File
@@ -1,10 +1,11 @@
# 注册无人值守用的两个计划任务 (在跑游戏的那个账号下, 普通 PowerShell 即可): # 注册无人值守用的两个计划任务 (在跑游戏的那个账号下, 普通 PowerShell 即可):
# LcMCPKeepDisplay 每 5 分钟跑 keep_display.ps1: 会话掉到 Disc 时重挂 console, 防止截图全黑 # LcMCPKeepDisplay 每 1 分钟跑 keep_display.ps1: 会话掉到 Disc 时重挂 console, 防止截图全黑
# LcMCPDailyCycle 每天定时跑 auto_cycle.py: 刷材料 -> 镜牢 -> 升级/同步, 报告写到 ~\lc_mcp\cycles # LcMCPDailyCycle 定时跑 auto_cycle.py: 刷材料 -> 镜牢 -> 升级/同步, 报告写到 ~\lc_mcp\cycles
# #
# 用法: # 用法:
# powershell -ExecutionPolicy Bypass -File scripts\install_unattended.ps1 # powershell -ExecutionPolicy Bypass -File scripts\install_unattended.ps1
# 可选: -At 05:30 每日运行时间。游戏每日重置为 06:00 (KST), 即北京时间 05:00 # 可选: -At 05:30 每日运行时间。游戏每日重置为 06:00 (KST), 即北京时间 05:00
# -EveryHours 2 改成"每 N 小时重复一轮"以持续刷取; 0 = 只按 -At 每天一次
# -Mirror 1 每轮镜牢局数, 0 = 不打镜牢 # -Mirror 1 每轮镜牢局数, 0 = 不打镜牢
# -Target 34 把队内人格升到的等级 # -Target 34 把队内人格升到的等级
# -Python <路径> 默认 vendor\aalc\.venv\Scripts\pythonw.exe (无窗口, 不抢游戏焦点) # -Python <路径> 默认 vendor\aalc\.venv\Scripts\pythonw.exe (无窗口, 不抢游戏焦点)
@@ -15,6 +16,7 @@
# 先手动跑一轮确认无误再装: python scripts\auto_cycle.py --mirror 1 # 先手动跑一轮确认无误再装: python scripts\auto_cycle.py --mirror 1
param( param(
[string]$At = "05:30", [string]$At = "05:30",
[int]$EveryHours = 0,
[int]$Mirror = 1, [int]$Mirror = 1,
[int]$Target = 34, [int]$Target = 34,
[string]$Python = "", [string]$Python = "",
@@ -57,18 +59,31 @@ if (-not $NoWatchdog) {
-ExecutionTimeLimit (New-TimeSpan -Minutes 3) -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 3) -MultipleInstances IgnoreNew
Register-ScheduledTask -TaskName $Watchdog -Action $action -Trigger $trigger -Principal $principal ` Register-ScheduledTask -TaskName $Watchdog -Action $action -Trigger $trigger -Principal $principal `
-Settings $settings -Force | Out-Null -Settings $settings -Force | Out-Null
Write-Output "registered $Watchdog (every 5 min) -> $script" Write-Output "registered $Watchdog (every 1 min) -> $script"
} }
$cycle = Join-Path $PSScriptRoot "auto_cycle.py" $cycle = Join-Path $PSScriptRoot "auto_cycle.py"
$action = New-ScheduledTaskAction -Execute $Python -WorkingDirectory $Repo ` $action = New-ScheduledTaskAction -Execute $Python -WorkingDirectory $Repo `
-Argument "-X utf8 `"$cycle`" --mirror $Mirror --target $Target" -Argument "-X utf8 `"$cycle`" --mirror $Mirror --target $Target"
$trigger = New-ScheduledTaskTrigger -Daily -At $At
# 一轮 daily 约 20 分钟, 每局镜牢约 40 分钟; 超过上限由计划任务强杀 # 一轮 daily 约 20 分钟, 每局镜牢约 40 分钟; 超过上限由计划任务强杀
$limit = New-TimeSpan -Minutes (60 + 75 * [Math]::Max($Mirror, 0)) $limit = New-TimeSpan -Minutes (60 + 75 * [Math]::Max($Mirror, 0))
if ($EveryHours -gt 0) {
# 持续刷取: 每 N 小时重复一轮。开始时间取"现在", 装完即进入节奏。
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) `
-RepetitionInterval (New-TimeSpan -Hours $EveryHours) `
-RepetitionDuration (New-TimeSpan -Days 3650)
$desc = "every $EveryHours h"
# 重复周期必须大于单轮上限, 否则会在上一轮还没结束时又起一轮
if ((New-TimeSpan -Hours $EveryHours) -lt $limit) {
Write-Warning "EveryHours=$EveryHours 短于单轮上限 $limit, 可能重叠; MultipleInstances=IgnoreNew 会跳过, 但建议调大"
}
} else {
$trigger = New-ScheduledTaskTrigger -Daily -At $At
$desc = "daily at $At"
}
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries ` $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
-StartWhenAvailable -ExecutionTimeLimit $limit -MultipleInstances IgnoreNew -StartWhenAvailable -ExecutionTimeLimit $limit -MultipleInstances IgnoreNew
Register-ScheduledTask -TaskName $Daily -Action $action -Trigger $trigger -Principal $principal ` Register-ScheduledTask -TaskName $Daily -Action $action -Trigger $trigger -Principal $principal `
-Settings $settings -Force | Out-Null -Settings $settings -Force | Out-Null
Write-Output "registered $Daily (daily at $At, mirror=$Mirror, target=Lv.$Target, limit=$limit)" Write-Output "registered $Daily ($desc, mirror=$Mirror, target=Lv.$Target, limit=$limit)"
Write-Output "reports -> $env:USERPROFILE\lc_mcp\cycles\cycle_*.json" Write-Output "reports -> $env:USERPROFILE\lc_mcp\cycles\cycle_*.json"