forked from fusionpit/ClassTrainerPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbilityStorage.lua
95 lines (93 loc) · 2.78 KB
/
AbilityStorage.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
local _, ctp = ...
local spellsToStripSubtextFrom = {
[3127] = true, -- Parry, which is flagged Passive by GetSpellSubtext but not by GetTrainerServiceInfo
[674] = true, -- Dual Wield, same as Parry
[2836] = true, -- Detect Traps, passive
[20608] = true -- Reincarnation, passive
}
local spellsToAllowRanklessMatch = {
[921] = true, -- Pick Pocket, has Rank 1 in trainer ui, no rank from spell info
[29166] = true -- Innervate, has Rank 1 in trainer ui, no rank from spell info
}
ctp.RealSpellNameMap = {}
ctp.Abilities = {
_store = {},
_spellIds = {},
_partialMatchSpells = {},
_getKey = function(serviceName, serviceSubText)
local abilityKey = serviceName
if (serviceSubText ~= nil and serviceSubText ~= "") then
abilityKey = abilityKey .. " " .. serviceSubText
end
return abilityKey
end,
_getAlternateKey = function(serviceName)
return serviceName .. " *"
end,
-- postStoreFunc gets key as input
_storeSpellInfo = function(self, spellId, isIgnored, postStoreFunc)
local spell = Spell:CreateFromSpellID(spellId)
spell:ContinueOnSpellLoad(
function()
local spellName = spell:GetSpellName()
local subText = spell:GetSpellSubtext()
if (spellsToStripSubtextFrom[spellId]) then
subText = ""
end
if (spellsToAllowRanklessMatch[spellId]) then
subText = "*"
end
local key = self._getKey(spellName, subText)
self._store[key] = {
spellId = spellId,
isIgnored = isIgnored
}
if (postStoreFunc ~= nil) then
postStoreFunc(key)
end
end
)
end,
GetByNameAndSubText = function(self, serviceName, serviceSubText)
local key = self._getKey(serviceName, serviceSubText)
if (self._store[key] == nil) then
key = self._getAlternateKey(serviceName)
if (self._store[key] ~= nil) then
return self._store[key]
end
end
if (ctp.RealSpellNameMap[serviceName] and ctp.RealSpellNameMap[serviceName][serviceSubText]) then
key = self._getKey(ctp.RealSpellNameMap[serviceName][serviceSubText], serviceSubText)
end
return self._store[key]
end,
IsIgnored = function(self, serviceName, serviceSubText)
local ability = self:GetByNameAndSubText(serviceName, serviceSubText)
return ability ~= nil and ability.isIgnored
end,
IsSpellIdStored = function(self, spellId)
return self._spellIds[spellId] ~= nil
end,
Load = function(self, table)
self._store = {}
self._spellIds = {}
for _, spellId in pairs(table) do
self:_storeSpellInfo(
spellId,
false,
function(key)
self._spellIds[spellId] = key
if (ClassTrainerPlusFrame and ClassTrainerPlusFrame:IsVisible()) then
ctp.TrainerServices:Update()
ClassTrainerPlusFrame_Update()
end
end
)
end
end,
Update = function(self, table)
for spellId, isIgnored in pairs(table) do
self:_storeSpellInfo(spellId, isIgnored)
end
end
}