comparison Spirit.lua @ 1:766d8a40a1d6

first commit?
author Nenue
date Tue, 15 Dec 2015 08:07:21 -0500
parents
children
comparison
equal deleted inserted replaced
0:ebbcc148a407 1:766d8a40a1d6
1 -- User: Krakyn
2 -- Created: 12/8/2015 7:30 PM
3 local T = LibStub("AceAddon-3.0"):GetAddon("Turok")
4 local TL = 'Spirit'
5 local print = function(...) _G.print(TL, ...) end
6 local LSM = LibStub("LibSharedMedia-3.0")
7 local mod = T:NewModule("Spirit", "AceTimer-3.0")
8 local time = _G.ct
9 local auras = {
10 168811, -- sniper training
11 168809, -- sniper training: recently moved
12 13159, -- aspect of the pack,
13 187615, -- Maalus
14 }
15 local spells = {
16 3045, -- rapid fire,
17 26297, -- berserking,
18 121818, -- stampede,
19
20 }
21 local FRAME_PREFIX = 'TkSpirit'
22 local FADE_TIME = 0.5
23 -- local repetitive tasks
24 local function FindSpirit(id)
25 local db = T.db
26 local c = db.spirit
27 local isIcon = false
28 if db.spirit.progressbar[id] then
29 c = db.spirit.progressbar[id]
30 elseif db.spirit.icon[id] then
31 c = db.spirit.icon[id]
32 isIcon = true
33 end
34 local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(id)
35 local s = {
36 name = name,
37 rank = rank,
38 icon = icon,
39 castingTime = castingTime,
40 minRange = minRange,
41 maxRange = maxRange,
42 spellID = spellID
43 }
44
45 return s, c, isIcon
46 end
47
48 function mod:OnEnable()
49 local db = _G.TurokData
50 self.aura_watch = {}
51 self.cooldown_watch = {}
52 self.item_watch = {}
53 self.myGUID = UnitGUID('player')
54
55
56 db.spirit = {
57 foreground_color = {1, 1, 1, 0.7},
58 foreground_texture = 'Cilo',
59 foreground_blend = 'BLEND',
60 foreground_inset = -1,
61 background_color = {0, 0, 0, 0.7},
62 background_blend = 'BLEND',
63 background_texture = 'Cilo',
64 icon_show = true,
65 width = 250, height = 20,
66 anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
67 posX = 0, posY = -150,
68 label_color = {1, 1, 1, 1},
69 label_font = 'turok',
70 label_size = 14,
71 label_inset = -2,
72 label_point = 'LEFT',
73 label_outline = 'OUTLINE',
74 label_string = '%n %p',
75 label_strata = 'HIGH',
76 expire_sound = LSM:Fetch('sound'),
77 strata = 'LOW',
78 icon = {
79 [13159] = { -- Aspect of the Pack
80 posX = 20, posY = 20, width = 140, height = 140,
81 },
82 [3045] = {
83 parent = 13159, anchor = 'RIGHT', anchorTo = 'LEFT',
84 posx = 0, posY = 0, width = 64, height = 64,
85 }
86 },
87 progressbar = {
88 [168811] = { -- Sniper Training (duration)
89 background_color = {0,0,0,0},
90 foreground_color = {1,0,0,1},
91 anchor = 'BOTTOMLEFT', parent = 'TkFocusBar', anchorTo = 'TOPLEFT',
92 posX = 0, posY = 0, height = 16, width = 250,
93 label_string = '',
94 label_point = 'TOPLEFT',
95 strata = 'LOW',
96 attach = {{
97 width_relative = 0.5,
98 height_relative = 1,
99 background_color = {1,0,0,1},
100 foreground_color = {1,1,0.5, 1},
101 background_blend = 'ADD',
102 foreground_blend = 'ADD',
103
104 anchor = 'LEFT',
105 anchorTo = 'LEFT',
106 strata = 'MEDIUM',
107 }}
108 },
109 [168809] = { -- Sniper Training: Recently Moved
110 background_color = {0,0,0,0 },
111 foreground_color = {1,1,1,1},
112 foreground_blend = 'ADD',
113 anchor = 'BOTTOMLEFT', parent = 'TkFocusBar', anchorTo = 'TOPLEFT',
114 strata = 'HIGH',
115 posX = 0, posY = 0, height = 16, width = 125,
116 icon_show = false,
117 label_string = '',
118 exceptions = {
119 function(aura)
120 return (mod.aura_watch[168811].expires < aura.expires)
121 end
122 },
123 },
124 },
125 }
126
127 for _, id in pairs(auras) do
128 -- store spellinfo fetch
129 self.aura_watch[id] = self:CreateSpiritFrame(id)
130 self.aura_watch[id].count = 0
131 self.aura_watch[id].duration = 0
132 self.aura_watch[id].expires = 0
133 self.aura_watch[id].caster = 0
134 print('AURA', id, self.aura_watch[id].name)
135 end
136
137 for _, id in ipairs(spells) do
138 self.cooldown_watch[id] = self:CreateSpiritFrame(id)
139 print('COOLDOWN', id, self.cooldown_watch[id].name)
140 end
141
142 self:SpiritScan()
143 self:RegisterEvent('UNIT_AURA')
144 self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
145 self:RegisterEvent('PLAYER_REGEN_DISABLED')
146 self:RegisterEvent('PLAYER_REGEN_ENABLED')
147 end
148
149 -- StatusBar factory
150 function mod:CreateSpiritFrame(id)
151 local s, c, isIcon = FindSpirit(id)
152
153 -- how much frame do we need?
154 local f
155 if isIcon then
156 f = CreateFrame('Frame', FRAME_PREFIX..id, UIParent)
157 f.db = c
158 function f:Update() end
159 else
160 f = T:CreateBar('TkAuraBar'..id, c)
161 f.isTimer = true
162 if (c.label_string ~= '') then
163 print('has label, add it', id)
164 T:AddLabel(f, c)
165 end
166 end
167 f:Hide()
168
169 -- general display
170 f:SetPoint(c.anchor, c.parent, c.anchorTo, c.posX, c.posY)
171 f:SetSize(c.width, c.height)
172 f:SetFrameStrata(c.strata)
173
174 -- icon?
175 f.icon = s.icon
176 T:CreateStatusIcon(f)
177
178 -- attachment frames?
179 if c.attach then
180 for i, e in ipairs(c.attach) do
181 local ef = CreateFrame('Frame', 'TkExtra'..id, f)
182 f[i] = ef
183 ef:SetPoint(e.anchor, f, e.anchorTo)
184 ef:SetSize(c.width * e.width_relative or e.width, c.height * e.height_relative or e.height)
185 ef:SetFrameStrata(e.strata or c.strata)
186 T:CreateStatusTextures(ef, e)
187 end
188 end
189
190 -- setup suppression checking
191 if c.exceptions then
192 function s:ExceptionCheck ()
193 for i, func in ipairs(c.exceptions) do
194 if not func(self) then
195 return false, i
196 end
197 end
198 return true
199 end
200 else
201 function s:ExceptionCheck () return true end
202 end
203
204 -- access linkage
205 f.format = c.label_string
206 f.spirit = s
207 f.name = s.name
208 s.frame = f
209 return s
210 end
211
212 function mod:UNIT_AURA(e, unit)
213 if unit == 'player' then
214 self:SpiritScan()
215 end
216 end
217
218 -- Updates aura watches
219 function mod:SpiritScan()
220 local db = _G.TurokData
221 for id, aura in pairs(self.aura_watch) do
222 local c = aura.conf
223 local f = aura.frame
224
225 local name, _, _, count, _, duration, expires, caster = UnitAura('player', aura.name)
226
227 if name then
228 aura.duration = duration
229 aura.expires = expires
230 aura.caster = caster
231 aura.count = count
232 local test, i = aura:ExceptionCheck()
233 print(name, duration, expires)
234 if not test then
235 print('suppressing '..aura.name..' (failed test #'..i..')')
236 else
237 f.name = name
238 f:Update(nil, duration, expires)
239 f:Show()
240 end
241 end
242 end
243 end
244
245 function mod:PLAYER_REGEN_ENABLED()
246 for id, aura in pairs(self.aura_watch) do
247 print('non-combat alpha for #', id, aura.name, 'is', aura.frame.db.alpha_ooc)
248 aura.frame.fadeTo = aura.frame.db.alpha_ooc
249 aura.frame.fadeDuration = FADE_TIME
250 end
251 end
252
253 function mod:PLAYER_REGEN_DISABLED()
254 for id, aura in pairs(self.aura_watch) do
255 print('combat alpha for #', id, aura.name, 'is', aura.frame.db.alpha)
256 aura.frame.fadeTo = aura.frame.db.alpha
257 aura.frame.fadeDuration = FADE_TIME
258 end
259 end
260
261 -- This is the most reliable way of catching item and spell uses, other events are delayed or too vague to be useful
262 function mod:COMBAT_LOG_EVENT_UNFILTERED(e, ...)
263 local timestamp, combatEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags =
264 ...; -- Those arguments appear for all combat event variants.
265 local eventPrefix, eventSuffix = combatEvent:match("^(.-)_?([^_]*)$");
266 if eventPrefix ~= 'SPELL_' or sourceGUID ~= self.myGUID then
267 return
268 end
269
270 local spellid, name, count, type = select(13, select('#', ...), ...)
271 local kc = ''
272 for i=1,4 do
273 kc = kc .. string.format('%X',((string.byte(eventSuffix,i) % 8) + 8))
274 end
275 print('|cFFFF'..kc..eventSuffix..'|r', sourceName, destName, spellid, name)
276 end