-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEarthShield.lua
355 lines (307 loc) · 12.4 KB
/
EarthShield.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
if select(2, UnitClass("player")) ~= "SHAMAN" then
return
end
local _, TotemTimers = ...
local SpellNames = TotemTimers.SpellNames
local SpellIDs = TotemTimers.SpellIDs
local SpellTextures = TotemTimers.SpellTextures
local AvailableSpells = TotemTimers.AvailableSpells
local earthShieldTarget = UnitName("player")
local earthShieldTargetGUID = UnitGUID("player")
local earthshieldTimer = nil
local buttons = { "LeftButton", "RightButton", "MiddleButton", "Button4" }
local function splitString(ustring)
local c = 0
local s = ""
for uchar in string.gmatch(ustring, "([%z\1-\127\194-\244][\128-\191]*)") do
c = c + 1
s = s .. uchar
if c == 5 then
break
end
end
return s
end
TotemTimers.splitString = splitString
function TotemTimers.CreateEarthShieldTracker()
earthshieldTimer = XiTimers:new(1)
earthshieldTimer.button.icons[1]:SetTexture(SpellTextures[SpellIDs.EarthShield])
earthshieldTimer.button.anchorframe = TotemTimers_TrackerFrame
earthshieldTimer.button:SetScript("OnEvent", TotemTimers.EarthShieldEvent)
earthshieldTimer.events[1] = "COMBAT_LOG_EVENT_UNFILTERED"
earthshieldTimer.events[2] = "UNIT_AURA"
earthshieldTimer.events[3] = "GROUP_ROSTER_UPDATE"
earthshieldTimer.events[4] = "PLAYER_REGEN_ENABLED"
earthshieldTimer.events[5] = "PARTY_LEADER_CHANGED"
earthshieldTimer.events[6] = "PLAYER_ENTERING_WORLD"
earthshieldTimer.playerEvents[1] = "UNIT_SPELLCAST_SUCCEEDED"
earthshieldTimer.events[7] = "UNIT_SPELLCAST_SENT"
earthshieldTimer.timeStyle = "blizz"
earthshieldTimer.button:SetAttribute("*type*", "spell")
earthshieldTimer.Activate = function(self)
XiTimers.Activate(self)
self.button:SetAttribute("*spell*", SpellNames[SpellIDs.EarthShield])
if not TotemTimers.ActiveProfile.EarthShieldTracker then
self.button:Hide()
end
end
earthshieldTimer.button:RegisterForClicks("LeftButtonDown", "RightButtonDown", "MiddleButtonDown", "Button4Down")
earthshieldTimer.manaCheck = SpellNames[SpellIDs.EarthShield]
earthshieldTimer.name = earthshieldTimer.button:CreateFontString("TotemTimers_EarthShieldName")
earthshieldTimer.name:SetPoint("TOP", earthshieldTimer.button, 0, 2)
earthshieldTimer.name:SetFont("Fonts\\FRIZQT__.TTF", 11, "OUTLINE")
earthshieldTimer.expirationMsgs[1] = "EarthShield"
earthshieldTimer.earlyExpirationMsgs[1] = "EarthShield"
earthshieldTimer.warningIcons[1] = SpellTextures[SpellIDs.EarthShield]
earthshieldTimer.warningSpells[1] = SpellNames[SpellIDs.EarthShield]
earthshieldTimer.warningPoint = 0
earthshieldTimer.Stop = function(self, nr)
XiTimers.Stop(self, nr)
if earthShieldTarget then
self.name:SetText(splitString(earthShieldTarget))
end
end
earthshieldTimer.Start = function(self, nr, time, duration)
XiTimers.Start(self, nr, time, duration)
if earthShieldTarget then
self.name:SetText(splitString(earthShieldTarget))
end
end
--create maintank bar for es
earthshieldTimer.actionBar = TTActionBars:new(4, earthshieldTimer.button, nil, TotemTimers_TrackerFrame)
for i = 1, 4 do
earthshieldTimer.button:WrapScript(earthshieldTimer.actionBar.buttons[i], "PostClick", [[
local p = self:GetParent()
local nr = p:GetAttribute("RecastButton")
if nr then
p:SetAttribute("*unit"..nr, self:GetAttribute("*unit1"))
control:CallMethod("UpdateESName")
end
]])
end
earthshieldTimer.button.UpdateESName = function(self)
if self.timer.timers[1] <= 0 then
local button = self:GetAttribute("RecastButton")
if button then
local unit = self:GetAttribute("*unit" .. button)
if unit and UnitExists(unit) then
self.timer.name:SetText(splitString(UnitName(unit)))
end
end
end
end
TotemTimers.SetEarthShieldMainTankList()
earthshieldTimer.button:SetScript("OnDragStop", function(self)
XiTimers.StopMoving(self)
TotemTimers.ProcessSetting("ESMainTankMenuDirection")
if not InCombatLockdown() then
earthshieldTimer.button:SetAttribute("hide", true)
end
end)
TotemTimers.EarthShieldTracker = earthshieldTimer
TotemTimers.SetEarthShieldButtons()
end
table.insert(TotemTimers.Modules, TotemTimers.CreateEarthShieldTracker)
local earthShieldRecast = false
function TotemTimers.SetEarthShieldButtons()
local Settings = TotemTimers.ActiveProfile
local recastbutton = nil
local menubutton = nil
earthShieldRecast = false
earthshieldTimer.button:SetAttribute("OpenMenu", nil)
earthshieldTimer.button:SetAttribute("RecastButton", nil)
for k,v in pairs({"EarthShieldLeftButton", "EarthShieldRightButton", "EarthShieldMiddleButton", "EarthShieldButton4"}) do
if Settings[v] == "recast" then
recastbutton = k
earthShieldRecast = true
earthshieldTimer.button:SetAttribute("*spell"..k, SpellNames[SpellIDs.EarthShield])
elseif Settings[v] == "menu" and not menubutton then
menubutton = k
earthshieldTimer.button:SetAttribute("*spell"..k, nil)
else
earthshieldTimer.button:SetAttribute("*unit"..k, Settings[v])
earthshieldTimer.button:SetAttribute("*spell"..k, SpellNames[SpellIDs.EarthShield])
end
end
if not menubutton and Settings.ESMainTankMenu then
earthshieldTimer.button:SetAttribute("OpenMenu", "mouseover")
end
if menubutton then
earthshieldTimer.button:SetAttribute("OpenMenu", buttons[menubutton])
end
earthshieldTimer.button:SetAttribute("RecastButton", recastbutton)
end
-- This frame is activated if the class of a unit cannot be determined at the time the unit enters the group
local MainTankUpdateTimer = 5
local MainTankListUpdateFrame = CreateFrame("Frame")
MainTankListUpdateFrame:Hide()
MainTankListUpdateFrame:SetScript("OnShow", function(self)
MainTankUpdateTimer = 5
end)
MainTankListUpdateFrame:SetScript("OnUpdate", function(self, elapsed)
MainTankUpdateTimer = MainTankUpdateTimer - elapsed
if MainTankUpdateTimer <= 0 then
if InCombatLockdown() then
MainTankUpdateTimer = 5
else
self:Hide()
TotemTimers.SetEarthShieldMainTankList()
end
end
end)
local function SetUnit(unit, button)
button:SetAttribute("*unit1", unit)
button.name:SetText(splitString(UnitName(unit)))
local _, class = UnitClass(unit)
if class then
if RAID_CLASS_COLORS[class] then
button.name:SetTextColor(RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b)
end
button.icon:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
button.icon:SetTexCoord(unpack(CLASS_ICON_TCOORDS[class]))
else
MainTankListUpdateFrame:Show()
end
end
function TotemTimers.SetEarthShieldMainTankList()
earthshieldTimer.actionBar:ResetSpells()
if GetNumGroupMembers() > 0 then
local b = 0
for i = 1, 40 do
local unit = "raid" .. i
if b < 4 and UnitExists(unit) then
if GetPartyAssignment("MAINTANK", unit)
or UnitGroupRolesAssigned(unit) == "TANK" then
b = b + 1
earthshieldTimer.actionBar:AddSpell(SpellNames[SpellIDs.EarthShield])
SetUnit(unit, earthshieldTimer.actionBar.buttons[b])
end
end
end
if b < 4 then
earthshieldTimer.actionBar:AddSpell(SpellNames[SpellIDs.EarthShield])
SetUnit("player", earthshieldTimer.actionBar.buttons[b + 1])
end
else
earthshieldTimer.actionBar:AddSpell(SpellNames[SpellIDs.EarthShield])
SetUnit("player", earthshieldTimer.actionBar.buttons[1])
end
end
function TotemTimers.ChangeEarthShieldTarget()
for k, v in pairs(buttons) do
if TotemTimers.ActiveProfile["EarthShield" .. v] == "recast" then
earthshieldTimer.button:SetAttribute("*unit" .. k, earthShieldTarget)
end
end
end
local EarthShieldSpellName = SpellNames[SpellIDs.EarthShield]
local ESChargesOnly = false
local function checkESBuff(self)
local unit = earthShieldTarget
if UnitGUID("target") == earthShieldTargetGUID then
unit = "target"
elseif UnitGUID("focus") == earthShieldTargetGUID then
unit = "focus"
end
local hasBuff = false
for i = 1, 40 do
local name, _, count, _, duration, endtime, source = UnitBuff(unit, i)
if name == EarthShieldSpellName and source == "player" then
hasBuff = true
local timeleft = endtime - GetTime()
if not ESChargesOnly then
self.count:SetText(count)
end
if timeleft - self.timer.timers[1] > 0.1 or ESChargesOnly then
self.timer.expirationMsgs[1] = "EarthShield"
self.timer.earlyExpirationMsgs[1] = "EarthShield"
if not ESChargesOnly then
self.timer:Start(1, timeleft, duration)
else
self.timer:Start(1, count, 9)
end
end
break
end
end
if not hasBuff and self.timer.timers[1] > 0 then
self.timer:Stop(1)
self.count:SetText("")
end
end
local lastESCastGUID = nil
local lastESCastTarget = nil
local lastESCastUnitGUID = nil
local changeEarthShieldRecast = nil
function TotemTimers.EarthShieldEvent(self, event, ...)
if not AvailableSpells[SpellIDs.EarthShield] then
return
end
if event == "UNIT_SPELLCAST_SENT" then
local _, target, castGUID, spellID = ...
local spellName = GetSpellInfo(spellID)
if spellName == EarthShieldSpellName then
lastESCastTarget = target
lastESCastGUID = castGUID
lastESCastUnitGUID = UnitGUID(target)
if not lastESCastUnitGUID then
if target == UnitName("target") then lastESCastUnitGUID = UnitGUID("target")
elseif target == UnitName("focus") then lastESCastUnitGUID = UnitGUID("focus") end
end
end
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
local start, duration, enable = GetSpellCooldown(EarthShieldSpellName)
if start and duration and (not self.timer.timerOnButton or self.timer.timers[1] <= 0) then
CooldownFrame_Set(self.cooldown, start, duration, enable)
end
local _, castGUID = ...
if castGUID == lastESCastGUID then
earthShieldTarget = lastESCastTarget
earthShieldTargetGUID = lastESCastUnitGUID
if earthShieldRecast then
if not InCombatLockdown() then
TotemTimers.ChangeEarthShieldTarget()
else
changeEarthShieldRecast = true
end
end
end
elseif event == "UNIT_AURA" and earthShieldTargetGUID then
local unit = ...
if UnitGUID(unit) == earthShieldTargetGUID then
checkESBuff(self)
end
elseif event == "PLAYER_REGEN_ENABLED" and earthShieldRecast and changeEarthShieldRecast then
TotemTimers.ChangeEarthShieldTarget()
elseif (event == "GROUP_ROSTER_UPDATE" or event == "PLAYER_ENTERING_WORLD") then
if earthShieldRecast and earthShieldTarget then
if InCombatLockdown() then
changeEarthShieldRecast = true
else
TotemTimers.ChangeEarthShieldTarget()
end
end
if not InCombatLockdown() then
TotemTimers.SetEarthShieldMainTankList()
else
MainTankListUpdateFrame:Show()
end
end
end
local function EmptyESUpdate()
end
function TotemTimers.SetEarthShieldUpdate()
ESChargesOnly = TotemTimers.ActiveProfile.ESChargesOnly
if TotemTimers.ActiveProfile.ESChargesOnly then
earthshieldTimer.Update = EmptyESUpdate
earthshieldTimer.prohibitCooldown = true
earthshieldTimer.timeStyle = "sec"
else
earthshieldTimer.Update = nil
earthshieldTimer.prohibitCooldown = false
earthshieldTimer.timeStyle = "blizz"
end
if earthShieldTarget then
TotemTimers.EarthShieldEvent(earthshieldTimer.button, "UNIT_AURA", earthShieldTarget)
end
end