--Necrolords have to be special, can't use it unless you are one. Also, covenant check can't occur until fully loaded; moving this to check along stone checking.
--AllHearthToyIndex[182773] = 340200 --Necrolord
AllHearthToyIndex[180290]=326064--Night Fae
AllHearthToyIndex[184353]=345393--Kyrian
AllHearthToyIndex[183716]=342122--Venthyr
-- This is the meat right here.
functionSetRandomHearthToy()
-- Setting the new stone while in combat is bad.
--if not InCombatLockdown() then
-- Find the macro.
CheckMacroIndex()
-- Rebuild the stone list if it's empty.
ifnext(UsableHearthToyIndex)==nilthen
GetLearnedStones()
end
localitemID,toyName=''
-- Randomly pick one.
localk=RandomKey(UsableHearthToyIndex)
localitemID,toyName=C_ToyBox.GetToyInfo(k)
iftoyNamethen
-- Remove it from the list so we don't pick it again.
-- Checking to see if we're a Necrolord. We should be fully loaded by now since we're wating for the ToyBox to load.
ifC_Covenants.GetActiveCovenantID()==4then
AllHearthToyIndex[182773]=340200--Necrolord
end
-- Get the current setting for the toybox so we can set it back after we're done.
ToyCollSetting=C_ToyBox.GetCollectedShown()
ToyUnCollSetting=C_ToyBox.GetUncollectedShown()
ToyUsableSetting=C_ToyBox.GetUnusableShown()
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)
-- Hopefully no other macro ever made has "RHT.b" in it...
ifstring.find(macroCont,"RHT.b")then
RHTIndex=i
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.
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/run if not InCombatLockdown() then RHT.b:SetAttribute(\"item\",\""..toyName.."\") end\r/click RHTB")
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/run if not InCombatLockdown() then RHT.b:SetAttribute(\"item\",\""..toyName.."\") end\r/click RHTB")
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]then
SetRandomHearthToy()
break
end
end
end
end
-- Old function to delete the base HS from bags. Leaving in case I can find a workaround from Blizz's change.