參考資料 › 函式參考 › Platform

Platform.health_forecast.GetHealthForecastProviderObservation

公用

呼叫方式

addon.Platform:GetHealthForecastProviderObservation(unit)

可直接透過 addon 使用,不需要相依項目。

作用

使用確切的單參數點號呼叫讀取選擇性的 RealMobHealth。命名空間不存在(nil/false)時傳回空記錄。分別標準化目前值與最大值:nil/false 欄位允許改用原生值,數字零仍視為存在。所使用的提供者資訊格式錯誤、失敗、受限、為負或非有限時為無法使用。不使用提供者或過期的備用快取。

參數

名稱類型作用
selfRMPlatformRotation Master 平台轉接器(使用冒號呼叫時隱含傳入)。
unitstring作為唯一的提供者參數轉送的所選單位代碼。

傳回值

1table | nil部分的目前值/最大值記錄;提供者不存在時為空,無法使用時為 nil。
2string | 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

相依項目

原始碼

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}

返回函式參考