Complete own-item attribute lock selection and tooltip flow

This commit is contained in:
shen
2026-10-18 16:28:16 -07:00
parent 5decc93798
commit 95f1c30be2
13 changed files with 342 additions and 4 deletions
+38
View File
@@ -0,0 +1,38 @@
# AVA2 属性锁定
2026-10-18,feature/ava2-unlock;只部署 sbtest。
## 来源与流程
AVA2 `char_item.cpp` 的 ENABLE_LOCK_ATTR 分支规定:右键使用 50348/50349 进入 quest 选择材料 socket 0 的 1~5 序号,再拖到未穿戴装备;最多两组锁定,普通/技能伤害的 addon 属性作为一组。`uitooltip.py` 用黄色 `<<属性>>` 显示锁定,材料提示已选择的序号。
完整 FILES+SRC 归档没有这两件材料的 use 任务,服务端 proto 也未含其行;材料原型在原客户端 DumpProto 定义里。`prepare.py` 采用与完整语言包相同的回退读取,两行输出已逐字节核对一致;`attr_lock.quest` 是根据原 C++ 契约补的中文选择任务,不能称为从 AVA2 归档复制的原任务。保留现有独立 `mt_item_attr_lock` 表,不占用七条属性或物品孔。
## 生成和安装
```sh
python3 tools/server/ava2-attr-lock/prepare.py --ava ../AVA2 \
--reader ../metin2-server/src/server/db/src/ProtoReader.cpp --output build/ava2-attr-lock
```
上传该目录及 `tools/server/ava2-items/install_items.py` 到测试服。先退出 QA 客户端并停止 sbtest;两行原型通过公共安装器合并 conf 和独立 db,禁止整体覆盖表:
```sh
python3.9 install_items.py /usr/metin2/server/sbtest items-server.tsv FRESH_PROTO_BACKUP
python3.9 install_quest.py /usr/metin2/server/sbtest FRESH_QUEST_BACKUP
sh /usr/metin2/server/sbtest/tools/restart.sh
```
`install_quest.py` 校验独立目录和测试端口已停止,在备份内编译,成功后只替换 attr_lock 的对象、任务名单和函数白名单;重装保留旧对象和新对象清单用于回退。旧物品 flags 无需改变,使用时显式登记两个 quest vnum。
服务端 Lua `item.select_attr_lock` 在选择返回后重新按物品 ID 查找并校验所有者、背包、交易/装备/锁定及角色状态;物品移动给别人或销毁不会写到原指针。选择不消耗材料。拖放仍走 PortAttrLockUse,只有 SQL 保存成功后消耗一张;SQL 读取失败也拒绝本次操作。锁定路径放在时装/护符专用洗练分支之前,避免材料被错误的类型分支拦截。
## 提示同步与验证
客户端 `mt_attr_lock` 只读查询自己背包、装备及闲置 SWITCHBOT 物品的掩码。请求携带序号,回复时核对当前物品、属性与孔快照;物品移动、过期回复、非法掩码及断线均不沿用旧状态。可见提示每 1.25 秒复查,服务端限频。活动中的自动洗练保留原动态提示行为。
真实 QA1017 联机已验证:选第4条将材料 socket 0 写为4,锁定符4→3,数据库掩码8,提示为黄色 `<<力量:+4>>`;真实洗练卷20→19,其他属性变化而第4条保持 (5,4);重复锁定拒绝且锁定符仍为3。证据在客户端 `build/parity-acceptance-20261018/attr-lock-*`。测试 db/auth/game 全部冷重启后再启动客户端,读回掩码8、材料序号4和第4条 (5,4);取消选择不改序号也不消耗,解锁符4→3。任务安装器重新编译、发布所得对象与前一版逐字节一致。
测试:客户端 `tests/wiki/test_attr_lock_ui.py` 覆盖高亮、addon 成对显示、物品变化和迟到回复、异常回复、旧界面回退和断线清理;服务端 `tests/features/test_attr_lock_use.py` 直接运行选择与支付函数,原 `test_attr_lock.py` 验证实际洗练保存和组数规则。
边界:独立存储不能直接随原七条属性包传给其他玩家;交易、他人装备和商店里的锁定高亮尚未接入。Android APK 编译并保留数据安装通过,物理拖放/触控尚未验收。一次在测试驱动 OnUpdate 内重新操作登录界面的重连发生窗口遍历崩溃,已记录到 audit/evidence/2026-10-18-window-lifecycle-qa.md;冷启动持久化通过,不将该结果计作进程内重连验收。正式服未发布。
@@ -0,0 +1,18 @@
quest attr_lock begin
state start begin
when 50348.use or 50349.use begin
local uid = item.get_id()
say_title("属性锁定")
say("选择要锁定或解锁的普通属性序号。")
say("选好后,将这张符拖到未穿戴的装备上。")
say("锁定需要五条普通属性,最多锁定两组。")
local choice = select("第1条属性", "第2条属性", "第3条属性", "第4条属性", "第5条属性", "取消")
if choice == 6 then return end
if item.select_attr_lock(choice, uid) then
syschat("属性序号已保存,请将符拖到对应装备上。")
else
syschat("材料或角色状态已变化,请重新使用。")
end
end
end
end
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""Install only the lock selector in a stopped sbtest farm; compile before publishing."""
import argparse,subprocess,shutil,json
from pathlib import Path
HERE=Path(__file__).resolve().parent
p=argparse.ArgumentParser(description=__doc__);p.add_argument('sbtest',type=Path);p.add_argument('backup',type=Path);a=p.parse_args()
sb=a.sbtest.resolve();q=sb/'share/locale/newcibn/quest';back=a.backup
if sb!=Path('/usr/metin2/server/sbtest') or not str(q.resolve()).startswith(str(sb)+'/'):raise SystemExit('requires isolated sbtest quest directory')
ports=subprocess.check_output(['sockstat','-4','-l']).decode()
if any(':'+port+' ' in ports for port in ('13040','15040')):raise SystemExit('stop sbtest game and db first')
if back.exists():raise SystemExit('use a fresh backup directory')
back.mkdir(parents=True);stage=back/'stage';stage.mkdir()
raw=(HERE/'attr_lock.quest').read_text()
if any(ch.encode('gbk')[-1:]==b'\\' for ch in raw if ord(ch)>127):raise SystemExit('GBK trail backslash in quest text')
(stage/'attr_lock.quest').write_bytes(raw.encode('gbk'))
functions=(q/'quest_functions').read_bytes().rstrip()+b'\n'
if b'item.select_attr_lock' not in functions.splitlines():functions+=b'item.select_attr_lock\n'
(stage/'quest_functions').write_bytes(functions)
with (back/'qc.log').open('wb') as log:subprocess.run([str(q/'qc'),'attr_lock.quest'],cwd=stage,stdout=log,stderr=subprocess.STDOUT,check=True)
if not (stage/'object/state/attr_lock').is_file():raise SystemExit('no compiled state')
for name in ('quest_functions','locale_list','attr_lock.quest'):
if (q/name).exists():shutil.copy2(q/name,back/name)
for path in (q/'object').rglob('*'):
if path.is_file() and (path.name.startswith('attr_lock.') or path.relative_to(q/'object').as_posix()=='state/attr_lock'):
dest=back/'object'/path.relative_to(q/'object');dest.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,dest);path.unlink()
manifest=[]
for path in (stage/'object').rglob('*'):
if path.is_file():
rel=path.relative_to(stage/'object');dest=q/'object'/rel;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,dest);manifest.append(rel.as_posix())
shutil.copy2(stage/'attr_lock.quest',q/'attr_lock.quest');(q/'quest_functions').write_bytes(functions)
listing=(q/'locale_list').read_bytes().rstrip()+b'\n'
if b'attr_lock.quest' not in listing.splitlines():listing+=b'attr_lock.quest\n'
(q/'locale_list').write_bytes(listing);(back/'new-objects.json').write_text(json.dumps(manifest,indent=2)+'\n')
print('lock selector installed; restart sbtest to load; backup:',back)
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
"""Stage only the two original AVA2 lock materials; the shared locale builder provides their client assets."""
import argparse,hashlib,importlib.util,json,shutil
from pathlib import Path
HERE=Path(__file__).resolve().parent
spec=importlib.util.spec_from_file_location('ava2_items',HERE.parent/'ava2-items/make_items.py')
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
def prepare(ava,reader,out):
raw=m.server_proto(ava,'item_proto.txt');ids={50348:'属性锁定符',50349:'属性解锁符'}
source={int(c[0]):[x.decode('latin1') for x in c] for line in raw.splitlines() if len(c:=line.split(b'\t'))>=33 and c[0].isdigit() and int(c[0]) in ids}
dump=ava/'3. Source BIN/Tools/DumpProto/Release/item_proto.txt'
if not dump.is_file():dump=ava.parent/'3. Source BIN/Tools/DumpProto/Release/item_proto.txt'
for line in dump.read_bytes().splitlines():
c=line.split(b'\t')
if c[0].isdigit() and int(c[0]) in ids and int(c[0]) not in source:source[int(c[0])]=[x.decode('latin1') for x in c]
if set(source)!=set(ids):raise ValueError('AVA2 lock materials are missing')
out.mkdir(parents=True,exist_ok=True);rows=[];E=m.enums(reader)
for v,c in sorted(source.items()):
s,n,kept=m.convert(c,E,set(source))
if not kept or s[2:4]!=['ITEM_USE','USE_CHANGE_ATTRIBUTE']:raise ValueError('AVA2 lock material type changed')
s[1]=ids[v];rows.append('\t'.join(s).encode('gbk'))
(out/'items-server.tsv').write_bytes(b'\n'.join(rows)+b'\n')
shutil.copy2(HERE/'attr_lock.quest',out/'attr_lock.quest')
shutil.copy2(HERE/'install_quest.py',out/'install_quest.py')
(out/'source.json').write_text(json.dumps({'server_proto_sha256':hashlib.sha256(raw).hexdigest(),'client_proto_sha256':hashlib.sha256(dump.read_bytes()).hexdigest(),'items':ids},ensure_ascii=False,indent=2)+'\n')
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--ava',type=Path,required=True);p.add_argument('--reader',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args();prepare(a.ava,a.reader,a.output)