调用方式
addon.Platform:GetSpellRangeState(id, unit, bank)
可直接通过 addon 使用,无需依赖项。
作用
使用适当的客户端 API 或法术书栏位,读取某个单位针对特定法术的距离。没有距离限制的法术返回 applicable=false;否则 applicable=true,inRange 记录该单位是否在距离内。未知或无法访问的观测会返回 nil 及原因。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器。点号引用需要将 addon.Platform 作为第一个参数;冒号调用会隐含提供它。 |
id | number | 要检查其距离的法术 ID。 |
unit | string | nil | 单位标识,例如 target;为 nil 时使用 target。 |
bank | string | 法术书范围:spell、pet 或 any。 |
返回值
| 1 | table | nil | 距离记录,包含 applicable,适用时还包含 inRange;不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 记录为 nil 时的可用性或验证原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(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依赖项
call→Platform.actions.callfindSlot→Platform.actions.findSlotrangeIn(builtin:Platform/actions.lua:rangeIn)rangeNotApplicable(builtin:Platform/actions.lua:rangeNotApplicable)rangeOut(builtin:Platform/actions.lua:rangeOut)spellID→Platform.actions.spellID
源码
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




