Fix background MCP input and add mirror dungeon feedback records
This commit is contained in:
+13
-1
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""MCP (JSON-RPC 2.0) 处理: 与传输方式无关, handle(msg) -> 响应 dict 或 None(通知)。"""
|
"""MCP (JSON-RPC 2.0) 处理: 与传输方式无关, handle(msg) -> 响应 dict 或 None(通知)。"""
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ from .engine import find_hits
|
|||||||
|
|
||||||
MAX_WAIT = 300.0
|
MAX_WAIT = 300.0
|
||||||
WAIT_INTERVAL = 1.0
|
WAIT_INTERVAL = 1.0
|
||||||
INPUT_TOOLS = {'click', 'click_text', 'click_image', 'keypress', 'type_text'}
|
INPUT_TOOLS = {'click', 'click_text', 'click_image', 'keypress', 'type_text', 'drag'}
|
||||||
TASK_TOOLS = {'run_task', 'task_status', 'stop_task'}
|
TASK_TOOLS = {'run_task', 'task_status', 'stop_task'}
|
||||||
|
|
||||||
|
|
||||||
@@ -46,6 +47,10 @@ TOOLS = [
|
|||||||
'inputSchema': _obj({'x': _NUM, 'y': _NUM, 'times': {'type': 'number', 'default': 1}}, ['x', 'y'])},
|
'inputSchema': _obj({'x': _NUM, 'y': _NUM, 'times': {'type': 'number', 'default': 1}}, ['x', 'y'])},
|
||||||
{'name': 'keypress', 'description': '按一次键: a-z 0-9 enter esc space tab shift ctrl alt up down left right',
|
{'name': 'keypress', 'description': '按一次键: a-z 0-9 enter esc space tab shift ctrl alt up down left right',
|
||||||
'inputSchema': _obj({'key': _STR}, ['key'])},
|
'inputSchema': _obj({'key': _STR}, ['key'])},
|
||||||
|
{'name': 'drag', 'description': '在游戏客户区保持左键按下并缓慢拖动,适用于卡包下拉;duration 是移动秒数,0.1–10,默认 1。先 get_state 核对坐标',
|
||||||
|
'inputSchema': _obj({'from_x': _NUM, 'from_y': _NUM, 'to_x': _NUM, 'to_y': _NUM,
|
||||||
|
'duration': {'type': 'number', 'default': 1.0, 'minimum': 0.1, 'maximum': 10}},
|
||||||
|
['from_x', 'from_y', 'to_x', 'to_y'])},
|
||||||
{'name': 'type_text', 'description': '向游戏窗口输入文本', 'inputSchema': _obj({'text': _STR}, ['text'])},
|
{'name': 'type_text', 'description': '向游戏窗口输入文本', 'inputSchema': _obj({'text': _STR}, ['text'])},
|
||||||
{'name': 'run_task', 'description': (
|
{'name': 'run_task', 'description': (
|
||||||
'后台运行 AALC 现成的完整任务流程(会自动启动游戏、处理战斗/掉线重试)。立即返回, 用 task_status 看进度。'
|
'后台运行 AALC 现成的完整任务流程(会自动启动游戏、处理战斗/掉线重试)。立即返回, 用 task_status 看进度。'
|
||||||
@@ -157,6 +162,13 @@ class Server:
|
|||||||
if name == 'keypress':
|
if name == 'keypress':
|
||||||
e.keypress(str(a['key']))
|
e.keypress(str(a['key']))
|
||||||
return {'ok': True, 'key': str(a['key'])}
|
return {'ok': True, 'key': str(a['key'])}
|
||||||
|
if name == 'drag':
|
||||||
|
duration = float(a.get('duration', 1.0))
|
||||||
|
if not math.isfinite(duration) or not 0.1 <= duration <= 10:
|
||||||
|
raise ValueError('duration must be between 0.1 and 10 seconds')
|
||||||
|
points = [int(a[k]) for k in ('from_x', 'from_y', 'to_x', 'to_y')]
|
||||||
|
e.drag(*points, duration=duration)
|
||||||
|
return {'ok': True, 'from': points[:2], 'to': points[2:], 'duration': duration}
|
||||||
if name == 'type_text':
|
if name == 'type_text':
|
||||||
e.type_text(str(a['text']))
|
e.type_text(str(a['text']))
|
||||||
return {'ok': True, 'typed': str(a['text'])}
|
return {'ok': True, 'typed': str(a['text'])}
|
||||||
|
|||||||
Reference in New Issue
Block a user