参考 › 函数参考 › Platform

Platform.range.GetRangeCheckBounds

公共

调用方式

addon.Platform:GetRangeCheckBounds(unit)

可直接通过 addon 使用,无需依赖项。

作用

读取某个单位的公开 LibRangeCheck 距离区间。成功的上限是包含的;正的失败下限是严格的。零下限是合成的。两个边界都不是精确距离,缺少上限也不能证明该单位在所有半径之外。不可用、格式错误、受限或失败的观测会返回 nil 及原因。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
unitstring要观测其与玩家距离的当前单位标识。

返回值

1table | nil可读的区间,带有可选的最小和最大边界(码)。至少存在一个边界;不可用时为 nil。
2string | nil结果为 nil 时的可用性或验证原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

它不直接读取任何游戏 API。

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

示例

local bounds = addon.Platform:GetRangeCheckBounds("target")
if not bounds then return nil end
if bounds.maximum and bounds.maximum <= 8 then return true end
if bounds.minimum and bounds.minimum >= 8 then return false end
return nil -- the interval straddles 8 yards

源码

Platform/range.lua,第 129 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Platform.range.GetRangeCheckBounds(self, unit)
    if not self:CanReadValue(unit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if not LibStub then return nil,'missing-range-provider' end
    local loaded,provider=pcall(function() return LibStub('LibRangeCheck-3.0',true) end)
    if not loaded or not provider or type(provider.GetRange)~='function' then return nil,'missing-range-provider' end
    local ok,minimum,maximum=pcall(provider.GetRange,provider,unit)
    if not ok then return nil,'range-provider-error' end
    if not self:CanReadValue(minimum) or not self:CanReadValue(maximum) then return nil,'restricted-value' end
    for _,bound in pairs({minimum=minimum,maximum=maximum}) do
        if type(bound)~='number' or bound~=bound or bound<0 or bound==math.huge then return nil,'invalid-range-result' end
    end
    if minimum==nil and maximum==nil then return nil,'range-unavailable' end
    if minimum and maximum and minimum>maximum then return nil,'invalid-range-result' end
    return {minimum=minimum,maximum=maximum}

返回函数参考