调用方式
addon.Platform:GetUnitCreatureTypeID(unit)
可直接通过 addon 使用,无需依赖项。
作用
在探测或受限策略客户端上,从原生 UnitCreatureType 的第二个返回值观测生物身份。先检查确切的 UnitExists(unit);可读的 false 会直接返回 false,不需要也不调用生物元数据。存在的单位要求可读的有限数字 ID;未使用的本地化名称不影响可用性。带符号、小数、零以及未来的有限 ID 都会作为已知值保留。所需信息缺失、失败、为 nil、受限或格式错误时返回 nil 及原因。不会添加生物枚举、翻译标题比较或长期缓存。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 可读的非空所选单位标识,作为单个参数原样传给存在性和生物元数据查询。 |
返回值
| 1 | number | boolean | nil | 有限的原生生物 ID;已知单位不存在时为 false,所需观测不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | ID 为 nil 时的策略、查询验证或所需观测的可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local id = addon.Platform:GetUnitCreatureTypeID("target")
if id == nil then return nil end
-- false (no target) never equals 6, the Undead creature type.
return id == 6源码
Platform/creature_type.lua,第 17 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.creature_type.GetUnitCreatureTypeID(self, unit)
local policy=self:GetCombatDataPolicy()
if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
if not self:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if type(UnitExists)~='function' then return nil,'missing-api' end
local existsOk,exists=pcall(UnitExists,unit)
if not existsOk then return nil,'api-error' end
if not self:CanReadValue(exists) then return nil,'restricted-value' end
if exists==nil then return nil,'unit-data-unavailable' end
if type(exists)~='boolean' then return nil,'invalid-api-result' end
if not exists then return false end
local native=UnitCreatureType
if type(native)~='function' then return nil,'missing-api' end
local observed,_,id=pcall(native,unit)
if not observed then return nil,'api-error' end
if not self:CanReadValue(id) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(id) then return nil,'restricted-value' end
if id==nil then return nil,'unit-creature-type-unavailable' end
if type(id)~='number' or id~=id or id==math.huge or id==-math.huge then return nil,'invalid-api-result' end
return id




