参考 › 函数参考 › Platform

Platform.items.GetItemInfoInstant

公共

调用方式

addon.Platform:GetItemInfoInstant(item)

可直接通过 addon 使用,无需依赖项。

作用

读取规范化的原生物品分类元数据。记录包含规范的 itemID、classID 和 subClassID,以及在可读且非空时的 equipLoc(未本地化的 INVTYPE_* 装备位置标记);不要求物品显示文本已加载。元数据缺失、失败、格式错误或受限时返回 nil 及原因。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
itemnumber | string要分类的正数物品 ID,或原生可识别的物品名称/链接。

返回值

1table | nil可读的规范物品分类记录(itemID、classID、subClassID 和可选的 equipLoc),不可用时为 nil。
2string | nil结果为 nil 时的验证或可用性原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
C_Item.GetItemInfoInstant经典旧世TBC 周年版经典进阶服永久服正式服
GetItemInfoInstant经典旧世TBC 周年版经典进阶服永久服正式服

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

示例

local item = addon.Platform:GetItemInfoInstant(5512) -- Healthstone
if not item then return nil end
return item.classID == 0 -- consumable

依赖项

源码

Platform/items.lua,第 132 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Platform.items.GetItemInfoInstant(self, item)
    local valid,reason=identifier(item)
    if not valid then return nil,reason end
    local fn=C_Item and C_Item.GetItemInfoInstant
    if type(fn)~='function' then fn=GetItemInfoInstant end
    if type(fn)~='function' then return nil,'missing-api' end
    local ok,tuple=pcall(function() return {fn(item)} end)
    if not ok then return nil,'api-error' end
    local id,class,subclass=tuple[1],tuple[6],tuple[7]
    if not self:CanReadValue(id) or not self:CanReadValue(class) or not self:CanReadValue(subclass) then return nil,'restricted-value' end
    if id==nil then return nil,'item-data-unavailable' end
    if not finite(id) or id<=0 or id%1~=0 or not finite(class) or class%1~=0
        or not finite(subclass) or subclass%1~=0 or type(item)=='number' and id~=item then return nil,'invalid-api-result' end
    -- The equip location is a non-localized INVTYPE_* token (two-hand,
    -- shield, ...). An empty or unreadable token is simply absent.
    local equipLoc=tuple[4]
    if not self:CanReadValue(equipLoc) or type(equipLoc)~='string' or equipLoc=='' then equipLoc=nil end
    return {itemID=id,classID=class,subClassID=subclass,equipLoc=equipLoc}

返回函数参考