Skip to content

Generate the TotemSpells table

老虎会游泳 edited this page Dec 19, 2019 · 12 revisions
-- 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.

LogTotemInfo = {}

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

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)
            if subtext and #subtext > 0 then
                name = name .. ' ' .. subtext
            end
            local duration = getDuration(i, name)
            local element = getElement(i, name)
            if duration > 0 and element then
                local totem = {
                    element = element,
                    name = name,
                    duration = duration
                }
                LogTotemInfo[i] = totem
                if ViragDevTool_AddData then
                    ViragDevTool_AddData(totem, name .. ' (' .. i .. ')')
                end
            end
        end
    end
end

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

Clone this wiki locally