參考資料 › 函式參考 › Platform

Platform.actions.GetSpellRangeState

公用

呼叫方式

addon.Platform:GetSpellRangeState(id, unit, bank)

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

作用

使用適當的用戶端 API 或法術書欄位,讀取某個單位針對特定法術的距離。沒有距離限制的法術傳回 applicable=false;否則 applicable=true,inRange 記錄該單位是否在距離內。未知或無法存取的觀測會傳回 nil 及原因。

參數

名稱類型作用
selfRMPlatformRotation Master 平台轉接器。點號參照需要將 addon.Platform 作為第一個參數;冒號呼叫會隱含提供它。
idnumber要檢查其距離的法術 ID。
unitstring | nil單位代碼,例如 target;為 nil 時使用 target。
bankstring法術書範圍:spell、pet 或 any。

傳回值

1table | nil距離記錄,包含 applicable,適用時還包含 inRange;無法使用時為 nil。
2string | nil記錄為 nil 時的可用性或驗證原因。

版本

內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。

  • 該版本無法使用(原因請見提示)
  • 僅在暴雪的棄用相容層開啟時
遊戲 API經典時代TBC 週年版經典進程永久正式版
C_Spell.IsSpellInRange經典時代TBC 週年版經典進程永久正式版
C_Spell.SpellHasRange經典時代TBC 週年版經典進程永久正式版
IsSpellInRange經典時代TBC 週年版經典進程永久正式版
SpellHasRange經典時代TBC 週年版經典進程永久正式版

機密值(正式版與永久)

在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。

範例

local record = addon.Platform:GetSpellRangeState(value.spell, "target", "any")
if not record then return nil end
-- A spell with no range restriction can always reach the target.
return not record.applicable or record.inRange

相依項目

原始碼

Platform/actions.lua,第 120 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。

Platform.actions.GetSpellRangeState(self, id, unit, bank)
    local valid,reason=spellID(id)
    if not valid then return nil,reason end
    if not self:CanReadValue(unit) or not self:CanReadValue(bank) then return nil,"restricted-value" end
    if unit~=nil and (type(unit)~="string" or unit=="") then return nil,"invalid-unit" end
    if bank~="spell" and bank~="pet" and bank~="any" then return nil,"invalid-spell-bank" end
    unit=unit or "target"
    local nativeRange=C_Spell and C_Spell.IsSpellInRange
    local nativeShape=C_Spell and C_Spell.SpellHasRange
    local slot,book,slotReason
    local hasRange,why,queriedShape
    if type(nativeShape)=="function" then
        queriedShape=true
        hasRange,why=call(nativeShape,id)
    elseif type(nativeRange)~="function" and type(SpellHasRange)=="function" then
        if not slot then slot,book,slotReason=findSlot(id,bank) end
        if not slot then return nil,slotReason end
        queriedShape=true
        hasRange,why=call(SpellHasRange,slot,book)
    end
    if why then return nil,why end
    if hasRange~=nil then
        if type(hasRange)~="boolean" then return nil,"invalid-api-result" end
        if not hasRange then return rangeNotApplicable end
    elseif queriedShape then return nil,"invalid-api-result" end
    local inRange
    if type(nativeRange)=="function" then
        inRange,why=call(nativeRange,id,unit)
        if why then return nil,why end
        if inRange~=nil and type(inRange)~="boolean" then return nil,"invalid-api-result" end
    else
        if type(IsSpellInRange)~="function" then return nil,"missing-api" end
        if not slot then slot,book,slotReason=findSlot(id,bank) end
        if not slot then return nil,slotReason end
        inRange,why=call(IsSpellInRange,slot,book,unit)
        if why then return nil,why end
        if inRange==0 then inRange=false elseif inRange==1 then inRange=true end
        if inRange~=nil and type(inRange)~="boolean" then return nil,"invalid-api-result" end
    end
    if inRange==nil then return nil,"invalid-range-check" end
    return inRange and rangeIn or rangeOut

返回函式參考