local _G = getfenv(0) local addon, L = ...; DS_Color1 = "|cff3399ff" DS_Color2 = "|cff1eff00" DS_Loaded = false DS_pName = UnitName("player") DS_pClass = UnitClass("player") local function myprint(msg) if msg ~= nil then msg = tostring(msg) print(DS_Color1..addon..": "..DS_Color2..msg) return end end local function DS_PadiSpellId(t) if strlen(t) == 2 then tnum = "0000"..t return tnum elseif strlen(t) == 3 then tnum = "000"..t return tnum elseif strlen(t) == 4 then tnum = "00"..t return tnum elseif strlen(t) == 5 then tnum = "0"..t return tnum end return t end function Init_DS_Tables() -- known spells if DS_kSpellsTable == nil then DS_kSpellsTable = {} end if DS_kSpellsTable2 == nil then DS_kSpellsTable2 = {} end if DS_kSpellsTable3 == nil then DS_kSpellsTable3 = {} end if DS_ktblSpellNames == nil then DS_ktblSpellNames = {} end if DS_kSpellsRank == nil then DS_kSpellsRank = {} end if DS_ktblSpellCount == nil then DS_ktblSpellCount = {} end DS_kSpellsTable[DS_pName] = {} DS_kSpellsTable2[DS_pName] = {} DS_kSpellsTable3[DS_pName] = {} DS_ktblSpellNames[DS_pName] = {} DS_kSpellsRank[DS_pName] = {} DS_ktblSpellCount[DS_pName] = 0 -- all spells not pet if DS_aSpellsTable == nil then DS_aSpellsTable = {} end if DS_aSpellsTable2 == nil then DS_aSpellsTable2 = {} end if DS_atblSpellNames == nil then DS_atblSpellNames = {} end if DS_aSpellsRank == nil then DS_aSpellsRank = {} end if DS_atblSpellCount == nil then DS_atblSpellCount = {} end DS_aSpellsTable[DS_pName] = {} DS_aSpellsTable2[DS_pName] = {} DS_atblSpellNames[DS_pName] = {} DS_aSpellsRank[DS_pName] = {} DS_atblSpellCount[DS_pName] = 0 end -- RegisterEvents local DS_Eventframe = CreateFrame("FRAME") DS_Eventframe:RegisterEvent("ADDON_LOADED") DS_Eventframe:RegisterEvent("PLAYER_LOGIN") local function DS_OnEvent(self, event, arg1, ...) if event == "ADDON_LOADED" and arg1 == addon then myprint("Addon_Loaded") DS_Loaded = true self:UnregisterEvent("ADDON_LOADED") end if event == "PLAYER_LOGIN" and DS_Loaded then myprint("Player_Loaded") myprint("Current Player :"..DS_pName) myprint("Current Class :"..DS_pClass) DS_GetSpellBook() DS_Eventframe:UnregisterEvent("PLAYER_LOGIN") end end DS_Eventframe:SetScript("OnEvent", DS_OnEvent) -- Parse player's spellbook and build a list of available spells function DS_GetSpellBook() Init_DS_Tables() -- known spells for character local i = 0 local iIndex = 0 local iSpellId = 0 local old_iSpellId = 0 local txt_iSpellId = "" for i = 1, GetNumSpellTabs() do local _, _, offset, numSlots = GetSpellTabInfo(i) for iIndex = offset, offset+numSlots do local slotType, iSpellId = GetSpellBookItemInfo(iIndex, BOOKTYPE_SPELL) if slotType == "SPELL" then local slotName = GetSpellBookItemName(iIndex, "spell") local spellName = GetSpellInfo(slotName) if (spellName) then txt_iSpellId = DS_PadiSpellId(tostring(iSpellId)) -- make sure iSpellId has not been seen if not DS_kSpellsRank[DS_pName][iSpellId] then DS_kSpellsRank[DS_pName][iSpellId] = 0 DS_ktblSpellNames[DS_pName][spellName] = spellName if old_iSpellId ~= iSpellId then old_iSpellId = iSpellId DS_ktblSpellCount[DS_pName] = DS_ktblSpellCount[DS_pName] + 1 DS_kSpellsTable2[DS_pName][DS_ktblSpellCount[DS_pName]] = DS_pClass..", known, "..spellName..", "..txt_iSpellId DS_kSpellsTable[DS_pName][DS_ktblSpellCount[DS_pName]] = { DS_pClass, "known", spellName, txt_iSpellId, 0 } end end end end end -- for end -- for -- all non pet spells for character local i = 0 local iIndex = 0 local iSpellId = 0 local old_iSpellId = 0 local txt_iSpellId = "" for i = 1, GetNumSpellTabs() do local _, _, offset, numSlots = GetSpellTabInfo(i) for iIndex = offset, offset+numSlots do local slotType, iSpellId = GetSpellBookItemInfo(iIndex, BOOKTYPE_SPELL) if slotType == "SPELL" or slotType == "FUTURESPELL" then local slotName = GetSpellBookItemName(iIndex, "spell") local spellName = GetSpellInfo(slotName) if (spellName) then txt_iSpellId = DS_PadiSpellId(tostring(iSpellId)) -- make sure iSpellId has not been seen if not DS_aSpellsRank[DS_pName][iSpellId] then DS_aSpellsRank[DS_pName][iSpellId] = 0 DS_atblSpellNames[DS_pName][spellName] = spellName if old_iSpellId ~= iSpellId then old_iSpellId = iSpellId DS_atblSpellCount[DS_pName] = DS_atblSpellCount[DS_pName] + 1 DS_aSpellsTable2[DS_pName][DS_atblSpellCount[DS_pName]] = DS_pClass..", all, "..spellName..", "..txt_iSpellId DS_aSpellsTable[DS_pName][DS_atblSpellCount[DS_pName]] = { DS_pClass, "all", spellName, txt_iSpellId, 0 } end end end end end -- for end -- for table.sort({DS_aSpellsTable[DS_pName]}) table.sort(DS_aSpellsTable2[DS_pName]) table.sort({DS_kSpellsTable[DS_pName]}) table.sort(DS_kSpellsTable2[DS_pName]) local spellRank = 0 local findinstr = "" local findinstr2 = "" -- known entries for spellName, _ in pairs(DS_ktblSpellNames[DS_pName]) do spellRank = 0 for loop = 1, DS_ktblSpellCount[DS_pName] do findinstr = DS_kSpellsTable2[DS_pName][loop] if string.match(findinstr, spellName) then spellRank = spellRank + 1 DS_kSpellsTable2[DS_pName][loop] = findinstr..", Rank-"..spellRank findinstr2 = DS_kSpellsTable2[DS_pName][loop] for loop2 = 1, DS_ktblSpellCount[DS_pName] do txt_iSpellId = DS_kSpellsTable[DS_pName][loop2][4] if string.match(findinstr2,txt_iSpellId) then DS_kSpellsTable[DS_pName][loop2][5] = spellRank DS_kSpellsRank[DS_pName][tonumber(txt_iSpellId)] = spellRank end end end end end -- build table3 for loop = 1, DS_atblSpellCount[DS_pName] do spellName = DS_kSpellsTable[DS_pName][loop][3] iSpellId = tonumber(DS_kSpellsTable[DS_pName][loop][4]) if DS_kSpellsTable3[DS_pName][spellName] == nil then DS_kSpellsTable3[DS_pName][spellName] = {} end table.insert(DS_kSpellsTable3[DS_pName][spellName], iSpellId) end -- test getting spellid for a rank -- spellName = "Healing Touch" -- r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14 = unpack(DS_kSpellsTable3[DS_pName][spellName]) -- myprint("Spell is: "..spellName..", Max Ranks for this spell is: "..#DS_kSpellsTable3[DS_pName][spellName]..", Rank 10 spellId is: "..r10) -- all entries for spellName, _ in pairs(DS_atblSpellNames[DS_pName]) do spellRank = 0 for loop = 1, DS_atblSpellCount[DS_pName] do findinstr = DS_aSpellsTable2[DS_pName][loop] if string.match(findinstr, spellName) then spellRank = spellRank + 1 DS_aSpellsTable2[DS_pName][loop] = findinstr..", Rank-"..spellRank findinstr2 = DS_aSpellsTable2[DS_pName][loop] for loop2 = 1, DS_atblSpellCount[DS_pName] do txt_iSpellId = DS_aSpellsTable[DS_pName][loop2][4] if string.match(findinstr2,txt_iSpellId) then DS_aSpellsTable[DS_pName][loop2][5] = spellRank DS_aSpellsRank[DS_pName][tonumber(txt_iSpellId)] = spellRank end end end end end end