Fix background MCP input and add mirror dungeon feedback records
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
// Only send a concise game-state description and explicit permitted choices.
|
||||||
|
// Credentials are supplied in memory or OPENCODE_API_KEY, never stored here.
|
||||||
|
export async function decide(state, criteria, options = {}) {
|
||||||
|
const apiKey = options.apiKey ?? process.env.OPENCODE_API_KEY;
|
||||||
|
if (!apiKey) throw new Error('OPENCODE_API_KEY is required');
|
||||||
|
if (typeof state !== 'string' || !state.trim()) throw new Error('State text is required');
|
||||||
|
if (!criteria || Object.keys(criteria).length < 2) throw new Error('At least two choices are required');
|
||||||
|
const started = performance.now();
|
||||||
|
const response = await fetch('https://opencode.ai/zen/v1/systemone', {
|
||||||
|
method: 'POST',
|
||||||
|
redirect: 'error',
|
||||||
|
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
||||||
|
signal: AbortSignal.timeout(options.timeoutMs ?? 7000),
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: options.model ?? 'jev-1.13-free',
|
||||||
|
state,
|
||||||
|
questions: {
|
||||||
|
action: {
|
||||||
|
type: 'choice',
|
||||||
|
instructions: 'Choose the action that respects the stated user rules and completes the Limbus Company Mirror Dungeon fastest. Use only the supplied choices.',
|
||||||
|
criteria,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error(`Jev HTTP ${response.status}`);
|
||||||
|
const body = await response.json();
|
||||||
|
const answer = body.answers?.action;
|
||||||
|
if (answer?.type !== 'choice' || !Object.hasOwn(criteria, answer.choice)) {
|
||||||
|
throw new Error('Jev returned an unsupported choice');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
choice: answer.choice,
|
||||||
|
confidence: answer.confidence,
|
||||||
|
probabilities: answer.probabilities,
|
||||||
|
latencyMs: Math.round(performance.now() - started),
|
||||||
|
model: body.model,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,592 @@
|
|||||||
|
"""Jev chooses every scene/action; lc-mcp performs only validated candidates."""
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from lc_agent import Bridge
|
||||||
|
|
||||||
|
STOP_FILE = Path(r'{source_root}\JEV_STOP')
|
||||||
|
|
||||||
|
SYSTEM_RULES = (
|
||||||
|
'你负责识别固定场景、路线和所有下一步决策。目标是最快完成当前一局镜牢。'
|
||||||
|
'只能选择所给候选;不要反复点击未生效的按钮。战斗选 battle 宏,P+回车,不用空格。'
|
||||||
|
'刚选路线、回车开战或上一动作是战斗时,特写或加载没有OCR文字很正常;选短等或战斗宏,不仅因OCR为空要求分析。'
|
||||||
|
'遇到事件判定先点SKIP跳过对话,跳完后再选择事件选项、罪人或进行判定;剧情同样优先SKIP。'
|
||||||
|
'事件当前有“选择后获得”且无需判定、无需战斗的选项时直接选择它,不反复滚动;避开写着战斗胜利后的选项。'
|
||||||
|
'确定确认/进入/开始战斗直接执行。地图优先可达事件和商店,减少战斗。'
|
||||||
|
'选好路线直接回车进入,关卡编队界面也直接回车开战;保留原编队,不再检查人员。'
|
||||||
|
'保留当前编队。成捆的符咒++和鸡胸为核心,略过额外观测;其他苦难避开敌方体力上限和防御等级。'
|
||||||
|
'3层起辛克莱1换3,黑兽奥提斯2换3,其他出战1换3。只在商店强化饰品。'
|
||||||
|
'商店没有出战角色可替换技能时允许刷新,当前商店最多4次;有可替换角色先按技能表替换。'
|
||||||
|
'第五层优先2号线卡包;卡包刷新次数为零时允许使用卡包观测。层末必须选择苦难再推进,不能当额外观测默认拒绝饰品。'
|
||||||
|
'卡包信息不清先点对应放大镜查看;核心饰品齐全时按通关速度选择现有卡包,不为可选饰品反复刷新。'
|
||||||
|
'信息不足、重复操作仍无效、苦难无法明确核对,或你判断需要主助手分析时选 requires_analysis。'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def text_items(state):
|
||||||
|
return state.get('items') or []
|
||||||
|
|
||||||
|
|
||||||
|
def button_enabled(state, item):
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
import numpy as np
|
||||||
|
x, y, w, h = (int(item[k]) for k in ('x', 'y', 'w', 'h'))
|
||||||
|
with Image.open(state['screen']['path']) as image:
|
||||||
|
crop = np.array(image.convert('L').crop((x, y, x + w, y + h)))
|
||||||
|
return float(np.quantile(crop, 0.9)) > 85
|
||||||
|
except (OSError, KeyError, ImportError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def map_candidates(state):
|
||||||
|
"""Only observe reachable nodes; Jev chooses their route."""
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
assets = Path(r'D:\codex\lc-mcp\vendor\aalc\assets\images\default\share\mirror')
|
||||||
|
with Image.open(state['screen']['path']) as image:
|
||||||
|
rgb = np.array(image.convert('RGB'))
|
||||||
|
gray = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)
|
||||||
|
scale = min(rgb.shape[0] / 1440, rgb.shape[1] / 2560)
|
||||||
|
with Image.open(assets / 'mybus_default_distance.png') as image:
|
||||||
|
bus = cv2.cvtColor(np.array(image.convert('RGB')), cv2.COLOR_RGB2GRAY)
|
||||||
|
bus = cv2.resize(bus, None, fx=scale, fy=scale, interpolation=cv2.INTER_AREA)
|
||||||
|
_, confidence, _, location = cv2.minMaxLoc(cv2.matchTemplate(gray, bus, cv2.TM_CCOEFF_NORMED))
|
||||||
|
if confidence < 0.88:
|
||||||
|
return {}
|
||||||
|
bx, by = location[0] + bus.shape[1] // 2, location[1] + bus.shape[0] // 2
|
||||||
|
result = {}
|
||||||
|
orb = cv2.ORB_create(nfeatures=1000, scaleFactor=1.2, edgeThreshold=10)
|
||||||
|
for key, dy, direction in (('w', -400, '上方'), ('d', 50, '正前方'), ('s', 450, '下方')):
|
||||||
|
x, y = int(bx + 500 * scale), int(by + dy * scale)
|
||||||
|
if not (0 < x < rgb.shape[1] and 0 < y < rgb.shape[0]*.82):
|
||||||
|
continue
|
||||||
|
radius = int(125 * scale)
|
||||||
|
roi = rgb[max(0,y-radius):min(rgb.shape[0],y+radius), max(0,x-radius):min(rgb.shape[1],x+radius)]
|
||||||
|
hsv = cv2.cvtColor(roi, cv2.COLOR_RGB2HSV)
|
||||||
|
red = ((hsv[:,:,0] < 12) | (hsv[:,:,0] > 168)) & (hsv[:,:,1] > 150) & (hsv[:,:,2] > 150)
|
||||||
|
green = (hsv[:,:,0] > 27) & (hsv[:,:,0] < 85) & (hsv[:,:,1] > 110) & (hsv[:,:,2] > 150)
|
||||||
|
white = (hsv[:,:,1] < 100) & (hsv[:,:,2] > 175)
|
||||||
|
colored = int((red | green).sum()) >= 80
|
||||||
|
if not colored and int(white.sum()) < 80:
|
||||||
|
continue
|
||||||
|
target = cv2.resize(cv2.cvtColor(roi, cv2.COLOR_RGB2GRAY), None, fx=2, fy=2)
|
||||||
|
_, target_desc = orb.detectAndCompute(target, None)
|
||||||
|
scores = []
|
||||||
|
if target_desc is not None:
|
||||||
|
for name, label in (('shop','商店'),('event','事件'),('battle','普通战斗'),
|
||||||
|
('risky_encounter','精英战斗'),('focused_encounter','集中战斗')):
|
||||||
|
with Image.open(assets / 'road_in_mir' / (name + '.png')) as image:
|
||||||
|
template = np.array(image.convert('L'))
|
||||||
|
template = cv2.resize(template, None, fx=2*scale, fy=2*scale)
|
||||||
|
_, desc = orb.detectAndCompute(template, None)
|
||||||
|
if desc is not None:
|
||||||
|
matches = cv2.BFMatcher(cv2.NORM_HAMMING).knnMatch(desc, target_desc, k=2)
|
||||||
|
score = sum(len(pair) == 2 and pair[0].distance < 0.7*pair[1].distance for pair in matches)
|
||||||
|
scores.append((score, label))
|
||||||
|
score, label = max(scores, default=(0, '类型未识别'))
|
||||||
|
if not colored and score < 8:
|
||||||
|
continue
|
||||||
|
if score < 8:
|
||||||
|
label = '类型未识别'
|
||||||
|
result['route_' + key] = {
|
||||||
|
'description': '%s有高亮可达节点:%s,图标匹配数%d,中心(%d,%d)。按方向键选中后直接回车进入,无需二次确认。' % (direction,label,score,x,y),
|
||||||
|
'action': {'tool': 'route', 'args': {'key': key}},
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def candidates(state, previous_battle=False, refresh_used=0):
|
||||||
|
items = text_items(state)
|
||||||
|
texts = [item['text'].replace(' ', '') for item in items]
|
||||||
|
combined = '\n'.join(texts)
|
||||||
|
width = state.get('screen', {}).get('w', 1920)
|
||||||
|
height = state.get('screen', {}).get('h', 1080)
|
||||||
|
options = {'requires_analysis': {
|
||||||
|
'description': '你判断信息不足或需要主助手分析:暂停并返回当前游戏截图和问题。',
|
||||||
|
'action': {'tool': 'requires_analysis', 'args': {}},
|
||||||
|
}, 'wait': {
|
||||||
|
'description': '短暂等待0.7秒后重新读取画面;CONNECTING或界面动画尚未完成时用,不发送输入。',
|
||||||
|
'action': {'tool': 'wait', 'args': {'seconds': 0.7}},
|
||||||
|
}}
|
||||||
|
# Refresh requests leave the previous stock visible until networking ends.
|
||||||
|
# Never buy, refresh again, or leave based on that stale inventory.
|
||||||
|
if any('CONNECTING' in t.upper() for t in texts):
|
||||||
|
return options
|
||||||
|
if '判定成功' in combined or '判定失败' in combined or '结果' in texts:
|
||||||
|
continuation = next((i for i in items if i['text'].replace(' ', '') == '继续'
|
||||||
|
and button_enabled(state,i)), None)
|
||||||
|
options['event_finish'] = {
|
||||||
|
'description': '判定结果已出现,快速连按回车结束事件并返回地图。',
|
||||||
|
'action': ({'tool':'click','args':{'x':continuation['x']+continuation['w']//2,
|
||||||
|
'y':continuation['y']+continuation['h']//2}}
|
||||||
|
if continuation else {'tool': 'advance_dialog', 'args': {'presses': 5}}),
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['text'].replace(' ', '').upper() == 'SKIP' and button_enabled(state, item):
|
||||||
|
options['skip_dialog'] = {
|
||||||
|
'description': '先点击SKIP跳过当前对话,再读取事件选项或判定;当前不选择罪人或进行判定。',
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
|
||||||
|
'y': item['y'] + item['h']//2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
if '应该让谁' in combined and '选择一位罪人' not in combined and '进行判定' not in combined:
|
||||||
|
options['event_advance'] = {
|
||||||
|
'description': '对话已经跳过,按回车继续到选择罪人的判定界面。',
|
||||||
|
'action': {'tool': 'advance_dialog', 'args': {}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['text'].replace(' ', '').lstrip('×xX') == '关闭':
|
||||||
|
options['close_%d' % index] = {
|
||||||
|
'description': '关闭当前饰品查看/强化窗口,返回商店继续换技能;电池不是当前必要强化目标。',
|
||||||
|
'action': {'tool': 'keypress', 'args': {'key': 'esc'}},
|
||||||
|
}
|
||||||
|
if '迷宫进度' in texts:
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['text'].replace(' ', '') == '继续':
|
||||||
|
options['resume_game'] = {
|
||||||
|
'description': '关闭迷宫进度菜单并继续当前商店操作。',
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x']+item['w']//2,
|
||||||
|
'y': item['y']+item['h']//2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
if any('是否消耗' in t and '技能替换' in t for t in texts):
|
||||||
|
header = next((t for t in texts if '替换' in t and '技能' in t and '是否' not in t), '')
|
||||||
|
skills = sorted([i for i in items if re.fullmatch(r'SKILL\s*[123]', i['text'])
|
||||||
|
and height*.28 < i['y'] < height*.5], key=lambda i: i['x'])
|
||||||
|
target = ('SKILL2', 'SKILL3') if '奥提斯' in header else (
|
||||||
|
('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3'))
|
||||||
|
if tuple(i['text'].replace(' ', '') for i in skills) == target:
|
||||||
|
for item in items:
|
||||||
|
if item['text'] == '购买':
|
||||||
|
options['buy_swap'] = {
|
||||||
|
'description': '已核对本层所需技能替换 %s→%s,点击购买完成。' % target,
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x']+item['w']//2,
|
||||||
|
'y': item['y']+item['h']//2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
if any('当前持有技能' in t for t in texts):
|
||||||
|
header = next((t for t in texts if '替换' in t and '技能' in t), '')
|
||||||
|
target = ('SKILL2', 'SKILL3') if '奥提斯' in header else (
|
||||||
|
('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3'))
|
||||||
|
target_selected = False
|
||||||
|
for number, fraction in enumerate((0.235, 0.49, 0.745), 1):
|
||||||
|
cx = round(width*fraction)
|
||||||
|
skill_texts = [i for i in items if 'SKILL' in i['text'].upper()
|
||||||
|
and abs(i['x']+i['w']/2 - (cx + width*.075)) < width*.05
|
||||||
|
and height*.3 < i['y'] < height*.7]
|
||||||
|
skill_texts.sort(key=lambda i: i['y'])
|
||||||
|
if len(skill_texts) == 2:
|
||||||
|
if tuple(i['text'].upper().replace(' ', '') for i in skill_texts) != target:
|
||||||
|
continue
|
||||||
|
detail = skill_texts[0]['text'] + ' → ' + skill_texts[1]['text']
|
||||||
|
options['skill_swap_%d' % number] = {
|
||||||
|
'description': header + ':第%d项 %s;按楼层技能表选这一项。' % (number, detail),
|
||||||
|
'action': {'tool': 'click', 'args': {'x': cx, 'y': round(height*.45)}},
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
with Image.open(state['screen']['path']) as image:
|
||||||
|
border = np.array(image.convert('RGB').crop((int(cx-width*.12), int(height*.31),
|
||||||
|
int(cx-width*.107), int(height*.69))))
|
||||||
|
hsv = cv2.cvtColor(border, cv2.COLOR_RGB2HSV)
|
||||||
|
target_selected = float(((hsv[:,:,0] > 8) & (hsv[:,:,0] < 35) &
|
||||||
|
(hsv[:,:,1] > 200) & (hsv[:,:,2] > 220)).mean()) > .18
|
||||||
|
except (KeyError, OSError, ImportError):
|
||||||
|
pass
|
||||||
|
for item in items:
|
||||||
|
if target_selected and item['text'].replace(' ', '') == '确认' and button_enabled(state, item):
|
||||||
|
options['confirm_swap'] = {
|
||||||
|
'description': '确认已经选中的技能替换,支付本项费用。未选项目时应先点技能替换项。',
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
|
||||||
|
'y': item['y'] + item['h']//2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
if '追加的苦难' in combined and '获得E.G.O' in combined:
|
||||||
|
for number, fraction in enumerate((.188, .395, .60, .813), 1):
|
||||||
|
cx = round(width*fraction)
|
||||||
|
details = ';'.join(i['text'] for i in items
|
||||||
|
if abs(i['x']+i['w']/2-cx) < width*.102
|
||||||
|
and height*.22 < i['y'] < height*.77)
|
||||||
|
if details:
|
||||||
|
options['hardship_%d' % number] = {
|
||||||
|
'description': '层末第%d张饰品与苦难:%s。必需饰品优先;其他避开体力上限和防御等级。' % (number,details),
|
||||||
|
'action': {'tool':'click', 'args':{'x':cx, 'y':round(height*.43)}},
|
||||||
|
}
|
||||||
|
for item in items:
|
||||||
|
if '选择' in item['text'] and '/' in item['text'] and button_enabled(state,item):
|
||||||
|
options['hardship_confirm'] = {
|
||||||
|
'description':'选择数量足够后确认层末饰品和苦难,直接前进。',
|
||||||
|
'action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
# Nested confirmation/detail windows override the reward/pack behind them.
|
||||||
|
modal_question = ('确认' in texts and any('取消' in t for t in texts)
|
||||||
|
and any('吗?' in t or '吗?' in t for t in texts))
|
||||||
|
pack_detail = '出现头目' in combined and '详细内容' in combined
|
||||||
|
if modal_question or pack_detail:
|
||||||
|
buttons = [i for i in items if i['text'].replace(' ', '') == '确认'
|
||||||
|
and button_enabled(state, i)]
|
||||||
|
if buttons:
|
||||||
|
item = min(buttons, key=lambda i: i['y'])
|
||||||
|
options['modal_confirm'] = {
|
||||||
|
'description': '确认当前最上层弹窗;不操作背景奖励卡或卡包。',
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
|
||||||
|
'y': item['y'] + item['h']//2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
if any('选择遭遇战奖励卡' in t for t in texts):
|
||||||
|
for number, fraction in enumerate((0.355, 0.514, 0.674), 1):
|
||||||
|
cx = round(width*fraction)
|
||||||
|
detail = ';'.join(i['text'] for i in items
|
||||||
|
if abs(i['x']+i['w']/2-cx) < width*.07 and height*.48 < i['y'] < height*.65)
|
||||||
|
if detail:
|
||||||
|
options['reward_card_%d' % number] = {
|
||||||
|
'description': '遭遇战奖励卡第%d张:%s。优先减少额外操作,略过无关饰品。' % (number, detail),
|
||||||
|
'action': {'tool': 'click', 'args': {'x': cx, 'y': round(height*.43)}},
|
||||||
|
}
|
||||||
|
if not any('0/1' in t for t in texts):
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['text'].replace(' ', '') == '确认' and button_enabled(state, item):
|
||||||
|
options['confirm_reward'] = {
|
||||||
|
'description': '奖励卡已选中,确认领取。',
|
||||||
|
'action': {'tool': 'keypress', 'args': {'key': 'enter'}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
# A confirmation dialog blocks the controls underneath it. Keep its
|
||||||
|
# observed coordinates instead of re-running an ambiguous text search.
|
||||||
|
confirmations = [(index, item) for index, item in enumerate(items)
|
||||||
|
if item['text'].replace(' ', '') == '确认']
|
||||||
|
modal = confirmations and (any('取消' in t for t in texts) or
|
||||||
|
any('吗?' in t or '吗?' in t for t in texts))
|
||||||
|
if modal:
|
||||||
|
for index, item in confirmations:
|
||||||
|
if button_enabled(state, item):
|
||||||
|
options['confirm_%d' % index] = {
|
||||||
|
'description': '当前确认弹窗的“确认”按钮;确认本次操作,背景控件被弹窗遮挡。',
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w'] // 2,
|
||||||
|
'y': item['y'] + item['h'] // 2}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
if any('选择' in t and '层主题卡包' in t for t in texts):
|
||||||
|
# This screen has five clipped bags; title OCR anchors each visible bag.
|
||||||
|
for number, fraction in enumerate((0.17, 0.335, 0.5, 0.665, 0.83), 1):
|
||||||
|
cx = round(width * fraction)
|
||||||
|
titles = [i['text'] for i in items if abs(i['x'] + i['w']/2 - cx) < width*.06
|
||||||
|
and height*.60 < i['y'] < height*.68]
|
||||||
|
label = '/'.join(titles) or '标题OCR暂未识别'
|
||||||
|
options['pack_inspect_%d' % number] = {
|
||||||
|
'description': '查看第%d个卡包“%s”的放大镜详情,核对怪物和通关奖励。' % (number, label),
|
||||||
|
'action': {'tool': 'click', 'args': {'x': round(cx + width*.042), 'y': round(height*.303)}},
|
||||||
|
}
|
||||||
|
if titles:
|
||||||
|
options['pack_drag_%d' % number] = {
|
||||||
|
'description': '选择第%d个卡包“%s”:长按卡包中部并缓慢向下拖到底。' % (number, label),
|
||||||
|
'action': {'tool': 'drag', 'args': {'from_x': cx, 'from_y': round(height*.45),
|
||||||
|
'to_x': cx, 'to_y': round(height*.91), 'duration': 1.8}},
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
in_shop = '商店' in texts and '刷新' in texts
|
||||||
|
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
|
||||||
|
swaps = [(index, item) for index, item in enumerate(items)
|
||||||
|
if '替换' in item['text'] and any(name in item['text'] for name in party)
|
||||||
|
and not any('已购买' in sold['text']
|
||||||
|
and abs(sold['x']+sold['w']/2-item['x']-item['w']/2) < width*.07
|
||||||
|
and 0 < item['y']-sold['y'] < height*.25 for sold in items)]
|
||||||
|
if in_shop:
|
||||||
|
for index, item in swaps:
|
||||||
|
options['swap_%d' % index] = {
|
||||||
|
'description': '商店出战角色技能替换入口:' + item['text'] + ';打开后核对技能表。',
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
|
||||||
|
'y': max(0, item['y'] - round(height*.095))}},
|
||||||
|
}
|
||||||
|
if not swaps and refresh_used < 4:
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['text'].replace(' ', '') == '刷新' and button_enabled(state, item):
|
||||||
|
options['shop_refresh'] = {
|
||||||
|
'description': '没有出战角色可替换技能,刷新商店;本店已刷新%d/4次。' % refresh_used,
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w'] // 2,
|
||||||
|
'y': item['y'] + item['h'] // 2}},
|
||||||
|
}
|
||||||
|
end_screen = any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
|
||||||
|
('正在探', '获得E.G.O饰品', '开始战斗', '主题卡包', '应该让谁上前', '选择遭遇战奖励卡')) for t in texts)
|
||||||
|
battle = any(m in combined.upper() for m in ('WAVE', 'TURN', 'DURANTE', '胜率', '伤害'))
|
||||||
|
if not end_screen and (battle or previous_battle):
|
||||||
|
options['battle'] = {'description': '仍处于战斗或特写:执行短批次 P→回车,两次后检查结算,不分析拼点。',
|
||||||
|
'action': {'tool': 'battle', 'args': {'rounds': 2}}}
|
||||||
|
known_buttons = ('确认', '继续', '进入', '开始战斗', 'SKIP', '进行判定', '拒绝饰品',
|
||||||
|
'离开', '下一层', '前往下一层', '领取奖励', '结束探索', 'TOUCHTOSTART', '选择')
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
label = item['text'].replace(' ', '')
|
||||||
|
if in_shop and (swaps or 'shop_refresh' in options) and label == '离开':
|
||||||
|
continue
|
||||||
|
if label in known_buttons and button_enabled(state, item):
|
||||||
|
options['button_%d' % index] = {
|
||||||
|
'description': '当前可见且非灰色按钮:%s;点击 OCR 中心。' % label,
|
||||||
|
'action': ({'tool': 'keypress', 'args': {'key': 'enter'}} if label in ('进入', '开始战斗')
|
||||||
|
else {'tool': 'click_text', 'args': {'text': item['text']}}),
|
||||||
|
}
|
||||||
|
if (not battle and not in_shop and state.get('screen', {}).get('path')
|
||||||
|
and Path(state['screen']['path']).is_file()
|
||||||
|
and not any(t in combined for t in ('确认', '继续', '获得E.G.O', 'SKIP', '选项'))):
|
||||||
|
options.update(map_candidates(state))
|
||||||
|
if any(t in combined for t in ('应该让谁', '选择一位罪人')):
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['text'] in ('极高', '高') and item['y'] > height * 0.8 and item['w'] < width * 0.07:
|
||||||
|
options['sinner_%d' % index] = {
|
||||||
|
'description': '选择预计成功率%s的罪人卡,卡中心x=%d。' % (item['text'], item['x'] + item['w'] // 2),
|
||||||
|
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w'] // 2,
|
||||||
|
'y': min(height - 35, item['y'] + int(height * 0.06))}},
|
||||||
|
}
|
||||||
|
if '选择一位罪人' in combined:
|
||||||
|
try:
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
with Image.open(state['screen']['path']) as image:
|
||||||
|
rgb = np.array(image.convert('RGB'))
|
||||||
|
for number in range(12):
|
||||||
|
cx = round(width*(.061 + number*.0542))
|
||||||
|
crop = rgb[round(height*.841):round(height*.878), max(0,cx-round(width*.026)):cx+round(width*.026)]
|
||||||
|
hsv = cv2.cvtColor(crop, cv2.COLOR_RGB2HSV)
|
||||||
|
gold = (hsv[:,:,0] > 18) & (hsv[:,:,0] < 36) & (hsv[:,:,1] > 160) & (hsv[:,:,2] > 180)
|
||||||
|
if int(gold.sum()) > 100:
|
||||||
|
options['sinner_card_%d' % number] = {
|
||||||
|
'description': '第%d张罪人卡的成功率标识为金黄色(高/极高),选择此卡。' % (number+1),
|
||||||
|
'action': {'tool': 'click', 'args': {'x': cx, 'y': round(height*.915)}},
|
||||||
|
}
|
||||||
|
except (OSError, KeyError, ImportError):
|
||||||
|
pass
|
||||||
|
if '选项' in texts:
|
||||||
|
if not any('选择后' in t and '获得' in t and '判定' not in t for t in texts):
|
||||||
|
options['event_scroll'] = {
|
||||||
|
'description': '向下拖动事件选项列表的滚动条,查看是否还有无需判定、无需战斗的直接离开选项。',
|
||||||
|
'action': {'tool': 'drag', 'args': {'from_x': round(width*.945), 'from_y': round(height*.255),
|
||||||
|
'to_x': round(width*.945), 'to_y': round(height*.68), 'duration': .8}},
|
||||||
|
}
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item['x'] > width * 0.52 and height * 0.23 < item['y'] < height * 0.75 and item['h'] > height * 0.025 and item.get('score', 0) > 0.93:
|
||||||
|
if not any(t in item['text'] for t in ('判定', '获得', '成功', '全体', '战斗胜利')):
|
||||||
|
outcome = ';'.join(i['text'] for i in items if i['x'] > width*.52
|
||||||
|
and item['y']+item['h'] < i['y'] < item['y']+height*.085)
|
||||||
|
options['event_%d' % index] = {'description': '当前事件选项:' + item['text'] + ';结果:' + outcome,
|
||||||
|
'action': {'tool': 'click_text', 'args': {'text': item['text']}}}
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
|
def decide(cfg, state, options, recent):
|
||||||
|
body = {'model': 'jev-1.13-free',
|
||||||
|
'state': '目标:按用户已配置的队伍和速通规则推进当前镜牢。当前楼层:%s\n当前游戏 OCR(坐标仅供辨识):\n' % state.get('floor', '尚未识别') +
|
||||||
|
'\n'.join('%s @%d,%d' % (i['text'], i['x'], i['y']) for i in text_items(state)
|
||||||
|
if not i['text'].upper().startswith('STEAM')) +
|
||||||
|
'\n截图视觉与可用控件观察(不是预先做出的决定):\n' +
|
||||||
|
'\n'.join(val['description'] for key,val in options.items() if key != 'requires_analysis') +
|
||||||
|
'\n最近动作和执行结果:' + json.dumps(recent[-4:], ensure_ascii=False),
|
||||||
|
'questions': {'action': {'type': 'choice', 'instructions': SYSTEM_RULES,
|
||||||
|
'criteria': {key: val['description'] for key, val in options.items()}}}}
|
||||||
|
request = urllib.request.Request(
|
||||||
|
'https://opencode.ai/zen/v1/systemone',
|
||||||
|
data=json.dumps(body, ensure_ascii=False).encode('utf-8'),
|
||||||
|
headers={'Authorization': 'Bearer ' + cfg['apiKey'], 'Content-Type': 'application/json',
|
||||||
|
'User-Agent': 'Mozilla/5.0'}, method='POST')
|
||||||
|
start = time.monotonic()
|
||||||
|
for attempt in range(2):
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(request, timeout=7) as response:
|
||||||
|
result = json.load(response)
|
||||||
|
break
|
||||||
|
except (OSError, TimeoutError):
|
||||||
|
if attempt:
|
||||||
|
raise
|
||||||
|
time.sleep(0.3)
|
||||||
|
answer = result.get('answers', {}).get('action', {})
|
||||||
|
choice = answer.get('choice')
|
||||||
|
if answer.get('type') != 'choice' or choice not in options:
|
||||||
|
raise ValueError('Jev returned an unsupported candidate')
|
||||||
|
return choice, round((time.monotonic() - start) * 1000)
|
||||||
|
|
||||||
|
|
||||||
|
def execute(bridge, action):
|
||||||
|
if action['tool'] == 'advance_dialog':
|
||||||
|
for _ in range(min(5, action.get('args', {}).get('presses', 2))):
|
||||||
|
result = bridge.call('keypress', {'key': 'enter'})
|
||||||
|
if not result.get('ok'):
|
||||||
|
return result
|
||||||
|
time.sleep(.2)
|
||||||
|
return result
|
||||||
|
if action['tool'] == 'route':
|
||||||
|
result = bridge.call('keypress', {'key': action['args']['key']})
|
||||||
|
if not result.get('ok'):
|
||||||
|
return result
|
||||||
|
time.sleep(0.35)
|
||||||
|
result = bridge.call('keypress', {'key': 'enter'})
|
||||||
|
if not result.get('ok'):
|
||||||
|
return result
|
||||||
|
time.sleep(0.7)
|
||||||
|
return bridge.call('keypress', {'key': 'enter'})
|
||||||
|
if action['tool'] == 'wait':
|
||||||
|
time.sleep(0.7)
|
||||||
|
return {'ok': True, 'waited': 0.7}
|
||||||
|
if action['tool'] == 'battle':
|
||||||
|
deadline = time.monotonic() + 45
|
||||||
|
pairs = 0
|
||||||
|
while time.monotonic() < deadline and not STOP_FILE.exists():
|
||||||
|
for _ in range(2):
|
||||||
|
for key in ('p', 'enter'):
|
||||||
|
result = bridge.call('keypress', {'key': key})
|
||||||
|
if not result.get('ok'):
|
||||||
|
return result
|
||||||
|
pairs += 1
|
||||||
|
time.sleep(0.8)
|
||||||
|
state = bridge.call('get_state')
|
||||||
|
if not state.get('ok'):
|
||||||
|
return state
|
||||||
|
texts = [i['text'].replace(' ', '') for i in text_items(state)]
|
||||||
|
terminal = any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
|
||||||
|
('正在探', '获得E.G.O饰品', '开始战斗', '主题卡包',
|
||||||
|
'应该让谁上前', '选择遭遇战奖励卡', '选项事件', '选择苦难')) for t in texts)
|
||||||
|
if terminal:
|
||||||
|
return {'ok': True, 'pairs': pairs, 'terminal': True, 'screen': state.get('screen')}
|
||||||
|
return {'ok': True, 'pairs': pairs, 'terminal': False}
|
||||||
|
return bridge.call(action['tool'], action.get('args'))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('config')
|
||||||
|
parser.add_argument('--steps', type=int, default=250)
|
||||||
|
parser.add_argument('--seconds', type=int, default=1200)
|
||||||
|
args = parser.parse_args()
|
||||||
|
# 防止另一个终端重复启动同一个游戏的执行器。
|
||||||
|
import ctypes
|
||||||
|
kernel = ctypes.windll.kernel32
|
||||||
|
kernel.CreateMutexW.restype = ctypes.c_void_p
|
||||||
|
kernel.CreateMutexW.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_wchar_p]
|
||||||
|
lease = kernel.CreateMutexW(None, False, 'Local\\LimbusMirrorJevController')
|
||||||
|
if not lease or kernel.GetLastError() == 183:
|
||||||
|
print(json.dumps({'state':'already_running'}), flush=True)
|
||||||
|
if lease:
|
||||||
|
kernel.CloseHandle(ctypes.c_void_p(lease))
|
||||||
|
return
|
||||||
|
cfg = json.loads(Path(args.config).read_text(encoding='utf-8'))
|
||||||
|
log = Path(r'{source_root}\jev_mirror_log.jsonl')
|
||||||
|
status = Path(r'{source_root}\jev_mirror_status.json')
|
||||||
|
bridge = Bridge()
|
||||||
|
deadline = time.monotonic() + args.seconds
|
||||||
|
recent = []
|
||||||
|
repeats = {}
|
||||||
|
previous_battle = False
|
||||||
|
if log.exists():
|
||||||
|
last_lines = log.read_text(encoding='utf-8').splitlines()
|
||||||
|
if last_lines:
|
||||||
|
last_record = json.loads(last_lines[-1])
|
||||||
|
previous_battle = last_record.get('battle_context', last_record.get('action', {}).get('tool') == 'battle')
|
||||||
|
context_path = Path(r'{source_root}\jev_shop_context.json')
|
||||||
|
context = json.loads(context_path.read_text(encoding='utf-8')) if context_path.exists() else {'refresh_used': 0}
|
||||||
|
stable_since = time.monotonic()
|
||||||
|
last_fingerprint = None
|
||||||
|
try:
|
||||||
|
for step in range(args.steps):
|
||||||
|
if STOP_FILE.exists() or time.monotonic() > deadline:
|
||||||
|
status.write_text(json.dumps({'state': 'stopped', 'step': step}), encoding='utf-8')
|
||||||
|
return
|
||||||
|
state = bridge.call('get_state')
|
||||||
|
if not state.get('ok'):
|
||||||
|
state = {'ok': False, 'items': [{'text': 'MCP 截图暂不可用;游戏窗口可能正在重建。' + str(state.get('error','')),
|
||||||
|
'x':0,'y':0,'w':0,'h':0,'score':1.0}]}
|
||||||
|
fingerprint = tuple(item['text'] for item in text_items(state)
|
||||||
|
if item.get('score', 0) > 0.93 and not item['text'].replace('.', '').isdigit())
|
||||||
|
if any('正在探' in i['text'] or '主题卡包' in i['text'] for i in text_items(state)):
|
||||||
|
context['refresh_used'] = 0
|
||||||
|
for item in text_items(state):
|
||||||
|
match = re.search(r'(?:第|选择)([1-5])层', item['text'].replace(' ', ''))
|
||||||
|
if match:
|
||||||
|
context['floor'] = int(match[1])
|
||||||
|
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||||
|
state['floor'] = context.get('floor', 3)
|
||||||
|
options = candidates(state, previous_battle, context['refresh_used'])
|
||||||
|
if fingerprint != last_fingerprint:
|
||||||
|
stable_since = time.monotonic()
|
||||||
|
last_fingerprint = fingerprint
|
||||||
|
stable_seconds = round(time.monotonic() - stable_since)
|
||||||
|
if stable_seconds > 30:
|
||||||
|
recent.append({'observation':'画面已%d秒没有有效改变,请你判断是否需要主助手排查。' % stable_seconds})
|
||||||
|
for key in list(options):
|
||||||
|
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
||||||
|
if (options[key]['action'] == {'tool': 'keypress', 'args': {'key': 'enter'}}
|
||||||
|
and repeats.get((fingerprint, action_id), 0) >= 1):
|
||||||
|
button = next((i for i in text_items(state)
|
||||||
|
if i['text'].replace(' ', '') in ('进入', '开始战斗', '确认', '继续')
|
||||||
|
and button_enabled(state, i)), None)
|
||||||
|
if button:
|
||||||
|
options[key]['action'] = {'tool': 'click', 'args': {
|
||||||
|
'x': button['x'] + button['w']//2, 'y': button['y'] + button['h']//2}}
|
||||||
|
options[key]['description'] += ' 回车未生效,改为点击当前按钮。'
|
||||||
|
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
||||||
|
if key not in ('requires_analysis', 'wait', 'battle') and repeats.get((fingerprint, action_id), 0) >= 2:
|
||||||
|
del options[key]
|
||||||
|
# User explicitly prescribed the complete battle loop. Only scene
|
||||||
|
# transitions return to Jev; combat does not require new decisions.
|
||||||
|
if 'event_finish' in options:
|
||||||
|
choice, latency = 'event_finish', 0
|
||||||
|
elif 'skip_dialog' in options:
|
||||||
|
choice, latency = 'skip_dialog', 0
|
||||||
|
elif 'event_advance' in options:
|
||||||
|
choice, latency = 'event_advance', 0
|
||||||
|
elif 'battle' in options:
|
||||||
|
choice, latency = 'battle', 0
|
||||||
|
else:
|
||||||
|
choice, latency = decide(cfg, state, options, recent)
|
||||||
|
action = options[choice]['action']
|
||||||
|
record = {'step': step, 'choice': choice, 'action': action, 'jev_ms': latency,
|
||||||
|
'screen': state.get('screen'), 'at': time.strftime('%Y-%m-%dT%H:%M:%S')}
|
||||||
|
if choice == 'requires_analysis':
|
||||||
|
record.update(state='requires_analysis', items=text_items(state))
|
||||||
|
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
||||||
|
print(json.dumps(record, ensure_ascii=False), flush=True)
|
||||||
|
return
|
||||||
|
action_id = json.dumps(action, sort_keys=True)
|
||||||
|
repeats[(fingerprint, action_id)] = repeats.get((fingerprint, action_id), 0) + 1
|
||||||
|
result = execute(bridge, action)
|
||||||
|
if choice == 'shop_refresh':
|
||||||
|
context['refresh_used'] += 1
|
||||||
|
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||||
|
started_battle = choice.startswith('button_') and any(
|
||||||
|
i['text'].replace(' ', '') == '开始战斗' for i in text_items(state))
|
||||||
|
previous_battle = ((action['tool'] == 'battle' and not result.get('terminal')) or started_battle
|
||||||
|
or (previous_battle and action['tool'] == 'wait'))
|
||||||
|
record.update(result=result, state='running', battle_context=previous_battle)
|
||||||
|
with log.open('a', encoding='utf-8') as output:
|
||||||
|
output.write(json.dumps(record, ensure_ascii=False) + '\n')
|
||||||
|
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
||||||
|
recent.append({'action': action, 'ok': result.get('ok'), 'unchanged_attempt': repeats[(fingerprint, action_id)]})
|
||||||
|
print(json.dumps({k:v for k,v in record.items() if k != 'items'}, ensure_ascii=False), flush=True)
|
||||||
|
time.sleep(0.35)
|
||||||
|
except Exception as error:
|
||||||
|
record = {'state': 'requires_analysis', 'error': '%s: %s' % (type(error).__name__, str(error))}
|
||||||
|
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
||||||
|
print(json.dumps(record, ensure_ascii=False), flush=True)
|
||||||
|
finally:
|
||||||
|
bridge.proc.stdin.close()
|
||||||
|
try:
|
||||||
|
bridge.proc.wait(timeout=5)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
bridge.proc.kill()
|
||||||
|
kernel.CloseHandle(ctypes.c_void_p(lease))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -0,0 +1,367 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Closed-loop Limbus Company Mirror Dungeon driver.
|
||||||
|
|
||||||
|
IO goes through the user's lc-mcp (AALC) bridge: OCR state + background
|
||||||
|
click/keypress/drag. Decisions come from deepseek-v4.1-flash on the zen API.
|
||||||
|
|
||||||
|
Usage: python lc_agent.py <config.json>
|
||||||
|
|
||||||
|
config.json:
|
||||||
|
{
|
||||||
|
"steps": 200,
|
||||||
|
"model": "deepseek-v4.1-flash",
|
||||||
|
"apiKey": "oc_sk_...",
|
||||||
|
"baseUrl": "https://opencode.ai/zen/go/v1",
|
||||||
|
"logFile": "D:\\codex\\limbus_tools\\lc_agent_log.jsonl",
|
||||||
|
"shotDir": "D:\\codex\\limbus_tools\\lc_shots"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
import base64
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(r"D:\codex\lc-mcp")
|
||||||
|
BRIDGE = ROOT / "lc_mcp" / "bridge.py"
|
||||||
|
STOP_FILE = Path(r"{source_root}\STOP")
|
||||||
|
|
||||||
|
SKY = {
|
||||||
|
"tool": "click|click_text|keypress|drag|wait_for_text|screenshot|get_state",
|
||||||
|
}
|
||||||
|
|
||||||
|
TOOLS_DOC = """可用工具(只输出一个 JSON):
|
||||||
|
{"tool":"battle","args":{"rounds":8}} // 战斗宏:自动 p → enter 循环 rounds 轮,战斗中优先用这个
|
||||||
|
{"tool":"keys","args":{"keys":["enter","enter"],"delay":0.8}} // 顺序按几个键
|
||||||
|
{"tool":"keypress","args":{"key":"enter"}} // 单键: enter/esc/space/p/a-z/up/down/left/right
|
||||||
|
{"tool":"click_text","args":{"text":"进入"}} // 按 OCR 文字点击(有文字时最稳)
|
||||||
|
{"tool":"click_image","args":{"name":"mirror/road_in_mir/event.png"}} // 按 AALC 模板图点击(没文字的图标/按钮/地图节点用这个,最稳)
|
||||||
|
{"tool":"find_image","args":{"name":"mirror/road_in_mir/shop.png"}} // 只查找模板图,返回 found/x/y
|
||||||
|
{"tool":"list_images","args":{"prefix":"mirror/"}} // 列出可选模板图
|
||||||
|
{"tool":"click","args":{"x":960,"y":540}} // 按客户区坐标点击(1920x1080),最后手段
|
||||||
|
{"tool":"drag","args":{"from_x":600,"from_y":330,"to_x":600,"to_y":640,"duration":1.2}} // 长按拖拽,卡包选择用
|
||||||
|
{"tool":"wait_for_text","args":{"text":"SKIP","timeout":20}}
|
||||||
|
{"tool":"get_state"} // 重新观察
|
||||||
|
{"tool":"done","args":{"reason":"..."}} // 整局通关结算出现,或确实需要人类接管
|
||||||
|
|
||||||
|
常用模板图(AALC 自带):
|
||||||
|
mirror/road_in_mir/event.png(事件节点) shop.png(商店) battle.png(普通战斗) risky_encounter.png(危险战斗)
|
||||||
|
mirror/road_in_mir/enter_assets.png(进入按钮) up.png / down.png / mid.png(地图上下选节点)
|
||||||
|
mirror/road_in_mir/acquire_ego_gift_refuse_assets.png(观测「拒绝饰品」) refuse_gift_assets.png
|
||||||
|
mirror/road_in_mir/select_encounter_reward_card_assets.png mirror/get_reward_card/get_reward_card_confirm_assets.png
|
||||||
|
mirror/road_in_mir/clear_floor.png mirror/road_in_mir/to_window_assets.png
|
||||||
|
"""
|
||||||
|
|
||||||
|
SYSTEM = f"""你是《边狱公司》(Limbus Company) 镜像迷宫速通的**执行器**。你看到的是游戏窗口的 OCR 文字清单 + 截图,要输出**下一步一个操作**,追求整局最快通关。
|
||||||
|
|
||||||
|
{TOOLS_DOC}
|
||||||
|
|
||||||
|
决策规则(按优先级):
|
||||||
|
0. **工具选择**:有图标没文字时优先 click_image(模板图);有文字时用 click_text;click 坐标是最后手段。
|
||||||
|
1. **战斗中**(OCR 出现 WAVE / TURN / 胜率 / 伤害 / MAX):立刻用 {{"tool":"battle","args":{{"rounds":8}}}}。不要按 space(会暂停)。战斗动画中也可以继续发,游戏会排队。
|
||||||
|
2. **剧情/对话**(出现 SKIP 按钮):用 click_text 点 "SKIP" 跳过整段。只有多段文本才用 enter。
|
||||||
|
3. **判定事件**("应该让谁上前"/"选择一位罪人来进行判定"):点带「极高」标记的出战罪人卡(底部一排,卡上有 极高/高/低)。用 click 点那张卡的中下部。
|
||||||
|
4. **事件选项**:避开额外战斗和判定;优先能直接结束的选项。选完出现 SKIP 就 skip。
|
||||||
|
5. **奖励界面**:优先含「破裂」的 E.G.O 饰品;避开「体力上限」「防御等级」增加的苦难;有「选择 N/M」按钮时选完再点它。
|
||||||
|
5b. **额外E.G.O饰品观测**(画面中央单张饰品卡 + 右下「拒绝饰品」/「选择」两个按钮):**用 click_image("mirror/road_in_mir/acquire_ego_gift_refuse_assets.png")** 或 click_text "拒绝饰品"。用户明确要求:不要额外观测饰品。
|
||||||
|
5c. 如果「选择」按钮点了没用,说明还没选中卡片或该按钮不可用 —— 改点「拒绝饰品」或按 esc,不要在同一个按钮上反复点。
|
||||||
|
6. **卡包选择**(标题「选择N层主题卡包」):必须拖拽。用 drag 从目标卡包中心向下拖(如 from(600,330) to(600,640), duration 1.2)。选哪个包都行,速度优先。
|
||||||
|
7. **地图**:先用 find_image 找 mirror/road_in_mir/event.png(事件)或 shop.png(商店),找到就 click_image 点它,减少战斗;找不到事件/商店就点 battle.png / risky_encounter.png。节点详情面板出现后用 click_text 点 "进入"。
|
||||||
|
8. **商店**:先看有没有我方人格(辛克莱/鸿璐/希斯克利夫/奥提斯/格里高尔/良秀/浮士德)的「替换XX的技能」,有就买;成捆的符咒还没 ++ 就先「强化饰品」。然后点 "离开" → "确认"。
|
||||||
|
9. **任何弹窗**:优先 click_text 点 "确认"/"继续"/"进入"。
|
||||||
|
10. 连续 3 步画面没变说明方法错了,换一个明显不同的操作(换工具或换坐标)。同一个动作别重复超过 2 次。
|
||||||
|
11. 只输出 JSON,不要解释。
|
||||||
|
|
||||||
|
已知:HARD 难度;队伍是破裂纯 P;关键饰品 成捆的符咒(要 ++)、干巴柴紧致鸡胸肉、荆棘索套、荧光灯、标准负载电池。
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Bridge:
|
||||||
|
def __init__(self):
|
||||||
|
self.proc = subprocess.Popen(
|
||||||
|
[sys.executable if False else r"D:\codex\lc-mcp\vendor\aalc\.venv\Scripts\python.exe",
|
||||||
|
"-X", "utf8", str(BRIDGE)],
|
||||||
|
cwd=str(ROOT), env=dict(os.environ, PYTHONUTF8="1"),
|
||||||
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
|
||||||
|
text=True, encoding="utf-8", bufsize=1,
|
||||||
|
)
|
||||||
|
self.n = 0
|
||||||
|
self.send({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {
|
||||||
|
"protocolVersion": "2024-11-05", "capabilities": {},
|
||||||
|
"clientInfo": {"name": "dsh-lc-agent", "version": "1"}}})
|
||||||
|
self.await_id(1)
|
||||||
|
self.send({"jsonrpc": "2.0", "method": "notifications/initialized"})
|
||||||
|
|
||||||
|
def send(self, obj):
|
||||||
|
self.proc.stdin.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
||||||
|
self.proc.stdin.flush()
|
||||||
|
|
||||||
|
def await_id(self, mid):
|
||||||
|
while True:
|
||||||
|
line = self.proc.stdout.readline()
|
||||||
|
if not line:
|
||||||
|
raise RuntimeError("bridge closed")
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
msg = json.loads(line)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
if msg.get("id") == mid:
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def call(self, tool, args=None, timeout=None):
|
||||||
|
self.n += 1
|
||||||
|
mid = 1000 + self.n
|
||||||
|
self.send({"jsonrpc": "2.0", "id": mid, "method": "tools/call",
|
||||||
|
"params": {"name": tool, "arguments": args or {}}})
|
||||||
|
msg = self.await_id(mid)
|
||||||
|
if msg is None:
|
||||||
|
return {"ok": False, "error": "no response"}
|
||||||
|
if "error" in msg:
|
||||||
|
return {"ok": False, "error": msg["error"]}
|
||||||
|
res = msg["result"]
|
||||||
|
try:
|
||||||
|
return json.loads(res["content"][0]["text"])
|
||||||
|
except Exception:
|
||||||
|
return {"ok": False, "raw": res}
|
||||||
|
|
||||||
|
|
||||||
|
def shrink(path, out_dir, max_w=1280):
|
||||||
|
"""Downscale the AALC PNG to a small JPEG data URL for the vision model."""
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
im = Image.open(path).convert("RGB")
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
if im.width > max_w:
|
||||||
|
im = im.resize((max_w, int(im.height * max_w / im.width)), Image.LANCZOS)
|
||||||
|
os.makedirs(out_dir, exist_ok=True)
|
||||||
|
out = os.path.join(out_dir, "model_view.jpg")
|
||||||
|
im.save(out, "JPEG", quality=72)
|
||||||
|
with open(out, "rb") as f:
|
||||||
|
return "data:image/jpeg;base64," + base64.b64encode(f.read()).decode("ascii")
|
||||||
|
|
||||||
|
|
||||||
|
def summarize(items, limit=90):
|
||||||
|
lines = []
|
||||||
|
for it in items[:limit]:
|
||||||
|
lines.append(f'{it["text"]} @({it["x"]},{it["y"]})')
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def ask(cfg, image_url, ocr_text, recent, step, stuck):
|
||||||
|
nudge = ""
|
||||||
|
if stuck:
|
||||||
|
nudge = ("\n\n⚠️ 最近几步画面完全没变化,说明当前操作方式无效:"
|
||||||
|
"立刻换一个**完全不同**的工具或目标(例如 keypress esc / click_text 拒绝饰品 / "
|
||||||
|
"click_text 确认 / click_text 进入 / drag 拖卡包),不要再点同一个按钮。\n")
|
||||||
|
body = {
|
||||||
|
"model": cfg["model"],
|
||||||
|
"temperature": 0,
|
||||||
|
"max_tokens": 900,
|
||||||
|
"reasoning_effort": "minimal",
|
||||||
|
"messages": [
|
||||||
|
{"role": "system", "content": SYSTEM},
|
||||||
|
{"role": "user", "content": [
|
||||||
|
{"type": "text", "text": (
|
||||||
|
f"第 {step} 步。\n最近操作:{' | '.join(recent[-5:]) or '无'}\n"
|
||||||
|
f"OCR 文字清单(text @x,y):\n{ocr_text}{nudge}\n\n输出下一步 JSON。")},
|
||||||
|
{"type": "image_url", "image_url": {"url": image_url, "detail": "low"}},
|
||||||
|
]},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
data = json.dumps(body, ensure_ascii=False).encode("utf-8")
|
||||||
|
req = urllib.request.Request(
|
||||||
|
cfg["baseUrl"].rstrip("/") + "/chat/completions", data=data,
|
||||||
|
headers={"Authorization": "Bearer " + cfg["apiKey"],
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-opencode-session": cfg.get("sessionId", "dsh-lc-agent"),
|
||||||
|
# Cloudflare in front of the zen API returns 1010 without a browser UA.
|
||||||
|
"User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||||
|
"(KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36")},
|
||||||
|
method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=120) as resp:
|
||||||
|
payload = json.loads(resp.read().decode("utf-8"))
|
||||||
|
msg = (payload.get("choices") or [{}])[0].get("message") or {}
|
||||||
|
return msg.get("content") or "", msg.get("reasoning_content") or ""
|
||||||
|
|
||||||
|
|
||||||
|
def parse_action(text):
|
||||||
|
raw = text.replace("```json", "\n").replace("```", "\n")
|
||||||
|
for i, ch in enumerate(raw):
|
||||||
|
if ch != "{":
|
||||||
|
continue
|
||||||
|
depth = 0
|
||||||
|
instr = False
|
||||||
|
esc = False
|
||||||
|
for j in range(i, len(raw)):
|
||||||
|
c = raw[j]
|
||||||
|
if instr:
|
||||||
|
if esc:
|
||||||
|
esc = False
|
||||||
|
elif c == "\\":
|
||||||
|
esc = True
|
||||||
|
elif c == '"':
|
||||||
|
instr = False
|
||||||
|
continue
|
||||||
|
if c == '"':
|
||||||
|
instr = True
|
||||||
|
elif c == "{":
|
||||||
|
depth += 1
|
||||||
|
elif c == "}":
|
||||||
|
depth -= 1
|
||||||
|
if depth == 0:
|
||||||
|
try:
|
||||||
|
obj = json.loads(raw[i:j + 1])
|
||||||
|
if isinstance(obj, dict) and isinstance(obj.get("tool"), str):
|
||||||
|
return obj
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
raise ValueError("no action JSON")
|
||||||
|
|
||||||
|
|
||||||
|
def run_action(br, action):
|
||||||
|
tool = action["tool"]
|
||||||
|
args = action.get("args") or {}
|
||||||
|
if tool == "battle":
|
||||||
|
rounds = max(1, min(int(args.get("rounds") or 6), 20))
|
||||||
|
done = 0
|
||||||
|
for _ in range(rounds):
|
||||||
|
br.call("keypress", {"key": "p"})
|
||||||
|
time.sleep(0.6)
|
||||||
|
br.call("keypress", {"key": "enter"})
|
||||||
|
time.sleep(1.0)
|
||||||
|
done += 1
|
||||||
|
return {"did": "battle", "rounds": done}
|
||||||
|
if tool == "keys":
|
||||||
|
keys = [k for k in (args.get("keys") or []) if isinstance(k, str)][:20]
|
||||||
|
delay = float(args.get("delay") or 0.8)
|
||||||
|
for k in keys:
|
||||||
|
br.call("keypress", {"key": k})
|
||||||
|
time.sleep(delay)
|
||||||
|
return {"did": "keys", "keys": keys}
|
||||||
|
if tool == "battle_until_text":
|
||||||
|
return {"did": "noop"}
|
||||||
|
res = br.call(tool, args)
|
||||||
|
res["did"] = tool
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cfg = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8"))
|
||||||
|
if cfg.get('decisionEngine') == 'jev':
|
||||||
|
from jev_mirror_agent import main as jev_main
|
||||||
|
return jev_main()
|
||||||
|
log_path = Path(cfg["logFile"])
|
||||||
|
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
recent = []
|
||||||
|
br = Bridge()
|
||||||
|
step = 0
|
||||||
|
last_sig = None
|
||||||
|
stuck = 0
|
||||||
|
model_errs = 0
|
||||||
|
while step < int(cfg["steps"]):
|
||||||
|
step += 1
|
||||||
|
if STOP_FILE.exists():
|
||||||
|
print(json.dumps({"status": "stopped-by-file", "step": step}, ensure_ascii=False))
|
||||||
|
return
|
||||||
|
t0 = time.time()
|
||||||
|
state = br.call("get_state")
|
||||||
|
if not state.get("ok"):
|
||||||
|
print(json.dumps({"step": step, "status": "state-error", "state": state}, ensure_ascii=False))
|
||||||
|
time.sleep(2)
|
||||||
|
continue
|
||||||
|
items = state.get("items") or []
|
||||||
|
shot = (state.get("screen") or {}).get("path")
|
||||||
|
|
||||||
|
# Progress watchdog: if the OCR text stops changing, the current approach
|
||||||
|
# is not reaching the game. Nudge the model, then force an escape.
|
||||||
|
sig = "|".join(it.get("text", "") for it in items)
|
||||||
|
if sig == last_sig:
|
||||||
|
stuck += 1
|
||||||
|
else:
|
||||||
|
stuck = 0
|
||||||
|
last_sig = sig
|
||||||
|
if stuck >= 4:
|
||||||
|
br.call("keypress", {"key": "esc"})
|
||||||
|
time.sleep(0.8)
|
||||||
|
rec = {"step": step, "status": "watchdog-esc", "stuck": stuck, "shot": shot,
|
||||||
|
"at": time.strftime("%Y-%m-%dT%H:%M:%S")}
|
||||||
|
log_path.open("a", encoding="utf-8").write(json.dumps(rec, ensure_ascii=False) + "\n")
|
||||||
|
print(json.dumps(rec, ensure_ascii=False))
|
||||||
|
stuck = 0
|
||||||
|
last_sig = None
|
||||||
|
continue
|
||||||
|
|
||||||
|
img = shrink(shot, cfg.get("shotDir", r"{source_root}\lc_shots")) if shot else None
|
||||||
|
if not img:
|
||||||
|
print(json.dumps({"step": step, "status": "no-image"}, ensure_ascii=False))
|
||||||
|
time.sleep(2)
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
content, reasoning = ask(cfg, img, summarize(items), recent, step, stuck >= 2)
|
||||||
|
try:
|
||||||
|
action = parse_action(content or reasoning)
|
||||||
|
except Exception:
|
||||||
|
# One stricter retry: the model sometimes answers in prose or
|
||||||
|
# spends the whole budget on reasoning.
|
||||||
|
content2, reasoning2 = ask(
|
||||||
|
cfg, img,
|
||||||
|
summarize(items) + "\n\n上一次回复没有给出 JSON。现在**只输出一行 JSON**,以 {\"tool\": 开头。",
|
||||||
|
recent, step, False)
|
||||||
|
try:
|
||||||
|
action = parse_action(content2 or reasoning2)
|
||||||
|
except Exception:
|
||||||
|
raise ValueError(f"no action JSON (raw={((content or reasoning) or '')[:200]!r})")
|
||||||
|
except Exception as e:
|
||||||
|
model_errs += 1
|
||||||
|
rec = {"step": step, "status": "model-error", "error": f"{type(e).__name__}: {e}",
|
||||||
|
"model_errs": model_errs, "shot": shot}
|
||||||
|
log_path.open("a", encoding="utf-8").write(json.dumps(rec, ensure_ascii=False) + "\n")
|
||||||
|
print(json.dumps(rec, ensure_ascii=False))
|
||||||
|
if model_errs >= 3:
|
||||||
|
# Don't stall on a flaky model: nudge the game forward so the next
|
||||||
|
# observation has new information to work with.
|
||||||
|
model_errs = 0
|
||||||
|
try:
|
||||||
|
br.call("keypress", {"key": "enter"})
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
time.sleep(1.5)
|
||||||
|
continue
|
||||||
|
model_errs = 0
|
||||||
|
try:
|
||||||
|
result = run_action(br, action)
|
||||||
|
except Exception as e:
|
||||||
|
rec = {"step": step, "status": "exec-error", "action": action,
|
||||||
|
"error": f"{type(e).__name__}: {e}", "shot": shot}
|
||||||
|
log_path.open("a", encoding="utf-8").write(json.dumps(rec, ensure_ascii=False) + "\n")
|
||||||
|
print(json.dumps(rec, ensure_ascii=False))
|
||||||
|
time.sleep(2)
|
||||||
|
continue
|
||||||
|
rec = {"step": step, "action": action, "result": result,
|
||||||
|
"ms": int((time.time() - t0) * 1000), "shot": shot,
|
||||||
|
"at": time.strftime("%Y-%m-%dT%H:%M:%S")}
|
||||||
|
log_path.open("a", encoding="utf-8").write(json.dumps(rec, ensure_ascii=False) + "\n")
|
||||||
|
print(json.dumps({"step": step, "action": json.dumps(action, ensure_ascii=False),
|
||||||
|
"did": result.get("did"), "ms": rec["ms"], "shot": shot}, ensure_ascii=False))
|
||||||
|
sys.stdout.flush()
|
||||||
|
recent.append(json.dumps(action, ensure_ascii=False))
|
||||||
|
if action.get("tool") == "done":
|
||||||
|
return
|
||||||
|
time.sleep(float(cfg.get("settle", 0.4)))
|
||||||
|
print(json.dumps({"status": "step-budget-exhausted", "step": step}, ensure_ascii=False))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# 镜牢速通:破裂黎明/黑兽纯 P
|
||||||
|
|
||||||
|
记录日期:2026-10-01;用户规则更新至 2026-10-02。
|
||||||
|
|
||||||
|
目标:尽快完成整局,按楼层推进;保留关键强化与换技能,减少无关运营。
|
||||||
|
|
||||||
|
## 开局固定配置(用户明确指定)
|
||||||
|
|
||||||
|
1. 星之恩惠选 :**起始之星、星际旅行、全面的可能性**。
|
||||||
|
2. **恩惠保持基础等级,不强化**;不要点击单项或全部强化按钮。
|
||||||
|
3. E.G.O. 饰品选**破裂**组的**荆棘套索、荧光灯**。
|
||||||
|
4. **不需要额外观测饰品**;进入额外 E.G.O. 饰品观测页面后,直接选择**拒绝饰品**。
|
||||||
|
5. **入层三级饰品选择“标准负载电池”**(简称“电池”)。
|
||||||
|
|
||||||
|
注意:不强化的是开局星之恩惠;二层的**符纸 ++**仍然必须做。
|
||||||
|
|
||||||
|
**饰品只能在商店强化**;地图饰品窗口的 +/++ 是效果预览。二层遇商店优先把成捆的符咒强化到 ++,以实际强化标识确认。
|
||||||
|
|
||||||
|
## 楼层推进顺序
|
||||||
|
|
||||||
|
**符纸的游戏内名称为“成捆的符咒”**(用户截图确认):Ⅰ级破裂饰品,图标是黑色底板上的两张折叠符纸,带红色符文和黄色纸边。按此名称与图标识别卡包奖励。
|
||||||
|
|
||||||
|
| 楼层 | 优先操作 | 有余力再做 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 1F | 优先选通关奖励含**符纸**的卡包,取得符纸;遇商店按下表换技能。 | — |
|
||||||
|
| 2F | **符纸强化到 ++**;优先选 **Hell's Chicken**,主动获取**鸡胸**以维持破裂层数;按下表换技能。 | — |
|
||||||
|
| 3F | 菲辛的换技能目标改为 **1 → 3**;原作者推荐 **Bearable** 卡包。 | 制作**快感**。 |
|
||||||
|
| 4F | 继续推进、按下表换技能。 | 补缺失的相关饰品。 |
|
||||||
|
| 5F | 优先换技能并通关,**不必专门做斩击四级饰品**。 | 顺路补高级饰品。 |
|
||||||
|
|
||||||
|
没拿到鸡胸也继续推进,**不要因此重开**。饰品与换技能竞争资源时,优先关键技能;符纸 ++ 的优先级保留。
|
||||||
|
|
||||||
|
## 技能替换速查
|
||||||
|
|
||||||
|
箭头表示“用左侧技能换成右侧技能”。
|
||||||
|
|
||||||
|
| 人格 | 1–2F | 3–5F |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 菲辛 | **1 → 2** | **1 → 3** |
|
||||||
|
| 黑兽奥 | **2 → 3** | **2 → 3** |
|
||||||
|
| 其他人格 | **1 → 3** | **1 → 3** |
|
||||||
|
|
||||||
|
看到符合上表的替换通常直接换,少做反复比较。
|
||||||
|
|
||||||
|
用户补充(2026-10-02):商店没有出战角色可替换技能时,允许刷新,**每个商店至多 4 次**。有出战角色可换时按技能表执行;达到上限即继续推进。
|
||||||
|
|
||||||
|
刷新后出现 CONNECTING 时,旧库存仍可见;必须等加载结束,禁止据旧库存再次刷新或退出。有未购买的出战角色技能替换时先完成替换,不能直接离开。快捷键一次未生效即点击当前对应按钮。
|
||||||
|
|
||||||
|
## 层末苦难
|
||||||
|
- 除必需饰品外,选择**不加敌方血量、不加防御等级**的选项。不要漏选后让系统随机分配苦难;
|
||||||
|
- 层末必须先选择苦难再直接推进,不能把此界面误当额外饰品观测而默认拒绝。
|
||||||
|
- 第五层优先“2号线”卡包;卡包刷新次数为零时允许使用卡包观测(用户补充 2026-10-02)。
|
||||||
|
|
||||||
|
## 执行原则
|
||||||
|
|
||||||
|
- 战斗循环按 **P → 回车**,直到结束;不逐回合截图分析,只在检查是否已结算时查看画面。
|
||||||
|
- **事件判定先点击 SKIP 跳过对话**,再选择事件选项、罪人或进行判定;SKIP 可用时不提前处理判定。其他对话也优先 SKIP,可用回车加快。
|
||||||
|
- 事件对话跳过后,继续按回车直到出现罪人选择界面;判定结果出现后快速连按回车结束事件。固定推进不逐按钮请求模型。
|
||||||
|
- **回车**可触发对话及其他按钮;有明确的确认、继续按钮时,优先使用快捷键。
|
||||||
|
- 路线优先选择可直接结束的事件、商店等非战斗节点,避免为小奖励增加复杂判定。
|
||||||
|
- 商店保留符纸 ++、关键维持饰品和快速换技能;略过无关采购、合成与反复比较。
|
||||||
|
- 困难镜牢与视频条件未全部核对,按当前画面修正,不能把视频用时直接套到当前局。
|
||||||
|
- 电脑操作优先使用用户安装的 limbus MCP 后台接口;只运行一个执行器,不抢前台焦点。用户要求快速执行,战斗使用有界 P+回车宏;需要选项的界面核对当前画面。
|
||||||
|
|
||||||
|
## 事件选择与可复用 skill
|
||||||
|
|
||||||
|
- 按**整局用时**选择:优先核心符咒/鸡胸,其次即时恢复、经费或直接结束;避免额外战斗、多段判定和无关奖励。大量理智损失可能拖慢后续纯 P。
|
||||||
|
- **炸鸡对决选第一项**,直接获得鸡胸与鸡翅;第三项也给鸡胸,第二项仅鸡翅。
|
||||||
|
- 当前游戏译名:鸡胸为**干巴柴涩鸡胸肉**,鸡腿为**火热多汁琵琶腿**。
|
||||||
|
- 商店符咒强化可直接选 **++**,本局一次支付 **150 经费**完成;以当前报价为准。
|
||||||
|
- 可复用 skill:[$limbus-mirror-speedrun]({skill_root}/SKILL.md)。[事件速查表]({skill_root}/references/event-choices.md)按名称查询,以当前选项文字核对编号。
|
||||||
|
|
||||||
|
## 游戏内快捷键(用户操作指南截图)
|
||||||
|
|
||||||
|
- **P → Enter**:胜率/伤害按键后开始战斗/行动。
|
||||||
|
- **Enter/Space**:弹窗确认、故事跳对话、提取跳动画、选项事件加载下一段文本;对话也可直接点 SKIP。
|
||||||
|
- **战斗 Space=暂停/继续**,不加入战斗循环。
|
||||||
|
- **关卡/商店:方向选中后直接按 Enter 进入,无需再次确认**(用户补充);执行器将选方向+回车合并为一个动作。
|
||||||
|
- 进入关卡后的编队界面继续按 **Enter** 开战,不再次检查编队;沿用原队伍。
|
||||||
|
- **快捷键未生效时立即改用鼠标点按钮**,不反复尝试(用户补充)。
|
||||||
|
- **地图 ↑/↓/→ 或 W/S/D**:移至下个节点后直接回车进入;**←/A**:取消节点选择;**Q/E**:地图左右平移。
|
||||||
|
- 战斗 **方向键/WASD** 移动视角,**滚轮/Q/E** 缩放,**Tab** 显示拼点箭头。
|
||||||
|
- **F1** 打开操作指南;**Esc** 随界面关闭弹窗、取消、返回或退出。完整表见 [快捷键速查]({skill_root}/references/shortcuts.md)。
|
||||||
|
|
||||||
|
## Jev 接入(用户授权)
|
||||||
|
|
||||||
|
- 已实测 `jev-1.13-free` 决策接口返回 HTTP 200,耗时约 1.3–1.5 秒;端点为 `https://opencode.ai/zen/v1/systemone`。
|
||||||
|
- 客户端:[jev_decision_client.mjs]({source_root}/jev_decision_client.mjs)。密钥仅在运行时内存或环境变量中,不写入文件。
|
||||||
|
- 用户更新(2026-10-02):固定场景、路线与常规动作均交给 Jev;仅在它返回 `requires_analysis` 或具体接口故障时由主助手排查。执行器只执行已核对的候选动作,不运行模型任意代码。
|
||||||
|
- 最新战斗指令:开战后仅 P+回车循环到结算,不逐批请求 Jev。批次末只识别是否已结束,战斗特写没有 OCR 文字也继续;结算后交回 Jev。
|
||||||
|
|
||||||
|
## 来源
|
||||||
|
|
||||||
|
- B 站 UP 绅士丶蚂蚱:[破裂黎明纯 P 周回](https://www.bilibili.com/video/BV1exaV6yELm/)。楼层规划采用其换技能优先策略。
|
||||||
|
- 原作者 Cabric:[黎明黑兽五层攻略](https://www.youtube.com/watch?v=h5wFVUd2X2c)。卡包、配队与机制补充来自原攻略。
|
||||||
|
- [边狱公司 Wiki:探索事件](https://limbuscompany.huijiwiki.com/wiki/%E6%8E%A2%E7%B4%A2%E4%BA%8B%E4%BB%B6)。事件结果于 2026-10-01 核对,速通排序为针对当前纯 P 流程的判断。
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest import mock
|
||||||
|
import jev_mirror_agent as agent
|
||||||
|
|
||||||
|
|
||||||
|
class SceneRegressionTest(unittest.TestCase):
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_event_dialog_skip_precedes_judgement_and_options(self, _enabled):
|
||||||
|
state = {'items': [{'text': text, 'x': 1200, 'y': 400, 'w': 120, 'h': 40, 'score': 1.0}
|
||||||
|
for text in ('SKIP', '进行判定', '选项', '侧耳倾听')]}
|
||||||
|
options = agent.candidates(state, previous_battle=True)
|
||||||
|
self.assertEqual(set(options), {'wait', 'requires_analysis', 'skip_dialog'})
|
||||||
|
self.assertEqual(options['skip_dialog']['action'],
|
||||||
|
{'tool': 'click', 'args': {'x': 1260, 'y': 420}})
|
||||||
|
|
||||||
|
def test_floor_three_sinclair_cannot_choose_first_floor_swap(self):
|
||||||
|
state = {'floor': 3, 'items': [
|
||||||
|
{'text': '当前持有技能', 'x': 900, 'y': 160, 'w': 100, 'h': 30},
|
||||||
|
{'text': '替换辛克莱的技能', 'x': 400, 'y': 180, 'w': 300, 'h': 40}]}
|
||||||
|
for x, first, second in ((543, 'SKILL1', 'SKILL2'), (1033, 'SKILL2', 'SKILL3'),
|
||||||
|
(1520, 'SKILL1', 'SKILL3')):
|
||||||
|
state['items'].extend({'text': label, 'x': x, 'y': y, 'w': 106, 'h': 42}
|
||||||
|
for label, y in ((first, 360), (second, 579)))
|
||||||
|
options = agent.candidates(state)
|
||||||
|
self.assertIn('skill_swap_3', options)
|
||||||
|
self.assertNotIn('skill_swap_1', options)
|
||||||
|
self.assertNotIn('skill_swap_2', options)
|
||||||
|
state['floor'] = 2
|
||||||
|
options = agent.candidates(state)
|
||||||
|
self.assertIn('skill_swap_1', options)
|
||||||
|
self.assertNotIn('skill_swap_3', options)
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_sold_swap_is_not_offered_again(self, _enabled):
|
||||||
|
state = {'items': [
|
||||||
|
{'text': '商店', 'x': 343, 'y': 162, 'w': 86, 'h': 50},
|
||||||
|
{'text': '刷新', 'x': 1496, 'y': 167, 'w': 54, 'h': 33},
|
||||||
|
{'text': '替换辛克莱的技能', 'x': 848, 'y': 499, 'w': 179, 'h': 28},
|
||||||
|
{'text': '已购买', 'x': 897, 'y': 326, 'w': 82, 'h': 34}]}
|
||||||
|
options = agent.candidates(state)
|
||||||
|
self.assertNotIn('swap_2', options)
|
||||||
|
self.assertIn('shop_refresh', options)
|
||||||
|
|
||||||
|
def test_real_green_shop_node_is_not_omitted(self):
|
||||||
|
screenshot = Path(r'{runtime_root}\shots\shot_20261002_123920_523.png')
|
||||||
|
if not screenshot.exists():
|
||||||
|
self.skipTest('local game fixture unavailable')
|
||||||
|
options = agent.map_candidates({'screen': {'path': str(screenshot)}})
|
||||||
|
self.assertIn('route_w', options)
|
||||||
|
self.assertIn('商店', options['route_w']['description'])
|
||||||
|
|
||||||
|
@mock.patch.object(agent.time, 'sleep')
|
||||||
|
def test_battle_macro_continues_through_empty_ocr_and_stops_at_reward(self, _sleep):
|
||||||
|
bridge = mock.Mock()
|
||||||
|
states = iter([{'ok': True, 'items': []},
|
||||||
|
{'ok': True, 'items': [{'text': '选择遭遇战奖励卡'}]}])
|
||||||
|
bridge.call.side_effect = lambda tool, args=None: next(states) if tool == 'get_state' else {'ok': True}
|
||||||
|
with mock.patch.object(agent, 'STOP_FILE') as stop:
|
||||||
|
stop.exists.return_value = False
|
||||||
|
result = agent.execute(bridge, {'tool': 'battle', 'args': {}})
|
||||||
|
self.assertEqual(result['pairs'], 4)
|
||||||
|
self.assertTrue(result['terminal'])
|
||||||
|
keys = [call.args[1]['key'] for call in bridge.call.call_args_list if call.args[0] == 'keypress']
|
||||||
|
self.assertEqual(keys, ['p', 'enter']*4)
|
||||||
|
|
||||||
|
@mock.patch.object(agent.time, 'sleep')
|
||||||
|
def test_route_enters_without_a_second_snapshot(self, _sleep):
|
||||||
|
bridge = mock.Mock()
|
||||||
|
bridge.call.return_value = {'ok': True}
|
||||||
|
agent.execute(bridge, {'tool': 'route', 'args': {'key': 'w'}})
|
||||||
|
self.assertEqual(bridge.call.call_args_list,
|
||||||
|
[mock.call('keypress', {'key': 'w'}),
|
||||||
|
mock.call('keypress', {'key': 'enter'}),
|
||||||
|
mock.call('keypress', {'key': 'enter'})])
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_battle_entry_uses_enter_without_party_changes(self, _enabled):
|
||||||
|
state = {'items': [{'text': '开始战斗', 'x': 100, 'y': 100, 'w': 100, 'h': 40}]}
|
||||||
|
self.assertEqual(agent.candidates(state)['button_0']['action'],
|
||||||
|
{'tool': 'keypress', 'args': {'key': 'enter'}})
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_shop_refresh_is_capped_and_only_for_missing_party_swap(self, _enabled):
|
||||||
|
state = {'items': [{'text': text, 'x': 100, 'y': 100, 'w': 100, 'h': 40}
|
||||||
|
for text in ('商店', '刷新', '替换以实玛利的技能')]}
|
||||||
|
self.assertIn('shop_refresh', agent.candidates(state, refresh_used=3))
|
||||||
|
self.assertNotIn('shop_refresh', agent.candidates(state, refresh_used=4))
|
||||||
|
state['items'][-1]['text'] = '替换辛克莱的技能'
|
||||||
|
self.assertNotIn('shop_refresh', agent.candidates(state))
|
||||||
|
self.assertIn('swap_2', agent.candidates(state))
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_confirmation_blocks_background_leave(self, _enabled):
|
||||||
|
items = [{'text': text, 'x': x, 'y': y, 'w': 80, 'h': 40}
|
||||||
|
for text, x, y in [('要离开商店吗?', 700, 400),
|
||||||
|
('取消', 700, 600), ('确认', 1100, 600),
|
||||||
|
('离开', 1650, 950)]]
|
||||||
|
options = agent.candidates({'items': items}, previous_battle=True)
|
||||||
|
self.assertEqual(set(options), {'wait', 'requires_analysis', 'modal_confirm'})
|
||||||
|
self.assertEqual(options['modal_confirm']['action'],
|
||||||
|
{'tool': 'click', 'args': {'x': 1140, 'y': 620}})
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_nested_reward_confirmation_excludes_background_cards(self, _enabled):
|
||||||
|
state = {'items': [{'text': t, 'x': x, 'y': y, 'w': 80, 'h': 40}
|
||||||
|
for t,x,y in [('选择遭遇战奖励卡',600,178), ('可选择0/1',1383,178),
|
||||||
|
('要在不选择奖励的情况下继续吗?',742,489),
|
||||||
|
('×取消',747,678),
|
||||||
|
('确认',1102,679), ('确认',1197,776)]]}
|
||||||
|
options = agent.candidates(state)
|
||||||
|
self.assertEqual(set(options), {'wait', 'requires_analysis', 'modal_confirm'})
|
||||||
|
self.assertEqual(options['modal_confirm']['action']['args']['y'], 699)
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_event_result_uses_visible_continue_button(self, _enabled):
|
||||||
|
state = {'items':[{'text':t,'x':x,'y':y,'w':80,'h':40}
|
||||||
|
for t,x,y in [('结果',1088,162),('继续',1639,936),
|
||||||
|
('是在感谢我们吗?',112,707)]]}
|
||||||
|
options = agent.candidates(state)
|
||||||
|
self.assertEqual(options['event_finish']['action'],
|
||||||
|
{'tool':'click','args':{'x':1679,'y':956}})
|
||||||
|
|
||||||
|
def test_loading_offers_wait_and_never_auto_escalates(self):
|
||||||
|
state = {'items': [{'text': 'CONNECTING', 'x': 100, 'y': 10, 'w': 100, 'h': 30}]}
|
||||||
|
options = agent.candidates(state)
|
||||||
|
self.assertEqual(set(options), {'wait', 'requires_analysis'})
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_shop_loading_blocks_stale_stock_refresh_and_leave(self, _enabled):
|
||||||
|
state = {'items': [{'text': text, 'x': 100, 'y': 100, 'w': 100, 'h': 40}
|
||||||
|
for text in ('商店', '刷新', '替换辛克莱的技能', '离开', 'CONNECTING')]}
|
||||||
|
self.assertEqual(set(agent.candidates(state)), {'wait', 'requires_analysis'})
|
||||||
|
|
||||||
|
@mock.patch.object(agent, 'button_enabled', return_value=True)
|
||||||
|
def test_shop_cannot_leave_with_party_swap_or_remaining_refresh(self, _enabled):
|
||||||
|
state = {'items': [{'text': text, 'x': 100, 'y': 100, 'w': 100, 'h': 40}
|
||||||
|
for text in ('商店', '刷新', '替换奥提斯的技能', '离开')]}
|
||||||
|
self.assertNotIn('button_3', agent.candidates(state, refresh_used=4))
|
||||||
|
state['items'][2]['text'] = '替换李箱的技能'
|
||||||
|
self.assertNotIn('button_3', agent.candidates(state, refresh_used=3))
|
||||||
|
self.assertIn('button_3', agent.candidates(state, refresh_used=4))
|
||||||
|
|
||||||
|
def test_disabled_selection_is_not_clickable_candidate(self):
|
||||||
|
state = {'items': [{'text': '选择', 'x': 100, 'y': 10, 'w': 80, 'h': 40}]}
|
||||||
|
self.assertFalse(any(o['action']['tool'] == 'click_text' for o in agent.candidates(state).values()))
|
||||||
|
|
||||||
|
def test_battle_cinematic_keeps_macro_available(self):
|
||||||
|
state = {'items': [{'text': '破裂+5', 'x': 100, 'y': 10, 'w': 80, 'h': 40}]}
|
||||||
|
self.assertIn('battle', agent.candidates(state, previous_battle=True))
|
||||||
|
|
||||||
|
def test_reward_stops_battle_candidates(self):
|
||||||
|
state = {'items': [{'text': text, 'x': 100, 'y': 10, 'w': 80, 'h': 40}
|
||||||
|
for text in ('获得E.G.O饰品', '造成更多伤害')]}
|
||||||
|
self.assertNotIn('battle', agent.candidates(state, previous_battle=True))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user