Skip to content

Commit

Permalink
Workaround for unlearned spellbook spells in TWW (#30)
Browse files Browse the repository at this point in the history
* Switching to `C_Spell.IsSpellInRange` for TWW

This replaces `C_SpellBook.IsSpellBookItemInRange` with `C_Spell.IsSpellInRange` in the TWW fallback, to ensure even unlearned spells can be used for range check. `IsSpellBookItemInRange` does not check unlearned spells.
To make this work, the spell index used and returned from `findSpellIdx` is now the `spellID` in retail, but still the spellbook index for classic/era.
  • Loading branch information
cont1nuity authored Jul 26, 2024
1 parent 0531c8a commit 7c73357
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions LibRangeCheck-3.0/LibRangeCheck-3.0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ License: MIT
-- @class file
-- @name LibRangeCheck-3.0
local MAJOR_VERSION = "LibRangeCheck-3.0"
local MINOR_VERSION = 20
local MINOR_VERSION = 21

---@class lib
local lib, oldminor = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
Expand Down Expand Up @@ -76,27 +76,24 @@ local UnitIsUnit = UnitIsUnit
local UnitGUID = UnitGUID
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local CheckInteractDistance = CheckInteractDistance
local IsSpellInRange = _G.IsSpellInRange or function(id, unit)
local result = C_Spell.IsSpellInRange(id, unit)
local IsSpellBookItemInRange = _G.IsSpellInRange or function(index, spellBank, unit)
local result = C_Spell.IsSpellInRange(index, unit)
if result == true then
return 1
elseif result == false then
return 0
end
return nil
end
local IsSpellBookItemInRange = _G.IsSpellInRange or function(index, spellBank, unit)
-- Deprecated_11_0_0.lua set BOOKTYPE_SPELL to "spell" but doesn't provide a compatibility wrapper for IsSpellBookItemInRange
local GetSpellBookItemInfo = _G.GetSpellBookItemInfo or function(index, spellBank)
if type(spellBank) == "string" then
spellBank = (spellBank == "spell") and Enum.SpellBookSpellBank.Player or Enum.SpellBookSpellBank.Pet;
end
local result = C_SpellBook.IsSpellBookItemInRange(index, spellBank, unit)
if result == true then
return 1
elseif result == false then
return 0
local info = C_SpellBook.GetSpellBookItemInfo(index, spellBank)
-- we are looking for "Spell" and "FutureSpell", but not passives here
if info and not info.isPassive and (info.itemType == Enum.SpellBookItemType.Spell or info.itemType == Enum.SpellBookItemType.FutureSpell) then
return info.itemType, info.spellID
end
return nil
end
local UnitClass = UnitClass
local UnitRace = UnitRace
Expand Down Expand Up @@ -168,7 +165,7 @@ for _, n in ipairs({ "EVOKER", "DEATHKNIGHT", "DEMONHUNTER", "DRUID", "HUNTER",
end

-- Evoker
tinsert(HarmSpells.EVOKER, 369819) -- Disintegrate (25 yards)
tinsert(HarmSpells.EVOKER, 362969) -- Azure Strike (25 yards)

tinsert(FriendSpells.EVOKER, 361469) -- Living Flame (25 yards)
tinsert(FriendSpells.EVOKER, 360823) -- Naturalize (Preservation) (30 yards)
Expand Down Expand Up @@ -646,7 +643,12 @@ local function findSpellIdx(spellName)
for i = 1, getNumSpells() do
local spell = GetSpellBookItemName(i, BOOKTYPE_SPELL)
if spell == spellName then
return i
local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_SPELL)
if spellType == "SPELL" or spellType == "FUTURESPELL" then -- classic/era
return i
elseif Enum.SpellBookItemType and (spellType == Enum.SpellBookItemType.Spell or spellType == Enum.SpellBookItemType.FutureSpell) then -- retail
return spellID
end
end
end
return nil
Expand All @@ -668,7 +670,7 @@ local function findMinRangeChecker(origMinRange, origRange, spellList, interactL
local sid = spellList[i]
local name, minRange, range, spellIdx = getSpellData(sid)
if range and spellIdx and origMinRange <= range and range <= origRange and minRange == 0 then
return checkers_Spell[findSpellIdx(name)]
return checkers_Spell[spellIdx]
end
end
for index, range in pairs(interactLists) do
Expand Down

0 comments on commit 7c73357

Please sign in to comment.