From 95f1c30be2328f6719e06cf0767402b872782d35 Mon Sep 17 00:00:00 2001 From: shen <> Date: Sun, 18 Oct 2026 16:28:16 -0700 Subject: [PATCH] Complete own-item attribute lock selection and tooltip flow --- .../2026-10-18-window-lifecycle-qa.md | 7 ++ audit/history.jsonl | 1 + .../EterPythonLib/PythonWindow.cpp.json | 12 ++ .../PythonWindowManager.cpp.json | 12 ++ docs/AVA2-PARITY-PLAN.md | 6 +- docs/AVA2-SWITCHBOT.md | 10 +- src/platform/ScriptLib/AttrLockScript.inc | 118 ++++++++++++++++++ src/platform/ScriptLib/PythonBoot.cpp | 2 + tests/wiki/test_attr_lock_ui.py | 61 +++++++++ tools/server/ava2-attr-lock/README.md | 38 ++++++ tools/server/ava2-attr-lock/attr_lock.quest | 18 +++ tools/server/ava2-attr-lock/install_quest.py | 34 +++++ tools/server/ava2-attr-lock/prepare.py | 27 ++++ 13 files changed, 342 insertions(+), 4 deletions(-) create mode 100644 audit/evidence/2026-10-18-window-lifecycle-qa.md create mode 100644 src/platform/ScriptLib/AttrLockScript.inc create mode 100644 tests/wiki/test_attr_lock_ui.py create mode 100644 tools/server/ava2-attr-lock/README.md create mode 100644 tools/server/ava2-attr-lock/attr_lock.quest create mode 100644 tools/server/ava2-attr-lock/install_quest.py create mode 100644 tools/server/ava2-attr-lock/prepare.py diff --git a/audit/evidence/2026-10-18-window-lifecycle-qa.md b/audit/evidence/2026-10-18-window-lifecycle-qa.md new file mode 100644 index 00000000..e50b8244 --- /dev/null +++ b/audit/evidence/2026-10-18-window-lifecycle-qa.md @@ -0,0 +1,7 @@ +# Window lifecycle investigation during AVA2 QA + +The scripted reconnect from a QARunner.OnUpdate callback crashed in UI::CWindow::Update on macOS (DiagnosticReports/mt_native_render-2026-10-18-105610.ips). No C++ lifecycle changes have been made in this investigation. + +Read and compared CWindow::Update, Clear, DeleteChild and reserve-child removal, plus CWindowManager::DestroyWindow, NotifyDestroyWindow, reserve-deletion drain and Update against the 40250 source. Their update/deletion ordering is unchanged. The test driver invokes login-board focus/order/phase changes inside the window traversal; normal user input is dispatched outside that traversal. This is evidence of an unsafe test/reconnect path, not evidence of a differing port algorithm or a fix. + +The acceptance driver now performs a process cold start to validate persisted locks. That cold start and server/db restart read back mask 8, material selection 4 and the preserved fourth attribute. In-process scripted reconnect remains unverified and the crash is retained as an open finding; no global parity status is upgraded. diff --git a/audit/history.jsonl b/audit/history.jsonl index 106c2f29..8b3e7c6e 100644 --- a/audit/history.jsonl +++ b/audit/history.jsonl @@ -654,3 +654,4 @@ {"date": "2026-10-16", "unit": "UserInterface/PythonApplication.cpp:Destroy / PythonBoot::Stop", "action": "fix-host-teardown-order", "finding": "40250 drains flying instances before effects/characters; host previously reset effects before CFlyingManager destruction. Explicit flying and character cleanup fixes live-projectile shutdown; overall Destroy remains DIVERGENT for unrelated omissions.", "evidence": ["tests/port/port_app_loop_test.cpp", "build/followup-shutdown-before.log", "build/followup-shutdown-after.log"]} {"date": "2026-10-17", "unit": "UserInterface/PythonPlayerAutoHunt.cpp::__AutoHunt_BuildPath", "action": "user-authorized-extension", "finding": "Live snow floor 1 knockback left the player at (18730.742,22544.762), inside blocked attribute row 225. Exact-start-only exemption rejected every path/attack sample, including monsters 90 units away. Permit only the occupied loaded blocked terrain cell, retaining adjacent blocked cells, scene collision and unloaded-data rejection. AutoHunt is an authorized extension, not a newly claimed 40250 counterpart.", "evidence": ["tests/host/autohunt_navigation_test.cpp", "docs/AVA2-FOLLOWUP-20261016.md"], "remaining": "Live dungeon soak pending; no parity status upgraded. Port-map helper script absent on this branch."} {"time": "2026-10-18T10:49:04.284335+00:00", "event": "platform_fix", "unit": "EterLib/GrpExpandedImageInstance.cpp", "result": "ADAPTED", "reason": "Preserve stage-0 U/V in UI command/sampler path instead of unconditional clamp; repeated Board backgrounds validated on macOS. Aggregate UI remains PARTIAL.", "evidence": ["audit/evidence/2026-10-18-ui-addressing.md", "tests/port/port_grp_resource_test.cpp", "tests/host/ui_sampler_capture_test.cpp"]} +{"time": "2026-10-18T17:58:20.857552+00:00", "event": "lifecycle_investigation", "units": ["EterPythonLib/PythonWindow.cpp", "EterPythonLib/PythonWindowManager.cpp"], "finding": "Scripted reconnect during OnUpdate crashed; relevant window lifecycle group matches 40250. No code changes or status upgrades; use cold-start QA and retain reconnect finding.", "evidence": ["audit/evidence/2026-10-18-window-lifecycle-qa.md"]} diff --git a/audit/port-map/EterPythonLib/PythonWindow.cpp.json b/audit/port-map/EterPythonLib/PythonWindow.cpp.json index 5c6a040f..2658870f 100644 --- a/audit/port-map/EterPythonLib/PythonWindow.cpp.json +++ b/audit/port-map/EterPythonLib/PythonWindow.cpp.json @@ -38,6 +38,9 @@ "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindow.cpp:CWindow::Clear" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindow::DestroyHandle": { @@ -68,12 +71,18 @@ "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindow.cpp:CWindow::__RemoveReserveChildren" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindow::Update": { "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindow.cpp:CWindow::Update" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindow::Render": { @@ -176,6 +185,9 @@ "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindow.cpp:CWindow::DeleteChild" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindow::SetTop": { diff --git a/audit/port-map/EterPythonLib/PythonWindowManager.cpp.json b/audit/port-map/EterPythonLib/PythonWindowManager.cpp.json index bf1f12f3..0d44705f 100644 --- a/audit/port-map/EterPythonLib/PythonWindowManager.cpp.json +++ b/audit/port-map/EterPythonLib/PythonWindowManager.cpp.json @@ -146,12 +146,18 @@ "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindowManager.cpp:CWindowManager::NotifyDestroyWindow" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindowManager::DestroyWindow": { "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindowManager.cpp:CWindowManager::DestroyWindow" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindowManager::IsDragging": { @@ -296,12 +302,18 @@ "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindowManager.cpp:CWindowManager::__ClearReserveDeleteWindowList" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindowManager::Update": { "status": "PORTED", "impl": [ "src/port/EterPythonLib/PythonWindowManager.cpp:CWindowManager::Update" + ], + "evidence": [ + "audit/evidence/2026-10-18-window-lifecycle-qa.md" ] }, "CWindowManager::Render": { diff --git a/docs/AVA2-PARITY-PLAN.md b/docs/AVA2-PARITY-PLAN.md index e1ca3898..4e5437c7 100644 --- a/docs/AVA2-PARITY-PLAN.md +++ b/docs/AVA2-PARITY-PLAN.md @@ -23,6 +23,8 @@ 原生 uitrack 双页窗口、五个世界首领刷新、地图 357 和原生门票兑换商店已接入 sbtest;已验证真实刷新/传送/实体、八项价格与实际道具兑换。旧副本增加真实冷却字段兼容,但八个副本的任务和入场条件尚未全部替换为 AVA2。提醒持久化冷启动已通过,Android 验收继续进行,详见 [AVA2-TRACK.md](AVA2-TRACK.md)。 +属性锁定已在 sbtest 验证:选第4条、实际消耗、洗练保留锁定值、重复操作拒绝、全测试集群冷重启后读回,以及取消和解锁。实现与边界见 [属性锁定说明](../tools/server/ava2-attr-lock/README.md)。进程内脚本重连发生窗口遍历崩溃,冷启动通过不替代该项;其他玩家/交易/商店锁定提示和物理触控仍未闭合。 + ## 1. 对齐的含义 对每个系统都使用 AVA2 自己的实现,参考源码如下: @@ -49,7 +51,7 @@ AVA2 功能包头号在当前服务端基本空闲,可以直接沿用: | 系统 | AVA2 | 当前实现 | 主要差异 | |---|---|---|---| | 自动洗练 | `uiswitchbot.py` + `switcher.py`,`PythonSwitchbot`,CG/GC 171,`new_switchbot.cpp`;独立 SWITCHBOT 窗口,5 个物品槽 + 1 个道具槽,0.1 秒/次,换线后通过 P2P 转移继续洗 | `/mt_switchbot`,物品留在背包,一次只洗 1 件,0.25 秒/次,每次调用原 `UseItem`;换线或下线即停止 | 窗口、物品存放(新增窗口类型 = 物品位置枚举和 DB)、协议、速度、换线续洗。**2026-10-16 已在 feature/ava2-unlock 按 AVA2 实现,联机测试通过(武器、戒指、护符、重新登录、同核心换地图;跨核心换线未测);2026-10-17 已确认正式服现役二进制包含实现,当前联机复测见上方执行状态**(`docs/AVA2-SWITCHBOT.md`、服务端 `FEATURE-SWITCHBOT.md`) | -| 属性锁定 | `ENABLE_LOCK_ATTR`:把 50348/50349 拖到装备上,选择属性;锁定信息存在属性数组第 7、8 位;物品提示里显示锁定 | 独立表 `mt_item_attr_lock`;入口是洗练窗口里的 5 个锁定按钮;main 的 `2222885` 已加入 50348/50349 的消耗 | 入口和提示改成 AVA2 的方式;存储继续用独立表(7 条属性的结构放不下)。洗练窗口里的锁定按钮和锁定命令已删,50348/50349 走服务端 UseItemEx;AVA2 选槽位界面和提示未做 | +| 属性锁定 | `ENABLE_LOCK_ATTR`:把 50348/50349 拖到装备上,选择属性;锁定信息存在属性数组第 7、8 位;物品提示里显示锁定 | 独立表 `mt_item_attr_lock`;入口是洗练窗口里的 5 个锁定按钮;main 的 `2222885` 已加入 50348/50349 的消耗 | 入口和提示改成 AVA2 的方式;存储继续用独立表(7 条属性的结构放不下)。洗练窗口里的锁定按钮和锁定命令已删,50348/50349 走服务端 UseItemEx;2026-10-18 sbtest 已补选槽流程与自有装备提示,其他玩家/交易/商店提示待做 | | 批量开箱 | `/chest_drop`,Ctrl + 右键弹出滑块,Ctrl + Z + 右键开整叠;`AutoGiveItemChest`,单次最多 1000 | `/mt_chest`,固定 1/10/50/全部,单次最多 200,逐个调用原 `UseItem` | 窗口、按键、命令、单次上限、发奖路径 | | 批量拾取 | CG 235 `ITEMS_PICKUP`;70002 自动拾取状态 | `/mt_pickup`,自建 8 类分类窗口,只在按 Z 时触发 | 包、自动拾取状态、分类方式 | | 世界 Boss | `uitrack.py`(世界 Boss + 副本两页) | `mt_boss` 自建窗口;main 已加入传送 | 窗口改为 uitrack,补上副本页 | @@ -103,7 +105,7 @@ AVA2 功能包头号在当前服务端基本空闲,可以直接沿用: 改动玩家正在用的系统,旧版和新版需要同时切换,并有回滚方案。 -1. 自动洗练(原生实现已部署,仍待纯释放速度自然完成、跨核心续洗和 Android 真机验收)+ 属性锁定(选槽界面和提示未做):SWITCHBOT 窗口类型、CG/GC 171、`new_switchbot` 和 `PythonSwitchbot`、`uiswitchbot`;锁定改成拖 50348/50349 并在物品提示里显示,存储继续用独立表。 +1. 自动洗练(原生实现已部署,纯释放速度自然完成已通过;仍待跨核心续洗和 Android 真机验收)+ 属性锁定(sbtest 已补选择流程和自有装备提示;其他容器/玩家提示待做):SWITCHBOT 窗口类型、CG/GC 171、`new_switchbot` 和 `PythonSwitchbot`、`uiswitchbot`;锁定改成拖 50348/50349 并在物品提示里显示,存储继续用独立表。 2. 批量开箱:`/chest_drop`、滑块、Ctrl + Z、`AutoGiveItemChest`。 3. 批量拾取:CG 235、70002 自动拾取。 4. 世界 Boss / 副本追踪:uitrack。 diff --git a/docs/AVA2-SWITCHBOT.md b/docs/AVA2-SWITCHBOT.md index c9a2e899..6a5000bb 100644 --- a/docs/AVA2-SWITCHBOT.md +++ b/docs/AVA2-SWITCHBOT.md @@ -35,7 +35,7 @@ 没有移植 AVA2 的 `uiswitch.DopadorMenu/DopadorManual`(另一套手动洗练菜单)。 -右键使用 50348/50349 不再打开洗练窗口。服务端仍支持把这两个道具用到物品上来锁定或解锁属性(槽位取道具的 socket 0),但 AVA2 选槽位的界面和物品提示还没做。 +2026-10-18:50348/50349 已在 sbtest 补齐选择属性序号的 quest 流程,材料 socket 0 记录1~5,再拖到装备;自有装备提示按 AVA2 用黄色 <<属性>> 显示。独立表存储保留,详见 [属性锁定说明](../tools/server/ava2-attr-lock/README.md)。他人/商店/交易提示尚未同步。 ## 证据 @@ -59,7 +59,7 @@ - 跨核心换线(P2P 转移)的联机测试:测试环境只有一个核心。 - 正式服当前版本的实际开始/停止和跨核心续洗验收仍需补齐;2026-10-17 已确认现役 game 含 CSwitchbotManager / switchbot_end,player.item.window 也已有 SWITCHBOT,不能再写成正式服仅有 v1。 - Android 构建和真机测试。 -- 属性锁定界面(AVA2 拖 50348/50349,并在物品提示里显示锁定)。 +- 属性锁定:他人装备、交易和商店提示同步;物理拖放与 Android 触控验收。 ## 2026-10-17 当前客户端复测 @@ -81,3 +81,9 @@ 驱动已结束,客户端已重新启动,当前没有该定时器。后续人工验收期间不再插入修改配置或定时停止。 新增回归直接编译执行服务端 CheckItem 函数,确认攻击速度 7 不能满足释放速度 9、数值门槛、同方案 AND 和备选方案 OR。 客户端回归通过真实选择回调确认释放速度编号 9 保持为 9,未错误发送成 7。 + +## 2026-10-18 纯释放速度自然完成 + +macOS 真实客户端连接 sbtest,普通 QA1017 的测试武器(19)起初无释放速度。三个备选方案均只设类型9(释放速度)≥1,未混入攻击速度7。开始后不发送手动 Stop:71084 总数2082→2069,约1.315秒后 active=0、finished=1,最终五条属性含 (9,10)。属性匹配、消耗和自然停止同时成立;不是“已有目标立即完成”测试。证据:build/parity-acceptance-20261018/switchbot-cast-natural.json。验收后物品移回背包,测试轮询窗口隐藏。 + +Android APK 已构建并保留数据安装,用户于本轮明确选择“暂时不测手机”,因此手机联机/触控保留未验收。 diff --git a/src/platform/ScriptLib/AttrLockScript.inc b/src/platform/ScriptLib/AttrLockScript.inc new file mode 100644 index 00000000..7ee79ce1 --- /dev/null +++ b/src/platform/ScriptLib/AttrLockScript.inc @@ -0,0 +1,118 @@ +// AVA2 lock material selection uses socket 0; lock highlights follow original uitooltip.py. +// The existing port stores masks outside the seven-attribute packet, so own-item tooltips query them read-only. +static const char c_szAttrLockScript[] = R"PY(# -*- coding: utf-8 -*- +import app,chat,game,net,player,uiToolTip,weakref,mt_switchbot +L=player.AutoHuntLocalize +Tip=uiToolTip.ItemToolTip +_clear=Tip.ClearToolTip +_inventory=Tip.SetInventoryItem +_append=Tip._ItemToolTip__AppendAttributeInformation +_add=Tip.AddItemData +_update=Tip.OnUpdate +_command=game.GameWindow.BINARY_ServerCommand_Run +_close=game.GameWindow.Close +_pending={} +_serial=0 + +def Snapshot(window,cell): + return (player.GetItemIndex(window,cell), + tuple(player.GetItemAttribute(window,cell,i) for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)), + tuple(player.GetItemMetinSocket(window,cell,i) for i in xrange(player.METIN_SOCKET_MAX_NUM))) + +def Clear(self): + if not getattr(self,'attrLockRendering',False): + self.attrLockContext=None;self.attrLockMask=0 + _clear(self) + +def Query(self): + global _serial + context=getattr(self,'attrLockContext',None) + if not context:return + window,cell,snapshot=context + if Snapshot(window,cell)!=snapshot: + self.attrLockContext=None;self.attrLockMask=0 + return + _serial=(_serial%2147483646)+1 + self.attrLockNext=app.GetTime()+1.25 + # A tooltip can be rebuilt frequently during rolling; retain no old requests or windows. + _pending.clear();_pending[_serial]=(weakref.ref(self),context) + net.SendChatPacket('/attr_lock_info %d %d %d'%(_serial,window,cell)) + +def Inventory(self,cell,window_type=player.INVENTORY): + _inventory(self,cell,window_type) + snapshot=Snapshot(window_type,cell) + if not snapshot[0] or not any(a[0] for a in snapshot[1][:5]):return + self.attrLockContext=(window_type,cell,snapshot) + Query(self) + +def Rebuild(self): + context=getattr(self,'attrLockContext',None) + if not context:return + window,cell,snapshot=context + if Snapshot(window,cell)!=snapshot:return + self.attrLockRendering=True + try:_inventory(self,cell,window) + finally:self.attrLockRendering=False + +def Update(self): + _update(self) + if self.IsShow() and getattr(self,'attrLockContext',None) and app.GetTime()>=getattr(self,'attrLockNext',0):Query(self) + +def AppendAttributes(self,attrs): + mask=getattr(self,'attrLockMask',0) + if not mask or getattr(self,'mtSash',None):return _append(self,attrs) + # Original AVA2: locked lines are enclosed in << >> and use SPECIAL_TITLE_COLOR. + for index,(kind,value) in enumerate(attrs): + if not value:continue + text=self._ItemToolTip__GetAffectString(kind,value) + if text: + if index<5 and mask&(1<>',self.SPECIAL_TITLE_COLOR) + else:self.AppendTextLine(text,self._ItemToolTip__GetAttributeColor(index,value)) + +def AddItemData(self,vnum,metinSlot=0,attrSlot=0,*args,**kwargs): + _add(self,vnum,metinSlot,attrSlot,*args,**kwargs) + if vnum in (50348,50349): + index=int(metinSlot[0]) if metinSlot else 0 + self.AppendSpace(5) + self.AppendTextLine(L('已选择第%d条普通属性'%index if 1<=index<=5 else '先使用此符选择属性序号'),self.SPECIAL_TITLE_COLOR) + self.ShowToolTip() + +def Command(self,line): + words=line.split() + if words and words[0]=='AttrLockResult': + messages={'ok':'属性锁定状态已更新','item':'请使用未穿戴且未被交易或占用的装备','material':'请使用对应的锁定符或解锁符','slot':'请先使用此符选择有效的属性序号','five_attr':'装备需要五条普通属性','max':'最多可锁定两组普通属性','db':'保存失败,本次未消耗材料'} + if len(words)==2:chat.AppendChat(chat.CHAT_TYPE_INFO,L(messages.get(words[1],'属性锁定失败'))) + return 1 + if words and words[0]=='AttrLockInfo': + if len(words)!=6:return 1 + try:token,window,cell,vnum,mask=map(int,words[1:]) + except (ValueError,OverflowError):return 1 + request=_pending.pop(token,None) + if request and -1<=mask<=31: + owner,context=request;tip=owner() + if tip and tip.IsShow() and getattr(tip,'attrLockContext',None)==context: + if (window,cell)==context[:2] and vnum==context[2][0] and Snapshot(window,cell)==context[2]: + if mask>=0 and mask!=getattr(tip,'attrLockMask',0): + tip.attrLockMask=mask;Rebuild(tip) + return 1 + return _command(self,line) + +def Close(self): + _pending.clear() + return _close(self) + +_switchOver=mt_switchbot.SwitchbotItemTab.OverInItem +def SwitchOver(self,slot): + if self.IsEmpty() or self.IsActive():return _switchOver(self,slot) + self.itemSlot.SetUsableItem(True) + if self.tooltipItem:self.tooltipItem.SetInventoryItem(self.slot_num,player.SWITCHBOT) + +Tip.ClearToolTip=Clear +Tip.SetInventoryItem=Inventory +Tip._ItemToolTip__AppendAttributeInformation=AppendAttributes +Tip.AddItemData=AddItemData +Tip.OnUpdate=Update +mt_switchbot.SwitchbotItemTab.OverInItem=SwitchOver +game.GameWindow.BINARY_ServerCommand_Run=Command +game.GameWindow.Close=Close +)PY"; diff --git a/src/platform/ScriptLib/PythonBoot.cpp b/src/platform/ScriptLib/PythonBoot.cpp index 6813a853..d00d8d8d 100644 --- a/src/platform/ScriptLib/PythonBoot.cpp +++ b/src/platform/ScriptLib/PythonBoot.cpp @@ -1041,6 +1041,7 @@ namespace PythonBoot #include "PendantScript.inc" #include "RingsScript.inc" #include "ItemActionsScript.inc" +#include "AttrLockScript.inc" #include "MinimapOuterRingScript.inc" #ifdef MT_HAS_MESHPORT #include "MeshPortScript.inc" @@ -1144,6 +1145,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error) install_script_module("mt_pendant", c_szPendantScript); install_script_module("mt_rings", c_szRingsScript); install_script_module("mt_item_actions", c_szItemActionsScript); + install_script_module("mt_attr_lock", c_szAttrLockScript); install_script_module("mt_minimap_buttons", c_szMinimapOuterRingScript); if (g_touch_input) install_script_module("mt_mobile_hud", c_szMobileHUDScript); diff --git a/tests/wiki/test_attr_lock_ui.py b/tests/wiki/test_attr_lock_ui.py new file mode 100644 index 00000000..bda42557 --- /dev/null +++ b/tests/wiki/test_attr_lock_ui.py @@ -0,0 +1,61 @@ +"""Exercise actual lock tooltip bridge with asynchronous replies and item movement.""" +import unittest,types,sys +from pathlib import Path +ROOT=Path(__file__).resolve().parents[2] +class Tooltip: + SPECIAL_TITLE_COLOR='lock' + def __init__(self):self.lines=[];self.shown=True + def ClearToolTip(self):self.lines=[] + def AddItemData(self,vnum,sockets=0,attrs=0,*a,**kw): + if attrs:self._ItemToolTip__AppendAttributeInformation(attrs) + def SetInventoryItem(self,cell,window=1): + self.ClearToolTip();self.AddItemData(self.player.GetItemIndex(window,cell),[self.player.GetItemMetinSocket(window,cell,i) for i in range(3)],[self.player.GetItemAttribute(window,cell,i) for i in range(7)]);self.ShowToolTip() + def OnUpdate(self):pass + def IsShow(self):return self.shown + def ShowToolTip(self):self.shown=True + def AppendSpace(self,n):pass + def AppendTextLine(self,text,color):self.lines.append((text,color)) +class AttrLockUI(unittest.TestCase): + def setUp(self): + self.previous={};self.mods={n:types.ModuleType(n) for n in ('app','chat','game','net','player','uiToolTip','mt_switchbot')} + self.sent=[];self.items={(1,4):[100,[(1,10),(2,20),(3,30),(4,40),(5,50),(0,0),(0,0)],[0,0,0]]};self.now=0 + m=self.mods;m['player'].INVENTORY=1;m['player'].SWITCHBOT=8;m['player'].ATTRIBUTE_SLOT_MAX_NUM=7;m['player'].METIN_SOCKET_MAX_NUM=3 + m['player'].GetItemIndex=lambda w,c:self.items.get((w,c),[0])[0] + m['player'].GetItemAttribute=lambda w,c,i:self.items.get((w,c),[0,[(0,0)]*7])[1][i] + m['player'].GetItemMetinSocket=lambda w,c,i:self.items.get((w,c),[0,[],[0]*3])[2][i] + m['player'].AutoHuntLocalize=lambda t:t + m['app'].GetTime=lambda:self.now;m['net'].SendChatPacket=self.sent.append + m['chat'].CHAT_TYPE_INFO=1;m['chat'].AppendChat=lambda *a:None + tip=type('ItemToolTip',(Tooltip,),{'player':m['player'],'_ItemToolTip__GetAffectString':lambda s,t,v:'attr%d=%d'%(t,v),'_ItemToolTip__GetAttributeColor':lambda s,i,v:'normal'}) + tip._ItemToolTip__AppendAttributeInformation=lambda s,attrs:[s.AppendTextLine('attr%d=%d'%(t,v),'normal') for t,v in attrs if v] + m['uiToolTip'].ItemToolTip=tip + m['game'].GameWindow=type('GameWindow',(),{'Close':lambda s:9,'BINARY_ServerCommand_Run':lambda s,line:0}) + m['mt_switchbot'].SwitchbotItemTab=type('Tab',(),{'OverInItem':lambda s,slot:'original'}) + for n,mod in m.items():self.previous[n]=sys.modules.get(n);sys.modules[n]=mod + self.ns={'xrange':range};source=(ROOT/'src/platform/ScriptLib/AttrLockScript.inc').read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0];exec(source,self.ns) + self.tip=tip();self.game=m['game'].GameWindow() + def tearDown(self): + for n,old in self.previous.items(): + if old is None:sys.modules.pop(n,None) + else:sys.modules[n]=old + def reply(self,mask,command=None): + token,w,c=(command or self.sent[-1]).split()[1:] + return self.game.BINARY_ServerCommand_Run('AttrLockInfo %s %s %s 100 %s'%(token,w,c,mask)) + def test_locked_lines_and_addon_pair(self): + self.tip.SetInventoryItem(4);self.reply(3) + self.assertEqual(self.tip.lines[:3],[('<>','lock'),('<>','lock'),('attr3=30','normal')]) + self.now=2;self.tip.OnUpdate();self.reply(0);self.assertFalse(any('<<' in s for s,c in self.tip.lines)) + def test_late_and_moved_replies_are_discarded(self): + self.tip.SetInventoryItem(4);first=self.sent[-1] + self.tip.SetInventoryItem(4);self.reply(1,first);self.assertEqual(self.tip.attrLockMask,0) + self.items[(1,4)][1][0]=(1,99);self.reply(1);self.assertEqual(self.tip.attrLockMask,0) + def test_invalid_reply_and_disconnect(self): + self.tip.SetInventoryItem(4);self.reply(32);self.assertEqual(self.tip.attrLockMask,0) + self.now=2;self.tip.OnUpdate();self.assertTrue(self.ns['_pending']);self.assertEqual(self.game.Close(),9);self.assertFalse(self.ns['_pending']) + def test_material_hint_and_regular_item_fallback(self): + self.tip.AddItemData(50348,[4,0,0]);self.assertIn('第4条',self.tip.lines[-1][0]) + self.tip.ClearToolTip();self.tip.AddItemData(50349,[0,0,0]);self.assertIn('先使用',self.tip.lines[-1][0]) + self.tip.ClearToolTip();self.tip.AddItemData(100,[0,0,0],[(1,10)]);self.assertEqual(self.tip.lines,[('attr1=10','normal')]) + def test_active_switchbot_uses_original_dynamic_tooltip(self): + tab=self.mods['mt_switchbot'].SwitchbotItemTab();tab.IsEmpty=lambda:False;tab.IsActive=lambda:True + self.assertEqual(tab.OverInItem(0),'original') diff --git a/tools/server/ava2-attr-lock/README.md b/tools/server/ava2-attr-lock/README.md new file mode 100644 index 00000000..d804351c --- /dev/null +++ b/tools/server/ava2-attr-lock/README.md @@ -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;冷启动持久化通过,不将该结果计作进程内重连验收。正式服未发布。 diff --git a/tools/server/ava2-attr-lock/attr_lock.quest b/tools/server/ava2-attr-lock/attr_lock.quest new file mode 100644 index 00000000..86bf475c --- /dev/null +++ b/tools/server/ava2-attr-lock/attr_lock.quest @@ -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 diff --git a/tools/server/ava2-attr-lock/install_quest.py b/tools/server/ava2-attr-lock/install_quest.py new file mode 100644 index 00000000..8386b1f1 --- /dev/null +++ b/tools/server/ava2-attr-lock/install_quest.py @@ -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) diff --git a/tools/server/ava2-attr-lock/prepare.py b/tools/server/ava2-attr-lock/prepare.py new file mode 100644 index 00000000..d10a315e --- /dev/null +++ b/tools/server/ava2-attr-lock/prepare.py @@ -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)