Skip to content

Generate the TotemSpells table

老虎会游泳 edited this page Dec 25, 2019 · 12 revisions

How to run

Run this script in WowLua.

Download Wowlua from https://www.curseforge.com/wow/addons/wowlua

Please switch the interface language to English, otherwise the result may be incorrect.

How to view the result

You can download ViragDevTool to view the result.

https://www.curseforge.com/wow/addons/varrendevtool

How to get the result as a Lua file?

Add this line to the .toc file of a addon:

## SavedVariables: TotemSpells

Then enter the game, run this code in WowLua window, and exit the game from the menu. (Don't use Alt + F4 or Task Manager, or the result will not be saved.)

Then, you can find <addon-name>.lua in World of Warcraft\_classic_\WTF\Account\<your-account-id>\SavedVariables folder with the TotemSpells table in it.

The code

TotemSpells = {}

local TotemItems = {
    Earth = EARTH_TOTEM_SLOT,
    Fire = FIRE_TOTEM_SLOT,
    Water = WATER_TOTEM_SLOT,
    Air = AIR_TOTEM_SLOT
}

local RankTable = {
    "I", "II", "III", "IV", "V", "VI", "VII", "VIII"
}

local function getElement(i, name)
    -- create a new GAMETOOLTIP object
    local tip = myTooltip or CreateFrame("GAMETOOLTIP", "myTooltip")
    local L = L or tip:CreateFontString()
    local R = R or tip:CreateFontString()
    L:SetFontObject(GameFontNormal)
    R:SetFontObject(GameFontNormal)
    tip:AddFontStrings(L, R)
    -- hide it
    tip:SetOwner(WorldFrame, "ANCHOR_NONE")

    -- "show" a tooltip for a spell
    tip:SetSpellByID(i)

    -- "Tools: xxx Totem" shows on myTooltipTextLeft4
    local text = myTooltipTextLeft4:GetText() or ""
    for name, elem in pairs(TotemItems) do
        if text:find(name) then return elem end
    end
    if text:find('Tools') then
        print('[no element]', i, name, text)
    else
        print('[no element]', i, name, '')
    end
    return nil
end

local function getDuration(i, name)
    local desc = (GetSpellDescription(i) or ""):lower()
    local duration = string.match(desc, 'lasts?%s*([0-9.]+)%s*min') or
                         string.match(desc, 'for%s*([0-9.]+)%s*min')
    if duration then
        duration = duration * 60
    else
        duration = string.match(desc, 'lasts?%s*([0-9.]+)%s*sec') or
                       string.match(desc, 'for%s*([0-9.]+)%s*sec')
    end
    if not duration then
        duration = 0
        print('[no duration]', i, name, desc)
    end
    return tonumber(duration)
end

local function run()
    for i = 1, 99999 do
        local args = {GetSpellInfo(i)}
        if args and args[1] and string.match(args[1], 'Totem$') then
            local name = args[1]
            local subtext = GetSpellSubtext(i)
            local rank = nil
            if subtext and #subtext > 0 then
                rank = subtext:match('[0-9]+')
                name = name .. ' ' .. RankTable[rank]
            end
            local duration = getDuration(i, name)
            local element = getElement(i, name)
            if duration > 0 and element then
                local totem = {
                    element = element,
                    name = name,
                    rank = rank,
                    duration = duration
                }
                TotemSpells[i] = totem
                if ViragDevTool_AddData then
                    ViragDevTool_AddData(totem, name .. ' (' .. i .. ')')
                end
            end
        end
    end
    if ViragDevTool_AddData then
        ViragDevTool_AddData(TotemSpells, 'TotemSpells')
    end
end

if WowLuaFrameOutput then
    WowLuaFrameOutput:Clear()
    WowLuaFrameOutput:SetTextCopyable(true)
end
run()

The current result

https://github.com/SwimmingTiger/LibTotemInfo/blob/master/GetTotemInfo.lua#L33

Check the table

See Check the TotemSpells table.

Clone this wiki locally