Skip to content

fix(基础库): 修复团队面板气血刷新取到空值的问题 - #120

Merged
yefansky merged 1 commit into
tinymins:masterfrom
ZhaoQisi:fix/life-fallback-to-single-bar
Oct 26, 2026
Merged

yefansky merged 1 commit into
tinymins:masterfrom
ZhaoQisi:fix/life-fallback-to-single-bar

Conversation

@ZhaoQisi

Copy link
Copy Markdown
Contributor

问题

29.0.12 发布后,团队面板在气血刷新时会抛错并中断:

...\interface\MY\MY_Cataclysm\src\my_cataclysmparty.lua:1935:
bad argument #2 to 'max' (number expected, got nil)
stack traceback:
	[C]: in function 'max'
	...\my_cataclysmparty.lua:1935: in function 'DrawHPMP'
	...\my_cataclysmparty.lua:1894: in function 'CallDrawHPMP'
	...\my_cataclysmparty.lua:1816: in function 'RefreshDistance'
	...\my_cataclysmparty.lua:1319: in function 'DrawParty'
	...\my_cataclysmparty.lua:1263: in function 'ReloadParty'

真机复现环境:重制版(zhcn)客户端,组队后打开团队面板即持续报错。

原因

29.0.12 把 GetCharacterLife 改成了直接返回 64 位字段:

return kTar.fCurrentLife64, kTar.fMaxLife64

这个函数不只有 userdata 入参。MY_CataclysmParty、MY_LifeBar 等会把它传给 X.GetTeamMemberInfo(dwID) 的返回值,而那是 MY_!Base/src/lib/Game.Team.lua 里构造的普通 Lua table:

return {
	dwID = dwID,
	...
	nMaxLife = info.nMaxLife,
	nCurrentLife = info.nCurrentLife,
	...
}

只有 nCurrentLife / nMaxLife,没有 fCurrentLife64 / fMaxLife64。于是取到 nil, nil,回退逻辑拿到的也是 nil,最后落在 math.max(1, fMaxLife) 上抛错。

触发路径(MY_CataclysmParty.lua):

if CFG.bFasterHP then
	player = X.GetPlayer(dwID)          -- 该配置默认 false
end
local obj = npc or player                -- 普通队友时为 nil
local fCurrentLife, fMaxLife = X.GetCharacterLife(obj)   -- nil, nil
if not fCurrentLife ... then
	fCurrentLife, fMaxLife = X.GetCharacterLife(info)    -- info 是纯 table,仍为 nil
end
fMaxLife = math.max(1, fMaxLife)         -- 抛错

修复

改为按字段是否存在取值,不再依赖版本判断:

return kTar.fCurrentLife64 or kTar.nCurrentLife,
	kTar.fMaxLife64 or kTar.nMaxLife
  • userdata(NPC / 玩家):有 f 字段,拿到的是引擎按 nMaxLifeCount 展开后的总血池 —— 29.0.12 想修的多管血百分比问题依然修好
  • GetTeamMemberInfo 的普通 table:没有 f 字段,回退单管值 —— 不再得到 nil
  • 缘起、重制版行为一致

验证

本地用 lua5.1 对四种实现 × 三种入参做了对照:

实现 多管血 NPC 单管 NPC team table
29.0.11 原版(IS_REMAKE 分支) 缘起:错误 通过 通过
29.0.12(直接取 f) 通过 通过 nil,崩溃
本 PR(f 优先回落 n) 通过 通过 通过
  • 多管血用例用的是实测数字:nMaxLife = 3,728,359,500、nMaxLifeCount = 1、fMaxLife64 = 7,456,719,000,百分比从错误的 73% 变为正确的 36%
  • GBK 编码往返无损、LF 行尾、lua5.1 语法检查通过

真机已在内网缘起环境验证团队面板不再报错、焦点列表百分比正确。重制版环境的回归验证欢迎协助确认。

说明

  • 只改 GetCharacterLife 一处,未动 MY_CataclysmParty 的回退逻辑(那边的 math.max 本身缺判空,但既是既有代码,也与本次回归无关,可另开一单处理)。
  • CHANGELOG.md 里把 29.0.12 遗留的「未发布」段合并为本次一条记录。

29.0.12 中 GetCharacterLife 直接返回 fCurrentLife64 / fMaxLife64。但该函数的
入参不只 userdata:MY_CataclysmParty、MY_LifeBar 等会把 X.GetTeamMemberInfo
返回的普通 table 传进来,这类 table 只有 nCurrentLife / nMaxLife,取 f 字段
得到 nil,最终在 MY_CataclysmParty 的 math.max(1, fMaxLife) 处抛出
bad argument tinymins#2 to 'max' (number expected, got nil),团队面板气血刷新中断。

改为按字段是否存在取值:有 fCurrentLife64 / fMaxLife64 就用(多管血 NPC 拿到
的是引擎展开后的总血池),没有则回退 nCurrentLife / nMaxLife(普通 table 与
单管角色)。缘起与重制版行为一致,也不再依赖 IS_REMAKE 判断。
@yefansky
yefansky merged commit 19c7c25 into tinymins:master Oct 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants