[P0][D04] 移除 engine.ts 掉落静默兜底(Act 1 H2H A / player.level + 2),改为 fail-fast #413

Closed
opened 2026-09-24 03:25:57 +00:00 by troytt · 1 comment
Owner

现状

src/game/engine.ts 在掉落入口处用魔法常量掩盖数据查找失败:

// engine.ts:857
const monsterLevel = event.monsterLevel ?? (player.level + 2)
// engine.ts:869-871
if (!tcName) {
  tcName = 'Act 1 H2H A'
}

两处都直接违反项目规则「禁止 if (!libraries) return true 式宽容兜底,缺失参数必须 fail fast」。
player.level + 2 更是把怪物掉落等级替换成了玩家等级,ilvl / TC 上限双双错位。

1.13c 真实行为

引擎不会在掉落循环中现编 TC 数据。合法的降级只发生在品质约束失败时
(例如 Unique 无可用条目 → 降 Rare 且 durability ×3,Set → 降 Magic 且 ×2),
这部分 drop-pipeline.ts 已正确实现。参数缺失属于数据错误,不是可降级场景。

验收标准

  • 删除 tcName = 'Act 1 H2H A' 兜底;tcName 无法从 superUniques / monsterKinds 解析时抛出带
    subjectId / difficulty / monsterType 上下文的错误。
  • 删除 ?? (player.level + 2);event.monsterLevel 缺失即抛错。
  • kill 事件契约固化:monsterLevel / subjectId / monsterType 改为必填字段(类型层面强制)。
  • vitest:构造一个 subjectId 不在 monsterKinds 中的 kill 事件,断言 tick() 抛错而非静默掉落。
  • 全谱系回归(依赖 D19):五幕三难度实跑零抛错,证明数据供给已完整。

依赖

D01、D02(必须先有真实数据,否则 fail-fast 会让游戏无法运行)。

## 现状 `src/game/engine.ts` 在掉落入口处用魔法常量掩盖数据查找失败: ```ts // engine.ts:857 const monsterLevel = event.monsterLevel ?? (player.level + 2) // engine.ts:869-871 if (!tcName) { tcName = 'Act 1 H2H A' } ``` 两处都直接违反项目规则「禁止 `if (!libraries) return true` 式宽容兜底,缺失参数必须 fail fast」。 `player.level + 2` 更是把**怪物**掉落等级替换成了**玩家**等级,ilvl / TC 上限双双错位。 ## 1.13c 真实行为 引擎不会在掉落循环中现编 TC 数据。合法的降级只发生在**品质约束失败**时 (例如 Unique 无可用条目 → 降 Rare 且 durability ×3,Set → 降 Magic 且 ×2), 这部分 `drop-pipeline.ts` 已正确实现。参数缺失属于数据错误,不是可降级场景。 ## 验收标准 - [ ] 删除 `tcName = 'Act 1 H2H A'` 兜底;`tcName` 无法从 `superUniques` / `monsterKinds` 解析时抛出带 `subjectId` / `difficulty` / `monsterType` 上下文的错误。 - [ ] 删除 `?? (player.level + 2)`;`event.monsterLevel` 缺失即抛错。 - [ ] `kill` 事件契约固化:`monsterLevel` / `subjectId` / `monsterType` 改为必填字段(类型层面强制)。 - [ ] vitest:构造一个 `subjectId` 不在 `monsterKinds` 中的 kill 事件,断言 `tick()` 抛错而非静默掉落。 - [ ] 全谱系回归(依赖 D19):五幕三难度实跑零抛错,证明数据供给已完整。 ## 依赖 D01、D02(必须先有真实数据,否则 fail-fast 会让游戏无法运行)。
troytt added this to the [M18] 打怪掉落物品:怪物死亡掉落全链路 1.13c 还原 milestone 2026-09-24 03:25:57 +00:00
Author
Owner

Resolution Summary (Issue #413 — Commit 9022579)

  • Removed permissive Act 1 H2H A and player.level + 2 fallbacks in src/game/engine.ts.\n- Enforced strict fail-fast validation on missing/invalid monsterLevel, unknown monsters, and unresolvable/unregistered TCs while preserving 0-drop handling for authentic non-dropping entities.\n- Verified in tests/fail-fast-drop.test.ts.

  • Verification: npx tsc --noEmit (0 errors), full Vitest drop/combat/item/E2E parity suites (100% pass), and scripts/verify-m5.ts / scripts/verify-net.ts (0 problems).

### Resolution Summary (Issue #413 — Commit `9022579`) - Removed permissive `Act 1 H2H A` and `player.level + 2` fallbacks in `src/game/engine.ts`.\n- Enforced strict fail-fast validation on missing/invalid `monsterLevel`, unknown monsters, and unresolvable/unregistered TCs while preserving 0-drop handling for authentic non-dropping entities.\n- Verified in `tests/fail-fast-drop.test.ts`. - **Verification**: `npx tsc --noEmit` (0 errors), full Vitest drop/combat/item/E2E parity suites (100% pass), and `scripts/verify-m5.ts` / `scripts/verify-net.ts` (0 problems).
Sign in to join this conversation.
No Label
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: troytt/diablo2-web#413
No description provided.