-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
134 lines (124 loc) · 5.16 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
local CURRENT_PHASE = 2;
local _, _addon = ...
local L = _addon:GetLocalization()
local _, race = UnitRace("player")
local faction = UnitFactionGroup("player")
--- Check if spell can be aquired
-- Cheks if spell can be learned in phase, is already learned, if char has right faction and race and has learned required talents.
-- @param spell A spell table from the spells table
-- @param filterLearned Whether to filter out already learned spells
local function IsSpellAvailable(spell, filterLearned)
if spell.phase and spell.phase > CURRENT_PHASE then return false end
if filterLearned and IsSpellKnown(spell.id, false) then return false end
if spell.faction and spell.faction ~= faction then return false end
if spell.talentReq then
local _,_,_,_, currentRank = GetTalentInfo(spell.talentReq[1] , spell.talentReq[2])
if currentRank == 0 then return false end
end
if spell.race and spell.race ~= race then return false end
if spell.races then
local found = false
for k,v in ipairs(spell.races) do
if v == race then
found = true
break
end
end
if not found then return false end
end
if spell.requires and not IsSpellKnown(spell.requires, false) then
return false;
end
if spell.isUnique then
local spellName, spellRank = GetSpellInfo(spell.id);
spellRank = string.match(spellRank, "%d");
local i = 1;
while true do
local itemName, itemRank = GetSpellBookItemName(i, BOOKTYPE_SPELL);
if not itemName then
break;
end
itemRank = string.match(itemRank, "%d");
if itemName == spellName then
if spellRank and itemRank and spellRank < itemRank then
return false;
end
break;
end
i = i + 1;
end
end
return true
end
--- Get level up spells
-- Get all trainable spells for a certain level for the logged in character class
-- @param level The level to get spells for
-- @param filterLearned Whether to filter out spells that are already learned
-- @param spellTable (optional) An existing table to add the level subtable to
-- @return A table containing the level as key for a table with the spells for that level, nil if no spells found
-- @return Number of spells found
function _addon:GetSpellsForLevel(level, filterLearned, spellTable)
if _addon.spells[level] == nil then return nil, 0 end
local spells = spellTable or {}
local spellsOnLevel = {}
local foundSpells = 0
for _, spell in ipairs(_addon.spells[level]) do
if IsSpellAvailable(spell, filterLearned) then
table.insert(spellsOnLevel, spell)
foundSpells = foundSpells + 1
end
end
if foundSpells > 0 then
spells[level] = spellsOnLevel
return spells, foundSpells
end
return nil, foundSpells
end
--- Get trainable spells
-- Return all not yet learned spells up to the current level for logged in character class.
-- @return A table containing level keyed sub tables with the appropriate spells, nil if no spells found
-- @return Number of spells found
function _addon:GetAllTrainableSpells()
local spells, found, count = {}, 0, 0
for level = 1, UnitLevel("player"), 1 do
_, found = _addon:GetSpellsForLevel(level, true, spells)
count = count + found
end
if count > 0 then return spells, count end
return nil, count
end
--- Print spell list
-- @param spells A list from the Get... functions
-- @param dontPrintLevel If true don't prepend "Level x:"
function _addon:OutputSpellList(spells, dontPrintLevel)
local line, name, rank = "", "", "";
for level = 1, 60, 1 do
if spells[level] ~= nil then
if dontPrintLevel ~= true then print(L["CHATLINE_LEVEL"]:format(level)) end
for _, spell in ipairs(spells[level]) do
name, rank = GetSpellInfo(spell.id)
if name == nil then
line = "|cFFFF5500 ERROR: SPELL " .. spell.id .. " NOT FOUND" .. " |h|r"
else
if rank and rank ~= "" then name = name .. " (" .. rank .. ")" end
line = "|cFF77FF77|Hspell:" .. spell.id .. "|h[" .. name .. "] |h|r"
if spell.aquire ~= nil then
if spell.aquire == "quest" then
line = line .. L["SOURCE_CLASS_QUEST"] .. "."
elseif spell.aquire == "book" then
line = line .. L["SOURCE_BOOK"] .. ". "
if spell.source == nil then
line = line .. L["SOURCE_BOOK_SPECIFY"]:format(L["DUNGEONS"]) .. "."
else
line = line .. L["SOURCE_BOOK_SPECIFY_MORE"]:format(L[spell.source], L[spell.from]) .. "."
end
end
else
line = line .. GetCoinTextureString(spell.cost)
end
end
print(line)
end
end
end
end