敌方血条偏高:头顶高度按"原点以上的高度"算(bounds.y + bounds.height),而不是包围盒高度

玩家反馈:逐腐兽的血条明显偏高。

原因:单位血条/名字牌的头顶高度用的是 spine setup-pose 包围盒的**高度**(units.js headTilesForUnit 里
`bounds.height × 1/320 × 模型系数 × 0.92`)。这个公式默认包围盒是**脚锚定**的 —— 大多数敌人确实如此
(猎狗pro y=−3.7、大鲍勃 y=−2.6,height 与"脚以上高度"几乎相等)。但有些模型的**原点在身体中间**:
逐腐兽的包围盒是 y=−404.7 / height=722.6,锏是 y=−798 / height=1183 —— 对它们,包围盒高度比可见顶端多出
大半个模型,于是血条被顶到上限 2.2 格(非 Boss)之上,看起来就是"明显偏高"。

改法:定位改用**原点以上的高度**(`Number.isFinite(b.y) ? b.y + b.height : b.height`,仍按 20…900 夹取)。
同时把这段计算从 UnitView 内联代码提成一个纯函数 `headTilesForUnit()`(放 units.js,紧挨 UNIT/EL_BAR 常量),
入参只有 isEnemy / isBoss / spineShown / bounds / modelK / modelKY,便于直接测;UnitView 仍然保留
"没显示 spine 就不看模型"的短路语义。spine.js 的 `height` getter 语义不变(别处也用它,例如替身的纵向拉伸)。

影响面(用真实 bounds 扫过 167 个有模型数据的敌人):
  逐腐兽 / 疯狂的逐腐兽   1.85 → 0.81 格(降 1.03)
  锏(Boss)             2.59 → 1.11 格(降 1.48)
  萨卡兹大剑手 / 组长     1.54 → 1.23 格(降 0.31)
  枯朽之种 0.72 → 0.55、萨卡兹百夫长 1.51 → 1.34、妖怪MKII 0.71 → 0.55
  其余 103 / 167 个敌人的变化 ≤ 0.02 格(脚锚定模型几乎无感)

测试:
  test/render/bar-head.test.js(新增 5 条):用真实的逐腐兽 / 猎狗pro / 大鲍勃 / 锏 包围盒断言新公式、
  夹取上限、以及三个回退分支(无 bounds 用 chibi 余量 × 系数、Boss 无模型用 2.2、干员与召唤物用固定余量),
  并做源码断言把"y + height"这条规则钉住。
  test/render/playtest6-enemies.test.js:两条 prefab 测试的期望值原本写死 `390 × …`(合成夹具的 bounds 是
  y=−150 / height=390,即当年就把这个 bug 当成了正确行为),现在改为从**被测 view 自己的 bounds** 推导
  (240 而不是 390),夹具本身不动。
  test/render 全量 552 项 / 546 通过 / 0 失败;test/ui + test/render 1279 项 / 1265 通过 / 0 失败。

未触碰 server/sim,test/golden 无变动。
This commit is contained in:
xcdoge committed 2026-10-11 22:49:56 +08:00
1 parent bc50cac01f
commit 7b4f512ce9
3 files changed
+119 -11

No files matched your search

+40 -7
View File
@@ -228,6 +228,38 @@ export const ALIAS_TINT = Object.freeze({ enemy_1305_mhslim: 0xffc48a, enemy_130
* between `pulse` and 1 at `pulseHz` (real time).
*/
export const EL_BAR = Object.freeze({ icon: 0.15, min: 8, max: 15, enemy: 0.8, gap: 1, pulse: 0.45, pulseHz: 1.5 });
/** The share of a model's height a bar is placed above (the head is not the very top of the silhouette). */
export const HEAD_TOP_K = 0.92;
/** Enemies whose model is taller than this many tiles keep their bar at the cap — a bar must stay on screen. */
export const HEAD_TILES_CAP = 2.2;
export const HEAD_TILES_CAP_BOSS = 3.2;
/**
* Tiles above the feet where a unit's HP bar / name tag sits.
*
* Operators and tokens are uniform chibis (UNIT.headroom). Enemies vary: with a known model they use **how far the model
* reaches above its own origin** (spine.js `top` = `bounds.y + bounds.height`, not the box's raw height — a body whose
* origin sits mid-model, 逐腐兽, would otherwise push its bar ~a tile too high), scaled by the official model factor and
* the vertical-stretch quirk; without bounds they fall back to the chibi headroom × that factor.
* @param {{ isEnemy:boolean, isBoss:boolean, spineShown:boolean, bounds?:{y?:number,height?:number}|null, modelK:number, modelKY:number }} o
* @returns {number} tiles
*/
export function headTilesForUnit(o) {
const k = (Number.isFinite(o.modelK) ? o.modelK : 1) * (Number.isFinite(o.modelKY) ? o.modelKY : 1);
if (!o.isEnemy) return UNIT.headroom;
const cap = o.isBoss ? HEAD_TILES_CAP_BOSS : HEAD_TILES_CAP;
const b = o.spineShown ? o.bounds : null;
if (b && Number.isFinite(b.height) && b.height > 20) {
// how far the box reaches *above the origin*: 猎狗pro −3.7, 大鲍勃 −2.6 (feet-anchored, ≈ height), 逐腐兽 −404.7 of
// 722.6 and 锏 −798 of 1183 (origin mid-body). Using the raw height there put the bar about a tile too high.
const top = Number.isFinite(b.y) ? b.y + b.height : b.height;
return clamp(Math.min(Math.max(top, 20), 900) * UNIT.modelScale * k * HEAD_TOP_K, 0.55, cap);
}
if (o.isBoss) return HEAD_TILES_CAP;
if (o.spineShown) return clamp(UNIT.headroom * k, 0.55, HEAD_TILES_CAP);
return UNIT.headroom;
}
/**
* The HP-bar readouts under the bars (b.snap `ammo`, `wolves`, `neg`; render/interp.js header):
* - AMMO_BAR — the ammo skill's segmented bar replaces the SP bar: a cell per round, `height` of the HP bar's thickness
@@ -1297,13 +1329,14 @@ export class UnitView {
this.aura.scale.set((s * 1.3) / 128, (s * 1.9) / 128);
}
// head height: operators/tokens are uniform chibis; enemies vary (setup-pose bounds, when known; else the chibi
// headroom × their official model factor)
let headTiles = UNIT.headroom;
if (this.isEnemy && spineShown && this.actor.entry.bounds) headTiles = clamp(this.actor.height * UNIT.modelScale * this.modelK * this.modelKY * 0.92, 0.55, this.isBoss ? 3.2 : 2.2);
else if (this.isEnemy && this.isBoss) headTiles = 2.2;
else if (this.isEnemy && spineShown) headTiles = clamp(UNIT.headroom * this.modelK * this.modelKY, 0.55, 2.2);
this._headTiles = headTiles;
// keep the original short-circuit: many views never build an actor (prep chips, diamonds, tests), so the model
// only counts when a spine is actually shown
const actor = spineShown ? this.actor : null;
const headTiles = this._headTiles = headTilesForUnit({
isEnemy: this.isEnemy, isBoss: this.isBoss, spineShown,
bounds: actor && actor.entry ? actor.entry.bounds : null,
modelK: this.modelK, modelKY: this.modelKY,
});
this.screen.top = by - headTiles * s;
this._updateHud(dt, s, bx, by - headTiles * s, alpha, t);
}