参考 › 函数参考 › Platform

Platform.health_forecast.GetHealthForecastValueObservation

公共

调用方式

addon.Platform:GetHealthForecastValueObservation(unit, kind)

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

作用

在单独的身份检查之后读取惰性的生命值标量。current 种类使用确切的 UnitHealth(unit);maximum 使用确切的 UnitHealthMax(unit)。探测或受限策略客户端接受可读的有限非负数字(包括零)。不会重复调用存在性/GUID 查询,也不会回退到其他元组。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
unitstring所选的非空单位标识;仅凭此调用不能确定其存在。
kindstring封闭的标量种类:current 或 maximum。

返回值

1number | nil有限的非负原生生命值标量;不可用时为 nil。
2string | nil策略、验证或所需观测的可用性原因。

版本

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

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

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

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

示例

local current = addon.Platform:GetHealthForecastValueObservation("target", "current")
local maximum = addon.Platform:GetHealthForecastValueObservation("target", "maximum")
if not current or not maximum or maximum == 0 then return nil end
return current / maximum <= 0.35

依赖项

源码

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

Platform.health_forecast.GetHealthForecastValueObservation(self, unit, kind)
    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(kind) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    local api
    if kind=='current' then api=UnitHealth
    elseif kind=='maximum' then api=UnitHealthMax
    else return nil,'invalid-health-forecast-query' end
    if type(api)~='function' then return nil,'missing-api' end
    local ok,value=pcall(api,unit)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(value) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(value) then return nil,'restricted-value' end
    if value==nil then return nil,'health-data-unavailable' end
    if not finite(value) or value<0 then return nil,'invalid-api-result' end
    return value

返回函数参考