-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathLegionInvasionTimer.lua
More file actions
474 lines (443 loc) · 14.2 KB
/
LegionInvasionTimer.lua
File metadata and controls
474 lines (443 loc) · 14.2 KB
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
local addonName, mod = ...
local L = mod.L
local candy = LibStub("LibCandyBar-3.0")
local media = LibStub("LibSharedMedia-3.0")
local Timer = C_Timer.After
local frame = CreateFrame("Frame", addonName, UIParent)
frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetWidth(180)
frame:SetHeight(15)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetClampedToScreen(true)
frame:Show()
frame:SetScript("OnDragStart", function(f) f:StartMoving() end)
frame:SetScript("OnDragStop", function(f)
f:StopMovingOrSizing()
local a, _, b, c, d = f:GetPoint()
f.db.profile.position[1] = a
f.db.profile.position[2] = b
f.db.profile.position[3] = c
f.db.profile.position[4] = d
end)
do
local function openOpts()
local EnableAddOn = C_AddOns.EnableAddOn or EnableAddOn
local LoadAddOn = C_AddOns.LoadAddOn or LoadAddOn
EnableAddOn("LegionInvasionTimer_Options") -- Make sure it wasn't left disabled for whatever reason
LoadAddOn("LegionInvasionTimer_Options")
LibStub("AceConfigDialog-3.0"):Open(addonName)
end
SlashCmdList[addonName] = openOpts
SLASH_LegionInvasionTimer1 = "/lit"
SLASH_LegionInvasionTimer2 = "/legioninvasiontimer"
frame:SetScript("OnMouseUp", function(_, btn)
if btn == "RightButton" then
openOpts()
end
end)
end
do
-- saved variables database setup
local defaults = {
profile = {
lock = false,
position = {"CENTER", "CENTER", 0, 0},
fontSize = 10,
barTexture = "Blizzard Raid Bar",
outline = "NONE",
monochrome = false,
font = media:GetDefault("font"),
width = 200,
height = 20,
icon = true,
timeText = true,
labelText = true,
fill = false,
growUp = false,
alignText = "LEFT",
alignTime = "RIGHT",
alignIcon = "LEFT",
colorText = {1,1,1,1},
colorComplete = {0,1,0,1},
colorIncomplete = {1,0,0,1},
colorNext = {0.25,0.33,0.68,1},
colorBarBackground = {0,0,0,0.75},
tooltip12hr = true,
tooltipHideAchiev = false,
tooltipHideNethershard = false,
tooltipHideWarSupplies = false,
zoneWarnings = false,
hideInRaid = false,
mode = 1,
},
}
frame.db = LibStub("AceDB-3.0"):New("LegionInvasionTimerDB", defaults, true)
frame:ClearAllPoints()
frame:SetPoint(frame.db.profile.position[1], UIParent, frame.db.profile.position[2], frame.db.profile.position[3], frame.db.profile.position[4])
local bg = frame:CreateTexture()
bg:SetAllPoints(frame)
bg:SetColorTexture(0, 1, 0, 0.3)
frame.bg = bg
local header = frame:CreateFontString(nil, "OVERLAY", "TextStatusBarText")
header:SetAllPoints(frame)
header:SetText(addonName)
frame.header = header
if frame.db.profile.lock then
frame:EnableMouse(false)
frame:SetMovable(false)
frame.bg:Hide()
frame.header:Hide()
end
if frame.db.profile.mode == 3 then
frame:SetParent(WorldMapFrame)
frame:SetFrameStrata("FULLSCREEN")
frame:SetFrameLevel(10)
end
end
local OnEnter, ShowTip, HideTip
do
local id = 11544 -- Defender of the Broken Isles
local tt = CreateFrame("GameTooltip", "LITtooltip", UIParent, "GameTooltipTemplate")
local FormatShortDate = FormatShortDate
ShowTip = function(tip)
local _, name, _, _, month, day, year, description, _, _, _, _, wasEarnedByMe = GetAchievementInfo(id)
if not wasEarnedByMe or not frame.db.profile.tooltipHideAchiev then
if wasEarnedByMe then
tip:AddDoubleLine(name, FormatShortDate(day, month, year), nil, nil, nil, .5, .5, .5)
else
tip:AddLine(name, nil, nil, nil, .5, .5, .5)
end
tip:AddLine(description, 1, 1, 1, true)
for i = 1, GetAchievementNumCriteria(id) do
local criteriaString, _, completed = GetAchievementCriteriaInfo(id, i)
if completed == false then
criteriaString = "|CFF808080 - " .. criteriaString .. "|r"
else
criteriaString = "|CFF00FF00 - " .. criteriaString .. "|r"
end
tip:AddLine(criteriaString)
end
tip:AddLine(" ")
end
local splitLine = false
if not frame.db.profile.tooltipHideNethershard then
splitLine = true
local tbl = C_CurrencyInfo.GetCurrencyInfo(1226) -- Nethershard
tip:AddDoubleLine(tbl.name, ("|T%d:15:15:0:0:64:64:4:60:4:60|t %d"):format(tbl.iconFileID, tbl.quantity), 1, 1, 1, 1, 1, 1)
end
if not frame.db.profile.tooltipHideWarSupplies then
splitLine = true
local tbl = C_CurrencyInfo.GetCurrencyInfo(1342) -- Legionfall War Supplies
tip:AddDoubleLine(tbl.name, ("|T%d:15:15:0:0:64:64:4:60:4:60|t %d"):format(tbl.iconFileID, tbl.quantity), 1, 1, 1, 1, 1, 1)
end
if splitLine then
tip:AddLine(" ")
end
tip:AddLine(L.nextInvasions)
if LegionInvasionTime then -- Have we seen our first invasion?
local elapsed = time() - LegionInvasionTime
while elapsed > 52200 do
elapsed = elapsed - 52200
end
local t = 52200-elapsed
t = t+time()
local upper, date = string.upper, date
local check = date("%M", t)
if check == "29" or check == "59" then
t = t + 60 -- Round up to 00min/30min if we're at 29min/59min
end
if frame.db.profile.tooltip12hr then
for i = 1, 4 do
tip:AddDoubleLine(
_G["WEEKDAY_"..upper(date("%A", t))].." "..date("%I:%M", t) .. " " .. _G["TIMEMANAGER_"..upper(date("%p", t))],
_G["WEEKDAY_"..upper(date("%A", t+52200))].." "..date("%I:%M", t+52200) .. " " .. _G["TIMEMANAGER_"..upper(date("%p", t+52200))],
1, 1, 1, 1, 1, 1
)
t = t + 52200 + 52200
end
else
for i = 1, 4 do
tip:AddDoubleLine(
_G["WEEKDAY_"..upper(date("%A", t))].." "..date("%H:%M", t),
_G["WEEKDAY_"..upper(date("%A", t+52200))].." "..date("%H:%M", t+52200),
1, 1, 1, 1, 1, 1
)
t = t + 52200 + 52200
end
end
else
tip:AddLine(L.waiting, 1, 1, 1)
end
end
HideTip = function()
tt:Hide()
end
OnEnter = function(f)
tt:SetOwner(f, "ANCHOR_NONE")
tt:SetPoint("BOTTOM", f, "TOP")
ShowTip(tt)
tt:Show()
end
end
local function RearrangeBar()
frame.Bar:ClearAllPoints()
if frame.db.profile.growUp then
frame.Bar:SetPoint("BOTTOM", frame, "TOP")
else
frame.Bar:SetPoint("TOP", frame, "BOTTOM")
end
end
frame.RearrangeBar = RearrangeBar
local ChangeBarColor
do
-- We use different quest ids here.
-- The invasion is split into 2 quests. The quest to complete 4 world quests, and the quest to complete the scenario.
-- These are the ids for the scenario, because we don't want to mark the bar green until that is done.
-- We use the other ids when creating the bar/login/reload ui/etc because these ids don't seem to reset, they stay marked as completed.
-- So if we did use these ids for bar creation, they would always show up as green.
local quests = {
[46182] = true, -- Highmountain
[46110] = true, -- Stormheim
[45856] = true, -- Val'Sharah
[46199] = true, -- Azsuna
}
ChangeBarColor = function(id)
if quests[id] then
frame.Bar:Set("LegionInvasionTimer:complete", 1)
frame.Bar:SetColor(unpack(frame.db.profile.colorComplete))
end
end
end
local StartBar
local hiddenBars = false
do
local IsQuestFlaggedCompleted = C_QuestLog.IsQuestFlaggedCompleted
StartBar = function(text, timeLeft, rewardQuestID, icon, paused)
if frame.Bar then frame.Bar:Stop() end
local bar = candy:New(media:Fetch("statusbar", frame.db.profile.barTexture), frame.db.profile.width, frame.db.profile.height)
frame.Bar = bar
bar:SetScript("OnEnter", OnEnter)
bar:SetScript("OnLeave", HideTip)
bar:SetParent(frame)
bar:SetLabel(text)
bar.candyBarLabel:SetJustifyH(frame.db.profile.alignText)
bar.candyBarDuration:SetJustifyH(frame.db.profile.alignTime)
bar:SetDuration(timeLeft)
bar:Set("LegionInvasionTimer:icon", icon)
if rewardQuestID > 0 then
if IsQuestFlaggedCompleted(rewardQuestID) then
bar:SetColor(unpack(frame.db.profile.colorComplete))
bar:Set("LegionInvasionTimer:complete", 1)
else
bar:SetColor(unpack(frame.db.profile.colorIncomplete))
bar:Set("LegionInvasionTimer:complete", 0)
end
else
bar:SetColor(unpack(frame.db.profile.colorNext))
end
bar.candyBarBackground:SetVertexColor(unpack(frame.db.profile.colorBarBackground))
bar:SetTextColor(unpack(frame.db.profile.colorText))
if frame.db.profile.icon then
bar:SetIcon(icon)
bar:SetIconPosition(frame.db.profile.alignIcon)
end
bar:SetTimeVisibility(frame.db.profile.timeText)
bar:SetLabelVisibility(frame.db.profile.labelText)
bar:SetFill(frame.db.profile.fill)
local flags = nil
if frame.db.profile.monochrome and frame.db.profile.outline ~= "NONE" then
flags = "MONOCHROME," .. frame.db.profile.outline
elseif frame.db.profile.monochrome then
flags = "MONOCHROME"
elseif frame.db.profile.outline ~= "NONE" then
flags = frame.db.profile.outline
end
bar.candyBarLabel:SetFont(media:Fetch("font", frame.db.profile.font), frame.db.profile.fontSize, flags)
bar.candyBarDuration:SetFont(media:Fetch("font", frame.db.profile.font), frame.db.profile.fontSize, flags)
if paused then -- Searching bars
bar:Start()
bar:Pause()
bar:SetTimeVisibility(false)
elseif rewardQuestID > 0 then -- Invasion duration bars
bar:Start(21600) -- 6hrs = 60*6 = 360min = 360*60 = 21,600sec
else -- Next invasion bars
bar:Start(45000) -- 12.5hrs = 60*12.5 = 750min = 750*60 = 45,000sec
end
RearrangeBar()
if hiddenBars then
bar:Hide()
end
end
end
local StartBroker
do
local obj
local prevTime, label, repeater = 0, "", false
local function update()
prevTime = prevTime - 60
obj.text = label..": ".. SecondsToTime(prevTime, true)
end
StartBroker = function(text, timeLeft, icon)
if not obj then
obj = LibStub("LibDataBroker-1.1"):NewDataObject("LegionInvasionTimer", {
type = "data source",
icon = icon,
text = text..": ".. SecondsToTime(timeLeft, true),
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine or not tooltip.AddDoubleLine then return end
ShowTip(tooltip)
end
})
end
if obj then
obj.icon = icon
obj.text = text..": ".. SecondsToTime(timeLeft, true)
prevTime = timeLeft
label = text
if repeater then repeater:Cancel() end
repeater = C_Timer.NewTicker(60, update)
end
end
end
local FindInvasion
local justLoggedIn = true
do
local GetAreaPOISecondsLeft = C_AreaPoiInfo.GetAreaPOISecondsLeft
local isWaiting = false
local zonePOIIds = {
5177, -- Highmountain
5178, -- Stormheim
5210, -- Val'Sharah
5175, -- Azsuna
}
local zoneNames = {
C_Map.GetMapInfo(650).name, -- Highmountain
C_Map.GetMapInfo(634).name, -- Stormheim
C_Map.GetMapInfo(641).name, -- Val'Sharah
C_Map.GetMapInfo(630).name, -- Azsuna
}
local questIds = {
45840, -- Highmountain
45839, -- Stormheim
45812, -- Val'Sharah
45838, -- Azsuna
}
FindInvasion = function()
local mode = frame.db.profile.mode
local found = false
for i = 1, #zonePOIIds do
local timeLeftSeconds = GetAreaPOISecondsLeft(zonePOIIds[i])
-- On some realms timeLeftSeconds can return massive values during the initialization of a new event
if timeLeftSeconds and timeLeftSeconds > 60 and timeLeftSeconds < 21601 then -- 6 hours: (6*60)*60 = 21600
if mode == 2 then
StartBroker(zoneNames[i], timeLeftSeconds, 236292) -- 236292 = Interface\\Icons\\Ability_Warlock_DemonicEmpowerment
else
StartBar(zoneNames[i], timeLeftSeconds, questIds[i], 236292) -- 236292 = Interface\\Icons\\Ability_Warlock_DemonicEmpowerment
frame:RegisterEvent("QUEST_TURNED_IN")
end
Timer(timeLeftSeconds+60, FindInvasion)
found = true
-- Not fighting a boss, didn't just log in, legion assault has just spawned (6hrs - 10min), feature is enabled
if not IsEncounterInProgress() and not justLoggedIn and timeLeftSeconds > 21000 and frame.db.profile.zoneWarnings then
FlashClientIcon()
local text = L.underAttack:format(zoneNames[i])
print("|cFF33FF99LegionInvasionTimer|r:", text)
RaidNotice_AddMessage(RaidBossEmoteFrame, text, {r=1, g=1, b=1})
PlaySound(8959, "Master", false) -- SOUNDKIT.RAID_WARNING
end
justLoggedIn = false
local curTime = time()
local elapsed = 21600-timeLeftSeconds
local latestInvasionTime = curTime - elapsed
LegionInvasionTime = latestInvasionTime
break
end
end
if not found then
local tableOfPOIs = C_AreaPoiInfo.GetAreaPOIForMap(619) -- Broken Isles map
for numPOIs = 1, #tableOfPOIs do
local poi = tableOfPOIs[numPOIs]
for i = 1, #zonePOIIds do
if poi == zonePOIIds[i] then
Timer(5, FindInvasion)
if not isWaiting then
isWaiting = true
if mode == 2 then
StartBroker(L.waiting, 0, 132177) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
else
StartBar(L.waiting, 100, 0, 132177, true) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
frame:UnregisterEvent("QUEST_TURNED_IN")
end
end
return
end
end
end
if LegionInvasionTime then
local elapsed = time() - LegionInvasionTime
while elapsed > 52200 do
elapsed = elapsed - 52200
end
local t = 52200-elapsed
if mode == 2 then
StartBroker(L.next, t, 132177) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
else
StartBar(L.next, t, 0, 132177) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
frame:UnregisterEvent("QUEST_TURNED_IN")
end
Timer(t + 5, FindInvasion)
else
Timer(60, FindInvasion)
if not isWaiting then
isWaiting = true
if mode == 2 then
StartBroker(L.waiting, 0, 132177) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
else
StartBar(L.waiting, 1000, 0, 132177, true) -- 132177 = Interface\\Icons\\Ability_Hunter_MasterMarksman
end
end
end
end
if isWaiting then
isWaiting = false
end
end
end
local function CheckIfInRaid()
if frame.db.profile.hideInRaid then
local _, iType = GetInstanceInfo()
if iType == "raid" then
hiddenBars = true
frame.Bar:Hide()
elseif hiddenBars then
hiddenBars = false
frame.Bar:Show()
end
end
end
frame:SetScript("OnEvent", function(f, e)
f:UnregisterEvent(e)
Timer(1, function()
FindInvasion()
Timer(15, function()
justLoggedIn = false
if not LegionInvasionTime then
print("|cFF33FF99LegionInvasionTimer|r:", L.firstRunWarning)
end
end)
if f.db.profile.mode == 1 then
CheckIfInRaid()
f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
end
end)
f:SetScript("OnEvent", function(_, event, id)
if event == "QUEST_TURNED_IN" then
ChangeBarColor(id)
else
CheckIfInRaid()
end
end)
end)
frame:RegisterEvent("LOADING_SCREEN_DISABLED")