参考 › 函数参考 › Platform

Platform.unit_identity.GetUnitIdentityObservation

公共

调用方式

addon.Platform:GetUnitIdentityObservation(unit, otherunit)

可直接通过 addon 使用,无需依赖项。

作用

只用 UnitExists 检查第一个单位标识后,使用 UnitIsUnit 比较两个确切的单位标识。若第一个单位可读且不存在,则不进行比较直接返回 false。所需的观测缺失、失败、受限或格式错误时返回 nil 及原因。不会额外进行第二次存在性查询、GUID 查找或推断身份。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
unitstring第一个确切的单位标识,在比较前会检查其存在性。
otherunitstring第二个确切的单位标识,原样传给 UnitIsUnit。

返回值

1boolean | nil可读的单位相等结果;已知第一个单位不存在时为 false,所需观测不可用时为 nil。
2string | nil身份结果为 nil 时的策略、标识验证或可用性原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
UnitExists经典旧世TBC 周年版经典进阶服永久服正式服
UnitIsUnit经典旧世TBC 周年版经典进阶服永久服正式服

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

示例

local same = addon.Platform:GetUnitIdentityObservation("targettarget", "player")
if same == nil then return nil end
return same -- the target is attacking you

源码

Platform/unit_identity.lua,第 21 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Platform.unit_identity.GetUnitIdentityObservation(self, unit, otherunit)
    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(otherunit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' or type(otherunit)~='string' or otherunit=='' 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
    if type(UnitIsUnit)~='function' then return nil,'missing-api' end
    local ok,same=pcall(UnitIsUnit,unit,otherunit)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(same) then return nil,'restricted-value' end
    if same==nil then return nil,'unit-identity-unavailable' end
    if type(same)~='boolean' then return nil,'invalid-api-result' end
    return same

返回函数参考