API

LibRangeCheck-2.0 provides an easy way to check for ranges and get suitable range checking functions for specific ranges.
The checkers use spell and item range checks, or interact based checks for special units where those two cannot be used.
The lib handles the refreshing of checker lists in case talents / spells / glyphs change and in some special cases when equipment changes (for example some of the mage pvp gloves change the range of the Fire Blast spell), and also handles the caching of items used for item-based range checks.
A callback is provided for those interested in checker changes.

Example

local rc = LibStub("LibRangeCheck-2.0")

rc.RegisterCallback(self, rc.CHECKERS_CHANGED, function() print("need to refresh my stored checkers") end)

local minRange, maxRange = rc:GetRange('target')
if not minRange then
    print("cannot get range estimate for target")
elseif not maxRange then
    print("target is over " .. minRange .. " yards")
else
    print("target is between " .. minRange .. " and " .. maxRange .. " yards")
end

local meleeChecker = rc:GetFriendMaxChecker(rc.MeleeRange) -- 5 yds
for i = 1, 4 do
    -- TODO: check if unit is valid, etc
    if meleeChecker("party" .. i) then
        print("Party member " .. i .. " is in Melee range")
    end
end

local safeDistanceChecker = rc:GetHarmMinChecker(30)
-- negate the result of the checker!
local isSafelyAway = not safeDistanceChecker('target')


checker(unit)

A checker function.
This type of function is returned by the various Get*Checker() calls.

Parameters

unit
the unit to check range to.

Return value

true if the unit is within the range for this checker.


lib.RegisterCallback()

Register a callback to get called when checkers are updated

Usage

    rc.RegisterCallback(self, rc.CHECKERS_CHANGED, "myCallback")
    -- or
    rc.RegisterCallback(self, "CHECKERS_CHANGED", someCallbackFunction)

See also

  • CallbackHandler-1.0 documentation for more details


lib:GetFriendChecker(range)

Return a checker for the given range for friendly units.

Parameters

range
the range to check for.

Return value

checker function or nil if no suitable checker is available.


lib:GetFriendCheckers()

Return an iterator for checkers usable on friendly units as (range, checker) pairs.


lib:GetFriendMaxChecker(range)

Return a checker suitable for in-range checking on friendly units, that is, a checker whose range is equal or smaller than the requested range.

Parameters

range
the range to check for.

Return value

checker, range pair or nil if no suitable checker is available. range is the actual range the returned checker checks for.


lib:GetFriendMinChecker(range)

Return a checker suitable for out-of-range checking on friendly units, that is, a checker whose range is equal or larger than the requested range.

Parameters

range
the range to check for.

Return value

checker, range pair or nil if no suitable checker is available. range is the actual range the returned checker checks for.


lib:GetHarmChecker(range)

Return a checker for the given range for enemy units.

Parameters

range
the range to check for.

Return value

checker function or nil if no suitable checker is available.


lib:GetHarmCheckers()

Return an iterator for checkers usable on enemy units as (range, checker) pairs.


lib:GetHarmMaxChecker(range)

Return a checker suitable for in-range checking on enemy units, that is, a checker whose range is equal or smaller than the requested range.

Parameters

range
the range to check for.

Return value

checker, range pair or nil if no suitable checker is available. range is the actual range the returned checker checks for.


lib:GetHarmMinChecker(range)

Return a checker suitable for out-of-range checking on enemy units, that is, a checker whose range is equal or larger than the requested range.

Parameters

range
the range to check for.

Return value

checker, range pair or nil if no suitable checker is available. range is the actual range the returned checker checks for.


lib:GetMiscChecker(range)

Return a checker for the given range for miscellaneous units.

Parameters

range
the range to check for.

Return value

checker function or nil if no suitable checker is available.


lib:GetMiscCheckers()

Return an iterator for checkers usable on miscellaneous units as (range, checker) pairs.
These units are neither enemy nor friendly, such as people in sanctuaries or corpses.


lib:GetMiscMaxChecker(range)

Return a checker suitable for in-range checking on miscellaneous units, that is, a checker whose range is equal or smaller than the requested range.

Parameters

range
the range to check for.

Return value

checker, range pair or nil if no suitable checker is available. range is the actual range the returned checker checks for.


lib:GetMiscMinChecker(range)

Return a checker suitable for out-of-range checking on miscellaneous units, that is, a checker whose range is equal or larger than the requested range.

Parameters

range
the range to check for.

Return value

checker, range pair or nil if no suitable checker is available. range is the actual range the returned checker checks for.


lib:GetRange(unit)

Get a range estimate as minRange, maxRange.

Parameters

unit
the target unit to check range to.

Return value

minRange, maxRange pair if a range estimate could be determined, nil otherwise. maxRange is nil if unit is further away than the highest possible range we can check. Includes checks for unit validity and friendly/enemy status.

Usage

local rc = LibStub("LibRangeCheck-2.0")
local minRange, maxRange = rc:GetRange('target')


lib:GetSmartChecker(range, fallback)

Return a checker for the given range that checks the unit type and calls the appropriate checker (friend/harm/misc).

Parameters

range
the range to check for.
fallback
optional fallback function that gets called as fallback(unit) if a checker is not available for the given type (friend/harm/misc) at the requested range. The default fallback function return nil.

Return value

checker function.


lib:GetSmartMaxChecker(range)

Return a checker suitable for in-of-range checking that checks the unit type and calls the appropriate checker (friend/harm/misc).

Parameters

range
the range to check for.

Return value

checker function.


lib:GetSmartMinChecker(range)

Return a checker suitable for out-of-range checking that checks the unit type and calls the appropriate checker (friend/harm/misc).

Parameters

range
the range to check for.

Return value

checker function.



Comments

Posts Quoted:
Reply
Clear All Quotes