参考 › 函数参考 › Core

Core.health_forecast_conditions.GetConditionHealthForecast

公共

调用方式

addon:GetConditionHealthForecast(unit, healthTarget, percentage, mode, cache)

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

作用

估算距离达到所选生命值的时间。每个评估轮次缓存完整的原生身份和惰性标量观测,而提供者、历史、窗口、时钟和预测保持实时。目标完全相等时,会在处理历史之前返回零。对于零速率或反向速率,保留刻意设计的“无估算”false 结果和初始化的零结果;所需信息无效、溢出或 4096 单位工作量耗尽时为不可用。绝不修改历史或编造部分估算。

参数

名称类型作用
selfRMAddonRotation Master 插件实例(使用冒号调用时隐含传入)。
unitstring所选的单位标识,在观测中保持不变。
healthTargetnumber绝对生命值目标(负数表示缺口)或百分比小数。
percentageboolean为 true 时选择百分比目标以及可选的全新提供者信息。
modeanynoheals 只选择伤害;nodmg 只选择治疗;其他可读的值会同时选择两者。
cachetable | nil评估轮次的原生观测缓存;为 nil 时重新查询。

返回值

1number | boolean | nil有限的预计时间(包括零);已知不存在/无估算时为 false,不可用时为 nil。
2string | nil观测、历史、工作量上限或运算的可用性原因。

版本

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

它不直接读取任何游戏 API。

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

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

插件如何调用它

依赖项

源码

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

Core.health_forecast_conditions.GetConditionHealthForecast(self, unit, healthTarget, percentage, mode, cache)
    local platform=self.Platform
    local policy=platform:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not platform:CanReadValue(unit) or not platform:CanReadValue(percentage) or not platform:CanReadValue(cache) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' or type(percentage)~='boolean' then return nil,'invalid-health-forecast-query' end
    if cache~=nil and type(cache)~='table' then return nil,'invalid-health-forecast-cache' end
    if type(platform.GetHealthForecastIdentityObservation)~='function' then return nil,'missing-api' end
    local guid,identityReason=addon.Functions.cache.getCached(cache,platform.GetHealthForecastIdentityObservation,platform,unit)
    if not platform:CanReadValue(guid) then return nil,'restricted-value' end
    if guid==nil then return nil,identityReason or 'unit-guid-unavailable' end
    if guid==false then return false end
    if type(guid)~='string' or guid=='' then return nil,'invalid-health-forecast-identity' end
    local current,maximum
    if percentage then
        if type(platform.GetHealthForecastProviderObservation)~='function' then return nil,'missing-api' end
        local provider,why=platform:GetHealthForecastProviderObservation(unit)
        if not platform:CanReadValue(provider) then return nil,'restricted-value' end
        if provider==nil then return nil,why or 'health-provider-unavailable' end
        current,why=readField(platform,provider,'current')
        if why then return nil,why end
        maximum,why=readField(platform,provider,'maximum')
        if why then return nil,why end
        if current==nil or current==false then current,why=nativeValue(self,unit,'current',cache);if current==nil then return nil,why end end
        if maximum==nil or maximum==false then maximum,why=nativeValue(self,unit,'maximum',cache);if maximum==nil then return nil,why end end
    else
        local why;current,why=nativeValue(self,unit,'current',cache)
        if current==nil then return nil,why end
    end
    local valid,reason=finite(platform,current)
    if not valid then return nil,reason end
    if current<0 then return nil,'invalid-health-forecast-number' end
    valid,reason=finite(platform,healthTarget)
    if not valid then return nil,reason end
    local target=healthTarget
    if percentage then
        valid,reason=finite(platform,maximum)
        if not valid then return nil,reason end
        if maximum<0 then return nil,'invalid-health-forecast-number' end
        target=maximum*healthTarget
    elseif healthTarget<0 then
        local why;maximum,why=nativeValue(self,unit,'maximum',cache)
        if maximum==nil then return nil,why end
        target=target+maximum
    end
    valid,reason=finite(platform,target)
    if not valid then return nil,reason end
    if current==target then return 0 end
    local history,why=readField(platform,self.damageHistory,guid)
    if why then return nil,why end
    if history==nil or history==false then return false end
    if type(history)~='table' then return nil,'invalid-forecast-history' end
    if not platform:CanReadValue(mode) then return nil,'restricted-value' end
    local noheals,nodmg=mode=='noheals',mode=='nodmg'
    local profile,profileReason=readField(platform,self.db,'profile')
    if profileReason then return nil,profileReason end
    local window,windowReason=readField(platform,profile,'damage_history')
    if windowReason then return nil,windowReason end
    valid,reason=finite(platform,window)
    if not valid then return nil,reason end
    if type(platform.GetHealthForecastTimeObservation)~='function' then return nil,'missing-api' end
    local now,timeReason=platform:GetHealthForecastTimeObservation()
    if not platform:CanReadValue(now) then return nil,'restricted-value' end
    if now==nil then return nil,timeReason or 'forecast-time-unavailable' end
    valid,reason=finite(platform,now)
    if not valid then return nil,reason end
    local functions=self.Functions.forecast
    if type(functions)~='table' or type(functions.calculate)~='function' then return nil,'forecast-kernel-unavailable' end
    local ok,rate,seconds,forecastReason=pcall(functions.calculate,platform,history,window,noheals,nodmg,now)
    if not ok then return nil,'forecast-kernel-error' end
    if not platform:CanReadValue(forecastReason) then return nil,'restricted-value' end
    if forecastReason~=nil then return nil,forecastReason end
    if not platform:CanReadValue(rate) then return nil,'restricted-value' end
    if rate==nil or rate==false then return false end
    valid,reason=finite(platform,rate)
    if not valid then return nil,reason end
    valid,reason=finite(platform,seconds)
    if not valid then return nil,reason end
    if seconds<=2 then return false end
    local eta=0
    local distance,divisor
    if rate<0 and target<current then distance=current-target;divisor=-rate
    elseif rate>0 and target>current then distance=target-current;divisor=rate end
    if distance~=nil then
        valid,reason=finite(platform,distance)
        if not valid then return nil,reason end
        eta=distance/divisor
    end
    valid,reason=finite(platform,eta)
    if not valid then return nil,reason end
    return eta

返回函数参考