Skip to content

Commit

Permalink
fix: fix Stone of the Hearth and add debug logging
Browse files Browse the repository at this point in the history
Stone of the Hearth uses the OG Hearthstone spellId, rather than the one
listed for the item in Wowhead. Also added a ton of debug logic to see
why sometimes the toyName is not returned. Still a WiP
  • Loading branch information
lyledouglass committed Jul 14, 2024
1 parent d3a70f3 commit e482c34
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions HearthstoneRandomizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ local function Event(self, event, arg1, arg2, arg3)
end
-- When a spell cast stops and it's the player's spell, send the ID to check if it's a stone.
if event == "UNIT_SPELLCAST_STOP" and arg1 == "player" then
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Spellcast stopped") end
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Spell ID of current spell: " ..arg3) end
SpellcastUpdate(arg3)
end
end
Expand Down Expand Up @@ -78,26 +80,32 @@ AllHearthToyIndex[190196] = 366945 --Enlightened
AllHearthToyIndex[209035] = 422284 --Larodar Flame
AllHearthToyIndex[200630] = 391042 --Windsage
AllHearthToyIndex[193588] = 375357 --Timewalker's
AllHearthToyIndex[212337] = 431644 --Stone of the Hearth
AllHearthToyIndex[212337] = 401802 --Stone of the Hearth - 401802 is the spell ID for the standard hearthstone but its consistently returned for this toy?


-- This is the meat right here.
function SetRandomHearthToy()
-- Find the macro.
GetMacro()
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Macro got - setting random hearthstone") end
-- Rebuild the stone list if it's empty.
if next(UsableHearthToyIndex) == nil then
GetLearnedStones()
end
local itemID, toyName = ''
local itemID, toyName = '',''
-- Randomly pick one.
local k = RandomKey(UsableHearthToyIndex)
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Random Hearthstone itemId: " ..k) end
local itemID, toyName = C_ToyBox.GetToyInfo(k)
if toyName then
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Random Hearthstone toy: " ..toyName) end
-- Remove it from the list so we don't pick it again.
RemoveStone(k)
-- Write the macro.
GenMacro(itemID, toyName)
else
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Random Hearthstone toy did not get set") end
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Faulting stones itemID: " ..itemID) end
end
end

Expand All @@ -118,6 +126,7 @@ function GetLearnedStones()
for k in pairs(AllHearthToyIndex) do
if k == C_ToyBox.GetToyFromIndex(i) then
UsableHearthToyIndex [k] = 1
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Usable Hearthstone found: " ..k) end
end
end
end
Expand All @@ -137,7 +146,7 @@ function GetMacro()
macroExists = GetMacroIndexByName("RHT")
if macroExists == 0 then
RHTIndex = false
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Macro is 0, index is: " .. RHTIndex) end
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","macroExists is 0, index is null") end
else
RHTIndex = macroExists
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Macro is not 0, index is: " .. RHTIndex) end
Expand All @@ -146,7 +155,7 @@ end

-- Macro writing time.
function GenMacro(itemID, toyName)
if RHTIndex then
if RHTIndex ~= false then
EditMacro(RHTIndex, "RHT", "INV_MISC_QUESTIONMARK", "#showtooltip item:" .. itemID .. "\r/cast " .. toyName)
-- Debug output
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Macro updated") end
Expand All @@ -168,6 +177,7 @@ function SpellcastUpdate(spellID)
if not InCombatLockdown() then
for k in pairs(AllHearthToyIndex) do
if spellID == AllHearthToyIndex[k] then
if DLAPI then DLAPI.DebugLog("HearthstoneRandomizer","Stone used: " ..k) end
SetRandomHearthToy()
break
end
Expand Down

0 comments on commit e482c34

Please sign in to comment.