feat: align travel ring menus and validate destinations against 203 maps

This commit is contained in:
shen
2026-10-17 16:40:54 -07:00
parent 0b828387aa
commit 9fbeaeb7a2
7 changed files with 2390 additions and 1884 deletions
+89 -88
View File
@@ -1,5 +1,5 @@
# coding: utf-8
"""Generate the quest from the audited server map catalog (Python 3)."""
"""Generate AVA2-style teleporter quest from maps.json (Python 3)."""
import json
from pathlib import Path
@@ -7,93 +7,94 @@ ROOT = Path(__file__).resolve().parent
def generate():
catalog = json.loads((ROOT / 'maps.json').read_text(encoding='utf-8'))
def quote(value):
return json.dumps(value, ensure_ascii=False)
lines = ['-- Generated by generate.py from maps.json. Do not edit by hand.',
'-- UTF-8 source; install.sh compiles GBK for the 203 server.',
'quest ring_warp begin', ' state start begin',
' function destinations()', ' return {']
for category in catalog['categories']:
lines.append(' {name = %s, maps = {' % quote(category['name']))
for m in category['maps']:
lines.append(' {id = %d, name = %s, x = %d, y = %d, mode = %s, note = %s},' %
(m['id'], quote(m['name']), m['target'][1], m['target'][2], quote(m['mode']), quote(m['note'])))
lines.append(' }},')
lines.extend([' }', ' end'])
lines.append(''' when 10031.sig_use begin
local categories = ring_warp.destinations()
local category_options = {}
for i = 1, table.getn(categories) do
table.insert(category_options, categories[i].name)
end
table.insert(category_options, "关闭")
while true do
say_title("移动戒指")
say("请选择地图分类:")
local category = select_table(category_options)
if category == table.getn(category_options) then return end
local maps = categories[category].maps
local page = 1
local browsing = true
while browsing do
local first = (page - 1) * 5 + 1
local last = math.min(first + 4, table.getn(maps))
local options = {}
for i = first, last do
local label = maps[i].name
if maps[i].mode == "entrance" then label = label .. "(入口)" end
table.insert(options, label)
end
local count = table.getn(options)
local previous = 0
local following = 0
if page > 1 then
table.insert(options, "上一页")
previous = table.getn(options)
end
if last < table.getn(maps) then
table.insert(options, "下一页")
following = table.getn(options)
end
table.insert(options, "返回分类")
say_title(categories[category].name)
say("第 " .. page .. " 页 / 共 " .. math.ceil(table.getn(maps) / 5) .. " 页")
local choice = select_table(options)
if choice == table.getn(options) then
browsing = false
elseif previous > 0 and choice == previous then
page = page - 1
elseif following > 0 and choice == following then
page = page + 1
elseif choice >= 1 and choice <= count then
local destination = maps[first + choice - 1]
say_title(destination.name)
say("地图编号:" .. destination.id)
if destination.mode == "gm" and not pc.is_gm() then
say(destination.note)
wait()
elseif destination.mode == "event" then
say(destination.note)
wait()
else
if destination.mode == "entrance" then say(destination.note) end
if destination.mode == "gm" then say("管理员专用测试地图。") end
if select("传送", "返回列表") == 1 then
if not pc.can_warp() then
say("当前无法传送,请结束交易或其他操作后再试。")
return
end
pc.warp(destination.x, destination.y)
return
end
end
end
end
end
end
end
end''')
result = '\n'.join(lines) + '\n'
def quote(s):
return json.dumps(s, ensure_ascii=False)
lines = [
'-- Generated by generate.py from maps.json. Do not edit by hand.',
'-- UTF-8 source; install.sh compiles GBK for the 203 server.',
'quest ring_warp begin',
' state start begin',
' function destinations()',
' return {'
]
for c in catalog['categories']:
lines.append(' {name = %s, ' % quote(c['name']))
if 'min_level' in c:
lines[-1] += 'min_level = %d, ' % c['min_level']
if 'destinations' in c:
lines.append(' destinations = {')
for d in c['destinations']:
lines.append(' {name = %s, x = %d, y = %d},' % (quote(d['name']), d['x'], d['y']))
lines.append(' }},')
elif 'subgroups' in c:
lines.append(' subgroups = {')
for sg in c['subgroups']:
lines.append(' {name = %s, destinations = {' % quote(sg['name']))
for d in sg['destinations']:
lines.append(' {name = %s, x = %d, y = %d},' % (quote(d['name']), d['x'], d['y']))
lines.append(' }},')
lines.append(' }},')
lines.extend([
' }',
' end',
' when 10031.sig_use or 70058.use or 76042.use begin',
' if not pc.can_warp() then',
' say("当前状态无法传送,请结束交易、战斗或其他操作后再试。")',
' return',
' end',
' local s = select('
])
cat_names = [quote(c['name']) for c in catalog['categories']] + [quote('关闭')]
lines.append(' ' + ', '.join(cat_names))
lines.append(' )')
for idx, c in enumerate(catalog['categories'], 1):
if_stmt = 'if' if idx == 1 else 'elseif'
lines.append(' %s s == %d then' % (if_stmt, idx))
if 'min_level' in c:
lines.extend([
' if pc.get_level() < %d then' % c['min_level'],
' say("")',
' say(%s)' % quote(c.get('level_message', '等级不足!')),
' say("")',
' else'
])
indent = ' '
else:
indent = ' '
var_name = 'sub_%d' % idx
if 'destinations' in c:
d_names = [quote(d['name']) for d in c['destinations']] + [quote('关闭')]
lines.append(indent + 'local %s = select(%s)' % (var_name, ', '.join(d_names)))
for d_idx, d in enumerate(c['destinations'], 1):
sub_if = 'if' if d_idx == 1 else 'elseif'
lines.append(indent + '%s %s == %d then if not pc.can_warp() then say("当前状态无法传送,请稍后重试。") return end pc.warp(%d, %d) setskin(NOWINDOW)' % (sub_if, var_name, d_idx, d['x'], d['y']))
lines.append(indent + 'end')
elif 'subgroups' in c:
sg_names = [quote(sg['name']) for sg in c['subgroups']] + [quote('关闭')]
lines.append(indent + 'local %s = select(%s)' % (var_name, ', '.join(sg_names)))
for sg_idx, sg in enumerate(c['subgroups'], 1):
sg_if = 'if' if sg_idx == 1 else 'elseif'
lines.append(indent + '%s %s == %d then' % (sg_if, var_name, sg_idx))
sub_var = 'sub_%d_%d' % (idx, sg_idx)
d_names = [quote(d['name']) for d in sg['destinations']] + [quote('关闭')]
lines.append(indent + ' local %s = select(%s)' % (sub_var, ', '.join(d_names)))
for d_idx, d in enumerate(sg['destinations'], 1):
d_if = 'if' if d_idx == 1 else 'elseif'
lines.append(indent + ' %s %s == %d then if not pc.can_warp() then say("当前状态无法传送,请稍后重试。") return end pc.warp(%d, %d) setskin(NOWINDOW)' % (d_if, sub_var, d_idx, d['x'], d['y']))
lines.append(indent + ' end')
lines.append(indent + 'end')
if 'min_level' in c:
lines.append(' end')
lines.extend([
' end',
' end',
' end',
'end'
])
result = '\n'.join(line.rstrip() for line in lines) + '\n'
encoded = result.encode('gbk')
if b'\\' in encoded:
bad = sorted({c for c in result if b'\\' in c.encode('gbk')})