-
Notifications
You must be signed in to change notification settings - Fork 7
/
ccc.lua
638 lines (560 loc) · 15.2 KB
/
ccc.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
local addon_name, addon_table = ...
setfenv(1, setmetatable(addon_table, { __index = _G }))
do
local f = CreateFrame'Frame'
f:SetScript('OnEvent', function(self, event, ...)
getfenv(1)[event](...)
end)
for _, event in pairs{
'ADDON_LOADED',
'UNIT_SPELLCAST_SENT',
'UNIT_SPELLCAST_SUCCEEDED',
'COMBAT_LOG_EVENT_UNFILTERED',
'CHAT_MSG_COMBAT_HONOR_GAIN',
'PLAYER_REGEN_ENABLED',
'PLAYER_TARGET_CHANGED',
} do f:RegisterEvent(event) end
end
_G.ccc_settings = {}
local WIDTH = 170
local HEIGHT = 16
local MAXBARS = 11
local BARS, TIMERS, EFFECT = {}, {}, {}
local LATEST_TARGET
function Print(msg)
DEFAULT_CHAT_FRAME:AddMessage('<ccc> ' .. msg)
end
function CreateBar()
local texture = [[Interface\Addons\ccc\bar]]
local font, _, style = GameFontHighlight:GetFont()
local fontsize = 11
local f = CreateFrame('Frame', nil, UIParent)
f.fadetime = .5
f:SetHeight(HEIGHT)
f.icon = f:CreateTexture()
f.icon:SetWidth(HEIGHT)
f.icon:SetPoint('TOPLEFT', 0, 0)
f.icon:SetPoint('BOTTOMLEFT', 0, 0)
f.icon:SetTexture[[Interface\Icons\INV_Misc_QuestionMark]]
f.icon:SetTexCoord(.08, .92, .08, .92)
f.statusbar = CreateFrame('StatusBar', nil, f, 'BackdropTemplate')
f.statusbar:SetPoint('TOPLEFT', f.icon, 'TOPRIGHT', 0, 0)
f.statusbar:SetPoint('BOTTOMRIGHT', 0, 0)
f.statusbar:SetStatusBarTexture(texture)
f.statusbar:SetStatusBarColor(.5, .5, .5, 1)
f.statusbar:SetMinMaxValues(0, 1)
f.statusbar:SetValue(1)
f.statusbar:SetBackdrop{ bgFile = texture }
f.statusbar:SetBackdropColor(.5, .5, .5, .3)
f.spark = f.statusbar:CreateTexture(nil, 'OVERLAY')
f.spark:SetTexture[[Interface\CastingBar\UI-CastingBar-Spark]]
f.spark:SetWidth(16)
f.spark:SetHeight(HEIGHT + 25)
f.spark:SetBlendMode'ADD'
f.text = f.statusbar:CreateFontString(nil, 'OVERLAY')
-- f.text:SetFontObject(GameFontHighlightSmallOutline)
f.text:SetFontObject(GameFontHighlight)
f.text:SetFont(font, fontsize, style)
f.text:SetPoint('TOPLEFT', 2, 0)
f.text:SetPoint('BOTTOMRIGHT', -2, 0)
f.text:SetJustifyH'LEFT'
f.text:SetText''
f.timertext = f.statusbar:CreateFontString(nil, 'OVERLAY')
-- f.text:SetFontObject(GameFontHighlightSmallOutline)
f.timertext:SetFontObject(GameFontHighlight)
f.timertext:SetFont(font, fontsize, style)
f.timertext:SetPoint('TOPLEFT', 2, 0)
f.timertext:SetPoint('BOTTOMRIGHT', -2, 0)
f.timertext:SetJustifyH'RIGHT'
f.timertext:SetText''
return f
end
function FadeBar(bar)
if bar.fadeelapsed > bar.fadetime then
bar:SetAlpha(0)
else
local t = bar.fadetime - bar.fadeelapsed
local a = t / bar.fadetime * ccc_settings.alpha
bar:SetAlpha(a)
end
end
function UpdateBars()
for i = 1, MAXBARS do
UpdateBar(BARS[i])
end
end
do
local function formatTime(t)
local h = floor(t / 3600)
local m = floor((t - h * 3600) / 60)
local s = t - (h * 3600 + m * 60)
if h > 0 then
return format('%d:%02d:02d', h, m, s)
elseif m > 0 then
return format('%d:%02d', m, s)
elseif s < 10 then
return format('%.1f', s)
else
return format('%.0f', s)
end
end
function UpdateBar(bar)
if not LOCKED then
return
end
local timer = bar.timer
if timer.stopped then
if bar:GetAlpha() > 0 then
bar.spark:Hide()
bar.fadeelapsed = GetTime() - timer.stopped
FadeBar(bar)
end
else
bar:SetAlpha(ccc_settings.alpha)
bar.icon:SetTexture(timer.texture or [[Interface\Icons\INV_Misc_QuestionMark]])
bar.text:SetText(timer.unit_name)
local fraction
if timer.start then
local duration = timer.expiration - timer.start
local remaining = timer.expiration - GetTime()
fraction = remaining / duration
local invert = ccc_settings.invert and not timer.DR
bar.statusbar:SetValue( invert and 1 - fraction or fraction)
local sparkPosition = WIDTH * fraction
bar.spark:Show()
bar.spark:SetPoint('CENTER', bar.statusbar, invert and 'RIGHT' or 'LEFT', invert and -sparkPosition or sparkPosition, 0)
bar.timertext:SetText(formatTime(remaining))
else
fraction = 1
bar.statusbar:SetValue(1)
bar.spark:Hide()
bar.timertext:SetText()
end
local r, g, b
if timer.DR == 1 then
r, g, b = .9, .9, .3
elseif timer.DR == 2 then
r, g, b = .9, .6, 0
elseif timer.DR == 3 then
r, g, b = .9, .3, .3
else
r, g, b = .3, .9, .3
end
bar.statusbar:SetStatusBarColor(r, g, b)
bar.statusbar:SetBackdropColor(r, g, b, .3)
end
end
end
function UnlockBars()
LOCKED = false
BARS:EnableMouse(true)
for i = 1, MAXBARS do
local f = BARS[i]
f:SetAlpha(ccc_settings.alpha)
f.statusbar:SetStatusBarColor(1, 1, 1)
f.statusbar:SetValue(1)
f.icon:SetTexture[[Interface\Icons\INV_Misc_QuestionMark]]
f.text:SetText('ccc bar')
f.timertext:SetText((ccc_settings.growth == 'up' and i or MAXBARS - i + 1))
f.spark:Hide()
end
end
function LockBars()
LOCKED = true
BARS:EnableMouse(false)
for i = 1, MAXBARS do
BARS[i]:SetAlpha(0)
end
end
do
local factor = { [0] = 1, 1/2, 1/4, 0 }
function DiminishedDuration(unit, effect, full_duration)
if IsPlayer(unit) then
local pvp_duration = PVP_DURATION[effect] or full_duration
local class = DR_CLASS[effect]
local timer = class and TIMERS[class .. '@' .. unit]
local DR = timer and timer.DR or 0
return pvp_duration * factor[DR]
else
return full_duration
end
end
end
function TargetDebuffs()
local debuffs = {}
local i = 1
while UnitDebuff('target', i) do
local debuff_name, _, _, _, _, _, source = UnitDebuff('target', i)
if source == 'player' then
debuffs[debuff_name] = true
end
i = i + 1
end
return debuffs
end
function UNIT_SPELLCAST_SENT(_, _, _, spell)
if SPECIAL_EVENT[spell] then
SetEffectDurations(spell)
end
end
function UNIT_SPELLCAST_SUCCEEDED(_, _, spell)
SetEffectDurations(spell)
end
function SetEffectDurations(spell)
local effects = SPELL_EFFECTS[spell] or {spell}
for _, effect in pairs(effects) do
local duration = DURATION[effect]
if duration then
if COMBO[effect] then
duration = duration + COMBO[effect] * GetComboPoints('player', 'target')
end
if BONUS[effect] then
duration = duration + BONUS[effect](duration)
end
EFFECT[GetSpellInfo(effect)] = { id = effect, duration = duration }
end
end
end
function AuraGone(unit, effect_name)
local key = effect_name .. '@' .. unit
local timer = TIMERS[key]
if timer then
StopTimer(key)
end
end
function ActivateDRTimer(timer, unit)
local dr_class = DR_CLASS[timer.effect]
if dr_class then
for k, v in pairs(DR_CLASS) do
if v == dr_class and EffectActive(k, unit) then
return
end
end
local timer = TIMERS[dr_class .. '@' .. unit]
if timer then
timer.start = GetTime()
timer.expiration = timer.start + 20
end
PlaceTimers()
end
end
function CHAT_MSG_COMBAT_HONOR_GAIN(_, _, _, _, player_name)
UnitDied(player_name)
end
function PLAYER_REGEN_ENABLED()
for k, timer in pairs(TIMERS) do
if not IsPlayer(timer.unit) and not OOC[timer.effect] then
StopTimer(k)
end
end
end
function PlaceTimers()
for _, timer in pairs(TIMERS) do
if not timer.visible and (not timer.DR or timer.DR > 1 or timer.expiration) then
local up = ccc_settings.growth == 'up'
for i = (up and 1 or MAXBARS), (up and MAXBARS or 1), (up and 1 or -1) do
if BARS[i].timer.stopped then
BARS[i].timer = timer
timer.visible = true
break
end
end
end
end
end
function UpdateTimers()
local t = GetTime()
for k, timer in pairs(TIMERS) do
if timer.expiration and t > timer.expiration then
StopTimer(k)
end
end
end
function EffectActive(effect, unit)
return TIMERS[GetSpellInfo(effect) .. '@' .. unit] and true or false
end
function StartTimer(effect, unit, unit_name, duration)
local effect_name, _, texture = GetSpellInfo(effect)
if ccc_settings.ignore[effect_name] then
return
end
if ccc_settings.aoe == 'target' and AOE[effect] and unit ~= LATEST_TARGET then
return
end
duration = DiminishedDuration(unit, effect, duration)
if duration == 0 then
return
end
local key = effect_name .. '@' .. unit
local timer = TIMERS[key] or {}
if UNIQUENESS_CLASS[effect] then
for k, v in pairs(TIMERS) do
if v ~= timer and not v.DR and UNIQUENESS_CLASS[v.effect] == UNIQUENESS_CLASS[effect] then
StopTimer(k)
end
end
end
TIMERS[key] = timer
timer.effect = effect
timer.effect_name = effect_name
timer.unit = unit
timer.unit_name = unit_name
timer.start = GetTime()
timer.expiration = timer.start + duration
timer.texture = texture
if IsPlayer(unit) then
StartDR(timer, unit)
end
timer.stopped = nil
PlaceTimers()
end
function StartDR(effect_timer, unit)
local dr_class = DR_CLASS[effect_timer.effect]
if dr_class then
local key = dr_class .. '@' .. unit
local timer = TIMERS[key] or {}
if not timer.DR or timer.DR < 3 then
TIMERS[key] = timer
timer.effect_name = effect_timer.effect_name
timer.unit = unit
timer.unit_name = effect_timer.unit_name
timer.start = nil
timer.expiration = nil
timer.DR = min(3, (timer.DR or 0) + 1)
timer.texture = effect_timer.texture
PlaceTimers()
end
end
end
function StopTimer(key)
local timer = TIMERS[key]
TIMERS[key] = nil
timer.stopped = GetTime()
if not timer.DR then
ActivateDRTimer(timer, timer.unit)
end
PlaceTimers()
end
function UnitDied(unit) -- TODO retail does aura gone not fire when unit dies?
for k, timer in pairs(TIMERS) do
if timer.unit == unit then
StopTimer(k)
end
end
end
function COMBAT_LOG_EVENT_UNFILTERED()
local _, event, _, source, _, _, _, unit, unit_name, _, _, spell, effect_name = CombatLogGetCurrentEventInfo()
if event == 'UNIT_DIED' then
UnitDied(unit)
return
end
if source ~= UnitGUID'player' and source ~= UnitGUID'pet' then
return
end
if event == 'SPELL_AURA_APPLIED' or event == 'SPELL_AURA_REFRESH' then
local effect_info = EFFECT[effect_name]
if effect_info then
StartTimer(effect_info.id, unit, unit_name, effect_info.duration)
return
end
local effect, duration
if effect_name == GetSpellInfo(6358) then -- Seduction
effect = 6358
local _, _, _, _, rank = GetTalentInfo(2, 7)
duration = 15 * (1 + rank * .1)
elseif effect_name == GetSpellInfo(11201) then -- Crippling Poison
effect = 11201
duration = 12
elseif effect_name == GetSpellInfo(13810) then -- Frost Trap Aura
effect = 13810
duration = 30
elseif effect_name == GetSpellInfo(15269) then -- Blackout
effect = 15269
duration = 3
elseif effect_name == GetSpellInfo(20170) then -- Stun
effect = 20170
duration = 2
elseif effect_name == GetSpellInfo(12360) then -- Impact
effect = 12360
duration = 2
elseif effect_name == GetSpellInfo(18118) then -- Aftermath
effect = 18118
duration = 5
elseif effect_name == GetSpellInfo(12494) then -- Frostbite
effect = 12494
duration = 5
elseif effect_name == GetSpellInfo(19229) then -- Improved Wing Clip
effect = 19229
duration = 5
elseif effect_name == GetSpellInfo(23694) then -- Improved Hamstring
effect = 23694
duration = 5
elseif effect_name == GetSpellInfo(18425) then -- Kick - Silenced
effect = 18425
duration = 2
elseif effect_name == GetSpellInfo(18469) then -- Counterspell - Silenced
effect = 18469
duration = 4
elseif effect_name == GetSpellInfo(18498) then -- Shield Bash - Silenced
effect = 18498
duration = 3
elseif effect_name == GetSpellInfo(5530) then -- Mace Stun Effect
effect = 5530
duration = 3
elseif effect_name == GetSpellInfo(43523) then -- Unstable
effect = 43523
duration = 5
end
if effect then
StartTimer(effect, unit, unit_name, duration)
end
elseif event == 'SPELL_AURA_REMOVED' then
AuraGone(unit, effect_name)
end
end
do
local isPlayer = {}
function PLAYER_TARGET_CHANGED()
local target_guid = UnitGUID'target'
if target_guid then
LATEST_TARGET = target_guid
if UnitIsPlayer'target' or UnitPlayerControlled'target' then
isPlayer[target_guid] = true
end
end
end
function IsPlayer(guid)
return isPlayer[guid]
end
end
CreateFrame'Frame':SetScript('OnUpdate', function()
UpdateTimers()
if not LOCKED then
return
end
UpdateBars()
end)
do
local defaultSettings = {
invert = false,
growth = 'up',
scale = 1,
alpha = .85,
aoe = 'target',
ignore = {},
}
function ADDON_LOADED(name)
if name ~= addon_name then
return
end
for k, v in pairs(defaultSettings) do
if ccc_settings[k] == nil then
ccc_settings[k] = v
end
end
local dummyTimer = { stopped = 0 }
local height = HEIGHT * MAXBARS + 4 * (MAXBARS - 1)
BARS = CreateFrame('Frame', 'ccc', UIParent)
BARS:SetWidth(WIDTH + HEIGHT)
BARS:SetHeight(height)
BARS:SetMovable(true)
BARS:SetUserPlaced(true)
BARS:SetClampedToScreen(true)
BARS:SetScript('OnMouseDown', function(self)
self:StartMoving()
end)
BARS:SetScript('OnMouseUp', function(self)
self:StopMovingOrSizing()
end)
BARS:SetPoint('CENTER', 0, 150)
for i = 1, MAXBARS do
local bar = CreateBar()
bar:SetParent(BARS)
bar:SetAlpha(ccc_settings.alpha)
local offset = 20 * (i - 1)
bar:SetPoint('BOTTOMLEFT', 0, offset)
bar:SetPoint('BOTTOMRIGHT', 0, offset)
bar.timer = dummyTimer
tinsert(BARS, bar)
end
BARS:SetScale(ccc_settings.scale)
_G.SLASH_CCC1 = '/ccc'
SlashCmdList.CCC = SlashCommandHandler
LockBars()
end
Print('loaded - /ccc')
end
do
local function tokenize(str)
local tokens = {}
for token in string.gmatch(str, '%S+') do
tinsert(tokens, token)
end
return tokens
end
function SlashCommandHandler(command)
if command then
local args = tokenize(command)
if command == 'unlock' then
UnlockBars()
Print('Bars unlocked.')
elseif command == 'lock' then
LockBars()
Print('Bars locked.')
elseif command == 'invert' then
ccc_settings.invert = not ccc_settings.invert
Print('Bar inversion ' .. (ccc_settings.invert and 'on.' or 'off.'))
elseif args[1] == 'growth' and (args[2] == 'up' or args[2] == 'down') then
ccc_settings.growth = args[2]
Print('Growth: ' .. args[2])
if not LOCKED then UnlockBars() end
elseif args[1] == 'scale' then
local scale = tonumber(args[2])
if scale then
scale = max(.5, min(3, scale))
ccc_settings.scale = scale
BARS:SetScale(scale)
Print('Scale: ' .. scale)
else
Usage()
end
elseif args[1] == 'alpha' then
local alpha = tonumber(args[2])
if alpha then
alpha = max(0, min(1, alpha))
ccc_settings.alpha = alpha
if not LOCKED then UnlockBars() end
Print('Alpha: ' .. alpha)
else
Usage()
end
elseif args[1] == 'aoe' and (args[2] == 'target' or args[2] == 'all') then
ccc_settings.aoe = args[2]
Print('AOE: ' .. args[2])
if not LOCKED then UnlockBars() end
elseif command == 'ignore' then
for effect_name in pairs(ccc_settings.ignore) do
Print('Ignored effects:')
Print(' ' .. effect_name)
end
elseif args[1] == 'ignore' then
local _, _, effect_name = strfind(command, '^%s*ignore%s+(.*)')
ccc_settings.ignore[effect_name] = not ccc_settings.ignore[effect_name] or nil
Print('Ignoring "' .. effect_name .. '" ' .. (ccc_settings.ignore[effect_name] and 'on. ' or 'off.'))
else
Usage()
end
end
end
end
function Usage()
Print('Usage:')
Print(' lock | unlock')
Print(' invert')
Print(' growth (up | down)')
Print(' scale [0.5,3]')
Print(' alpha [0,1]')
Print(' aoe (target | all)')
Print(' ignore {name}')
Print(' ignore')
end