呼叫方式
addon.Platform:GetUnitPointPowerObservation(unit, powerType, kind)
可直接透過 addon 使用,不需要相依項目。
作用
使用確切的雙參數 UnitPower 或 UnitPowerMax 查詢,讀取一個明確選擇的點數資源數量。選擇器為必要;不會推斷主要資源或重新對應角色。保留有限的帶正負號、小數與零數量,不進行截斷。缺少、失敗、受限或非有限的資料維持為無法使用。目前值與最大值是分開的觀測,因此呼叫端可以共用目前值快照,同時依需要延遲請求最大值。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台轉接器(使用冒號呼叫時隱含傳入)。 |
unit | string | 要請求其所選資源數量的確切單位代碼。 |
powerType | number | 明確、可讀、有限的非負整數能量選擇器,包括零。 |
kind | string | 只能是 current(對應 UnitPower)或 maximum(對應 UnitPowerMax);不會新增其他原生查詢。 |
傳回值
| 1 | number | nil | 有限的原生資源數量,保留其正負號與小數部分;無法使用時為 nil。 |
|---|---|---|
| 2 | string | nil | 數量為 nil 時的政策、查詢驗證或可用性原因。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
- 該版本無法使用(原因請見提示)
- 僅在暴雪的棄用相容層開啟時
| 遊戲 API | |||||
|---|---|---|---|---|---|
UnitPower | |||||
UnitPowerMax | |||||
canaccessvalue |
機密值(正式版與永久)
在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。
範例
local holyPower = addon.Platform:GetUnitPointPowerObservation("player", Enum.PowerType.HolyPower, "current")
if holyPower == nil then return nil end
return holyPower >= 3相依項目
pointFragmentType(builtin:Platform/points.lua:pointFragmentType)
原始碼
Platform/points.lua,第 189 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Platform.points.GetUnitPointPowerObservation(self, unit, powerType, kind)
local policy=self:GetCombatDataPolicy()
if policy~='probe' and (policy~='restricted' or not self:IsNeverSecretPointPower(powerType)) then return nil,'unsupported-policy' end
if not self:CanReadValue(unit) or not self:CanReadValue(powerType) or not self:CanReadValue(kind) then return nil,'restricted-value' end
if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
if type(powerType)~='number' or powerType~=powerType or powerType<0 or powerType==math.huge or powerType%1~=0 then return nil,'invalid-point-power-query' end
if kind~='current' and kind~='maximum' then return nil,'invalid-point-power-query' end
if powerType==pointFragmentType then return self:GetUnitPointFragmentObservation(unit,powerType,kind) end
local api
if kind=='current' then api=UnitPower else api=UnitPowerMax end
if type(api)~='function' then return nil,'missing-api' end
local ok,result=pcall(api,unit,powerType)
if not ok then return nil,'api-error' end
if not self:CanReadValue(result) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(result) then return nil,'restricted-value' end
if result==nil then return nil,'point-power-unavailable' end
if type(result)~='number' or result~=result or result==math.huge or result==-math.huge then return nil,'invalid-api-result' end
return result




