Reference › Function reference › Platform

Platform.actions.GetSpellRangeState

public

Call as

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

Available directly through addon; no dependency is needed.

What it does

Read spell-specific range for a unit using the appropriate client API or spell-book slot. A spell without a range restriction returns applicable=false; otherwise applicable=true and inRange records whether the unit is in range. Unknown or inaccessible observations return nil with a reason.

Arguments

NameTypeWhat it does
selfRMPlatformRotation Master platform adapter. A dot reference requires addon.Platform as the first argument; a colon call supplies it implicitly.
idnumberSpell ID whose range should be checked.
unitstring | nilUnit token, such as target; nil uses target.
bankstringSpell-book scope: spell, pet or any.

Returns

1table | nilRange record with applicable and, when applicable, inRange; nil when unavailable.
2string | nilAvailability or validation reason when the record is nil.

Editions

Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.

  • Not available on that edition (the reason is in the tooltip)
  • Only while Blizzard's deprecation fallbacks are on
Game APIClassic EraTBC AnniversaryClassic progressionForeverRetail
C_Spell.IsSpellInRangeClassic EraTBC AnniversaryClassic progressionForeverRetail
C_Spell.SpellHasRangeClassic EraTBC AnniversaryClassic progressionForeverRetail
IsSpellInRangeClassic EraTBC AnniversaryClassic progressionForeverRetail
SpellHasRangeClassic EraTBC AnniversaryClassic progressionForeverRetail

Secret values (Retail and Forever)

On Retail and Forever the game hands addons secret values. This helper checks what it reads (addon.Platform:CanReadValue) and returns nil with a reason such as restricted-value instead of a secret it cannot compare. Treat nil as unavailable, not as false.

Example

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

Dependencies

Source

Platform/actions.lua, line 120. Read only in game; Duplicate makes an editable copy.

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

Back to Function reference