-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeneral.lua
119 lines (95 loc) · 3.08 KB
/
general.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
local _, ns = ...
ns = ns['__LibSpellbook-1.0']
local lib = ns.lib
if not lib then return end
local FoundSpell = ns.FoundSpell
local CleanUp = ns.CleanUp
local supportedBookTypes = {
pet = true,
pvp = true,
spell = true,
talent = true,
}
local playerClass
local function ScanFlyout(flyoutId, bookType)
local _, _, numSlots, isKnown = GetFlyoutInfo(flyoutId)
if not isKnown or numSlots < 1 then return end
local changed = false
for i = 1, numSlots do
local _, id, isKnown, name = GetFlyoutSlotInfo(flyoutId, i)
if isKnown then
changed = FoundSpell(id, name, bookType) or changed
end
end
return changed
end
local function ScanPvpTalents()
local changed = false
if C_PvP.IsWarModeDesired() then
local selectedPvpTalents = C_SpecializationInfo.GetAllSelectedPvpTalentIDs()
for _, talentId in next, selectedPvpTalents do
local _, name, _, _, _, spellId = GetPvpTalentInfoByID(talentId)
if IsPlayerSpell(spellId) then
changed = FoundSpell(spellId, name, 'pvp') or changed
end
end
end
end
local function ScanSpellbook(bookType, numSpells, offset)
local changed = false
offset = offset or 0
for i = offset + 1, offset + numSpells do
local info = C_SpellBook.GetSpellBookItemInfo(i, bookType)
local itemType = info.itemType
if itemType == Enum.SpellBookItemType.Spell then
changed = FoundSpell(info.actionID, info.name, bookType) or changed
if (info.spellID and info.spellID ~= info.actionID) then
changed = FoundSpell(info.spellID, C_Spell.GetSpellName(info.spellID), bookType) or changed
end
elseif itemType == Enum.SpellBookItemType.Flyout then
changed = ScanFlyout(info.actionID, bookType)
elseif itemType == Enum.SpellBookItemType.PetAction then
if info.spellID then
changed = FoundSpell(info.spellID, info.name, bookType) or changed
end
else
break
end
end
return changed
end
local function ScanSpells(event)
local changed = false
ns.generation = ns.generation + 1
for skillLine = 1, C_SpellBook.GetNumSpellBookSkillLines() do
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(skillLine)
if not skillLineInfo.offspecID then
changed = ScanSpellbook(Enum.SpellBookSpellBank.Player, skillLineInfo.numSpellBookItems, skillLineInfo.itemIndexOffset) or changed
end
end
local numPetSpells = C_SpellBook.HasPetSpells()
if numPetSpells then
changed = ScanSpellbook(Enum.SpellBookSpellBank.Pet, numPetSpells) or changed
end
local inCombat = InCombatLockdown()
changed = ScanPvpTalents() or changed
local current = ns.generation
for id, generation in next, ns.spells.lastSeen do
if generation < current then
local bookType = ns.spells.book[id]
if supportedBookTypes[bookType] and (not inCombat or bookType ~= 'talent') then
CleanUp(id)
changed = true
end
end
end
if changed then
lib.callbacks:Fire('LibSpellbook_Spells_Changed')
end
if event == 'PLAYER_ENTERING_WORLD' then
lib:UnregisterEvent(event, ScanSpells)
end
end
lib:RegisterEvent('PLAYER_ENTERING_WORLD', ScanSpells)
lib:RegisterEvent('PVP_TIMER_UPDATE', ScanSpells, true)
lib:RegisterEvent('SPELLS_CHANGED', ScanSpells)