呼叫方式
addon:GetConditionUnitLevel(unit, cache)
可直接透過 addon 使用,不需要相依項目。
作用
為條件評估解析可讀的原始單位等級。已知不存在時傳回 false;觀測無法使用時傳回 nil 及原因。在所提供的評估輪次內快取觀測。只有有效的玩家等級會在輪次之間保留,直到技能、設定檔或等級更新。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
self | RMAddon | Rotation Master 插件實例(使用冒號呼叫時隱含傳入)。 |
unit | string | 要解析其原始等級的單位代碼。 |
cache | table | nil | 共用的評估快取;為 nil 時直接觀測,不使用每輪次的快取。 |
傳回值
| 1 | number | boolean | nil | 正整數等級;已知單位不存在時為 false,無法使用時為 nil。 |
|---|---|---|
| 2 | string | nil | 等級為 nil 時的可用性或查詢驗證原因。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
它不會直接讀取任何遊戲 API。
機密值(正式版與永久)
在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。
插件如何呼叫它
原始碼
Core/level_conditions.lua,第 21 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Core.level_conditions.GetConditionUnitLevel(self, unit, cache)
if not self.Platform:CanReadValue(unit) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if self.Platform:GetClientFamily()=='unknown' then return nil,'unsupported-client' end
local longterm=self.longtermCache
if unit=='player' and type(longterm)=='table' then
local level=longterm.conditionPlayerLevel
if not self.Platform:CanReadValue(level) then return nil,'restricted-value' end
if level~=nil then
if type(level)~='number' or level~=level or level<=0 or level==math.huge or level%1~=0 then return nil,'invalid-api-result' end
return level
end
end
local record,reason=addon.Functions.cache.getCached(cache,self.Platform.GetUnitLevelObservation,self.Platform,unit)
if not record then return nil,reason end
if not record.exists then return false end
if unit=='player' and type(longterm)=='table' then longterm.conditionPlayerLevel=record.level end
return record.level