File src/ChorusRangeFrameTemplate.lua changed (mode: 100644) (index c2333fb..5c5bd94) |
|
1 |
|
local GetSpellName = GetSpellName |
1 |
2 |
local IsSpellInRange = IsSpellInRange |
local IsSpellInRange = IsSpellInRange |
2 |
3 |
|
|
|
4 |
|
local MAX_SPELLS = MAX_SPELLS |
|
5 |
|
|
3 |
6 |
local Chorus = Chorus |
local Chorus = Chorus |
4 |
7 |
|
|
5 |
|
--[[ Populate range spell map at runtime initialization. ]]-- |
|
6 |
|
local spellMap = { |
|
7 |
|
--[[ Paladin ]]-- |
|
8 |
|
['Beacon of Light'] = 60, |
|
9 |
|
['Blessing of Might'] = 30, |
|
10 |
|
['Cleanse'] = 40, |
|
11 |
|
['Hammer of Justice'] = 10, |
|
12 |
|
['Purify'] = 40, |
|
13 |
|
['Holy Shock'] = 20, |
|
14 |
|
['Exorcism'] = 30, |
|
15 |
|
--[[ Priest ]]-- |
|
16 |
|
['Lesser Heal'] = 40, |
|
17 |
|
['Smite'] = 30, |
|
18 |
|
['Power Word: Fortitude'] = 30, |
|
19 |
|
['Resurrection'] = 30, |
|
20 |
|
['Mind Control'] = 20, |
|
21 |
|
--[[ Any ]]-- |
|
22 |
|
['Shoot'] = 30, |
|
23 |
|
} |
|
|
8 |
|
--[[ See ChorusRangeFrameTemplate.lua:function spellRangeMapUpdate. ]]-- |
|
9 |
|
--[[ See ChorusRangeFrameTemplate.lua:function rangeFrameUpdate. ]]-- |
|
10 |
|
local spellRangeMap = {} |
|
11 |
|
|
|
12 |
|
local function spellRangeMapUpdate() |
|
13 |
|
local maxSpells = MAX_SPELLS or 1024 |
|
14 |
|
maxSpells = math.min(math.max(1, math.abs(math.floor(maxSpells)), 8192)) |
|
15 |
|
|
|
16 |
|
local buffer = {} |
|
17 |
|
|
|
18 |
|
local i = 0 |
|
19 |
|
while (i < maxSpells) do |
|
20 |
|
i = i + 1 |
|
21 |
|
|
|
22 |
|
--[[ Get player spell book button number "i", and request it's |
|
23 |
|
corresponding spell name. This is NOT a unique spell |
|
24 |
|
identifier. Every spell rank is a separate button. ]]-- |
|
25 |
|
local spellName = GetSpellName(i, 'player') |
|
26 |
|
if not spellName then |
|
27 |
|
break |
|
28 |
|
end |
|
29 |
|
|
|
30 |
|
--[[ When GetSpellInfo is called with localized spell name |
|
31 |
|
string, it only returns data on the spells stored in the |
|
32 |
|
current player character's spell book. ]]-- |
|
33 |
|
local _, _, _, _, _, _, _, _, maxRangeYards = GetSpellInfo(spellName) |
|
34 |
|
if spellName and maxRangeYards then |
|
35 |
|
assert(spellName ~= nil) |
|
36 |
|
assert('string' == type(spellName)) |
|
37 |
|
spellName = strtrim(spellName) |
|
38 |
|
assert(string.len(spellName) >= 1) |
|
39 |
|
assert(string.len(spellName) <= 8192) |
|
40 |
|
|
|
41 |
|
assert(maxRangeYards ~= nil) |
|
42 |
|
assert('number' == type(maxRangeYards)) |
|
43 |
|
maxRangeYards = math.abs(math.floor(maxRangeYards)) |
|
44 |
|
|
|
45 |
|
if maxRangeYards >= 1 then |
|
46 |
|
local oldRangeYards = spellRangeMap[spellName] |
|
47 |
|
|
|
48 |
|
--[[ |
|
49 |
|
Previous rank of the spell already mapped. |
|
50 |
|
Only the most potentially efficient spell rank |
|
51 |
|
will be mapped. ]]-- |
|
52 |
|
|
|
53 |
|
if oldRangeYards then |
|
54 |
|
maxRangeYards = math.max(maxRangeYards, oldRangeYards) |
|
55 |
|
end |
|
56 |
|
|
|
57 |
|
--[[ |
|
58 |
|
Priest spell "Mind Vision" has range of 50_000 |
|
59 |
|
yards. This isn't a useful specificity, so |
|
60 |
|
filter it out. Only allow spell ranges that can |
|
61 |
|
be reasonably displayed and understood by the |
|
62 |
|
user during game combat play. Do not round down |
|
63 |
|
the value itself. Only store correct |
|
64 |
|
values.]]-- |
|
65 |
|
if maxRangeYards < 99 then |
|
66 |
|
buffer[spellName] = maxRangeYards |
|
67 |
|
end |
|
68 |
|
end |
|
69 |
|
end |
|
70 |
|
end |
|
71 |
|
|
|
72 |
|
--[[ At this point assume no errors occurred. Re-write the actual spell |
|
73 |
|
range map. ]]-- |
|
74 |
|
spellRangeMap = buffer |
|
75 |
|
end |
24 |
76 |
|
|
25 |
77 |
--[[ Duplicate getUnit logic to make sure it cannot be overriden at runtime. ]]-- |
--[[ Duplicate getUnit logic to make sure it cannot be overriden at runtime. ]]-- |
26 |
78 |
|
|
|
... |
... |
local function rangeFrameUpdate(self) |
56 |
108 |
local rangeFlag = nil |
local rangeFlag = nil |
57 |
109 |
local distanceYards = nil |
local distanceYards = nil |
58 |
110 |
local maxRangeYards = 0 |
local maxRangeYards = 0 |
59 |
|
for spellName, rangeYards in pairs(spellMap) do |
|
|
111 |
|
for spellName, rangeYards in pairs(spellRangeMap) do |
60 |
112 |
local flag = IsSpellInRange(spellName, unitDesignation) |
local flag = IsSpellInRange(spellName, unitDesignation) |
61 |
113 |
--[[ 1 == flag: in range; ]]-- |
--[[ 1 == flag: in range; ]]-- |
62 |
114 |
--[[ 0 == flag: out of range; ]]-- |
--[[ 0 == flag: out of range; ]]-- |
|
... |
... |
local function rangeFrameMain(self) |
112 |
164 |
self:SetScript('OnUpdate', rangeFrameUpdateProcessor) |
self:SetScript('OnUpdate', rangeFrameUpdateProcessor) |
113 |
165 |
end |
end |
114 |
166 |
|
|
|
167 |
|
local function rangeSpellMapFrameMain(self) |
|
168 |
|
assert(self ~= nil) |
|
169 |
|
|
|
170 |
|
self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED') |
|
171 |
|
self:RegisterEvent('LEARNED_SPELL_IN_TAB') |
|
172 |
|
self:RegisterEvent('PLAYER_LOGIN') |
|
173 |
|
self:RegisterEvent('PLAYER_TALENT_UPDATE') |
|
174 |
|
self:RegisterEvent('SPELLS_CHANGED') |
|
175 |
|
self:SetScript('OnEvent', spellRangeMapUpdate) |
|
176 |
|
end |
|
177 |
|
|
115 |
178 |
--[[ Hide reference to the internal function, for some reason. ]]-- |
--[[ Hide reference to the internal function, for some reason. ]]-- |
116 |
179 |
Chorus.rangeFrameMain = function(...) |
Chorus.rangeFrameMain = function(...) |
117 |
180 |
return rangeFrameMain(...) |
return rangeFrameMain(...) |
118 |
181 |
end |
end |
|
182 |
|
|
|
183 |
|
Chorus.rangeSpellMapFrameMain = function(...) |
|
184 |
|
return rangeSpellMapFrameMain(...) |
|
185 |
|
end |