forked from SwimmingTiger/TotemTimers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LongCooldowns.lua
executable file
·236 lines (196 loc) · 7.3 KB
/
LongCooldowns.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
-- Copyright © 2008-2012 Xianghar <[email protected]>
-- All Rights Reserved.
-- This code is not to be modified or distributed without written permission by the author.
-- Current distribution permissions only include curse.com, wowinterface.com and their respective addon updaters
if select(2,UnitClass("player")) ~= "SHAMAN" then return end
local L = LibStub("AceLocale-3.0"):GetLocale("TotemTimers", true)
local SpellIDs = TotemTimers.SpellIDs
local SpellTextures = TotemTimers.SpellTextures
local SpellNames = TotemTimers.SpellNames
local AvailableSpells = TotemTimers.AvailableSpells
local cds = {}
local player = UnitName("player")
-- spells: bloodlust, astral shift, spiritwalkers grace, ancestral guidance,
-- call of the elements, elemental mastery, ancestral swiftness, ascendance
local CDEvent
local BuffEvent
local FeralSpiritEvent
local FeralSpiritCDEvent
local Ascendances = {SpellIDs.AscendanceElemental, SpellIDs.AscendanceEnhancement, SpellIDs.AscendanceRestoration}
local function ConfigureTimer(nr, spell, altcdspell)
cds[nr].cdspell = spell
cds[nr].altcdspell = altcdspell
cds[nr].durationTimer.buffSpell = spell
cds[nr].button.icon:SetTexture(SpellTextures[spell])
cds[nr].durationTimer.button.icon:SetTexture(SpellTextures[spell])
cds[nr].durationTimer.button.buffSpellName = SpellNames[spell]
cds[nr].durationTimer.button.cooldown:SetAlpha(0.6)
cds[nr].button:SetAttribute("*type*", "spell")
if altcdspell then
spell = GetSpellInfo(altcdspell)
end
cds[nr].button:SetAttribute("*spell1", spell)
end
function TotemTimers.CreateLongCooldowns()
for i = 1,8 do
cds[i] = XiTimers:new(1)
cds[i].durationTimer = XiTimers:new(1, true)
cds[i].durationTimer.cdTimer = cds[i]
cds[i].durationTimer.button:SetParent(cds[i].button)
cds[i].durationTimer.button:EnableMouse(false)
cds[i].button.anchorframe = TotemTimers_LongCooldownsFrame
cds[i].durationTimer.hideInactive = true
cds[i].durationTimer:SetPoint("CENTER", cds[i], "CENTER")
cds[i].SetWidth = function(self, width)
XiTimers.SetWidth(self, width)
self.durationTimer:SetWidth(width)
end
cds[i].SetHeight = function(self, height)
XiTimers.SetHeight(self, height)
self.durationTimer:SetHeight(height)
end
cds[i].durationTimer:SetScale(2)
cds[i].durationTimer.button:SetFrameStrata("BACKGROUND")
cds[i].button:SetScript("OnEvent", CDEvent)
cds[i].durationTimer.button:SetScript("OnEvent", BuffEvent)
cds[i].durationTimer.maxAlpha = 0.2
cds[i].button:RegisterForClicks("LeftButtonDown", "RightButtonDown", "MiddleButtonDown")
cds[i].events[1] = "SPELL_UPDATE_COOLDOWN"
cds[i].durationTimer.Activate = function(self)
self.button:RegisterUnitEvent("UNIT_AURA", "player")
XiTimers.Activate(self)
end
cds[i].durationTimer.Deactivate = function(self)
self.button:UnregisterEvent("UNIT_AURA")
XiTimers.Deactivate(self)
end
cds[i].durationTimer.showCooldown = true
cds[i].durationTimer.hideTime = true
cds[i].durationTimer.dontFlash = true
cds[i].SetScale = function(self, scale)
XiTimers.SetScale(self, scale)
self.durationTimer:SetScale(scale*2)
end
end
TotemTimers.LongCooldowns = cds
if UnitFactionGroup("player") == "Alliance" then
ConfigureTimer(1, SpellIDs.Heroism)
else
ConfigureTimer(1, SpellIDs.Bloodlust)
end
ConfigureTimer(3, SpellIDs.SpiritwalkersGrace)
ConfigureTimer(7, SpellIDs.AstralShift)
ConfigureTimer(4, SpellIDs.AncestralGuidance)
ConfigureTimer(5, SpellIDs.CallOfElements)
ConfigureTimer(6, SpellIDs.ElementalMastery)
ConfigureTimer(2, SpellIDs.Ascendance)
ConfigureTimer(8, SpellIDs.FeralSpirit)
cds[8].durationTimer.button:SetScript("OnEvent", FeralSpiritEvent)
cds[8].Update = FeralSpiritUpdate
cds[8].durationTimer.Activate = function(self)
self.button:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
XiTimers.Activate(self)
end
cds[8].durationTimer.Deactivate = function(self)
self.button:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
XiTimers.Deactivate(self)
end
-- T15 Elemental 4pc, check Ascendance CD after every spellcast
cds[2].durationTimer.Activate = function(self)
self.button:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
XiTimers.Activate(self)
end
cds[2].durationTimer.Deactivate = function(self)
self.button:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
XiTimers.Deactivate(self)
end
end
function TotemTimers.ActivateLongCooldowns(activate)
TotemTimers.ActiveProfile.LongCooldownSpells[SpellIDs.Heroism] = TotemTimers.ActiveProfile.LongCooldownSpells[SpellIDs.Bloodlust] --workaround for heroism
for i = 1,8 do
cds[i]:Deactivate()
cds[i].durationTimer:Deactivate()
end
if AvailableSpells[SpellIDs.ElementalMastery] then ConfigureTimer(6, SpellIDs.ElementalMastery) else ConfigureTimer(6, SpellIDs.AncestralSwiftness) end
local role = GetSpecialization()
ConfigureTimer(2, SpellIDs.Ascendance, Ascendances[role])
if activate then
for i = 1,8 do
if TotemTimers.ActiveProfile.LongCooldownSpells[cds[i].cdspell] and AvailableSpells[cds[i].cdspell] then
cds[i]:Activate()
cds[i].durationTimer:Activate()
end
end
end
TotemTimers.LayoutLongCooldowns()
end
local activecds = {}
function TotemTimers.LayoutLongCooldowns()
wipe(activecds)
for i = 1,#cds do
cds[i]:ClearAnchors()
end
local point1, point2
if TotemTimers.ActiveProfile.LongCooldownsArrange ~= "vertical" then
point1 = "LEFT"
point2 = "RIGHT"
else
point1 = "TOP"
point2 = "BOTTOM"
end
for i=1,#cds do
if cds[i].active then tinsert(activecds,cds[i]) end
end
if #activecds > 0 then
activecds[1]:SetPoint("CENTER", TotemTimers_LongCooldownsFrame, "CENTER")
end
for i = 2,#activecds do
activecds[i]:Anchor(activecds[i-1], point1, point2)
end
end
CDEvent = function(self, event, unit, spell)
local spell = self.timer.cdspell
if (self.timer.altcdspell) then spell = self.timer.altcdspell end
local start, duration, enable = GetSpellCooldown(spell)
if (not start and not duration) or (duration <= 1.5 and not InCombatLockdown()) then
self.timer:Stop(1)
else
if duration == 0 then
self.timer:Stop(1)
elseif duration > 2 and self.timer.timers[1]<=0 then
self.timer:Start(1,start+duration-GetTime(),duration)
end
CooldownFrame_Set(self.cooldown, start, duration, enable)
end
end
BuffEvent = function(self, event)
local name,_,_,count,_,duration,expiration = UnitBuff("player", self.buffSpellName)
if duration and duration > 0 then
self.timer:Start(1, expiration-GetTime(), duration)
elseif self.timer.timers[1] > 0 then
self.timer:Stop(1)
--self.timer.cdTimer.button:CDEvent()
end
end
local FeralSpiritName = SpellNames[SpellIDs.FeralSpirit]
FeralSpiritEvent = function(self,event,unit, spell)
if spell == FeralSpiritName then
self.timer:Start(1,30)
end
end
local updates = 0
FeralSpiritUpdate = function(self, elapsed)
if self.timers[1] > 0 then
updates = updates + 1
if updates > 5 then
updates = 0
local start, duration, enable = GetSpellCooldown(SpellIDs.FeralSpirit)
if (start and duration) then
self.timers[1] = start+duration-GetTime()
end
XiTimers.Update(self, 0)
else
XiTimers.Update(self, elapsed)
end
end
end