參考資料 › 函式參考 › 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

返回函式參考