呼叫方式
addon.Platform:GetSpellCooldown(spell)
可直接透過 addon 使用,不需要相依項目。
作用
讀取各支援用戶端的法術冷卻並將其正規化。傳回的記錄包含 startTime、duration、isEnabled 與 modRate。時間戳記與持續時間已經以 GetTime() 秒數描述到期時間;不要再除以 modRate。當用戶端隱藏時間時(正式版與永久的戰鬥中),記錄為 nil,原因為 restricted-value,在可以讀取時其後會附上永不為機密的 isEnabled、isActive 與 isOnGCD 旗標。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台轉接器。點號參照需要將 addon.Platform 作為第一個參數;冒號呼叫會隱含提供它。 |
spell | number | string | 要讀取其冷卻的法術 ID 或用戶端可辨識的法術名稱。 |
傳回值
| 1 | table | nil | 可讀的冷卻記錄;無法使用時為 nil。 |
|---|---|---|
| 2 | string | nil | 記錄為 nil 時的可用性或驗證原因。 |
| 3 | boolean | nil | 僅限 restricted-value:isEnabled,冷卻處於暫停時為 false。 |
| 4 | boolean | nil | 僅限 restricted-value:isActive,在冷卻(其自身冷卻或共用冷卻)進行中時為 true。 |
| 5 | boolean | nil | 僅限 restricted-value:isOnGCD,當進行中的冷卻是共用冷卻時為 true;可能為 nil。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
- 該版本無法使用(原因請見提示)
- 僅在暴雪的棄用相容層開啟時
機密值(正式版與永久)
在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。
範例
local record, reason, isEnabled, isActive = addon.Platform:GetSpellCooldown(value.spell)
if record then return record.isEnabled and record.duration == 0 end
-- Times are secret in combat on Retail and Forever; fall back to the flags.
if reason == "restricted-value" and isActive ~= nil then return isEnabled and not isActive end
return nil相依項目
cooldownFields(builtin:Platform/spells.lua:cooldownFields)cooldownFlags→Platform.spells.cooldownFlagsidentifier→Platform.spells.identifierown→Platform.spells.own
原始碼
Platform/spells.lua,第 393 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Platform.spells.GetSpellCooldown(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.GetSpellCooldown) == "function" then
ok, record = pcall(C_Spell.GetSpellCooldown, spell)
elseif type(GetSpellCooldown) == "function" then
local start, duration, enabled, rate
ok, start, duration, enabled, rate = pcall(GetSpellCooldown, spell)
if not ok then return nil, "api-error" end
if not self:CanReadValue(start) or not self:CanReadValue(duration) or not self:CanReadValue(enabled)
or not self:CanReadValue(rate) then return nil, "restricted-value" end
if start ~= nil then
if enabled ~= 0 and enabled ~= 1 then return nil, "invalid-api-result" end
record = {startTime=start, duration=duration, isEnabled=enabled == 1, modRate=rate or 1};built = true
end
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-data-unavailable" end
local cooldown, why = own(record, cooldownFields, built)
if not cooldown then
if why == "restricted-value" and not built then return nil, why, cooldownFlags(self, record) end
return nil, why
end
if cooldown.startTime == nil or cooldown.duration == nil or cooldown.isEnabled == nil
or cooldown.startTime < 0 or cooldown.duration < 0 or (cooldown.modRate and cooldown.modRate <= 0) then
return nil, "invalid-api-result"
end
cooldown.modRate = cooldown.modRate or 1
return cooldown




