调用方式
addon.Platform:GetRosterClassObservation(unit)
可直接通过 addon 使用,无需依赖项。
作用
在已识别的客户端系列上读取公开的名单身份。输入路由仅限 player、party1 到 party4,以及 raid1 到 raid40。先以该确切的单参数标识调用 UnitExists;已知为 false 时直接返回 false,不查询职业。对于存在的单位,只使用 UnitClass 的第二个返回值作为可读的非空职业文件名字符串,不限制职业枚举。所需信息缺失、失败、格式错误或受限时返回 nil 及原因。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 由辅助函数拥有的确切标识:player、party1..party4 或 raid1..raid40。 |
返回值
| 1 | string | boolean | nil | 观测到的职业文件名字符串;已知单位不存在时为 false,不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 结果为 nil 时的验证、策略或可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
UnitClass | |||||
UnitExists | |||||
canaccessvalue |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
for index = 1, 4 do
local class = addon.Platform:GetRosterClassObservation("party" .. index)
if class == "PRIEST" then return true end
end
return false依赖项
rosterUnit→Platform.roster_class.rosterUnit
源码
Platform/roster_class.lua,第 29 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.roster_class.GetRosterClassObservation(self, unit)
if not self:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or not rosterUnit(unit) then return nil,'invalid-roster-unit' end
if self:GetClientFamily()=='unknown' then return nil,'unsupported-client' end
if type(UnitExists)~='function' then return nil,'missing-api' end
local ok,exists=pcall(UnitExists,unit)
if not ok then return nil,'api-error' end
if not self:CanReadValue(exists) then return nil,'restricted-value' end
if exists==nil then return nil,'roster-data-unavailable' end
if type(exists)~='boolean' then return nil,'invalid-api-result' end
if not exists then return false end
if type(UnitClass)~='function' then return nil,'missing-api' end
local success,_,class=pcall(UnitClass,unit)
if not success then return nil,'api-error' end
if not self:CanReadValue(class) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(class) then return nil,'restricted-value' end
if class==nil then return nil,'roster-class-unavailable' end
if type(class)~='string' or class=='' then return nil,'invalid-api-result' end
return class




