C_ToyBox.SetCollectedShown(true)-- List collected toys
C_ToyBox.SetUncollectedShown(false)-- Don't list uncollected toys
C_ToyBox.SetUnusableShown(false)-- Don't list unusable toys in the the collection.
-- Go through all the toys to find the usable stons.
fori=1,C_ToyBox.GetNumFilteredToys()do
-- Go through all the stone to see if this toy is a stone.
forkinpairs(AllHearthToyIndex)do
ifk==C_ToyBox.GetToyFromIndex(i)then
UsableHearthToyIndex[k]=1
end
end
end
-- Reset the toybox filter
C_ToyBox.SetCollectedShown(ToyCollSetting)
C_ToyBox.SetUncollectedShown(ToyUnCollSetting)
C_ToyBox.SetUnusableShown(ToyUsableSetting)
ifnext(UsableHearthToyIndex)then
RHTInitialized=true
end
end
-- We've removed the name from the macro, so now we need to find it so we know which one to edit.
functionGetMacroIndex()
localnumg,numc=GetNumMacros()
fori=1,numgdo
localmacroCont=GetMacroBody(i)
if(macroCont)then-- apperently there's a chance of not having anything here
-- Hopefully no other macro ever made has "RHT.b" in it...
ifstring.find(macroCont,"RHT.b")then
-- check if we have the correct macro version, purge it if not
-- this fixes issues when the addon got broken and we need people to remake their macros
if(string.find(macroCont,"#macro version "..macroVersion))then
RHTIndex=i
else
DeleteMacro(i)
print"ATTENTION: Your random hearthstone macro had to be deleted due to an update of the game, a new one was created, please add the new macro to your action bar"
end
end
end
end
end
-- Have we found the macro yet? Also, make sure the macro we're editing is the right one in case the user rearranged things or deleted it. If not, go find it.
functionCheckMacroIndex()
localmacroCont=GetMacroBody(RHTIndex)
ifmacroContthen
ifstring.find(macroCont,"RHT.b")then
return
end
end
GetMacroIndex()
end
-- Macro writing time.
-- if this method is changed, increment macroVersion var
functionGenMacro(itemID,toyName)
-- Did we find the index? If so, edit that. The macro changes the button to the next stone, but only if we aren't in combat; can't SetAttribute. It then "clicks" the RHTB button
ifRHTIndexthen
EditMacro(RHTIndex,"","INV_MISC_QUESTIONMARK","#showtooltip item:"..itemID.."\r#macro version "..macroVersion.."\r/run if not InCombatLockdown() then RHT.b:SetAttribute(\"item\",\""..toyName.."\") end\r/click RHTB LeftButton"..(needsOne=="1"and" 1"or""))
else
-- No macro found, make a new one, get it's ID, then set the toy on the invisble button. This one is named so people can find it on first use.
CreateMacro("RHT","INV_MISC_QUESTIONMARK","#showtooltip item:"..itemID.."\r#macro version "..macroVersion.."\r/run if not InCombatLockdown() then RHT.b:SetAttribute(\"item\",\""..toyName.."\") end\r/click RHTB LeftButton"..(needsOne=="1"and" 1"or""))
GetMacroIndex()
end
end
-- Remove stone from the list so we don't use it again. (Here for debugging)
functionRemoveStone(k)
UsableHearthToyIndex[k]=nil
end
-- Did a stone get used?
functionSpellcastUpdate(spellID)
ifnotInCombatLockdown()then
forkinpairs(AllHearthToyIndex)do
ifspellID==AllHearthToyIndex[k]["spellId"]orspellID==346060then-- there are two necrolord spells, adding one here temporarily, should refactor the spell lists soon