[M19-P2] 实装 1.13c 商人库存生成引擎 (按商人 ID、游戏难度与角色等级生成出售物品) #482

Closed
opened 2026-09-26 04:22:14 +00:00 by troytt · 1 comment
Owner

背景与目标

严格按照 D2Game.dll 反编译源码实装商人库存生成引擎 (src/game/vendor-generator.ts),根据商人 ID (nNpcId)、游戏难度 (Normal/Nightmare/Hell) 与角色等级 (cLvl) 生成四分页出售物品。

1.13c Ground Truth 对标 (SUnitProxy.cpp & SUnitNpc.cpp)

  1. 全局缓存构建 (SUNITPROXY_FillIGlobaltemCacheRecordForNpc):
    • 按 Weapons.txt \rightarrow Armor.txt \rightarrow Misc.txt 顺序扫描 nSpawnable != 0 且 (nVendorMax > 0 || nVendorMagicMax > 0) 的物品。
    • PermStoreItem != 0 归入 pPermCache;其余归入 pItemCache。
  2. 商店物品等级 ilvl 计算 (D2GAME_NPC_FillStoreInventory_6FCC7100):
    • nItemLevel = Math.max(1, Math.min(99, nPlayerLevel + 5))。
    • 普通难度 (nDifficulty == 0) 按幕数 nAct = 0..4 强制上限 npcLevels[5] = [12, 20, 28, 36, 45];噩梦与地狱难度无幕数上限。
  3. 非固定商品生成 (pItemCache):
    • 跳过 base.level > nItemLevel 的底材。
    • 当且仅当 nItemLevel < 25 且 nMax > 0 时生成普通/劣质/超强底材:
      • nNormalItems = nMin + rand(nMax - nMin + 1)。
      • 品质掷骰 rand(100):ilvl < 5 时 > 90 为劣质 (ITEMQUAL_INFERIOR);5 <= ilvl < 10 时 > 85 为超强 (ITEMQUAL_SUPERIOR);10 <= ilvl < 25 时 >= 75 为超强;其余为普通白色 (ITEMQUAL_NORMAL)。
    • 魔法商品生成 (nMagicMax > 0 且 bitfield1 & 1):
      • nMinItems = (nItemLevel >= 25) ? ((rand(2)) + 2) : 1。
      • nRange = nMinItems + nMagicMax - nMagicMin,生成 ITEMQUAL_MAGIC 并调用词缀生成器赋予前后缀(若词缀骰子未出词缀则自动重掷确保有效魔法词缀)与法杖/手杖/权杖 Staffmods。
  4. 噩梦/地狱难度底材升级与药水替换 (D2GAME_NPC_GenerateStoreItem_6FCC6A60):
    • 当 nPlayerLevel > 25 时:
      • 噩梦难度:rand(100000) < (nItemLevel << 6) + 4000 升级为 UberCode(若 Uber.level <= nItemLevel),否则应用 NightmareUpgrade。
      • 地狱难度:nRand = rand(100000),资料片 < 16 * nItemLevel + 1000 升级为 UltraCode,否则 < (nItemLevel << 7) + 5000 升级为 UberCode;随后应用 HellUpgrade。
  5. 常驻商品 (pPermCache) 与四分页 10×10 网格排布:
    • 常驻物品标记 bPermStore = true,箭袋 (aqv/cqv) 设为满数量 maxstack。
    • 按 StorePage (armr -> Tab 0, weap -> Tab 1 溢出至 Tab 2, misc -> Tab 3) 自动进行 2D 网格碰撞排布。

验收标准

  • 完整实现 src/game/vendor-generator.ts。
  • 覆盖 Act 1~5 全部 17 位商人在普通/噩梦/地狱及不同等级下的库存生成单元测试。
## 背景与目标 严格按照 `D2Game.dll` 反编译源码实装商人库存生成引擎 (`src/game/vendor-generator.ts`),根据**商人 ID (`nNpcId`)**、**游戏难度 (`Normal/Nightmare/Hell`)** 与**角色等级 (`cLvl`)** 生成四分页出售物品。 ## 1.13c Ground Truth 对标 (`SUnitProxy.cpp` & `SUnitNpc.cpp`) 1. **全局缓存构建 (`SUNITPROXY_FillIGlobaltemCacheRecordForNpc`)**: - 按 `Weapons.txt` $\rightarrow$ `Armor.txt` $\rightarrow$ `Misc.txt` 顺序扫描 `nSpawnable != 0` 且 `(nVendorMax > 0 || nVendorMagicMax > 0)` 的物品。 - `PermStoreItem != 0` 归入 `pPermCache`;其余归入 `pItemCache`。 2. **商店物品等级 `ilvl` 计算 (`D2GAME_NPC_FillStoreInventory_6FCC7100`)**: - `nItemLevel = Math.max(1, Math.min(99, nPlayerLevel + 5))`。 - 普通难度 (`nDifficulty == 0`) 按幕数 `nAct = 0..4` 强制上限 `npcLevels[5] = [12, 20, 28, 36, 45]`;噩梦与地狱难度无幕数上限。 3. **非固定商品生成 (`pItemCache`)**: - 跳过 `base.level > nItemLevel` 的底材。 - **当且仅当 `nItemLevel < 25` 且 `nMax > 0` 时**生成普通/劣质/超强底材: - `nNormalItems = nMin + rand(nMax - nMin + 1)`。 - 品质掷骰 `rand(100)`:`ilvl < 5` 时 `> 90` 为劣质 (`ITEMQUAL_INFERIOR`);`5 <= ilvl < 10` 时 `> 85` 为超强 (`ITEMQUAL_SUPERIOR`);`10 <= ilvl < 25` 时 `>= 75` 为超强;其余为普通白色 (`ITEMQUAL_NORMAL`)。 - **魔法商品生成 (`nMagicMax > 0` 且 `bitfield1 & 1`)**: - `nMinItems = (nItemLevel >= 25) ? ((rand(2)) + 2) : 1`。 - `nRange = nMinItems + nMagicMax - nMagicMin`,生成 `ITEMQUAL_MAGIC` 并调用词缀生成器赋予前后缀(若词缀骰子未出词缀则自动重掷确保有效魔法词缀)与法杖/手杖/权杖 Staffmods。 4. **噩梦/地狱难度底材升级与药水替换 (`D2GAME_NPC_GenerateStoreItem_6FCC6A60`)**: - 当 `nPlayerLevel > 25` 时: - 噩梦难度:`rand(100000) < (nItemLevel << 6) + 4000` 升级为 `UberCode`(若 `Uber.level <= nItemLevel`),否则应用 `NightmareUpgrade`。 - 地狱难度:`nRand = rand(100000)`,资料片 `< 16 * nItemLevel + 1000` 升级为 `UltraCode`,否则 `< (nItemLevel << 7) + 5000` 升级为 `UberCode`;随后应用 `HellUpgrade`。 5. **常驻商品 (`pPermCache`) 与四分页 10×10 网格排布**: - 常驻物品标记 `bPermStore = true`,箭袋 (`aqv`/`cqv`) 设为满数量 `maxstack`。 - 按 `StorePage` (`armr -> Tab 0`, `weap -> Tab 1` 溢出至 `Tab 2`, `misc -> Tab 3`) 自动进行 2D 网格碰撞排布。 ## 验收标准 - [ ] 完整实现 `src/game/vendor-generator.ts`。 - [ ] 覆盖 Act 1~5 全部 17 位商人在普通/噩梦/地狱及不同等级下的库存生成单元测试。
troytt added this to the [M19] 原版商人 NPC 与交易经济系统 (1.13c Ground Truth) milestone 2026-09-26 04:22:14 +00:00
troytt changed title from [M15-P2] 实装 1.13c 商人库存生成引擎 (按商人 ID、游戏难度与角色等级生成出售物品) to [M19-P2] 实装 1.13c 商人库存生成引擎 (按商人 ID、游戏难度与角色等级生成出售物品) 2026-09-26 04:24:35 +00:00
Author
Owner

Implemented and verified in commit 3b993cf (tsc --noEmit 0 errors, vitest 17/17 passing, headless Chrome UI verification passing).

Implemented and verified in commit `3b993cf` (`tsc --noEmit` 0 errors, `vitest` 17/17 passing, headless Chrome UI verification passing).
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#482
No description provided.