表概述

npc_vendor表是NPC商人系统的核心配置,属于Npc System。每个商人可以有多个出售物品,每个物品通过(entry, item, ExtendedCost)组合唯一标识。

支持库存限制(maxcount)、库存刷新(incrtime)和扩展价格(ExtendedCost,如荣誉点数、竞技场点数等非金币货币)。

表结构

字段名数据类型默认值说明
entryINT UNSIGNED0商人NPC的生物entry ID
slotSMALLINT0物品在商人界面中的排序位置
itemINT0出售物品的ID,对应item_template.entry
maxcountTINYINT UNSIGNED0最大库存数量,0=无限
incrtimeINT UNSIGNED0库存刷新时间(秒),0=不刷新
ExtendedCostINT UNSIGNED0扩展价格ID,0=使用物品默认金币价格
VerifiedBuildINTNULL验证版本号

重要字段详解

entry (商人NPC ID)

对应creature_template表中的entry值,定义哪个NPC是商人。常见商人类型:

  • 杂货商 - 出售食物、水、材料等
  • 武器商 - 出售各类武器
  • 护甲商 - 出售各类护甲
  • 荣誉商人 - 出售PvP装备(使用ExtendedCost为荣誉点数)
  • 特殊货币商人 - 使用公正徽章、竞技场点数等
maxcount / incrtime (库存与刷新)

控制商人物品的库存管理:

  • maxcount = 0:无限库存,物品永远不会卖完
  • maxcount > 0, incrtime = 0:有限库存,不会刷新
  • maxcount > 0, incrtime > 0:有限库存,按incrtime秒数定时刷新补充

例如:maxcount=3, incrtime=7200 表示库存3个,每2小时刷新一次。

ExtendedCost (扩展价格)

定义物品的非金币购买价格。对应ItemExtendedCost.dbc中的ID:

  • 0 - 使用物品默认金币价格
  • 其他值 - 使用自定义货币(荣誉点数、竞技场点数、公正徽章等)

实战案例

查询某商人的全部出售物品:
SELECT nv.entry, nv.slot, nv.item, it.name, nv.maxcount, nv.incrtime, nv.ExtendedCost
FROM npc_vendor nv
JOIN item_template it ON nv.item = it.entry
WHERE nv.entry = 12345
ORDER BY nv.slot;
查询使用非金币价格的商品:
SELECT nv.entry, nv.item, nv.ExtendedCost
FROM npc_vendor nv
WHERE nv.ExtendedCost > 0
ORDER BY nv.entry;
为商人添加限时出售物品(库存5个,每小时刷新):
INSERT INTO npc_vendor (entry, slot, item, maxcount, incrtime, ExtendedCost, VerifiedBuild)
VALUES (12345, 10, 19019, 5, 3600, 0, NULL);

常见问题

Q: 商人添加了物品但不显示,如何排查?

检查以下几点:

  1. creature_template.npcflag是否包含商人标志(0x80)
  2. npc_vendor表中entry是否匹配creature_template.entry
  3. item在item_template表中是否存在
  4. 玩家是否满足ExtendedCost的购买条件

Q: 如何让限量物品自动刷新库存?

设置incrtime为大于0的值(秒)。如3600=每小时刷新一次。服务器重启时库存也会重置。