呼叫方式
addon.Platform:GetSpellCharges(spell)
可直接透過 addon 使用,不需要相依項目。
作用
讀取標準化的充能記錄:currentCharges、maxCharges、cooldownStartTime、cooldownDuration、chargeModRate 與 isActive。不受支援的法術或受限的用戶端資料會傳回 nil 及原因。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台轉接器。點號參照需要將 addon.Platform 作為第一個參數;冒號呼叫會隱含提供它。 |
spell | number | string | 要讀取其充能的法術 ID 或用戶端可辨識的法術名稱。 |
傳回值
| 1 | table | nil | 可讀的充能記錄;無法使用時為 nil。 |
|---|---|---|
| 2 | string | nil | 記錄為 nil 時的可用性或驗證原因。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
- 該版本無法使用(原因請見提示)
- 僅在暴雪的棄用相容層開啟時
機密值(正式版與永久)
在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。
範例
local charges = addon.Platform:GetSpellCharges(value.spell)
if not charges then return nil end
-- spend a charge rather than waste recharge time
return charges.currentCharges == charges.maxCharges相依項目
chargeFields(builtin:Platform/spells.lua:chargeFields)identifier→Platform.spells.identifierown→Platform.spells.own
原始碼
Platform/spells.lua,第 616 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Platform.spells.GetSpellCharges(self, spell)
local valid,reason=identifier(spell)
if not valid then return nil,reason end
local ok,record,built
if C_Spell and type(C_Spell.GetSpellCharges)=="function" then
ok,record=pcall(C_Spell.GetSpellCharges,spell)
elseif type(GetSpellCharges)=="function" then
local current,maximum,start,duration,rate
ok,current,maximum,start,duration,rate=pcall(GetSpellCharges,spell)
if not ok then return nil,"api-error" end
record={currentCharges=current,maxCharges=maximum,cooldownStartTime=start,cooldownDuration=duration,chargeModRate=rate};built=true
else return nil,"missing-api" end
if not ok then return nil,"api-error" end
if not self:CanReadValue(record) then return nil,"restricted-value" end
if record==nil then return nil,"spell-charges-unavailable" end
local charges,why=own(record,chargeFields,built)
if not charges then return nil,why end
if next(charges)==nil then return nil,"spell-charges-unavailable" end
local current,maximum,start,duration=charges.currentCharges,charges.maxCharges,charges.cooldownStartTime,charges.cooldownDuration
if current==nil or maximum==nil or start==nil or duration==nil or current<0 or current%1~=0
or maximum<1 or maximum%1~=0 or current>maximum or start<0 or duration<0
or charges.chargeModRate and charges.chargeModRate<=0 then return nil,"invalid-api-result" end
local active=current<maximum and start>0 and duration>0
if charges.isActive==nil then charges.isActive=active
elseif charges.isActive and not active then return nil,"invalid-api-result" end
charges.chargeModRate=charges.chargeModRate or 1
return charges




