调用方式
addon.Platform:GetHealthForecastProviderObservation(unit)
可直接通过 addon 使用,无需依赖项。
作用
使用确切的单参数点号调用读取可选的 RealMobHealth。命名空间不存在(nil/false)时返回空记录。分别规范化当前值和最大值:nil/false 字段允许回退到原生值,数字零仍视为存在。所使用的提供者信息格式错误、失败、受限、为负或非有限时为不可用。不使用提供者或过期的后备缓存。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
unit | string | 作为唯一的提供者参数转发的所选单位标识。 |
返回值
| 1 | table | nil | 部分的当前值/最大值记录;提供者不存在时为空,不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 提供者、验证或观测的可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
它不直接读取任何游戏 API。
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local record = addon.Platform:GetHealthForecastProviderObservation("target")
if not record or not record.current or not record.maximum then return nil end
if record.maximum == 0 then return nil end
return record.current / record.maximum < 0.2依赖项
providerValue→Platform.health_forecast.providerValuereadField→Platform.health_forecast.readField
源码
Platform/health_forecast.lua,第 107 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.health_forecast.GetHealthForecastProviderObservation(self, unit)
local policy=self:GetCombatDataPolicy()
if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
if not self:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
local provider=_G.RealMobHealth
if not self:CanReadValue(provider) then return nil,'restricted-value' end
if provider==nil or provider==false then return {} end
local api,why=readField(self,provider,'GetUnitHealth')
if why then return nil,why end
if type(api)~='function' then return nil,'missing-api' end
local ok,current,maximum=pcall(api,unit)
if not ok then return nil,'api-error' end
local value,reason=providerValue(self,current)
if reason then return nil,reason end
local max,maxReason=providerValue(self,maximum)
if maxReason then return nil,maxReason end
return {current=value,maximum=max}