Skip to content

[Bug]: DND5E 未设置 hpmax 时,.st hp±N 修改后生命值被钳制为 0(正值分支缺少 maxExists 判断) #1864

Open

Description

@SuellenQwQ

在提问之前...

  • 我理解 Issue 是用于反馈和解决问题的,而非吐槽评论区,将尽可能提供更多信息帮助问题解决
  • 我填写了简短且清晰明确的标题,以便开发者在翻阅 issue 列表时能快速确定大致问题。而不是“一个建议”、“卡住了”等
  • 我已查看master branch或最新测试版的更新内容,并未提及该 bug 已被修复的情况
  • 已有issue中并没有看见其他人与我反馈相同的问题

问题描述

dice/ext_dnd5e.go 的 ToModResult(.st hp±<表达式> 的修改回调)中,生命值上限的钳制逻辑存在一处不一致:未设置 hpmax 时,任何使 hp 保持正数的 .st hp±N 修改都会把生命值钳制为 0。

hpMax, maxExists := attrs.LoadX("hpmax")   // L304: 未设置时 maxExists=false
if maxExists {
    ...
}
if hpmaxBuff, exits := attrs.LoadX("$buff_hpmax"); exits {
    maxVal, _ := hpmaxBuff.ReadInt()
    curHpMax += maxVal
    maxExists = true // 任意一个存在,就视为上限存在,即使为0   // L319
}

curHpMax 声明为 var curHpMax ds.IntType,未设置 hpmax 且无 buff 时保持零值 0。随后:

if newHp <= 0 {
    // ... 承伤/昏迷分支
    if maxExists && -newHp >= curHpMax {     // L331: 有 maxExists 守卫
        ...
    }
    ...
} else {
    // 生命值变为大于0,移除死亡豁免标记
    deathSavingStable(ctx)
    if newHp > curHpMax {                    // L357: 缺少 maxExists 判断
        // 限制不超过hpmax
        return ds.NewIntVal(curHpMax)        // 未设 hpmax 时 = 返回 0
    }
}

attrs.LoadX 是对 sync.Map.Load 的直接封装(dice/dice_attrs_manager.go L390),没有模板默认值。同一函数内 L331 的承伤分支带了 maxExists && 守卫、L319 的 buff 分支也专门维护 maxExists——唯独 L357 的正值钳制漏掉了这个判断,应为笔误而非设计。

如何复现

1. .set dnd            // 切到 DND5E 模板
2. .st hp:10           // 直接设置不受影响(走 ToSet),hp=10,不设置 hpmax
3. .st hp+5            // 期望 15,实际 hp 变为 0
4. .st hp:10           // 重新设回
5. .st hp-2            // 期望 8,实际 hp 也变为 0(轻微扣血同样触发)

以上按 ToModResult 的代码逻辑推演(newHp > 0 == curHpMax 恒成立 → 返回 NewIntVal(0))。副作用:每次触发还会执行 deathSavingStable(ctx),把该角色的死亡豁免成功/失败计数清零。

你期望发生的

未设置 hpmax 时不应执行上限钳制:.st hp+5(hp 10→15)、.st hp-2(hp 10→8)按实际计算值生效。帮助文本也只承诺“增加hp时,hp的值不会超过hpmax”——未设置 hpmax 时钳到 0 与该语义不符。

实际上发生的

hp 被写入 0,同时死亡豁免计数被清零。

日志文件

无(代码静态审查 + 逻辑推演,问题点明确)。

截图

无。

海豹核心版本

master 分支源码(2026-10-15 最新提交)

操作系统

与操作系统无关(Windows 11 审查环境)

帐号类型

与帐号类型无关(DND5E 规则引擎逻辑)

使用协议

无

附加内容

修复建议(与 L331 写法对齐):

if maxExists && newHp > curHpMax {
    // 限制不超过hpmax
    return ds.NewIntVal(curHpMax)
}

(此前曾以 #1863 提交同一问题,因提交时未附带模板复选框被自动关闭且无法重开,故按模板重新提交。)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions