参考 › 函数参考 › Platform

Platform.unit_stat.GetUnitStatObservation

公共

调用方式

addon.Platform:GetUnitStatObservation(unit, stat)

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

作用

只从原生的第二个返回值观测有效属性。在探测或受限策略客户端上,先查询确切的 UnitExists(unit),然后对选择器 1..5 查询 UnitStat(unit,stat),或对选择器 6 查询 UnitArmor(unit)。已知不存在时返回 exists=false;所需信息缺失、失败、受限或非有限时返回 nil。保留有限的带符号、小数和零值;忽略所有未使用的元组字段。1..6 的路由是 RM 的选择器策略,而非原生值域的限制。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
unitstring所选的非空单位标识,在原生调用中保持不变。
statnumber整数形式的 RM 属性选择器 1..5,或 6 表示有效护甲。

返回值

1table | nil记录为 exists=false,或 exists=true 并带有有限的 value;不可用时为 nil。
2string | nil查询、策略或观测的可用性原因。

版本

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

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

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

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

示例

local armor = addon.Platform:GetUnitStatObservation("player", 6)
if not armor or not armor.exists then return nil end
return armor.value >= 10000

依赖项

源码

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

Platform.unit_stat.GetUnitStatObservation(self, unit, stat)
    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(stat) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if not finite(stat) or stat%1~=0 or stat<1 or stat>6 then return nil,'invalid-stat-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 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
    local fn
    if stat==6 then fn=UnitArmor else fn=UnitStat end
    if type(fn)~='function' then return nil,'missing-api' end
    local ok,_,effective
    if stat==6 then ok,_,effective=pcall(fn,unit)
    else ok,_,effective=pcall(fn,unit,stat) end
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(effective) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(effective) then return nil,'restricted-value' end
    if effective==nil then return nil,'stat-data-unavailable' end
    if not finite(effective) then return nil,'invalid-api-result' end
    return {exists=true,value=effective}

返回函数参考