调用方式
addon.Platform:GetInspectRoleObservation(unit)
可直接通过 addon 使用,无需依赖项。
作用
在探测或受限策略客户端上观测所选单位的职责,不发出观察请求。已知单位不存在时返回 false。优先使用可调用的现代观察 API,仅当它不可调用时才回退到旧版;所选 API 失败时绝不会回退。要求专精 ID 为正的有限整数,并且只使用确切的单参数 GetSpecializationInfoByID 调用的第五个返回值(职责)。所需信息缺失、失败、受限或格式错误时为不可用;可读的非空未来职责字符串保持原样。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 所选的非空单位标识;作为原生参数保持不变。 |
返回值
| 1 | string | boolean | nil | 已知的非空职责字符串;已知单位不存在时为 false,不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 策略、能力或所需观测的可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
C_SpecializationInfo | |||||
GetInspectSpecialization | |||||
GetSpecializationInfoByID | |||||
UnitExists | |||||
canaccessvalue |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local role = addon.Platform:GetInspectRoleObservation("target")
if role == nil then return nil end
return role == "HEALER"依赖项
readField→Platform.role.readFieldroleValue→Platform.role.roleValue
源码
Platform/role.lua,第 50 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.role.GetInspectRoleObservation(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 namespace,reason=readField(self,_G,'C_SpecializationInfo')
if reason then return nil,reason end
local inspect
if namespace~=nil then
inspect,reason=readField(self,namespace,'GetInspectSpecialization')
if reason then return nil,reason end
end
if type(inspect)~='function' then
inspect,reason=readField(self,_G,'GetInspectSpecialization')
if reason then return nil,reason end
end
if type(inspect)~='function' then return nil,'missing-api' end
local ok,spec=pcall(inspect,unit)
if not ok then return nil,'api-error' end
if not self:CanReadValue(spec) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(spec) then return nil,'restricted-value' end
if spec==nil or spec==0 then return nil,'specialization-unavailable' end
if type(spec)~='number' or spec~=spec or spec>=math.huge or spec<=0 or spec%1~=0 then return nil,'invalid-api-result' end
local metadata
metadata,reason=readField(self,_G,'GetSpecializationInfoByID')
if reason then return nil,reason end
if type(metadata)~='function' then return nil,'missing-api' end
local roleOk,role=pcall(function() return (select(5,metadata(spec))) end)
if not roleOk then return nil,'api-error' end
return roleValue(self,role)




