调用方式
addon.Platform:GetUnitPointIdentityObservation(unit, includeClass)
可直接通过 addon 使用,无需依赖项。
作用
为点数资源条件观测确切的所选单位是否存在,并可选地观测其职业文件名。已知不存在时返回 exists=false,不读取职业。存在的单位只在请求时需要 UnitClass 的第二个返回值;未使用的本地化名称和 ID 不影响可用性。所需观测缺失、失败、受限或格式错误时保持为不可用。这不会选择资源或缓存身份。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 原样传给 UnitExists 以及(必要时)UnitClass 的确切单位标识。 |
includeClass | boolean | 为 true 时还要求存在单位的职业文件名;为 false 时只读取存在性。 |
返回值
| 1 | table | nil | 可读记录,包含布尔值 exists,存在时还包含所请求的职业文件名;所需数据不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 记录为 nil 时的策略、查询验证或所需观测的可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
UnitClass | |||||
UnitExists | |||||
canaccessvalue |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local record = addon.Platform:GetUnitPointIdentityObservation("target", true)
if not record then return nil end
return record.exists and record.class == "ROGUE"源码
Platform/points.lua,第 87 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.points.GetUnitPointIdentityObservation(self, unit, includeClass)
local policy=self:GetCombatDataPolicy()
if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
if not self:CanReadValue(unit) or not self:CanReadValue(includeClass) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if type(includeClass)~='boolean' then return nil,'invalid-point-identity-query' 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 canaccessvalue and not canaccessvalue(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 not includeClass then return {exists=true} end
if type(UnitClass)~='function' then return nil,'missing-api' end
local ok,_,class=pcall(UnitClass,unit)
if not ok 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,'point-class-unavailable' end
if type(class)~='string' or class=='' then return nil,'invalid-api-result' end
return {exists=true,class=class}




