Work around bug in Blizzard's IsUsableSpell() API function.
Johnny C. Lam [04-06-14 - 18:47]
Work around bug in Blizzard's IsUsableSpell() API function.
IsUsableSpell() doesn't always return the truth when given a spell ID, but
its accuracy improves when given a spell name. Wrap the API function in
OvaleSpellBook so that it silently translates the spell ID to a spell name
before invoking IsUsableSpell().
Bug noted and workaround suggested by @ShmooDude.
git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1283 d5049fe3-3747-40f7-a4b5-f36d6801af5f
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index d752f94..738480c 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -56,7 +56,6 @@ local API_IsCurrentAction = IsCurrentAction
local API_IsItemInRange = IsItemInRange
local API_IsSpellInRange = IsSpellInRange
local API_IsUsableAction = IsUsableAction
-local API_IsUsableSpell = IsUsableSpell
local OVALE_DEFAULT_PRIORITY = 3
@@ -781,7 +780,7 @@ function OvaleBestAction:GetActionInfo(element)
end
end
- actionUsable = API_IsUsableSpell(spellId)
+ actionUsable = OvaleSpellBook:IsUsableSpell(spellId)
elseif element.func == "macro" then
local macro = element.params[1]
diff --git a/OvaleSpellBook.lua b/OvaleSpellBook.lua
index 43d4f4d..0bd013a 100644
--- a/OvaleSpellBook.lua
+++ b/OvaleSpellBook.lua
@@ -33,6 +33,7 @@ local API_GetSpellLink = GetSpellLink
local API_GetSpellTabInfo = GetSpellTabInfo
local API_GetTalentInfo = GetTalentInfo
local API_HasPetSpells = HasPetSpells
+local API_IsUsableSpell = IsUsableSpell
local BOOKTYPE_PET = BOOKTYPE_PET
local BOOKTYPE_SPELL = BOOKTYPE_SPELL
--</private-static-properties>
@@ -252,6 +253,18 @@ function OvaleSpellBook:IsKnownTalent(talentId)
end
end
+-- Returns true if the given spell ID is usable. A spell is *not* usable if:
+-- The player hasn't learned the spell.
+-- The player lacks required mana or reagents.
+-- Reactive conditions haven't been met.
+function OvaleSpellBook:IsUsableSpell(spellId)
+ local name = self:GetSpellName(spellId)
+ if name then
+ return API_IsUsableSpell(self:GetSpellName(spellId))
+ end
+ return false
+end
+
-- Print out the list of active glyphs in alphabetical order.
function OvaleSpellBook:DebugGlyphs()
PrintTableValues(self.glyph)
diff --git a/conditions/SpellUsable.lua b/conditions/SpellUsable.lua
index ce1843e..61ee191 100644
--- a/conditions/SpellUsable.lua
+++ b/conditions/SpellUsable.lua
@@ -12,8 +12,8 @@ local _, Ovale = ...
do
local OvaleCondition = Ovale.OvaleCondition
+ local OvaleSpellBook = Ovale.OvaleSpellBook
- local API_IsUsableSpell = IsUsableSpell
local TestBoolean = OvaleCondition.TestBoolean
--- Test if the given spell is usable.
@@ -33,7 +33,7 @@ do
local function SpellUsable(condition)
local spellId, yesno = condition[1], condition[2]
- local boolean = API_IsUsableSpell(spellId)
+ local boolean = OvaleSpellBook:IsUsableSpell(spellId)
return TestBoolean(boolean, yesno)
end