Как вызывать
addon:GetConditionHealthForecast(unit, healthTarget, percentage, mode, cache)
Доступен напрямую через addon; зависимость не нужна.
Что делает
Оценить время до выбранного уровня здоровья. Полные встроенные наблюдения идентичности и ленивые скалярные наблюдения кэшируются на проход вычисления, а поставщик, история, окно, часы и прогноз остаются действующими. Точное совпадение с целевым значением возвращает ноль до работы с историей. Сохраняются намеренные результаты false (нет оценки) и инициализированного нуля для нулевой или противоположной скорости; некорректные обязательные факты, переполнение или исчерпание бюджета в 4096 единиц дают «недоступно». История никогда не меняется, частичная оценка не придумывается.
Аргументы
| Имя | Тип | Что делает |
|---|---|---|
self | RMAddon | Экземпляр аддона Rotation Master (неявно при вызове через двоеточие). |
unit | string | Выбранный токен юнита, без изменений в наблюдениях. |
healthTarget | number | Абсолютный порог здоровья (отрицательный — дефицит) или доля в процентах. |
percentage | boolean | true выбирает процентную цель и необязательные свежие факты поставщика. |
mode | any | noheals выбирает только урон; nodmg — только исцеление; другие читаемые значения выбирают оба. |
cache | table | nil | Кэш встроенных наблюдений прохода вычисления; при nil запрос выполняется заново. |
Возвращает
| 1 | number | boolean | nil | Конечное оставшееся время, включая ноль; false при известном отсутствии или отсутствии оценки; nil, если недоступно. |
|---|---|---|
| 2 | string | nil | Причина недоступности наблюдения, истории, предела работы или арифметики. |
Издания
Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.
Не читает игровой API напрямую.
Секретные значения (Retail и Forever)
В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте nil недоступным значением, а не ложью.
Как его вызывает аддон
- Время до уровня здоровья (evaluate)
local eta,reason=addon:GetConditionHealthForecast(value.unit,value.health,false,value.mode,cache) - Время до процента здоровья (evaluate)
local eta,reason=addon:GetConditionHealthForecast(value.unit,value.health,true,value.mode,cache)
Зависимости
finite→Core.health_forecast_conditions.finitenativeValue→Core.health_forecast_conditions.nativeValuereadField→Core.health_forecast_conditions.readField
Исходный код
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