调用方式
addon.Platform:GetUnitLevelObservation(unit)
可直接通过 addon 使用,无需依赖项。
作用
在已知的客户端上观测可读的原始单位等级。可读且不存在的单位返回 exists=false;存在的单位要求 UnitLevel 为正的有限整数。未知的首领等级,以及缺失、失败、受限或格式错误的观测会返回 nil 及原因。这不使用有效等级或缩放后的等级。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 要观测其原始等级的单位标识。 |
返回值
| 1 | table | nil | 全新的可读记录,包含 exists,存在时还包含正整数 level。 |
|---|---|---|
| 2 | string | nil | 等级观测为 nil 时的可用性或查询验证原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
UnitExists | |||||
UnitLevel | |||||
canaccessvalue |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local target = addon.Platform:GetUnitLevelObservation("target")
local player = addon.Platform:GetUnitLevelObservation("player")
if not target or not player or not player.exists then return nil end
return target.exists and target.level < player.level依赖项
finite→Platform.unit_level.finite
源码
Platform/unit_level.lua,第 28 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.unit_level.GetUnitLevelObservation(self, unit)
if not self:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if self:GetClientFamily()=='unknown' then return nil,'unsupported-client' 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 {exists=false} end
if type(UnitLevel)~='function' then return nil,'missing-api' end
local levelOk,level=pcall(UnitLevel,unit)
if not levelOk then return nil,'api-error' end
if not self:CanReadValue(level) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(level) then return nil,'restricted-value' end
if level==nil then return nil,'level-data-unavailable' end
if not finite(level) then return nil,'invalid-api-result' end
if level<0 then return nil,'level-data-unavailable' end
if level==0 or level%1~=0 then return nil,'invalid-api-result' end
return {exists=true,level=level}




